diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:18:58 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:18:58 +0000 |
commit | a4b7ed7a42c716ab9f05e351f003d589124fd55d (patch) | |
tree | b620cd3f223850b28716e474e80c58059dca5dd4 /tests/ui/typeck | |
parent | Adding upstream version 1.67.1+dfsg1. (diff) | |
download | rustc-a4b7ed7a42c716ab9f05e351f003d589124fd55d.tar.xz rustc-a4b7ed7a42c716ab9f05e351f003d589124fd55d.zip |
Adding upstream version 1.68.2+dfsg1.upstream/1.68.2+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/ui/typeck')
264 files changed, 6391 insertions, 0 deletions
diff --git a/tests/ui/typeck/assign-non-lval-derefmut.fixed b/tests/ui/typeck/assign-non-lval-derefmut.fixed new file mode 100644 index 000000000..0c23199af --- /dev/null +++ b/tests/ui/typeck/assign-non-lval-derefmut.fixed @@ -0,0 +1,15 @@ +// run-rustfix + +fn main() { + let x = std::sync::Mutex::new(1usize); + *x.lock().unwrap() = 2; + //~^ ERROR invalid left-hand side of assignment + *x.lock().unwrap() += 1; + //~^ ERROR binary assignment operation `+=` cannot be applied to type `MutexGuard<'_, usize>` + + let mut y = x.lock().unwrap(); + *y = 2; + //~^ ERROR mismatched types + *y += 1; + //~^ ERROR binary assignment operation `+=` cannot be applied to type `MutexGuard<'_, usize>` +} diff --git a/tests/ui/typeck/assign-non-lval-derefmut.rs b/tests/ui/typeck/assign-non-lval-derefmut.rs new file mode 100644 index 000000000..ec1882f52 --- /dev/null +++ b/tests/ui/typeck/assign-non-lval-derefmut.rs @@ -0,0 +1,15 @@ +// run-rustfix + +fn main() { + let x = std::sync::Mutex::new(1usize); + x.lock().unwrap() = 2; + //~^ ERROR invalid left-hand side of assignment + x.lock().unwrap() += 1; + //~^ ERROR binary assignment operation `+=` cannot be applied to type `MutexGuard<'_, usize>` + + let mut y = x.lock().unwrap(); + y = 2; + //~^ ERROR mismatched types + y += 1; + //~^ ERROR binary assignment operation `+=` cannot be applied to type `MutexGuard<'_, usize>` +} diff --git a/tests/ui/typeck/assign-non-lval-derefmut.stderr b/tests/ui/typeck/assign-non-lval-derefmut.stderr new file mode 100644 index 000000000..e394cf820 --- /dev/null +++ b/tests/ui/typeck/assign-non-lval-derefmut.stderr @@ -0,0 +1,58 @@ +error[E0070]: invalid left-hand side of assignment + --> $DIR/assign-non-lval-derefmut.rs:5:23 + | +LL | x.lock().unwrap() = 2; + | ----------------- ^ + | | + | cannot assign to this expression + | +help: consider dereferencing here to assign to the mutably borrowed value + | +LL | *x.lock().unwrap() = 2; + | + + +error[E0368]: binary assignment operation `+=` cannot be applied to type `MutexGuard<'_, usize>` + --> $DIR/assign-non-lval-derefmut.rs:7:5 + | +LL | x.lock().unwrap() += 1; + | -----------------^^^^^ + | | + | cannot use `+=` on type `MutexGuard<'_, usize>` + | +help: `+=` can be used on `usize` if you dereference the left-hand side + | +LL | *x.lock().unwrap() += 1; + | + + +error[E0308]: mismatched types + --> $DIR/assign-non-lval-derefmut.rs:11:9 + | +LL | let mut y = x.lock().unwrap(); + | ----------------- expected due to this value +LL | y = 2; + | ^ expected struct `MutexGuard`, found integer + | + = note: expected struct `MutexGuard<'_, usize>` + found type `{integer}` +help: consider dereferencing here to assign to the mutably borrowed value + | +LL | *y = 2; + | + + +error[E0368]: binary assignment operation `+=` cannot be applied to type `MutexGuard<'_, usize>` + --> $DIR/assign-non-lval-derefmut.rs:13:5 + | +LL | y += 1; + | -^^^^^ + | | + | cannot use `+=` on type `MutexGuard<'_, usize>` + | +help: `+=` can be used on `usize` if you dereference the left-hand side + | +LL | *y += 1; + | + + +error: aborting due to 4 previous errors + +Some errors have detailed explanations: E0070, E0308, E0368. +For more information about an error, try `rustc --explain E0070`. diff --git a/tests/ui/typeck/assign-non-lval-mut-ref.fixed b/tests/ui/typeck/assign-non-lval-mut-ref.fixed new file mode 100644 index 000000000..10c7b9dbf --- /dev/null +++ b/tests/ui/typeck/assign-non-lval-mut-ref.fixed @@ -0,0 +1,15 @@ +// run-rustfix + +fn main() { + let mut x = vec![1usize]; + *x.last_mut().unwrap() = 2; + //~^ ERROR invalid left-hand side of assignment + *x.last_mut().unwrap() += 1; + //~^ ERROR binary assignment operation `+=` cannot be applied to type `&mut usize` + + let y = x.last_mut().unwrap(); + *y = 2; + //~^ ERROR mismatched types + *y += 1; + //~^ ERROR binary assignment operation `+=` cannot be applied to type `&mut usize` +} diff --git a/tests/ui/typeck/assign-non-lval-mut-ref.rs b/tests/ui/typeck/assign-non-lval-mut-ref.rs new file mode 100644 index 000000000..bceff0ef0 --- /dev/null +++ b/tests/ui/typeck/assign-non-lval-mut-ref.rs @@ -0,0 +1,15 @@ +// run-rustfix + +fn main() { + let mut x = vec![1usize]; + x.last_mut().unwrap() = 2; + //~^ ERROR invalid left-hand side of assignment + x.last_mut().unwrap() += 1; + //~^ ERROR binary assignment operation `+=` cannot be applied to type `&mut usize` + + let y = x.last_mut().unwrap(); + y = 2; + //~^ ERROR mismatched types + y += 1; + //~^ ERROR binary assignment operation `+=` cannot be applied to type `&mut usize` +} diff --git a/tests/ui/typeck/assign-non-lval-mut-ref.stderr b/tests/ui/typeck/assign-non-lval-mut-ref.stderr new file mode 100644 index 000000000..cbdc960ba --- /dev/null +++ b/tests/ui/typeck/assign-non-lval-mut-ref.stderr @@ -0,0 +1,56 @@ +error[E0070]: invalid left-hand side of assignment + --> $DIR/assign-non-lval-mut-ref.rs:5:27 + | +LL | x.last_mut().unwrap() = 2; + | --------------------- ^ + | | + | cannot assign to this expression + | +help: consider dereferencing here to assign to the mutably borrowed value + | +LL | *x.last_mut().unwrap() = 2; + | + + +error[E0368]: binary assignment operation `+=` cannot be applied to type `&mut usize` + --> $DIR/assign-non-lval-mut-ref.rs:7:5 + | +LL | x.last_mut().unwrap() += 1; + | ---------------------^^^^^ + | | + | cannot use `+=` on type `&mut usize` + | +help: `+=` can be used on `usize` if you dereference the left-hand side + | +LL | *x.last_mut().unwrap() += 1; + | + + +error[E0308]: mismatched types + --> $DIR/assign-non-lval-mut-ref.rs:11:9 + | +LL | let y = x.last_mut().unwrap(); + | --------------------- expected due to this value +LL | y = 2; + | ^ expected `&mut usize`, found integer + | +help: consider dereferencing here to assign to the mutably borrowed value + | +LL | *y = 2; + | + + +error[E0368]: binary assignment operation `+=` cannot be applied to type `&mut usize` + --> $DIR/assign-non-lval-mut-ref.rs:13:5 + | +LL | y += 1; + | -^^^^^ + | | + | cannot use `+=` on type `&mut usize` + | +help: `+=` can be used on `usize` if you dereference the left-hand side + | +LL | *y += 1; + | + + +error: aborting due to 4 previous errors + +Some errors have detailed explanations: E0070, E0308, E0368. +For more information about an error, try `rustc --explain E0070`. diff --git a/tests/ui/typeck/assign-non-lval-needs-deref.rs b/tests/ui/typeck/assign-non-lval-needs-deref.rs new file mode 100644 index 000000000..c979d76b4 --- /dev/null +++ b/tests/ui/typeck/assign-non-lval-needs-deref.rs @@ -0,0 +1,19 @@ +// issue #101376 + +use std::ops::AddAssign; +struct Foo; + +impl AddAssign<()> for Foo { + fn add_assign(&mut self, _: ()) {} +} + +impl AddAssign<()> for &mut Foo { + fn add_assign(&mut self, _: ()) {} +} + +fn main() { + (&mut Foo) += (); + //~^ ERROR invalid left-hand side of assignment + //~| NOTE cannot assign to this expression + //~| HELP consider dereferencing the left-hand side of this operation +} diff --git a/tests/ui/typeck/assign-non-lval-needs-deref.stderr b/tests/ui/typeck/assign-non-lval-needs-deref.stderr new file mode 100644 index 000000000..ee83b1453 --- /dev/null +++ b/tests/ui/typeck/assign-non-lval-needs-deref.stderr @@ -0,0 +1,16 @@ +error[E0067]: invalid left-hand side of assignment + --> $DIR/assign-non-lval-needs-deref.rs:15:16 + | +LL | (&mut Foo) += (); + | ---------- ^^ + | | + | cannot assign to this expression + | +help: consider dereferencing the left-hand side of this operation + | +LL | *(&mut Foo) += (); + | + + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0067`. diff --git a/tests/ui/typeck/autoderef-with-param-env-error.rs b/tests/ui/typeck/autoderef-with-param-env-error.rs new file mode 100644 index 000000000..ec96c61c6 --- /dev/null +++ b/tests/ui/typeck/autoderef-with-param-env-error.rs @@ -0,0 +1,9 @@ +fn foo() +where + T: Send, + //~^ cannot find type `T` in this scope +{ + let s = "abc".to_string(); +} + +fn main() {} diff --git a/tests/ui/typeck/autoderef-with-param-env-error.stderr b/tests/ui/typeck/autoderef-with-param-env-error.stderr new file mode 100644 index 000000000..182612d5e --- /dev/null +++ b/tests/ui/typeck/autoderef-with-param-env-error.stderr @@ -0,0 +1,14 @@ +error[E0412]: cannot find type `T` in this scope + --> $DIR/autoderef-with-param-env-error.rs:3:5 + | +LL | T: Send, + | ^ not found in this scope + | +help: you might be missing a type parameter + | +LL | fn foo<T>() + | +++ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0412`. diff --git a/tests/ui/typeck/auxiliary/issue-36708.rs b/tests/ui/typeck/auxiliary/issue-36708.rs new file mode 100644 index 000000000..bd8580f97 --- /dev/null +++ b/tests/ui/typeck/auxiliary/issue-36708.rs @@ -0,0 +1,5 @@ +#![crate_type = "lib"] + +pub trait Foo { + fn foo(); +} diff --git a/tests/ui/typeck/auxiliary/issue-81943-lib.rs b/tests/ui/typeck/auxiliary/issue-81943-lib.rs new file mode 100644 index 000000000..521c54f89 --- /dev/null +++ b/tests/ui/typeck/auxiliary/issue-81943-lib.rs @@ -0,0 +1,7 @@ +pub fn g(t: i32) -> i32 { t } +// This function imitates `dbg!` so that future changes +// to its macro definition won't make this test a dud. +#[macro_export] +macro_rules! d { + ($e:expr) => { match $e { x => { $crate::g(x) } } } +} diff --git a/tests/ui/typeck/auxiliary/tdticc_coherence_lib.rs b/tests/ui/typeck/auxiliary/tdticc_coherence_lib.rs new file mode 100644 index 000000000..ef2cd415f --- /dev/null +++ b/tests/ui/typeck/auxiliary/tdticc_coherence_lib.rs @@ -0,0 +1,6 @@ +#![feature(auto_traits, core)] +#![crate_type = "rlib"] + +pub auto trait DefaultedTrait { } + +pub struct Something<T> { t: T } diff --git a/tests/ui/typeck/auxiliary/xcrate-issue-43189-a.rs b/tests/ui/typeck/auxiliary/xcrate-issue-43189-a.rs new file mode 100644 index 000000000..9ab570fd1 --- /dev/null +++ b/tests/ui/typeck/auxiliary/xcrate-issue-43189-a.rs @@ -0,0 +1,7 @@ +#![crate_type="lib"] + + +pub trait A { + fn a(&self) {} +} +impl A for () {} diff --git a/tests/ui/typeck/auxiliary/xcrate-issue-43189-b.rs b/tests/ui/typeck/auxiliary/xcrate-issue-43189-b.rs new file mode 100644 index 000000000..31dfb050b --- /dev/null +++ b/tests/ui/typeck/auxiliary/xcrate-issue-43189-b.rs @@ -0,0 +1,3 @@ +#![crate_type="lib"] + +pub extern crate xcrate_issue_43189_a; diff --git a/tests/ui/typeck/auxiliary/xcrate-issue-46112-rexport-core.rs b/tests/ui/typeck/auxiliary/xcrate-issue-46112-rexport-core.rs new file mode 100644 index 000000000..2b517b578 --- /dev/null +++ b/tests/ui/typeck/auxiliary/xcrate-issue-46112-rexport-core.rs @@ -0,0 +1,3 @@ +#![crate_type="lib"] + +pub extern crate core; diff --git a/tests/ui/typeck/auxiliary/xcrate-issue-61711-b.rs b/tests/ui/typeck/auxiliary/xcrate-issue-61711-b.rs new file mode 100644 index 000000000..88a040529 --- /dev/null +++ b/tests/ui/typeck/auxiliary/xcrate-issue-61711-b.rs @@ -0,0 +1,5 @@ +// edition:2018 +#![crate_type="lib"] +#![crate_name="xcrate_issue_61711_b"] +pub struct Struct; +pub use crate as alias; diff --git a/tests/ui/typeck/call-block.rs b/tests/ui/typeck/call-block.rs new file mode 100644 index 000000000..0390d7db0 --- /dev/null +++ b/tests/ui/typeck/call-block.rs @@ -0,0 +1,3 @@ +fn main() { + let _ = {42}(); //~ ERROR expected function, found `{integer}` +} diff --git a/tests/ui/typeck/call-block.stderr b/tests/ui/typeck/call-block.stderr new file mode 100644 index 000000000..68984bc1c --- /dev/null +++ b/tests/ui/typeck/call-block.stderr @@ -0,0 +1,11 @@ +error[E0618]: expected function, found `{integer}` + --> $DIR/call-block.rs:2:13 + | +LL | let _ = {42}(); + | ^^^^-- + | | + | call expression requires function + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0618`. diff --git a/tests/ui/typeck/check-args-on-fn-err-2.rs b/tests/ui/typeck/check-args-on-fn-err-2.rs new file mode 100644 index 000000000..af57dbe33 --- /dev/null +++ b/tests/ui/typeck/check-args-on-fn-err-2.rs @@ -0,0 +1,5 @@ +fn main() { + a((), 1i32 == 2u32); + //~^ ERROR cannot find function `a` in this scope + //~| ERROR mismatched types +} diff --git a/tests/ui/typeck/check-args-on-fn-err-2.stderr b/tests/ui/typeck/check-args-on-fn-err-2.stderr new file mode 100644 index 000000000..301bb88db --- /dev/null +++ b/tests/ui/typeck/check-args-on-fn-err-2.stderr @@ -0,0 +1,23 @@ +error[E0308]: mismatched types + --> $DIR/check-args-on-fn-err-2.rs:2:19 + | +LL | a((), 1i32 == 2u32); + | ---- ^^^^ expected `i32`, found `u32` + | | + | expected because this is `i32` + | +help: change the type of the numeric literal from `u32` to `i32` + | +LL | a((), 1i32 == 2i32); + | ~~~ + +error[E0425]: cannot find function `a` in this scope + --> $DIR/check-args-on-fn-err-2.rs:2:5 + | +LL | a((), 1i32 == 2u32); + | ^ not found in this scope + +error: aborting due to 2 previous errors + +Some errors have detailed explanations: E0308, E0425. +For more information about an error, try `rustc --explain E0308`. diff --git a/tests/ui/typeck/check-args-on-fn-err.rs b/tests/ui/typeck/check-args-on-fn-err.rs new file mode 100644 index 000000000..04b98ddd9 --- /dev/null +++ b/tests/ui/typeck/check-args-on-fn-err.rs @@ -0,0 +1,6 @@ +fn main() { + unknown(1, |glyf| { + //~^ ERROR: cannot find function `unknown` in this scope + let actual = glyf; + }); +} diff --git a/tests/ui/typeck/check-args-on-fn-err.stderr b/tests/ui/typeck/check-args-on-fn-err.stderr new file mode 100644 index 000000000..864d33e0e --- /dev/null +++ b/tests/ui/typeck/check-args-on-fn-err.stderr @@ -0,0 +1,9 @@ +error[E0425]: cannot find function `unknown` in this scope + --> $DIR/check-args-on-fn-err.rs:2:5 + | +LL | unknown(1, |glyf| { + | ^^^^^^^ not found in this scope + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0425`. diff --git a/tests/ui/typeck/conversion-methods.rs b/tests/ui/typeck/conversion-methods.rs new file mode 100644 index 000000000..46c2e511f --- /dev/null +++ b/tests/ui/typeck/conversion-methods.rs @@ -0,0 +1,13 @@ +use std::path::{Path, PathBuf}; + + +fn main() { + let _tis_an_instants_play: String = "'Tis a fond Ambush—"; //~ ERROR mismatched types + let _just_to_make_bliss: PathBuf = Path::new("/ern/her/own/surprise"); + //~^ ERROR mismatched types + + let _but_should_the_play: String = 2; // Perhaps surprisingly, we suggest .to_string() here + //~^ ERROR mismatched types + + let _prove_piercing_earnest: Vec<usize> = &[1, 2, 3]; //~ ERROR mismatched types +} diff --git a/tests/ui/typeck/conversion-methods.stderr b/tests/ui/typeck/conversion-methods.stderr new file mode 100644 index 000000000..091502bdd --- /dev/null +++ b/tests/ui/typeck/conversion-methods.stderr @@ -0,0 +1,45 @@ +error[E0308]: mismatched types + --> $DIR/conversion-methods.rs:5:41 + | +LL | let _tis_an_instants_play: String = "'Tis a fond Ambush—"; + | ------ ^^^^^^^^^^^^^^^^^^^^^- help: try using a conversion method: `.to_string()` + | | | + | | expected struct `String`, found `&str` + | expected due to this + +error[E0308]: mismatched types + --> $DIR/conversion-methods.rs:6:40 + | +LL | let _just_to_make_bliss: PathBuf = Path::new("/ern/her/own/surprise"); + | ------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- help: try using a conversion method: `.to_path_buf()` + | | | + | | expected struct `PathBuf`, found `&Path` + | expected due to this + +error[E0308]: mismatched types + --> $DIR/conversion-methods.rs:9:40 + | +LL | let _but_should_the_play: String = 2; // Perhaps surprisingly, we suggest .to_string() here + | ------ ^- help: try using a conversion method: `.to_string()` + | | | + | | expected struct `String`, found integer + | expected due to this + +error[E0308]: mismatched types + --> $DIR/conversion-methods.rs:12:47 + | +LL | let _prove_piercing_earnest: Vec<usize> = &[1, 2, 3]; + | ---------- ^^^^^^^^^^ expected struct `Vec`, found `&[{integer}; 3]` + | | + | expected due to this + | + = note: expected struct `Vec<usize>` + found reference `&[{integer}; 3]` +help: try using a conversion method + | +LL | let _prove_piercing_earnest: Vec<usize> = (&[1, 2, 3]).to_vec(); + | + ++++++++++ + +error: aborting due to 4 previous errors + +For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/typeck/deref-multi.rs b/tests/ui/typeck/deref-multi.rs new file mode 100644 index 000000000..3dc4771fe --- /dev/null +++ b/tests/ui/typeck/deref-multi.rs @@ -0,0 +1,26 @@ +fn a(x: &&i32) -> i32 { + x + //~^ ERROR mismatched types +} + +fn a2(x: &&&&&i32) -> i32 { + x + //~^ ERROR mismatched types +} + +fn b(x: &i32) -> i32 { + &x + //~^ ERROR mismatched types +} + +fn c(x: Box<i32>) -> i32 { + &x + //~^ ERROR mismatched types +} + +fn d(x: std::sync::Mutex<&i32>) -> i32 { + x.lock().unwrap() + //~^ ERROR mismatched types +} + +fn main() {} diff --git a/tests/ui/typeck/deref-multi.stderr b/tests/ui/typeck/deref-multi.stderr new file mode 100644 index 000000000..bd6575c73 --- /dev/null +++ b/tests/ui/typeck/deref-multi.stderr @@ -0,0 +1,72 @@ +error[E0308]: mismatched types + --> $DIR/deref-multi.rs:2:5 + | +LL | fn a(x: &&i32) -> i32 { + | --- expected `i32` because of return type +LL | x + | ^ expected `i32`, found `&&i32` + | +help: consider dereferencing the borrow + | +LL | **x + | ++ + +error[E0308]: mismatched types + --> $DIR/deref-multi.rs:7:5 + | +LL | fn a2(x: &&&&&i32) -> i32 { + | --- expected `i32` because of return type +LL | x + | ^ expected `i32`, found `&&&&&i32` + | +help: consider dereferencing the borrow + | +LL | *****x + | +++++ + +error[E0308]: mismatched types + --> $DIR/deref-multi.rs:12:5 + | +LL | fn b(x: &i32) -> i32 { + | --- expected `i32` because of return type +LL | &x + | ^^ expected `i32`, found `&&i32` + | +help: consider removing the `&` and dereferencing the borrow instead + | +LL | *x + | ~ + +error[E0308]: mismatched types + --> $DIR/deref-multi.rs:17:5 + | +LL | fn c(x: Box<i32>) -> i32 { + | --- expected `i32` because of return type +LL | &x + | ^^ expected `i32`, found `&Box<i32>` + | + = note: expected type `i32` + found reference `&Box<i32>` +help: consider removing the `&` and dereferencing the borrow instead + | +LL | *x + | ~ + +error[E0308]: mismatched types + --> $DIR/deref-multi.rs:22:5 + | +LL | fn d(x: std::sync::Mutex<&i32>) -> i32 { + | --- expected `i32` because of return type +LL | x.lock().unwrap() + | ^^^^^^^^^^^^^^^^^ expected `i32`, found struct `MutexGuard` + | + = note: expected type `i32` + found struct `MutexGuard<'_, &i32>` +help: consider dereferencing the type + | +LL | **x.lock().unwrap() + | ++ + +error: aborting due to 5 previous errors + +For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/typeck/do-not-suggest-adding-missing-zero-to-floating-point-number.rs b/tests/ui/typeck/do-not-suggest-adding-missing-zero-to-floating-point-number.rs new file mode 100644 index 000000000..501f4b6ef --- /dev/null +++ b/tests/ui/typeck/do-not-suggest-adding-missing-zero-to-floating-point-number.rs @@ -0,0 +1,21 @@ +macro_rules! num { () => { 1 } } + +fn main() { + let x = 1i32; + x.e10; //~ERROR `i32` is a primitive type and therefore doesn't have fields + + let y = 1; + y.e10; //~ERROR `{integer}` is a primitive type and therefore doesn't have fields + + 2u32.e10; //~ERROR `u32` is a primitive type and therefore doesn't have fields + + num!().e10; //~ERROR `{integer}` is a primitive type and therefore doesn't have fields + + 2.e10foo; //~ERROR `{integer}` is a primitive type and therefore doesn't have fields + + 42._; + //~^ERROR expected identifier, found reserved identifier `_` + //~|ERROR `{integer}` is a primitive type and therefore doesn't have fields + + 42.a; //~ERROR `{integer}` is a primitive type and therefore doesn't have fields +} diff --git a/tests/ui/typeck/do-not-suggest-adding-missing-zero-to-floating-point-number.stderr b/tests/ui/typeck/do-not-suggest-adding-missing-zero-to-floating-point-number.stderr new file mode 100644 index 000000000..1ef1d4c28 --- /dev/null +++ b/tests/ui/typeck/do-not-suggest-adding-missing-zero-to-floating-point-number.stderr @@ -0,0 +1,51 @@ +error: expected identifier, found reserved identifier `_` + --> $DIR/do-not-suggest-adding-missing-zero-to-floating-point-number.rs:16:8 + | +LL | 42._; + | ^ expected identifier, found reserved identifier + +error[E0610]: `i32` is a primitive type and therefore doesn't have fields + --> $DIR/do-not-suggest-adding-missing-zero-to-floating-point-number.rs:5:7 + | +LL | x.e10; + | ^^^ + +error[E0610]: `{integer}` is a primitive type and therefore doesn't have fields + --> $DIR/do-not-suggest-adding-missing-zero-to-floating-point-number.rs:8:7 + | +LL | y.e10; + | ^^^ + +error[E0610]: `u32` is a primitive type and therefore doesn't have fields + --> $DIR/do-not-suggest-adding-missing-zero-to-floating-point-number.rs:10:10 + | +LL | 2u32.e10; + | ^^^ + +error[E0610]: `{integer}` is a primitive type and therefore doesn't have fields + --> $DIR/do-not-suggest-adding-missing-zero-to-floating-point-number.rs:12:12 + | +LL | num!().e10; + | ^^^ + +error[E0610]: `{integer}` is a primitive type and therefore doesn't have fields + --> $DIR/do-not-suggest-adding-missing-zero-to-floating-point-number.rs:14:7 + | +LL | 2.e10foo; + | ^^^^^^ + +error[E0610]: `{integer}` is a primitive type and therefore doesn't have fields + --> $DIR/do-not-suggest-adding-missing-zero-to-floating-point-number.rs:16:8 + | +LL | 42._; + | ^ + +error[E0610]: `{integer}` is a primitive type and therefore doesn't have fields + --> $DIR/do-not-suggest-adding-missing-zero-to-floating-point-number.rs:20:8 + | +LL | 42.a; + | ^ + +error: aborting due to 8 previous errors + +For more information about this error, try `rustc --explain E0610`. diff --git a/tests/ui/typeck/do-not-suggest-placeholder-to-const-static-without-type.rs b/tests/ui/typeck/do-not-suggest-placeholder-to-const-static-without-type.rs new file mode 100644 index 000000000..97e0b213f --- /dev/null +++ b/tests/ui/typeck/do-not-suggest-placeholder-to-const-static-without-type.rs @@ -0,0 +1,8 @@ +trait Foo { + const A; //~ ERROR missing type for `const` item + static B; + //~^ ERROR associated `static` items are not allowed + //~| ERROR missing type for `static` item +} + +fn main() {} diff --git a/tests/ui/typeck/do-not-suggest-placeholder-to-const-static-without-type.stderr b/tests/ui/typeck/do-not-suggest-placeholder-to-const-static-without-type.stderr new file mode 100644 index 000000000..8982d6285 --- /dev/null +++ b/tests/ui/typeck/do-not-suggest-placeholder-to-const-static-without-type.stderr @@ -0,0 +1,20 @@ +error: associated `static` items are not allowed + --> $DIR/do-not-suggest-placeholder-to-const-static-without-type.rs:3:5 + | +LL | static B; + | ^^^^^^^^^ + +error: missing type for `const` item + --> $DIR/do-not-suggest-placeholder-to-const-static-without-type.rs:2:12 + | +LL | const A; + | ^ help: provide a type for the item: `: <type>` + +error: missing type for `static` item + --> $DIR/do-not-suggest-placeholder-to-const-static-without-type.rs:3:13 + | +LL | static B; + | ^ help: provide a type for the item: `: <type>` + +error: aborting due to 3 previous errors + diff --git a/tests/ui/typeck/explain_clone_autoref.rs b/tests/ui/typeck/explain_clone_autoref.rs new file mode 100644 index 000000000..9279e4c39 --- /dev/null +++ b/tests/ui/typeck/explain_clone_autoref.rs @@ -0,0 +1,13 @@ +struct NotClone; + +fn main() { + clone_thing(&NotClone); +} + +fn clone_thing(nc: &NotClone) -> NotClone { + //~^ NOTE expected `NotClone` because of return type + nc.clone() + //~^ ERROR mismatched type + //~| NOTE `NotClone` does not implement `Clone`, so `&NotClone` was cloned instead + //~| NOTE expected struct `NotClone`, found `&NotClone` +} diff --git a/tests/ui/typeck/explain_clone_autoref.stderr b/tests/ui/typeck/explain_clone_autoref.stderr new file mode 100644 index 000000000..ff36e18d2 --- /dev/null +++ b/tests/ui/typeck/explain_clone_autoref.stderr @@ -0,0 +1,22 @@ +error[E0308]: mismatched types + --> $DIR/explain_clone_autoref.rs:9:5 + | +LL | fn clone_thing(nc: &NotClone) -> NotClone { + | -------- expected `NotClone` because of return type +LL | +LL | nc.clone() + | ^^^^^^^^^^ expected struct `NotClone`, found `&NotClone` + | +note: `NotClone` does not implement `Clone`, so `&NotClone` was cloned instead + --> $DIR/explain_clone_autoref.rs:9:5 + | +LL | nc.clone() + | ^^ +help: consider annotating `NotClone` with `#[derive(Clone)]` + | +LL | #[derive(Clone)] + | + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/typeck/issue-100164.fixed b/tests/ui/typeck/issue-100164.fixed new file mode 100644 index 000000000..a5f68beb1 --- /dev/null +++ b/tests/ui/typeck/issue-100164.fixed @@ -0,0 +1,9 @@ +// run-rustfix + +const _A: i32 = 123; +//~^ ERROR: missing type for `const` item + +fn main() { + const _B: i32 = 123; + //~^ ERROR: missing type for `const` item +} diff --git a/tests/ui/typeck/issue-100164.rs b/tests/ui/typeck/issue-100164.rs new file mode 100644 index 000000000..7efb9ac62 --- /dev/null +++ b/tests/ui/typeck/issue-100164.rs @@ -0,0 +1,9 @@ +// run-rustfix + +const _A: = 123; +//~^ ERROR: missing type for `const` item + +fn main() { + const _B: = 123; + //~^ ERROR: missing type for `const` item +} diff --git a/tests/ui/typeck/issue-100164.stderr b/tests/ui/typeck/issue-100164.stderr new file mode 100644 index 000000000..06a132d65 --- /dev/null +++ b/tests/ui/typeck/issue-100164.stderr @@ -0,0 +1,14 @@ +error: missing type for `const` item + --> $DIR/issue-100164.rs:3:10 + | +LL | const _A: = 123; + | ^ help: provide a type for the constant: `i32` + +error: missing type for `const` item + --> $DIR/issue-100164.rs:7:14 + | +LL | const _B: = 123; + | ^ help: provide a type for the constant: `i32` + +error: aborting due to 2 previous errors + diff --git a/tests/ui/typeck/issue-100246.rs b/tests/ui/typeck/issue-100246.rs new file mode 100644 index 000000000..8f0b34bab --- /dev/null +++ b/tests/ui/typeck/issue-100246.rs @@ -0,0 +1,30 @@ +#![recursion_limit = "5"] // To reduce noise + +//expect incompatible type error when ambiguous traits are in scope +//and not an overflow error on the span in the main function. + +struct Ratio<T>(T); + +pub trait Pow { + fn pow(self) -> Self; +} + +impl<'a, T> Pow for &'a Ratio<T> +where + &'a T: Pow, +{ + fn pow(self) -> Self { + self + } +} + +fn downcast<'a, W: ?Sized>() -> std::io::Result<&'a W> { + todo!() +} + +struct Other; + +fn main() -> std::io::Result<()> { + let other: Other = downcast()?;//~ERROR 28:24: 28:35: `?` operator has incompatible types + Ok(()) +} diff --git a/tests/ui/typeck/issue-100246.stderr b/tests/ui/typeck/issue-100246.stderr new file mode 100644 index 000000000..8b77de94e --- /dev/null +++ b/tests/ui/typeck/issue-100246.stderr @@ -0,0 +1,13 @@ +error[E0308]: `?` operator has incompatible types + --> $DIR/issue-100246.rs:28:24 + | +LL | let other: Other = downcast()?; + | ^^^^^^^^^^^ expected struct `Other`, found reference + | + = note: `?` operator cannot convert from `&_` to `Other` + = note: expected struct `Other` + found reference `&_` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/typeck/issue-100285.rs b/tests/ui/typeck/issue-100285.rs new file mode 100644 index 000000000..e206469b8 --- /dev/null +++ b/tests/ui/typeck/issue-100285.rs @@ -0,0 +1,22 @@ +fn foo(n: i32) -> i32 { + for i in 0..0 { + //~^ ERROR: mismatched types [E0308] + if n < 0 { + return i; + } else if n < 10 { + return 1; + } else if n < 20 { + return 2; + } else if n < 30 { + return 3; + } else if n < 40 { + return 4; + } else { + return 5; + } + + } + //~| help: return a value for the case when the loop has zero elements to iterate on, or consider changing the return type to account for that possibility +} + +fn main() {} diff --git a/tests/ui/typeck/issue-100285.stderr b/tests/ui/typeck/issue-100285.stderr new file mode 100644 index 000000000..42c64b039 --- /dev/null +++ b/tests/ui/typeck/issue-100285.stderr @@ -0,0 +1,34 @@ +error[E0308]: mismatched types + --> $DIR/issue-100285.rs:2:5 + | +LL | fn foo(n: i32) -> i32 { + | --- expected `i32` because of return type +LL | / for i in 0..0 { +LL | | +LL | | if n < 0 { +LL | | return i; +... | +LL | | +LL | | } + | |_____^ expected `i32`, found `()` + | +note: the function expects a value to always be returned, but loops might run zero times + --> $DIR/issue-100285.rs:2:5 + | +LL | for i in 0..0 { + | ^^^^^^^^^^^^^ this might have zero elements to iterate on +... +LL | return i; + | -------- if the loop doesn't execute, this value would never get returned +LL | } else if n < 10 { +LL | return 1; + | -------- if the loop doesn't execute, this value would never get returned +LL | } else if n < 20 { +LL | return 2; + | -------- if the loop doesn't execute, this value would never get returned + = note: if the loop doesn't execute, 3 other values would never get returned + = help: return a value for the case when the loop has zero elements to iterate on, or consider changing the return type to account for that possibility + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/typeck/issue-103899.rs b/tests/ui/typeck/issue-103899.rs new file mode 100644 index 000000000..ac9e4c716 --- /dev/null +++ b/tests/ui/typeck/issue-103899.rs @@ -0,0 +1,30 @@ +// check-fail +// failure-status: 101 +// dont-check-compiler-stderr +// known-bug: #103899 + +trait BaseWithAssoc { + type Assoc; +} + +trait WrapperWithAssoc { + type BaseAssoc: BaseWithAssoc; +} + +struct Wrapper<B> { + inner: B, +} + +struct ProjectToBase<T: BaseWithAssoc> { + data_type_h: T::Assoc, +} + +struct DoubleProject<L: WrapperWithAssoc> { + buffer: Wrapper<ProjectToBase<L::BaseAssoc>>, +} + +fn trigger<L: WrapperWithAssoc<BaseAssoc = ()>>() -> DoubleProject<L> { + loop {} +} + +fn main() {} diff --git a/tests/ui/typeck/issue-10401.rs b/tests/ui/typeck/issue-10401.rs new file mode 100644 index 000000000..d77ff381e --- /dev/null +++ b/tests/ui/typeck/issue-10401.rs @@ -0,0 +1,5 @@ +fn main() { + let mut a = "a"; + a += { "b" }; + //~^ ERROR: binary assignment operation `+=` cannot be applied +} diff --git a/tests/ui/typeck/issue-10401.stderr b/tests/ui/typeck/issue-10401.stderr new file mode 100644 index 000000000..1f68abcfb --- /dev/null +++ b/tests/ui/typeck/issue-10401.stderr @@ -0,0 +1,11 @@ +error[E0368]: binary assignment operation `+=` cannot be applied to type `&str` + --> $DIR/issue-10401.rs:3:5 + | +LL | a += { "b" }; + | -^^^^^^^^^^^ + | | + | cannot use `+=` on type `&str` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0368`. diff --git a/tests/ui/typeck/issue-104510-ice.rs b/tests/ui/typeck/issue-104510-ice.rs new file mode 100644 index 000000000..157bdf07e --- /dev/null +++ b/tests/ui/typeck/issue-104510-ice.rs @@ -0,0 +1,16 @@ +// needs-asm-support +// only-x86_64 + +struct W<T: ?Sized>(Oops); +//~^ ERROR cannot find type `Oops` in this scope + +unsafe fn test() { + let j = W(()); + let pointer = &j as *const _; + core::arch::asm!( + "nop", + in("eax") pointer, + ); +} + +fn main() {} diff --git a/tests/ui/typeck/issue-104510-ice.stderr b/tests/ui/typeck/issue-104510-ice.stderr new file mode 100644 index 000000000..ddb510ef0 --- /dev/null +++ b/tests/ui/typeck/issue-104510-ice.stderr @@ -0,0 +1,9 @@ +error[E0412]: cannot find type `Oops` in this scope + --> $DIR/issue-104510-ice.rs:4:21 + | +LL | struct W<T: ?Sized>(Oops); + | ^^^^ not found in this scope + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0412`. diff --git a/tests/ui/typeck/issue-104513-ice.rs b/tests/ui/typeck/issue-104513-ice.rs new file mode 100644 index 000000000..bcac0fa1e --- /dev/null +++ b/tests/ui/typeck/issue-104513-ice.rs @@ -0,0 +1,6 @@ +struct S; +fn f() { + let _: S<impl Oops> = S; //~ ERROR cannot find trait `Oops` in this scope + //~^ ERROR `impl Trait` only allowed in function and inherent method return types +} +fn main() {} diff --git a/tests/ui/typeck/issue-104513-ice.stderr b/tests/ui/typeck/issue-104513-ice.stderr new file mode 100644 index 000000000..42cfe38ae --- /dev/null +++ b/tests/ui/typeck/issue-104513-ice.stderr @@ -0,0 +1,16 @@ +error[E0405]: cannot find trait `Oops` in this scope + --> $DIR/issue-104513-ice.rs:3:19 + | +LL | let _: S<impl Oops> = S; + | ^^^^ not found in this scope + +error[E0562]: `impl Trait` only allowed in function and inherent method return types, not in variable binding + --> $DIR/issue-104513-ice.rs:3:14 + | +LL | let _: S<impl Oops> = S; + | ^^^^^^^^^ + +error: aborting due to 2 previous errors + +Some errors have detailed explanations: E0405, E0562. +For more information about an error, try `rustc --explain E0405`. diff --git a/tests/ui/typeck/issue-104582.rs b/tests/ui/typeck/issue-104582.rs new file mode 100644 index 000000000..104669dad --- /dev/null +++ b/tests/ui/typeck/issue-104582.rs @@ -0,0 +1,5 @@ +fn main(){ + let my_var: String(String?); + //~^ ERROR: invalid `?` in type + //~| ERROR: parenthesized type parameters may only be used with a `Fn` trait +} diff --git a/tests/ui/typeck/issue-104582.stderr b/tests/ui/typeck/issue-104582.stderr new file mode 100644 index 000000000..61b6b2364 --- /dev/null +++ b/tests/ui/typeck/issue-104582.stderr @@ -0,0 +1,25 @@ +error: invalid `?` in type + --> $DIR/issue-104582.rs:2:30 + | +LL | let my_var: String(String?); + | ^ `?` is only allowed on expressions, not types + | +help: if you meant to express that the type might not contain a value, use the `Option` wrapper type + | +LL | let my_var: String(Option<String>); + | +++++++ ~ + +error[E0214]: parenthesized type parameters may only be used with a `Fn` trait + --> $DIR/issue-104582.rs:2:17 + | +LL | let my_var: String(String?); + | ^^^^^^^^^^^^^^^ only `Fn` traits may use parentheses + | +help: use angle brackets instead + | +LL | let my_var: String<String?>; + | ~ ~ + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0214`. diff --git a/tests/ui/typeck/issue-105946.rs b/tests/ui/typeck/issue-105946.rs new file mode 100644 index 000000000..bf01751d5 --- /dev/null +++ b/tests/ui/typeck/issue-105946.rs @@ -0,0 +1,12 @@ +fn digit() -> str { + return {}; + //~^ ERROR: mismatched types [E0308] +} +fn main() { + let [_y..] = [box 1, box 2]; + //~^ ERROR: cannot find value `_y` in this scope [E0425] + //~| ERROR: `X..` patterns in slices are experimental [E0658] + //~| ERROR: box expression syntax is experimental; you can call `Box::new` instead [E0658] + //~| ERROR: box expression syntax is experimental; you can call `Box::new` instead [E0658] + //~| ERROR: pattern requires 1 element but array has 2 [E0527] +} diff --git a/tests/ui/typeck/issue-105946.stderr b/tests/ui/typeck/issue-105946.stderr new file mode 100644 index 000000000..d803de4df --- /dev/null +++ b/tests/ui/typeck/issue-105946.stderr @@ -0,0 +1,49 @@ +error[E0425]: cannot find value `_y` in this scope + --> $DIR/issue-105946.rs:6:10 + | +LL | let [_y..] = [box 1, box 2]; + | ^^ not found in this scope + +error[E0658]: `X..` patterns in slices are experimental + --> $DIR/issue-105946.rs:6:10 + | +LL | let [_y..] = [box 1, box 2]; + | ^^^^ + | + = note: see issue #67264 <https://github.com/rust-lang/rust/issues/67264> for more information + = help: add `#![feature(half_open_range_patterns_in_slices)]` to the crate attributes to enable + +error[E0658]: box expression syntax is experimental; you can call `Box::new` instead + --> $DIR/issue-105946.rs:6:19 + | +LL | let [_y..] = [box 1, box 2]; + | ^^^^^ + | + = note: see issue #49733 <https://github.com/rust-lang/rust/issues/49733> for more information + = help: add `#![feature(box_syntax)]` to the crate attributes to enable + +error[E0658]: box expression syntax is experimental; you can call `Box::new` instead + --> $DIR/issue-105946.rs:6:26 + | +LL | let [_y..] = [box 1, box 2]; + | ^^^^^ + | + = note: see issue #49733 <https://github.com/rust-lang/rust/issues/49733> for more information + = help: add `#![feature(box_syntax)]` to the crate attributes to enable + +error[E0308]: mismatched types + --> $DIR/issue-105946.rs:2:10 + | +LL | return {}; + | ^^ expected `str`, found `()` + +error[E0527]: pattern requires 1 element but array has 2 + --> $DIR/issue-105946.rs:6:9 + | +LL | let [_y..] = [box 1, box 2]; + | ^^^^^^ expected 2 elements + +error: aborting due to 6 previous errors + +Some errors have detailed explanations: E0308, E0425, E0527, E0658. +For more information about an error, try `rustc --explain E0308`. diff --git a/tests/ui/typeck/issue-10969.rs b/tests/ui/typeck/issue-10969.rs new file mode 100644 index 000000000..0b78fc1bb --- /dev/null +++ b/tests/ui/typeck/issue-10969.rs @@ -0,0 +1,7 @@ +fn func(i: i32) { + i(); //~ERROR expected function, found `i32` +} +fn main() { + let i = 0i32; + i(); //~ERROR expected function, found `i32` +} diff --git a/tests/ui/typeck/issue-10969.stderr b/tests/ui/typeck/issue-10969.stderr new file mode 100644 index 000000000..f64b61aae --- /dev/null +++ b/tests/ui/typeck/issue-10969.stderr @@ -0,0 +1,23 @@ +error[E0618]: expected function, found `i32` + --> $DIR/issue-10969.rs:2:5 + | +LL | fn func(i: i32) { + | - `i` has type `i32` +LL | i(); + | ^-- + | | + | call expression requires function + +error[E0618]: expected function, found `i32` + --> $DIR/issue-10969.rs:6:5 + | +LL | let i = 0i32; + | - `i` has type `i32` +LL | i(); + | ^-- + | | + | call expression requires function + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0618`. diff --git a/tests/ui/typeck/issue-13853-2.rs b/tests/ui/typeck/issue-13853-2.rs new file mode 100644 index 000000000..27319c98d --- /dev/null +++ b/tests/ui/typeck/issue-13853-2.rs @@ -0,0 +1,6 @@ +trait FromStructReader<'a> { } +trait ResponseHook { + fn get(&self); +} +fn foo(res : Box<dyn ResponseHook>) { res.get } //~ ERROR attempted to take value of method +fn main() {} diff --git a/tests/ui/typeck/issue-13853-2.stderr b/tests/ui/typeck/issue-13853-2.stderr new file mode 100644 index 000000000..92068df6c --- /dev/null +++ b/tests/ui/typeck/issue-13853-2.stderr @@ -0,0 +1,14 @@ +error[E0615]: attempted to take value of method `get` on type `Box<(dyn ResponseHook + 'static)>` + --> $DIR/issue-13853-2.rs:5:43 + | +LL | fn foo(res : Box<dyn ResponseHook>) { res.get } + | ^^^ method, not a field + | +help: use parentheses to call the method + | +LL | fn foo(res : Box<dyn ResponseHook>) { res.get() } + | ++ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0615`. diff --git a/tests/ui/typeck/issue-13853-5.rs b/tests/ui/typeck/issue-13853-5.rs new file mode 100644 index 000000000..2afdf95aa --- /dev/null +++ b/tests/ui/typeck/issue-13853-5.rs @@ -0,0 +1,13 @@ +trait Deserializer<'a> { } + +trait Deserializable { + fn deserialize_token<'a, D: Deserializer<'a>>(_: D, _: &'a str) -> Self; +} + +impl<'a, T: Deserializable> Deserializable for &'a str { + //~^ ERROR type parameter `T` is not constrained + fn deserialize_token<D: Deserializer<'a>>(_x: D, _y: &'a str) -> &'a str { + } +} + +fn main() {} diff --git a/tests/ui/typeck/issue-13853-5.stderr b/tests/ui/typeck/issue-13853-5.stderr new file mode 100644 index 000000000..3d8f824ec --- /dev/null +++ b/tests/ui/typeck/issue-13853-5.stderr @@ -0,0 +1,9 @@ +error[E0207]: the type parameter `T` is not constrained by the impl trait, self type, or predicates + --> $DIR/issue-13853-5.rs:7:10 + | +LL | impl<'a, T: Deserializable> Deserializable for &'a str { + | ^ unconstrained type parameter + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0207`. diff --git a/tests/ui/typeck/issue-13853.rs b/tests/ui/typeck/issue-13853.rs new file mode 100644 index 000000000..ac9886d2e --- /dev/null +++ b/tests/ui/typeck/issue-13853.rs @@ -0,0 +1,38 @@ +trait Node { + fn zomg(); +} + +trait Graph<N: Node> { + fn nodes<'a, I: Iterator<Item=&'a N>>(&'a self) -> I + where N: 'a; +} + +impl<N: Node> Graph<N> for Vec<N> { + fn nodes<'a, I: Iterator<Item=&'a N>>(&self) -> I + where N: 'a + { + self.iter() //~ ERROR mismatched types + } +} + +struct Stuff; + +impl Node for Stuff { + fn zomg() { + println!("zomg"); + } +} + +fn iterate<N: Node, G: Graph<N>>(graph: &G) { + for node in graph.iter() { //~ ERROR no method named `iter` found + node.zomg(); + } +} + +pub fn main() { + let graph = Vec::new(); + + graph.push(Stuff); + + iterate(graph); //~ ERROR mismatched types +} diff --git a/tests/ui/typeck/issue-13853.stderr b/tests/ui/typeck/issue-13853.stderr new file mode 100644 index 000000000..876ac2c67 --- /dev/null +++ b/tests/ui/typeck/issue-13853.stderr @@ -0,0 +1,40 @@ +error[E0308]: mismatched types + --> $DIR/issue-13853.rs:14:9 + | +LL | fn nodes<'a, I: Iterator<Item=&'a N>>(&self) -> I + | - this type parameter - expected `I` because of return type +... +LL | self.iter() + | ^^^^^^^^^^^ expected type parameter `I`, found struct `Iter` + | + = note: expected type parameter `I` + found struct `std::slice::Iter<'_, N>` + +error[E0599]: no method named `iter` found for reference `&G` in the current scope + --> $DIR/issue-13853.rs:27:23 + | +LL | for node in graph.iter() { + | ^^^^ method not found in `&G` + +error[E0308]: mismatched types + --> $DIR/issue-13853.rs:37:13 + | +LL | iterate(graph); + | ------- ^^^^^ + | | | + | | expected reference, found struct `Vec` + | | help: consider borrowing here: `&graph` + | arguments to this function are incorrect + | + = note: expected reference `&_` + found struct `Vec<Stuff>` +note: function defined here + --> $DIR/issue-13853.rs:26:4 + | +LL | fn iterate<N: Node, G: Graph<N>>(graph: &G) { + | ^^^^^^^ --------- + +error: aborting due to 3 previous errors + +Some errors have detailed explanations: E0308, E0599. +For more information about an error, try `rustc --explain E0308`. diff --git a/tests/ui/typeck/issue-18937-1.rs b/tests/ui/typeck/issue-18937-1.rs new file mode 100644 index 000000000..57e56d832 --- /dev/null +++ b/tests/ui/typeck/issue-18937-1.rs @@ -0,0 +1,21 @@ +// run-pass +// Test that we are able to type-check this example. In particular, +// knowing that `T: 'a` allows us to deduce that `[U]: 'a` (because +// when `T=[U]` it implies that `U: 'a`). +// +// Regr. test for live code we found in the wild when fixing #18937. + +pub trait Leak<T : ?Sized> { + fn leak<'a>(self) -> &'a T where T: 'a; +} + +impl<U> Leak<[U]> for Vec<U> { + fn leak<'a>(mut self) -> &'a [U] where [U]: 'a { + let r: *mut [U] = &mut self[..]; + std::mem::forget(self); + unsafe { &mut *r } + } +} +fn main() { + println!("Hello, world!"); +} diff --git a/tests/ui/typeck/issue-18937.rs b/tests/ui/typeck/issue-18937.rs new file mode 100644 index 000000000..af85e5b2b --- /dev/null +++ b/tests/ui/typeck/issue-18937.rs @@ -0,0 +1,40 @@ +// Regression test for #18937. + +use std::fmt; + +#[derive(Debug)] +struct MyString<'a>(&'a String); + +struct B { + list: Vec<Box<dyn fmt::Debug>>, +} + +trait A<'a> { + fn foo<F>(&mut self, f: F) + where F: fmt::Debug + 'a, + Self: Sized; +} + +impl<'a> A<'a> for B { + fn foo<F>(&mut self, f: F) + where F: fmt::Debug + 'static, //~ ERROR impl has stricter + { + self.list.push(Box::new(f)); + } +} + +fn main() { + let mut b = B { list: Vec::new() }; + + // Create a borrowed pointer, put it in `b`, then drop what's borrowing it + let a = "hello".to_string(); + b.foo(MyString(&a)); + + // Drop the data which `b` has a reference to + drop(a); + + // Use the data, probably segfaulting + for b in b.list.iter() { + println!("{:?}", b); + } +} diff --git a/tests/ui/typeck/issue-18937.stderr b/tests/ui/typeck/issue-18937.stderr new file mode 100644 index 000000000..5e2ba0ef4 --- /dev/null +++ b/tests/ui/typeck/issue-18937.stderr @@ -0,0 +1,14 @@ +error[E0276]: impl has stricter requirements than trait + --> $DIR/issue-18937.rs:20:31 + | +LL | / fn foo<F>(&mut self, f: F) +LL | | where F: fmt::Debug + 'a, +LL | | Self: Sized; + | |__________________________- definition of `foo` from trait +... +LL | where F: fmt::Debug + 'static, + | ^^^^^^^ impl has extra requirement `F: 'static` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0276`. diff --git a/tests/ui/typeck/issue-22375.rs b/tests/ui/typeck/issue-22375.rs new file mode 100644 index 000000000..21a1a4c83 --- /dev/null +++ b/tests/ui/typeck/issue-22375.rs @@ -0,0 +1,4 @@ +// check-pass +trait A<T: A<T>> {} + +fn main() {} diff --git a/tests/ui/typeck/issue-29124.rs b/tests/ui/typeck/issue-29124.rs new file mode 100644 index 000000000..dd2784841 --- /dev/null +++ b/tests/ui/typeck/issue-29124.rs @@ -0,0 +1,19 @@ +struct Ret; +struct Obj; + +impl Obj { + fn func() -> Ret { + Ret + } +} + +fn func() -> Ret { + Ret +} + +fn main() { + Obj::func.x(); + //~^ ERROR no method named `x` found + func.x(); + //~^ ERROR no method named `x` found +} diff --git a/tests/ui/typeck/issue-29124.stderr b/tests/ui/typeck/issue-29124.stderr new file mode 100644 index 000000000..a837a7d2d --- /dev/null +++ b/tests/ui/typeck/issue-29124.stderr @@ -0,0 +1,15 @@ +error[E0599]: no method named `x` found for fn item `fn() -> Ret {Obj::func}` in the current scope + --> $DIR/issue-29124.rs:15:15 + | +LL | Obj::func.x(); + | ^ method not found in `fn() -> Ret {Obj::func}` + +error[E0599]: no method named `x` found for fn item `fn() -> Ret {func}` in the current scope + --> $DIR/issue-29124.rs:17:10 + | +LL | func.x(); + | ^ method not found in `fn() -> Ret {func}` + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0599`. diff --git a/tests/ui/typeck/issue-31173.rs b/tests/ui/typeck/issue-31173.rs new file mode 100644 index 000000000..f678df5b4 --- /dev/null +++ b/tests/ui/typeck/issue-31173.rs @@ -0,0 +1,15 @@ +use std::vec::IntoIter; + +pub fn get_tok(it: &mut IntoIter<u8>) { + let mut found_e = false; + + let temp: Vec<u8> = it + .take_while(|&x| { + found_e = true; + false + }) + .cloned() //~ ERROR to be an iterator that yields `&_`, but it yields `u8` + .collect(); //~ ERROR the method +} + +fn main() {} diff --git a/tests/ui/typeck/issue-31173.stderr b/tests/ui/typeck/issue-31173.stderr new file mode 100644 index 000000000..f3be99f9b --- /dev/null +++ b/tests/ui/typeck/issue-31173.stderr @@ -0,0 +1,45 @@ +error[E0271]: expected `TakeWhile<&mut IntoIter<u8>, [closure@issue-31173.rs:7:21]>` to be an iterator that yields `&_`, but it yields `u8` + --> $DIR/issue-31173.rs:11:10 + | +LL | .cloned() + | ^^^^^^ expected reference, found `u8` + | + = note: expected reference `&_` + found type `u8` +note: the method call chain might not have had the expected associated types + --> $DIR/issue-31173.rs:3:20 + | +LL | pub fn get_tok(it: &mut IntoIter<u8>) { + | ^^^^^^^^^^^^^^^^^ `Iterator::Item` is `u8` here +... +LL | .take_while(|&x| { + | __________- +LL | | found_e = true; +LL | | false +LL | | }) + | |__________- `Iterator::Item` remains `u8` here +note: required by a bound in `cloned` + --> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL + +error[E0599]: the method `collect` exists for struct `Cloned<TakeWhile<&mut IntoIter<u8>, [closure@issue-31173.rs:7:21]>>`, but its trait bounds were not satisfied + --> $DIR/issue-31173.rs:12:10 + | +LL | .collect(); + | ^^^^^^^ method cannot be called due to unsatisfied trait bounds + --> $SRC_DIR/core/src/iter/adapters/take_while.rs:LL:COL + | + = note: doesn't satisfy `<_ as Iterator>::Item = &_` + --> $SRC_DIR/core/src/iter/adapters/cloned.rs:LL:COL + | + = note: doesn't satisfy `_: Iterator` + | + = note: the following trait bounds were not satisfied: + `<TakeWhile<&mut std::vec::IntoIter<u8>, [closure@$DIR/issue-31173.rs:7:21: 7:25]> as Iterator>::Item = &_` + which is required by `Cloned<TakeWhile<&mut std::vec::IntoIter<u8>, [closure@$DIR/issue-31173.rs:7:21: 7:25]>>: Iterator` + `Cloned<TakeWhile<&mut std::vec::IntoIter<u8>, [closure@$DIR/issue-31173.rs:7:21: 7:25]>>: Iterator` + which is required by `&mut Cloned<TakeWhile<&mut std::vec::IntoIter<u8>, [closure@$DIR/issue-31173.rs:7:21: 7:25]>>: Iterator` + +error: aborting due to 2 previous errors + +Some errors have detailed explanations: E0271, E0599. +For more information about an error, try `rustc --explain E0271`. diff --git a/tests/ui/typeck/issue-33575.rs b/tests/ui/typeck/issue-33575.rs new file mode 100644 index 000000000..de544afae --- /dev/null +++ b/tests/ui/typeck/issue-33575.rs @@ -0,0 +1,4 @@ +fn main() { + let baz = ().foo(); //~ ERROR no method named `foo` found + <i32 as std::str::FromStr>::from_str(&baz); // No complaints about `str` being unsized +} diff --git a/tests/ui/typeck/issue-33575.stderr b/tests/ui/typeck/issue-33575.stderr new file mode 100644 index 000000000..bbd8042d1 --- /dev/null +++ b/tests/ui/typeck/issue-33575.stderr @@ -0,0 +1,9 @@ +error[E0599]: no method named `foo` found for unit type `()` in the current scope + --> $DIR/issue-33575.rs:2:18 + | +LL | let baz = ().foo(); + | ^^^ method not found in `()` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0599`. diff --git a/tests/ui/typeck/issue-36708.rs b/tests/ui/typeck/issue-36708.rs new file mode 100644 index 000000000..c9d9f2a6d --- /dev/null +++ b/tests/ui/typeck/issue-36708.rs @@ -0,0 +1,12 @@ +// aux-build:issue-36708.rs + +extern crate issue_36708 as lib; + +struct Bar; + +impl lib::Foo for Bar { + fn foo<T>() {} + //~^ ERROR E0049 +} + +fn main() {} diff --git a/tests/ui/typeck/issue-36708.stderr b/tests/ui/typeck/issue-36708.stderr new file mode 100644 index 000000000..140f19f1f --- /dev/null +++ b/tests/ui/typeck/issue-36708.stderr @@ -0,0 +1,9 @@ +error[E0049]: method `foo` has 1 type parameter but its trait declaration has 0 type parameters + --> $DIR/issue-36708.rs:8:12 + | +LL | fn foo<T>() {} + | ^ found 1 type parameter, expected 0 + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0049`. diff --git a/tests/ui/typeck/issue-43189.rs b/tests/ui/typeck/issue-43189.rs new file mode 100644 index 000000000..ce667a500 --- /dev/null +++ b/tests/ui/typeck/issue-43189.rs @@ -0,0 +1,12 @@ +// Issue 46112: An extern crate pub re-exporting libcore was causing +// paths rooted from `std` to be misrendered in the diagnostic output. + +// ignore-windows +// aux-build:xcrate-issue-43189-a.rs +// aux-build:xcrate-issue-43189-b.rs + +extern crate xcrate_issue_43189_b; +fn main() { + ().a(); + //~^ ERROR no method named `a` found +} diff --git a/tests/ui/typeck/issue-43189.stderr b/tests/ui/typeck/issue-43189.stderr new file mode 100644 index 000000000..caf7530b8 --- /dev/null +++ b/tests/ui/typeck/issue-43189.stderr @@ -0,0 +1,20 @@ +error[E0599]: no method named `a` found for unit type `()` in the current scope + --> $DIR/issue-43189.rs:10:8 + | +LL | ().a(); + | ^ method not found in `()` + | + ::: $DIR/auxiliary/xcrate-issue-43189-a.rs:5:8 + | +LL | fn a(&self) {} + | - the method is available for `()` here + | + = help: items from traits can only be used if the trait is in scope +help: the following trait is implemented but not in scope; perhaps add a `use` for it: + | +LL | use xcrate_issue_43189_b::xcrate_issue_43189_a::A; + | + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0599`. diff --git a/tests/ui/typeck/issue-46112.rs b/tests/ui/typeck/issue-46112.rs new file mode 100644 index 000000000..0cdd2c27f --- /dev/null +++ b/tests/ui/typeck/issue-46112.rs @@ -0,0 +1,10 @@ +// Issue 46112: An extern crate pub re-exporting libcore was causing +// paths rooted from `std` to be misrendered in the diagnostic output. + +// ignore-windows +// aux-build:xcrate-issue-46112-rexport-core.rs + +extern crate xcrate_issue_46112_rexport_core; +fn test(r: Result<Option<()>, &'static str>) { } +fn main() { test(Ok(())); } +//~^ mismatched types diff --git a/tests/ui/typeck/issue-46112.stderr b/tests/ui/typeck/issue-46112.stderr new file mode 100644 index 000000000..8f5ff51fb --- /dev/null +++ b/tests/ui/typeck/issue-46112.stderr @@ -0,0 +1,27 @@ +error[E0308]: mismatched types + --> $DIR/issue-46112.rs:9:21 + | +LL | fn main() { test(Ok(())); } + | -- ^^ expected enum `Option`, found `()` + | | + | arguments to this enum variant are incorrect + | + = note: expected enum `Option<()>` + found unit type `()` +help: the type constructed contains `()` due to the type of the argument passed + --> $DIR/issue-46112.rs:9:18 + | +LL | fn main() { test(Ok(())); } + | ^^^--^ + | | + | this argument influences the type of `Ok` +note: tuple variant defined here + --> $SRC_DIR/core/src/result.rs:LL:COL +help: try wrapping the expression in `Some` + | +LL | fn main() { test(Ok(Some(()))); } + | +++++ + + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/typeck/issue-50687-ice-on-borrow.rs b/tests/ui/typeck/issue-50687-ice-on-borrow.rs new file mode 100644 index 000000000..7a8a12c2a --- /dev/null +++ b/tests/ui/typeck/issue-50687-ice-on-borrow.rs @@ -0,0 +1,41 @@ +// This previously caused an ICE at: +// librustc/traits/structural_impls.rs:180: impossible case reached + +#![no_main] + +use std::borrow::Borrow; +use std::io; +use std::io::Write; + +trait Constraint {} + +struct Container<T> { + t: T, +} + +struct Borrowed; +struct Owned; + +impl<'a, T> Write for &'a Container<T> +where + T: Constraint, + &'a T: Write, +{ + fn write(&mut self, buf: &[u8]) -> io::Result<usize> { + Ok(buf.len()) + } + + fn flush(&mut self) -> io::Result<()> { + Ok(()) + } +} + +impl Borrow<Borrowed> for Owned { + fn borrow(&self) -> &Borrowed { + &Borrowed + } +} + +fn func(owned: Owned) { + let _: () = Borrow::borrow(&owned); //~ ERROR mismatched types +} diff --git a/tests/ui/typeck/issue-50687-ice-on-borrow.stderr b/tests/ui/typeck/issue-50687-ice-on-borrow.stderr new file mode 100644 index 000000000..e6a0edac4 --- /dev/null +++ b/tests/ui/typeck/issue-50687-ice-on-borrow.stderr @@ -0,0 +1,18 @@ +error[E0308]: mismatched types + --> $DIR/issue-50687-ice-on-borrow.rs:40:17 + | +LL | let _: () = Borrow::borrow(&owned); + | -- ^^^^^^^^^^^^^^^^^^^^^^ expected `()`, found reference + | | + | expected due to this + | + = note: expected unit type `()` + found reference `&_` +help: consider dereferencing the borrow + | +LL | let _: () = *Borrow::borrow(&owned); + | + + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/typeck/issue-52082-type-param-shadows-existing-type.rs b/tests/ui/typeck/issue-52082-type-param-shadows-existing-type.rs new file mode 100644 index 000000000..7bf151514 --- /dev/null +++ b/tests/ui/typeck/issue-52082-type-param-shadows-existing-type.rs @@ -0,0 +1,54 @@ +// Fix issue 52082: Confusing error if accidentally defining a type parameter with the same name as +// an existing type +// +// To this end, make sure that when trying to retrieve a field of a (reference to) type parameter, +// rustc points to the point where the parameter was defined. +#[derive(Debug)] +struct Point +{ + x: i32, + y: i32 +} + +impl Point +{ + fn add(a: &Point, b: &Point) -> Point + { + Point {x: a.x + b.x, y: a.y + b.y} + } +} + +trait Eq +{ + fn equals_ref<T>(a: &T, b: &T) -> bool; + fn equals_val<T>(a: T, b: T) -> bool; +} + +impl Eq for Point +{ + fn equals_ref<Point>(a: &Point, b: &Point) -> bool + { + a.x == b.x && a.y == b.y //~ ERROR no field `x` on type `&Point` [E0609] + //~|ERROR no field `x` on type `&Point` [E0609] + //~|ERROR no field `y` on type `&Point` [E0609] + //~|ERROR no field `y` on type `&Point` [E0609] + } + + fn equals_val<Point>(a: Point, b: Point) -> bool + { + a.x == b.x && a.y == b.y //~ ERROR no field `x` on type `Point` [E0609] + //~|ERROR no field `x` on type `Point` [E0609] + //~|ERROR no field `y` on type `Point` [E0609] + //~|ERROR no field `y` on type `Point` [E0609] + } +} + +fn main() +{ + let p1 = Point {x: 0, y: 10}; + let p2 = Point {x: 20, y: 42}; + println!("{:?}", Point::add(&p1, &p2)); + println!("p1: {:?}, p2: {:?}", p1, p2); + println!("&p1 == &p2: {:?}", Point::equals_ref(&p1, &p2)); + println!("p1 == p2: {:?}", Point::equals_val(p1, p2)); +} diff --git a/tests/ui/typeck/issue-52082-type-param-shadows-existing-type.stderr b/tests/ui/typeck/issue-52082-type-param-shadows-existing-type.stderr new file mode 100644 index 000000000..4be4c91df --- /dev/null +++ b/tests/ui/typeck/issue-52082-type-param-shadows-existing-type.stderr @@ -0,0 +1,75 @@ +error[E0609]: no field `x` on type `&Point` + --> $DIR/issue-52082-type-param-shadows-existing-type.rs:31:11 + | +LL | fn equals_ref<Point>(a: &Point, b: &Point) -> bool + | ----- type parameter 'Point' declared here +LL | { +LL | a.x == b.x && a.y == b.y + | ^ + +error[E0609]: no field `x` on type `&Point` + --> $DIR/issue-52082-type-param-shadows-existing-type.rs:31:18 + | +LL | fn equals_ref<Point>(a: &Point, b: &Point) -> bool + | ----- type parameter 'Point' declared here +LL | { +LL | a.x == b.x && a.y == b.y + | ^ + +error[E0609]: no field `y` on type `&Point` + --> $DIR/issue-52082-type-param-shadows-existing-type.rs:31:25 + | +LL | fn equals_ref<Point>(a: &Point, b: &Point) -> bool + | ----- type parameter 'Point' declared here +LL | { +LL | a.x == b.x && a.y == b.y + | ^ + +error[E0609]: no field `y` on type `&Point` + --> $DIR/issue-52082-type-param-shadows-existing-type.rs:31:32 + | +LL | fn equals_ref<Point>(a: &Point, b: &Point) -> bool + | ----- type parameter 'Point' declared here +LL | { +LL | a.x == b.x && a.y == b.y + | ^ + +error[E0609]: no field `x` on type `Point` + --> $DIR/issue-52082-type-param-shadows-existing-type.rs:39:11 + | +LL | fn equals_val<Point>(a: Point, b: Point) -> bool + | ----- type parameter 'Point' declared here +LL | { +LL | a.x == b.x && a.y == b.y + | ^ + +error[E0609]: no field `x` on type `Point` + --> $DIR/issue-52082-type-param-shadows-existing-type.rs:39:18 + | +LL | fn equals_val<Point>(a: Point, b: Point) -> bool + | ----- type parameter 'Point' declared here +LL | { +LL | a.x == b.x && a.y == b.y + | ^ + +error[E0609]: no field `y` on type `Point` + --> $DIR/issue-52082-type-param-shadows-existing-type.rs:39:25 + | +LL | fn equals_val<Point>(a: Point, b: Point) -> bool + | ----- type parameter 'Point' declared here +LL | { +LL | a.x == b.x && a.y == b.y + | ^ + +error[E0609]: no field `y` on type `Point` + --> $DIR/issue-52082-type-param-shadows-existing-type.rs:39:32 + | +LL | fn equals_val<Point>(a: Point, b: Point) -> bool + | ----- type parameter 'Point' declared here +LL | { +LL | a.x == b.x && a.y == b.y + | ^ + +error: aborting due to 8 previous errors + +For more information about this error, try `rustc --explain E0609`. diff --git a/tests/ui/typeck/issue-55810-must-typeck-match-pats-before-guards.rs b/tests/ui/typeck/issue-55810-must-typeck-match-pats-before-guards.rs new file mode 100644 index 000000000..23ea0ad61 --- /dev/null +++ b/tests/ui/typeck/issue-55810-must-typeck-match-pats-before-guards.rs @@ -0,0 +1,23 @@ +// check-pass + +// rust-lang/rust#55810: types for a binding in a match arm can be +// inferred from arms that come later in the match. + +struct S; + +impl S { + fn method(&self) -> bool { + unimplemented!() + } +} + +fn get<T>() -> T { + unimplemented!() +} + +fn main() { + match get() { + x if x.method() => {} + &S => {} + } +} diff --git a/tests/ui/typeck/issue-57404.rs b/tests/ui/typeck/issue-57404.rs new file mode 100644 index 000000000..ecabca66a --- /dev/null +++ b/tests/ui/typeck/issue-57404.rs @@ -0,0 +1,7 @@ +#![feature(unboxed_closures)] +#![feature(fn_traits)] + +fn main() { + let handlers: Option<Box<dyn for<'a> FnMut<&'a mut (), Output=()>>> = None; + handlers.unwrap().as_mut().call_mut(&mut ()); //~ ERROR: `&mut ()` is not a tuple +} diff --git a/tests/ui/typeck/issue-57404.stderr b/tests/ui/typeck/issue-57404.stderr new file mode 100644 index 000000000..a631dbb39 --- /dev/null +++ b/tests/ui/typeck/issue-57404.stderr @@ -0,0 +1,19 @@ +error[E0277]: `&mut ()` is not a tuple + --> $DIR/issue-57404.rs:6:41 + | +LL | handlers.unwrap().as_mut().call_mut(&mut ()); + | -------- ^^^^^^^ the trait `Tuple` is not implemented for `&mut ()` + | | + | required by a bound introduced by this call + | +note: required by a bound in `call_mut` + --> $SRC_DIR/core/src/ops/function.rs:LL:COL +help: consider removing the leading `&`-reference + | +LL - handlers.unwrap().as_mut().call_mut(&mut ()); +LL + handlers.unwrap().as_mut().call_mut(()); + | + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/typeck/issue-57673-ice-on-deref-of-boxed-trait.rs b/tests/ui/typeck/issue-57673-ice-on-deref-of-boxed-trait.rs new file mode 100644 index 000000000..0a4e7da2b --- /dev/null +++ b/tests/ui/typeck/issue-57673-ice-on-deref-of-boxed-trait.rs @@ -0,0 +1,7 @@ +//extern crate has_assoc_type; + +//fn ice(x: Box<dyn has_assoc_type::Foo<Assoc=()>>) { +fn ice(x: Box<dyn Iterator<Item=()>>) { + *x //~ ERROR mismatched types [E0308] +} +fn main() {} diff --git a/tests/ui/typeck/issue-57673-ice-on-deref-of-boxed-trait.stderr b/tests/ui/typeck/issue-57673-ice-on-deref-of-boxed-trait.stderr new file mode 100644 index 000000000..b92a6f2ec --- /dev/null +++ b/tests/ui/typeck/issue-57673-ice-on-deref-of-boxed-trait.stderr @@ -0,0 +1,14 @@ +error[E0308]: mismatched types + --> $DIR/issue-57673-ice-on-deref-of-boxed-trait.rs:5:5 + | +LL | fn ice(x: Box<dyn Iterator<Item=()>>) { + | - help: try adding a return type: `-> (dyn Iterator<Item = ()> + 'static)` +LL | *x + | ^^ expected `()`, found trait object `dyn Iterator` + | + = note: expected unit type `()` + found trait object `(dyn Iterator<Item = ()> + 'static)` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/typeck/issue-61711-once-caused-rustc-inf-loop.rs b/tests/ui/typeck/issue-61711-once-caused-rustc-inf-loop.rs new file mode 100644 index 000000000..de7d6a0d8 --- /dev/null +++ b/tests/ui/typeck/issue-61711-once-caused-rustc-inf-loop.rs @@ -0,0 +1,11 @@ +// Issue 61711: A crate pub re-exporting `crate` was causing an +// infinite loop. + +// edition:2018 +// aux-build:xcrate-issue-61711-b.rs +// compile-flags:--extern xcrate_issue_61711_b + +// build-pass + +fn f<F: Fn(xcrate_issue_61711_b::Struct)>(_: F) { } +fn main() { } diff --git a/tests/ui/typeck/issue-65611.rs b/tests/ui/typeck/issue-65611.rs new file mode 100644 index 000000000..764531149 --- /dev/null +++ b/tests/ui/typeck/issue-65611.rs @@ -0,0 +1,63 @@ +use std::mem::MaybeUninit; +use std::ops::Deref; + +pub unsafe trait Array { + /// The array’s element type + type Item; + #[doc(hidden)] + /// The smallest index type that indexes the array. + type Index: Index; + #[doc(hidden)] + fn as_ptr(&self) -> *const Self::Item; + #[doc(hidden)] + fn as_mut_ptr(&mut self) -> *mut Self::Item; + #[doc(hidden)] + fn capacity() -> usize; +} + +pub trait Index : PartialEq + Copy { + fn to_usize(self) -> usize; + fn from(i: usize) -> Self; +} + +impl Index for usize { + fn to_usize(self) -> usize { self } + fn from(val: usize) -> Self { + val + } +} + +unsafe impl<T> Array for [T; 1] { + type Item = T; + type Index = usize; + fn as_ptr(&self) -> *const T { self as *const _ as *const _ } + fn as_mut_ptr(&mut self) -> *mut T { self as *mut _ as *mut _} + fn capacity() -> usize { 1 } +} + +impl<A: Array> Deref for ArrayVec<A> { + type Target = [A::Item]; + #[inline] + fn deref(&self) -> &[A::Item] { + panic!() + } +} + +pub struct ArrayVec<A: Array> { + xs: MaybeUninit<A>, + len: usize, +} + +impl<A: Array> ArrayVec<A> { + pub fn new() -> ArrayVec<A> { + panic!() + } +} + +fn main() { + let mut buffer = ArrayVec::new(); + let x = buffer.last().unwrap().0.clone(); + //~^ ERROR type annotations needed + //~| ERROR no field `0` on type `&_` + buffer.reverse(); +} diff --git a/tests/ui/typeck/issue-65611.stderr b/tests/ui/typeck/issue-65611.stderr new file mode 100644 index 000000000..003c63079 --- /dev/null +++ b/tests/ui/typeck/issue-65611.stderr @@ -0,0 +1,16 @@ +error[E0282]: type annotations needed + --> $DIR/issue-65611.rs:59:13 + | +LL | let x = buffer.last().unwrap().0.clone(); + | ^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type for type parameter `T` + +error[E0609]: no field `0` on type `&_` + --> $DIR/issue-65611.rs:59:36 + | +LL | let x = buffer.last().unwrap().0.clone(); + | ^ + +error: aborting due to 2 previous errors + +Some errors have detailed explanations: E0282, E0609. +For more information about an error, try `rustc --explain E0282`. diff --git a/tests/ui/typeck/issue-67971.rs b/tests/ui/typeck/issue-67971.rs new file mode 100644 index 000000000..8bf725cb5 --- /dev/null +++ b/tests/ui/typeck/issue-67971.rs @@ -0,0 +1,9 @@ +struct S {} + +fn foo(ctx: &mut S) -> String { //~ ERROR mismatched types + // Don't suggest to remove semicolon as it won't fix anything + ctx.sleep = 0; + //~^ ERROR no field `sleep` on type `&mut S` +} + +fn main() {} diff --git a/tests/ui/typeck/issue-67971.stderr b/tests/ui/typeck/issue-67971.stderr new file mode 100644 index 000000000..5d07f9cc7 --- /dev/null +++ b/tests/ui/typeck/issue-67971.stderr @@ -0,0 +1,18 @@ +error[E0609]: no field `sleep` on type `&mut S` + --> $DIR/issue-67971.rs:5:9 + | +LL | ctx.sleep = 0; + | ^^^^^ unknown field + +error[E0308]: mismatched types + --> $DIR/issue-67971.rs:3:24 + | +LL | fn foo(ctx: &mut S) -> String { + | --- ^^^^^^ expected struct `String`, found `()` + | | + | implicitly returns `()` as its body has no tail or `return` expression + +error: aborting due to 2 previous errors + +Some errors have detailed explanations: E0308, E0609. +For more information about an error, try `rustc --explain E0308`. diff --git a/tests/ui/typeck/issue-68590-reborrow-through-derefmut.rs b/tests/ui/typeck/issue-68590-reborrow-through-derefmut.rs new file mode 100644 index 000000000..e4436260e --- /dev/null +++ b/tests/ui/typeck/issue-68590-reborrow-through-derefmut.rs @@ -0,0 +1,25 @@ +// check-pass + +// rust-lang/rust#68590: confusing diagnostics when reborrowing through DerefMut. + +use std::cell::RefCell; + +struct A; + +struct S<'a> { + a: &'a mut A, +} + +fn take_a(_: &mut A) {} + +fn test<'a>(s: &RefCell<S<'a>>) { + let mut guard = s.borrow_mut(); + take_a(guard.a); + let _s2 = S { a: guard.a }; +} + +fn main() { + let a = &mut A; + let s = RefCell::new(S { a }); + test(&s); +} diff --git a/tests/ui/typeck/issue-69378-ice-on-invalid-type-node-after-recovery.rs b/tests/ui/typeck/issue-69378-ice-on-invalid-type-node-after-recovery.rs new file mode 100644 index 000000000..571692a53 --- /dev/null +++ b/tests/ui/typeck/issue-69378-ice-on-invalid-type-node-after-recovery.rs @@ -0,0 +1,9 @@ +// Regression test for #69378: no type for node after struct parse recovery + +struct Foo { 0: u8 } //~ ERROR expected identifier + +fn test(f: Foo) { + Foo{foo: 4, ..f}; +} + +fn main() {} diff --git a/tests/ui/typeck/issue-69378-ice-on-invalid-type-node-after-recovery.stderr b/tests/ui/typeck/issue-69378-ice-on-invalid-type-node-after-recovery.stderr new file mode 100644 index 000000000..fc7c23a22 --- /dev/null +++ b/tests/ui/typeck/issue-69378-ice-on-invalid-type-node-after-recovery.stderr @@ -0,0 +1,10 @@ +error: expected identifier, found `0` + --> $DIR/issue-69378-ice-on-invalid-type-node-after-recovery.rs:3:14 + | +LL | struct Foo { 0: u8 } + | --- ^ expected identifier + | | + | while parsing this struct + +error: aborting due to previous error + diff --git a/tests/ui/typeck/issue-72225-call-fnmut-through-derefmut.rs b/tests/ui/typeck/issue-72225-call-fnmut-through-derefmut.rs new file mode 100644 index 000000000..3ea05389f --- /dev/null +++ b/tests/ui/typeck/issue-72225-call-fnmut-through-derefmut.rs @@ -0,0 +1,21 @@ +// check-pass + +// rust-lang/rust#72225: confusing diagnostics when calling FnMut through DerefMut. + +use std::cell::RefCell; + +struct S { + f: Box<dyn FnMut()> +} + +fn test(s: &RefCell<S>) { + let mut guard = s.borrow_mut(); + (guard.f)(); +} + +fn main() { + let s = RefCell::new(S { + f: Box::new(|| ()) + }); + test(&s); +} diff --git a/tests/ui/typeck/issue-73592-borrow_mut-through-deref.fixed b/tests/ui/typeck/issue-73592-borrow_mut-through-deref.fixed new file mode 100644 index 000000000..7fdd618c2 --- /dev/null +++ b/tests/ui/typeck/issue-73592-borrow_mut-through-deref.fixed @@ -0,0 +1,59 @@ +// check-pass +// run-rustfix +// +// rust-lang/rust#73592: borrow_mut through Deref should work. +// +// Before #72280, when we see something like `&mut *rcvr.method()`, we +// incorrectly requires `rcvr` to be type-checked as a mut place. While this +// requirement is usually correct for smart pointers, it is overly restrictive +// for types like `Mutex` or `RefCell` which can produce a guard that +// implements `DerefMut` from `&self`. +// +// Making it more confusing, because we use Deref as the fallback when DerefMut +// is implemented, we won't see an issue when the smart pointer does not +// implement `DerefMut`. It only causes an issue when `rcvr` is obtained via a +// type that implements both `Deref` or `DerefMut`. +// +// This bug is only discovered in #73592 after it is already fixed as a side-effect +// of a refactoring made in #72280. + +#![warn(unused_mut)] + +use std::pin::Pin; +use std::cell::RefCell; + +struct S(RefCell<()>); + +fn test_pin(s: Pin<&S>) { + // This works before #72280. + let _ = &mut *s.0.borrow_mut(); +} + +fn test_pin_mut(s: Pin<&mut S>) { + // This should compile but didn't before #72280. + let _ = &mut *s.0.borrow_mut(); +} + +fn test_vec(s: &Vec<RefCell<()>>) { + // This should compile but didn't before #72280. + let _ = &mut *s[0].borrow_mut(); +} + +fn test_mut_pin(s: Pin<&S>) { + //~^ WARN variable does not need to be mutable + let _ = &mut *s.0.borrow_mut(); +} + +fn test_mut_pin_mut(s: Pin<&mut S>) { + //~^ WARN variable does not need to be mutable + let _ = &mut *s.0.borrow_mut(); +} + +fn main() { + let mut s = S(RefCell::new(())); + test_pin(Pin::new(&s)); + test_pin_mut(Pin::new(&mut s)); + test_mut_pin(Pin::new(&s)); + test_mut_pin_mut(Pin::new(&mut s)); + test_vec(&vec![s.0]); +} diff --git a/tests/ui/typeck/issue-73592-borrow_mut-through-deref.rs b/tests/ui/typeck/issue-73592-borrow_mut-through-deref.rs new file mode 100644 index 000000000..3b399e629 --- /dev/null +++ b/tests/ui/typeck/issue-73592-borrow_mut-through-deref.rs @@ -0,0 +1,59 @@ +// check-pass +// run-rustfix +// +// rust-lang/rust#73592: borrow_mut through Deref should work. +// +// Before #72280, when we see something like `&mut *rcvr.method()`, we +// incorrectly requires `rcvr` to be type-checked as a mut place. While this +// requirement is usually correct for smart pointers, it is overly restrictive +// for types like `Mutex` or `RefCell` which can produce a guard that +// implements `DerefMut` from `&self`. +// +// Making it more confusing, because we use Deref as the fallback when DerefMut +// is implemented, we won't see an issue when the smart pointer does not +// implement `DerefMut`. It only causes an issue when `rcvr` is obtained via a +// type that implements both `Deref` or `DerefMut`. +// +// This bug is only discovered in #73592 after it is already fixed as a side-effect +// of a refactoring made in #72280. + +#![warn(unused_mut)] + +use std::pin::Pin; +use std::cell::RefCell; + +struct S(RefCell<()>); + +fn test_pin(s: Pin<&S>) { + // This works before #72280. + let _ = &mut *s.0.borrow_mut(); +} + +fn test_pin_mut(s: Pin<&mut S>) { + // This should compile but didn't before #72280. + let _ = &mut *s.0.borrow_mut(); +} + +fn test_vec(s: &Vec<RefCell<()>>) { + // This should compile but didn't before #72280. + let _ = &mut *s[0].borrow_mut(); +} + +fn test_mut_pin(mut s: Pin<&S>) { + //~^ WARN variable does not need to be mutable + let _ = &mut *s.0.borrow_mut(); +} + +fn test_mut_pin_mut(mut s: Pin<&mut S>) { + //~^ WARN variable does not need to be mutable + let _ = &mut *s.0.borrow_mut(); +} + +fn main() { + let mut s = S(RefCell::new(())); + test_pin(Pin::new(&s)); + test_pin_mut(Pin::new(&mut s)); + test_mut_pin(Pin::new(&s)); + test_mut_pin_mut(Pin::new(&mut s)); + test_vec(&vec![s.0]); +} diff --git a/tests/ui/typeck/issue-73592-borrow_mut-through-deref.stderr b/tests/ui/typeck/issue-73592-borrow_mut-through-deref.stderr new file mode 100644 index 000000000..5f5f672c3 --- /dev/null +++ b/tests/ui/typeck/issue-73592-borrow_mut-through-deref.stderr @@ -0,0 +1,24 @@ +warning: variable does not need to be mutable + --> $DIR/issue-73592-borrow_mut-through-deref.rs:42:17 + | +LL | fn test_mut_pin(mut s: Pin<&S>) { + | ----^ + | | + | help: remove this `mut` + | +note: the lint level is defined here + --> $DIR/issue-73592-borrow_mut-through-deref.rs:20:9 + | +LL | #![warn(unused_mut)] + | ^^^^^^^^^^ + +warning: variable does not need to be mutable + --> $DIR/issue-73592-borrow_mut-through-deref.rs:47:21 + | +LL | fn test_mut_pin_mut(mut s: Pin<&mut S>) { + | ----^ + | | + | help: remove this `mut` + +warning: 2 warnings emitted + diff --git a/tests/ui/typeck/issue-74086.rs b/tests/ui/typeck/issue-74086.rs new file mode 100644 index 000000000..9b7c0d7cc --- /dev/null +++ b/tests/ui/typeck/issue-74086.rs @@ -0,0 +1,5 @@ +fn main() { + static BUG: fn(_) -> u8 = |_| 8; + //~^ ERROR the placeholder `_` is not allowed within types on item signatures for functions [E0121] + //~| ERROR the placeholder `_` is not allowed within types on item signatures for static items +} diff --git a/tests/ui/typeck/issue-74086.stderr b/tests/ui/typeck/issue-74086.stderr new file mode 100644 index 000000000..95ebf9a90 --- /dev/null +++ b/tests/ui/typeck/issue-74086.stderr @@ -0,0 +1,15 @@ +error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions + --> $DIR/issue-74086.rs:2:20 + | +LL | static BUG: fn(_) -> u8 = |_| 8; + | ^ not allowed in type signatures + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for static items + --> $DIR/issue-74086.rs:2:20 + | +LL | static BUG: fn(_) -> u8 = |_| 8; + | ^ not allowed in type signatures + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0121`. diff --git a/tests/ui/typeck/issue-74933.rs b/tests/ui/typeck/issue-74933.rs new file mode 100644 index 000000000..4b6c173b8 --- /dev/null +++ b/tests/ui/typeck/issue-74933.rs @@ -0,0 +1,38 @@ +// check-pass +// +// rust-lang/rust#74933: Lifetime error when indexing with borrowed index + +use std::ops::{Index, IndexMut}; + +struct S(V); +struct K<'a>(&'a ()); +struct V; + +impl<'a> Index<&'a K<'a>> for S { + type Output = V; + + fn index(&self, _: &'a K<'a>) -> &V { + &self.0 + } +} + +impl<'a> IndexMut<&'a K<'a>> for S { + fn index_mut(&mut self, _: &'a K<'a>) -> &mut V { + &mut self.0 + } +} + +impl V { + fn foo(&mut self) {} +} + +fn test(s: &mut S, k: &K<'_>) { + s[k] = V; + s[k].foo(); +} + +fn main() { + let mut s = S(V); + let k = K(&()); + test(&mut s, &k); +} diff --git a/tests/ui/typeck/issue-75883.rs b/tests/ui/typeck/issue-75883.rs new file mode 100644 index 000000000..885acc482 --- /dev/null +++ b/tests/ui/typeck/issue-75883.rs @@ -0,0 +1,22 @@ +// Regression test for #75883. + +pub struct UI {} + +impl UI { + pub fn run() -> Result<_> { + //~^ ERROR: this enum takes 2 generic arguments but 1 generic argument was supplied + //~| ERROR: the placeholder `_` is not allowed within types on item signatures for return types + let mut ui = UI {}; + ui.interact(); + + unimplemented!(); + } + + pub fn interact(&mut self) -> Result<_> { + //~^ ERROR: this enum takes 2 generic arguments but 1 generic argument was supplied + //~| ERROR: the placeholder `_` is not allowed within types on item signatures for return types + unimplemented!(); + } +} + +fn main() {} diff --git a/tests/ui/typeck/issue-75883.stderr b/tests/ui/typeck/issue-75883.stderr new file mode 100644 index 000000000..f5adcabe3 --- /dev/null +++ b/tests/ui/typeck/issue-75883.stderr @@ -0,0 +1,42 @@ +error[E0107]: this enum takes 2 generic arguments but 1 generic argument was supplied + --> $DIR/issue-75883.rs:6:21 + | +LL | pub fn run() -> Result<_> { + | ^^^^^^ - supplied 1 generic argument + | | + | expected 2 generic arguments + | +help: add missing generic argument + | +LL | pub fn run() -> Result<_, E> { + | +++ + +error[E0107]: this enum takes 2 generic arguments but 1 generic argument was supplied + --> $DIR/issue-75883.rs:15:35 + | +LL | pub fn interact(&mut self) -> Result<_> { + | ^^^^^^ - supplied 1 generic argument + | | + | expected 2 generic arguments + | +help: add missing generic argument + | +LL | pub fn interact(&mut self) -> Result<_, E> { + | +++ + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types + --> $DIR/issue-75883.rs:15:42 + | +LL | pub fn interact(&mut self) -> Result<_> { + | ^ not allowed in type signatures + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types + --> $DIR/issue-75883.rs:6:28 + | +LL | pub fn run() -> Result<_> { + | ^ not allowed in type signatures + +error: aborting due to 4 previous errors + +Some errors have detailed explanations: E0107, E0121. +For more information about an error, try `rustc --explain E0107`. diff --git a/tests/ui/typeck/issue-75889.rs b/tests/ui/typeck/issue-75889.rs new file mode 100644 index 000000000..84c067ed0 --- /dev/null +++ b/tests/ui/typeck/issue-75889.rs @@ -0,0 +1,6 @@ +// Regression test for #75889. + +const FOO: dyn Fn() -> _ = ""; //~ ERROR E0121 +static BOO: dyn Fn() -> _ = ""; //~ ERROR E0121 + +fn main() {} diff --git a/tests/ui/typeck/issue-75889.stderr b/tests/ui/typeck/issue-75889.stderr new file mode 100644 index 000000000..1438f481e --- /dev/null +++ b/tests/ui/typeck/issue-75889.stderr @@ -0,0 +1,15 @@ +error[E0121]: the placeholder `_` is not allowed within types on item signatures for constant items + --> $DIR/issue-75889.rs:3:24 + | +LL | const FOO: dyn Fn() -> _ = ""; + | ^ not allowed in type signatures + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for static items + --> $DIR/issue-75889.rs:4:25 + | +LL | static BOO: dyn Fn() -> _ = ""; + | ^ not allowed in type signatures + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0121`. diff --git a/tests/ui/typeck/issue-79040.rs b/tests/ui/typeck/issue-79040.rs new file mode 100644 index 000000000..941612542 --- /dev/null +++ b/tests/ui/typeck/issue-79040.rs @@ -0,0 +1,5 @@ +fn main() { + const FOO = "hello" + 1; //~ ERROR cannot add `{integer}` to `&str` + //~^ missing type for `const` item + println!("{}", FOO); +} diff --git a/tests/ui/typeck/issue-79040.stderr b/tests/ui/typeck/issue-79040.stderr new file mode 100644 index 000000000..c820d1e08 --- /dev/null +++ b/tests/ui/typeck/issue-79040.stderr @@ -0,0 +1,17 @@ +error[E0369]: cannot add `{integer}` to `&str` + --> $DIR/issue-79040.rs:2:25 + | +LL | const FOO = "hello" + 1; + | ------- ^ - {integer} + | | + | &str + +error: missing type for `const` item + --> $DIR/issue-79040.rs:2:14 + | +LL | const FOO = "hello" + 1; + | ^ help: provide a type for the item: `: <type>` + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0369`. diff --git a/tests/ui/typeck/issue-80207-unsized-return.rs b/tests/ui/typeck/issue-80207-unsized-return.rs new file mode 100644 index 000000000..75430da14 --- /dev/null +++ b/tests/ui/typeck/issue-80207-unsized-return.rs @@ -0,0 +1,20 @@ +// check-pass + +trait Foo { + fn do_stuff() -> Self; +} + +trait Bar { + type Output; +} + +impl<T> Foo for dyn Bar<Output = T> +where + Self: Sized, +{ + fn do_stuff() -> Self { + todo!() + } +} + +fn main() {} diff --git a/tests/ui/typeck/issue-80779.rs b/tests/ui/typeck/issue-80779.rs new file mode 100644 index 000000000..1624f6b77 --- /dev/null +++ b/tests/ui/typeck/issue-80779.rs @@ -0,0 +1,13 @@ +// Regression test for #80779. + +pub struct T<'a>(&'a str); + +pub fn f<'a>(val: T<'a>) -> _ { + //~^ ERROR: the placeholder `_` is not allowed within types on item signatures for return types + g(val) +} + +pub fn g(_: T<'static>) -> _ {} +//~^ ERROR: the placeholder `_` is not allowed within types on item signatures for return types + +fn main() {} diff --git a/tests/ui/typeck/issue-80779.stderr b/tests/ui/typeck/issue-80779.stderr new file mode 100644 index 000000000..2261ba616 --- /dev/null +++ b/tests/ui/typeck/issue-80779.stderr @@ -0,0 +1,21 @@ +error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types + --> $DIR/issue-80779.rs:10:28 + | +LL | pub fn g(_: T<'static>) -> _ {} + | ^ + | | + | not allowed in type signatures + | help: replace with the correct return type: `()` + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types + --> $DIR/issue-80779.rs:5:29 + | +LL | pub fn f<'a>(val: T<'a>) -> _ { + | ^ + | | + | not allowed in type signatures + | help: replace with the correct return type: `()` + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0121`. diff --git a/tests/ui/typeck/issue-81293.rs b/tests/ui/typeck/issue-81293.rs new file mode 100644 index 000000000..076b8c944 --- /dev/null +++ b/tests/ui/typeck/issue-81293.rs @@ -0,0 +1,9 @@ +fn main() { + let a: u16; + let b: u16 = 42; + let c: usize = 5; + + a = c + b * 5; //~ ERROR: mismatched types [E0308] + //~| ERROR: mismatched types [E0308] + //~| ERROR: cannot add `u16` to `usize` [E0277] +} diff --git a/tests/ui/typeck/issue-81293.stderr b/tests/ui/typeck/issue-81293.stderr new file mode 100644 index 000000000..6976be711 --- /dev/null +++ b/tests/ui/typeck/issue-81293.stderr @@ -0,0 +1,32 @@ +error[E0308]: mismatched types + --> $DIR/issue-81293.rs:6:13 + | +LL | a = c + b * 5; + | ^^^^^ expected `usize`, found `u16` + +error[E0308]: mismatched types + --> $DIR/issue-81293.rs:6:9 + | +LL | let a: u16; + | --- expected due to this type +... +LL | a = c + b * 5; + | ^^^^^^^^^ expected `u16`, found `usize` + +error[E0277]: cannot add `u16` to `usize` + --> $DIR/issue-81293.rs:6:11 + | +LL | a = c + b * 5; + | ^ no implementation for `usize + u16` + | + = help: the trait `Add<u16>` is not implemented for `usize` + = help: the following other types implement trait `Add<Rhs>`: + <&'a usize as Add<usize>> + <&usize as Add<&usize>> + <usize as Add<&usize>> + <usize as Add> + +error: aborting due to 3 previous errors + +Some errors have detailed explanations: E0277, E0308. +For more information about an error, try `rustc --explain E0277`. diff --git a/tests/ui/typeck/issue-81885.rs b/tests/ui/typeck/issue-81885.rs new file mode 100644 index 000000000..fb3949478 --- /dev/null +++ b/tests/ui/typeck/issue-81885.rs @@ -0,0 +1,9 @@ +const TEST4: fn() -> _ = 42; + //~^ ERROR the placeholder `_` is not allowed within types on item signatures for functions + //~| ERROR the placeholder `_` is not allowed within types on item signatures for constant items + +fn main() { + const TEST5: fn() -> _ = 42; + //~^ ERROR the placeholder `_` is not allowed within types on item signatures for functions + //~| ERROR the placeholder `_` is not allowed within types on item signatures for constant items +} diff --git a/tests/ui/typeck/issue-81885.stderr b/tests/ui/typeck/issue-81885.stderr new file mode 100644 index 000000000..91c08bd82 --- /dev/null +++ b/tests/ui/typeck/issue-81885.stderr @@ -0,0 +1,27 @@ +error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions + --> $DIR/issue-81885.rs:1:22 + | +LL | const TEST4: fn() -> _ = 42; + | ^ not allowed in type signatures + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for constant items + --> $DIR/issue-81885.rs:1:22 + | +LL | const TEST4: fn() -> _ = 42; + | ^ not allowed in type signatures + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions + --> $DIR/issue-81885.rs:6:26 + | +LL | const TEST5: fn() -> _ = 42; + | ^ not allowed in type signatures + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for constant items + --> $DIR/issue-81885.rs:6:26 + | +LL | const TEST5: fn() -> _ = 42; + | ^ not allowed in type signatures + +error: aborting due to 4 previous errors + +For more information about this error, try `rustc --explain E0121`. diff --git a/tests/ui/typeck/issue-81943.rs b/tests/ui/typeck/issue-81943.rs new file mode 100644 index 000000000..18f5970a3 --- /dev/null +++ b/tests/ui/typeck/issue-81943.rs @@ -0,0 +1,13 @@ +// aux-build:issue-81943-lib.rs +extern crate issue_81943_lib as lib; + +fn f<F: Fn(i32)>(f: F) { f(0); } +fn g(t: i32) -> i32 { t } +fn main() { + f(|x| lib::d!(x)); //~ERROR + f(|x| match x { tmp => { g(tmp) } }); //~ERROR + macro_rules! d { + ($e:expr) => { match $e { x => { g(x) } } } //~ERROR + } + f(|x| d!(x)); +} diff --git a/tests/ui/typeck/issue-81943.stderr b/tests/ui/typeck/issue-81943.stderr new file mode 100644 index 000000000..041ff1075 --- /dev/null +++ b/tests/ui/typeck/issue-81943.stderr @@ -0,0 +1,51 @@ +error[E0308]: mismatched types + --> $DIR/issue-81943.rs:7:9 + | +LL | f(|x| lib::d!(x)); + | ^^^^^^^^^^ expected `()`, found `i32` + | + = note: this error originates in the macro `lib::d` (in Nightly builds, run with -Z macro-backtrace for more info) + +error[E0308]: mismatched types + --> $DIR/issue-81943.rs:8:28 + | +LL | f(|x| match x { tmp => { g(tmp) } }); + | -------------------^^^^^^---- + | | | + | | expected `()`, found `i32` + | expected this to be `()` + | +help: consider using a semicolon here + | +LL | f(|x| match x { tmp => { g(tmp); } }); + | + +help: consider using a semicolon here + | +LL | f(|x| match x { tmp => { g(tmp) } };); + | + + +error[E0308]: mismatched types + --> $DIR/issue-81943.rs:10:38 + | +LL | ($e:expr) => { match $e { x => { g(x) } } } + | ------------------^^^^---- + | | | + | | expected `()`, found `i32` + | expected this to be `()` +LL | } +LL | f(|x| d!(x)); + | ----- in this macro invocation + | + = note: this error originates in the macro `d` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider using a semicolon here + | +LL | ($e:expr) => { match $e { x => { g(x); } } } + | + +help: consider using a semicolon here + | +LL | ($e:expr) => { match $e { x => { g(x) } }; } + | + + +error: aborting due to 3 previous errors + +For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/typeck/issue-82772.rs b/tests/ui/typeck/issue-82772.rs new file mode 100644 index 000000000..326273bfe --- /dev/null +++ b/tests/ui/typeck/issue-82772.rs @@ -0,0 +1,13 @@ +// edition:2018 + +fn main() { + use a::ModPrivateStruct; + let Box { 0: _, .. }: Box<()>; //~ ERROR field `0` of + let Box { 1: _, .. }: Box<()>; //~ ERROR field `1` of + let ModPrivateStruct { 1: _, .. } = ModPrivateStruct::default(); //~ ERROR field `1` of +} + +mod a { + #[derive(Default)] + pub struct ModPrivateStruct(u8, u8); +} diff --git a/tests/ui/typeck/issue-82772.stderr b/tests/ui/typeck/issue-82772.stderr new file mode 100644 index 000000000..321143cb9 --- /dev/null +++ b/tests/ui/typeck/issue-82772.stderr @@ -0,0 +1,21 @@ +error[E0451]: field `0` of struct `Box` is private + --> $DIR/issue-82772.rs:5:15 + | +LL | let Box { 0: _, .. }: Box<()>; + | ^^^^ private field + +error[E0451]: field `1` of struct `Box` is private + --> $DIR/issue-82772.rs:6:15 + | +LL | let Box { 1: _, .. }: Box<()>; + | ^^^^ private field + +error[E0451]: field `1` of struct `ModPrivateStruct` is private + --> $DIR/issue-82772.rs:7:28 + | +LL | let ModPrivateStruct { 1: _, .. } = ModPrivateStruct::default(); + | ^^^^ private field + +error: aborting due to 3 previous errors + +For more information about this error, try `rustc --explain E0451`. diff --git a/tests/ui/typeck/issue-83621-placeholder-static-in-extern.rs b/tests/ui/typeck/issue-83621-placeholder-static-in-extern.rs new file mode 100644 index 000000000..16ec2a546 --- /dev/null +++ b/tests/ui/typeck/issue-83621-placeholder-static-in-extern.rs @@ -0,0 +1,7 @@ +// Regression test for #83621. + +extern "C" { + static x: _; //~ ERROR: [E0121] +} + +fn main() {} diff --git a/tests/ui/typeck/issue-83621-placeholder-static-in-extern.stderr b/tests/ui/typeck/issue-83621-placeholder-static-in-extern.stderr new file mode 100644 index 000000000..9376e8bcf --- /dev/null +++ b/tests/ui/typeck/issue-83621-placeholder-static-in-extern.stderr @@ -0,0 +1,9 @@ +error[E0121]: the placeholder `_` is not allowed within types on item signatures for static variables + --> $DIR/issue-83621-placeholder-static-in-extern.rs:4:15 + | +LL | static x: _; + | ^ not allowed in type signatures + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0121`. diff --git a/tests/ui/typeck/issue-83693.rs b/tests/ui/typeck/issue-83693.rs new file mode 100644 index 000000000..a42558220 --- /dev/null +++ b/tests/ui/typeck/issue-83693.rs @@ -0,0 +1,19 @@ +// Regression test for the ICE described in #83693. + +#![feature(fn_traits)] +#![crate_type="lib"] + +impl F { +//~^ ERROR: cannot find type `F` in this scope [E0412] + fn call() { + <Self as Fn(&TestResult)>::call + //~^ ERROR: cannot find type `TestResult` in this scope [E0412] + //~| associated type bindings are not allowed here [E0229] + } +} + +fn call() { + <x as Fn(&usize)>::call + //~^ ERROR: cannot find type `x` in this scope [E0412] + //~| ERROR: associated type bindings are not allowed here [E0229] +} diff --git a/tests/ui/typeck/issue-83693.stderr b/tests/ui/typeck/issue-83693.stderr new file mode 100644 index 000000000..ce4f73b82 --- /dev/null +++ b/tests/ui/typeck/issue-83693.stderr @@ -0,0 +1,37 @@ +error[E0412]: cannot find type `F` in this scope + --> $DIR/issue-83693.rs:6:6 + | +LL | impl F { + | ^ help: a trait with a similar name exists: `Fn` + --> $SRC_DIR/core/src/ops/function.rs:LL:COL + | + = note: similarly named trait `Fn` defined here + +error[E0412]: cannot find type `TestResult` in this scope + --> $DIR/issue-83693.rs:9:22 + | +LL | <Self as Fn(&TestResult)>::call + | ^^^^^^^^^^ not found in this scope + +error[E0412]: cannot find type `x` in this scope + --> $DIR/issue-83693.rs:16:6 + | +LL | <x as Fn(&usize)>::call + | ^ not found in this scope + +error[E0229]: associated type bindings are not allowed here + --> $DIR/issue-83693.rs:9:18 + | +LL | <Self as Fn(&TestResult)>::call + | ^^^^^^^^^^^^^^^ associated type not allowed here + +error[E0229]: associated type bindings are not allowed here + --> $DIR/issue-83693.rs:16:11 + | +LL | <x as Fn(&usize)>::call + | ^^^^^^^^^^ associated type not allowed here + +error: aborting due to 5 previous errors + +Some errors have detailed explanations: E0229, E0412. +For more information about an error, try `rustc --explain E0229`. diff --git a/tests/ui/typeck/issue-84160.rs b/tests/ui/typeck/issue-84160.rs new file mode 100644 index 000000000..7b444df85 --- /dev/null +++ b/tests/ui/typeck/issue-84160.rs @@ -0,0 +1,9 @@ +fn mismatched_types_with_reference(x: &u32) -> &u32 { + if false { + return x; + } + return "test"; + //~^ERROR mismatched types +} + +fn main() {} diff --git a/tests/ui/typeck/issue-84160.stderr b/tests/ui/typeck/issue-84160.stderr new file mode 100644 index 000000000..24c188b3f --- /dev/null +++ b/tests/ui/typeck/issue-84160.stderr @@ -0,0 +1,15 @@ +error[E0308]: mismatched types + --> $DIR/issue-84160.rs:5:12 + | +LL | fn mismatched_types_with_reference(x: &u32) -> &u32 { + | ---- expected `&u32` because of return type +... +LL | return "test"; + | ^^^^^^ expected `u32`, found `str` + | + = note: expected reference `&u32` + found reference `&'static str` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/typeck/issue-84768.rs b/tests/ui/typeck/issue-84768.rs new file mode 100644 index 000000000..ffa92823b --- /dev/null +++ b/tests/ui/typeck/issue-84768.rs @@ -0,0 +1,10 @@ +// Regression test for the ICE described in #84768. + +#![feature(fn_traits)] +#![crate_type="lib"] + +fn transform_mut<F>(f: F) where F: for<'b> FnOnce(&'b mut u8) { + <F as FnOnce(&mut u8)>::call_once(f, 1) + //~^ ERROR: associated type bindings are not allowed here [E0229] + //~| ERROR: mismatched types [E0308] +} diff --git a/tests/ui/typeck/issue-84768.stderr b/tests/ui/typeck/issue-84768.stderr new file mode 100644 index 000000000..09f3aee2d --- /dev/null +++ b/tests/ui/typeck/issue-84768.stderr @@ -0,0 +1,30 @@ +error[E0229]: associated type bindings are not allowed here + --> $DIR/issue-84768.rs:7:11 + | +LL | <F as FnOnce(&mut u8)>::call_once(f, 1) + | ^^^^^^^^^^^^^^^ associated type not allowed here + +error[E0308]: mismatched types + --> $DIR/issue-84768.rs:7:42 + | +LL | <F as FnOnce(&mut u8)>::call_once(f, 1) + | --------------------------------- ^ expected tuple, found integer + | | + | arguments to this function are incorrect + | + = note: expected tuple `(&mut u8,)` + found type `{integer}` +help: the return type of this call is `{integer}` due to the type of the argument passed + --> $DIR/issue-84768.rs:7:5 + | +LL | <F as FnOnce(&mut u8)>::call_once(f, 1) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-^ + | | + | this argument influences the return type of `FnOnce` +note: associated function defined here + --> $SRC_DIR/core/src/ops/function.rs:LL:COL + +error: aborting due to 2 previous errors + +Some errors have detailed explanations: E0229, E0308. +For more information about an error, try `rustc --explain E0229`. diff --git a/tests/ui/typeck/issue-84831.rs b/tests/ui/typeck/issue-84831.rs new file mode 100644 index 000000000..c646f7107 --- /dev/null +++ b/tests/ui/typeck/issue-84831.rs @@ -0,0 +1,9 @@ +fn f() { + std::<0>; //~ ERROR expected value +} +fn j() { + std::<_ as _>; //~ ERROR expected value + //~^ ERROR expected one of `,` or `>`, found keyword `as` +} + +fn main () {} diff --git a/tests/ui/typeck/issue-84831.stderr b/tests/ui/typeck/issue-84831.stderr new file mode 100644 index 000000000..461ccb142 --- /dev/null +++ b/tests/ui/typeck/issue-84831.stderr @@ -0,0 +1,26 @@ +error: expected one of `,` or `>`, found keyword `as` + --> $DIR/issue-84831.rs:5:13 + | +LL | std::<_ as _>; + | ^^ expected one of `,` or `>` + | +help: expressions must be enclosed in braces to be used as const generic arguments + | +LL | std::<{ _ as _ }>; + | + + + +error[E0423]: expected value, found crate `std` + --> $DIR/issue-84831.rs:2:5 + | +LL | std::<0>; + | ^^^^^^^^ not a value + +error[E0423]: expected value, found crate `std` + --> $DIR/issue-84831.rs:5:5 + | +LL | std::<_ as _>; + | ^^^^^^^^^^^^^ not a value + +error: aborting due to 3 previous errors + +For more information about this error, try `rustc --explain E0423`. diff --git a/tests/ui/typeck/issue-86721-return-expr-ice.rev1.stderr b/tests/ui/typeck/issue-86721-return-expr-ice.rev1.stderr new file mode 100644 index 000000000..b1111fcf1 --- /dev/null +++ b/tests/ui/typeck/issue-86721-return-expr-ice.rev1.stderr @@ -0,0 +1,9 @@ +error[E0572]: return statement outside of function body + --> $DIR/issue-86721-return-expr-ice.rs:9:22 + | +LL | const U: usize = return; + | ^^^^^^ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0572`. diff --git a/tests/ui/typeck/issue-86721-return-expr-ice.rev2.stderr b/tests/ui/typeck/issue-86721-return-expr-ice.rev2.stderr new file mode 100644 index 000000000..f489ae200 --- /dev/null +++ b/tests/ui/typeck/issue-86721-return-expr-ice.rev2.stderr @@ -0,0 +1,9 @@ +error[E0572]: return statement outside of function body + --> $DIR/issue-86721-return-expr-ice.rs:15:20 + | +LL | fn foo(a: [(); return]); + | ^^^^^^ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0572`. diff --git a/tests/ui/typeck/issue-86721-return-expr-ice.rs b/tests/ui/typeck/issue-86721-return-expr-ice.rs new file mode 100644 index 000000000..cd7135f18 --- /dev/null +++ b/tests/ui/typeck/issue-86721-return-expr-ice.rs @@ -0,0 +1,17 @@ +// Regression test for the ICE described in #86721. + +// revisions: rev1 rev2 +#![cfg_attr(any(), rev1, rev2)] +#![crate_type="lib"] + +#[cfg(any(rev1))] +trait T { + const U: usize = return; + //[rev1]~^ ERROR: return statement outside of function body [E0572] +} + +#[cfg(any(rev2))] +trait T2 { + fn foo(a: [(); return]); + //[rev2]~^ ERROR: return statement outside of function body [E0572] +} diff --git a/tests/ui/typeck/issue-87181/empty-tuple-method.rs b/tests/ui/typeck/issue-87181/empty-tuple-method.rs new file mode 100644 index 000000000..96b3f8dab --- /dev/null +++ b/tests/ui/typeck/issue-87181/empty-tuple-method.rs @@ -0,0 +1,14 @@ +struct Bar<T> { + bar: T +} + +struct Foo(); +impl Foo { + fn foo(&self) { } +} + +fn main() { + let thing = Bar { bar: Foo }; + thing.bar.foo(); + //~^ ERROR no method named `foo` found for struct constructor `fn() -> Foo {Foo}` in the current scope [E0599] +} diff --git a/tests/ui/typeck/issue-87181/empty-tuple-method.stderr b/tests/ui/typeck/issue-87181/empty-tuple-method.stderr new file mode 100644 index 000000000..f0ca49e6d --- /dev/null +++ b/tests/ui/typeck/issue-87181/empty-tuple-method.stderr @@ -0,0 +1,14 @@ +error[E0599]: no method named `foo` found for struct constructor `fn() -> Foo {Foo}` in the current scope + --> $DIR/empty-tuple-method.rs:12:15 + | +LL | thing.bar.foo(); + | ^^^ method not found in `fn() -> Foo {Foo}` + | +help: use parentheses to construct this tuple struct + | +LL | (thing.bar)().foo(); + | + +++ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0599`. diff --git a/tests/ui/typeck/issue-87181/enum-variant.rs b/tests/ui/typeck/issue-87181/enum-variant.rs new file mode 100644 index 000000000..ed01656ce --- /dev/null +++ b/tests/ui/typeck/issue-87181/enum-variant.rs @@ -0,0 +1,16 @@ +struct Bar<T> { + bar: T +} + +enum Foo{ + Tup() +} +impl Foo { + fn foo(&self) { } +} + +fn main() { + let thing = Bar { bar: Foo::Tup }; + thing.bar.foo(); + //~^ ERROR no method named `foo` found for enum constructor `fn() -> Foo {Foo::Tup}` in the current scope [E0599] +} diff --git a/tests/ui/typeck/issue-87181/enum-variant.stderr b/tests/ui/typeck/issue-87181/enum-variant.stderr new file mode 100644 index 000000000..d313a887a --- /dev/null +++ b/tests/ui/typeck/issue-87181/enum-variant.stderr @@ -0,0 +1,14 @@ +error[E0599]: no method named `foo` found for enum constructor `fn() -> Foo {Foo::Tup}` in the current scope + --> $DIR/enum-variant.rs:14:15 + | +LL | thing.bar.foo(); + | ^^^ method not found in `fn() -> Foo {Foo::Tup}` + | +help: use parentheses to construct this tuple variant + | +LL | (thing.bar)().foo(); + | + +++ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0599`. diff --git a/tests/ui/typeck/issue-87181/tuple-field.rs b/tests/ui/typeck/issue-87181/tuple-field.rs new file mode 100644 index 000000000..00e3b460e --- /dev/null +++ b/tests/ui/typeck/issue-87181/tuple-field.rs @@ -0,0 +1,14 @@ +struct Bar<T> { + bar: T +} + +struct Foo(char, u16); +impl Foo { + fn foo() { } +} + +fn main() { + let thing = Bar { bar: Foo }; + thing.bar.0; + //~^ ERROR no field `0` on type `fn(char, u16) -> Foo {Foo}` [E0609] +} diff --git a/tests/ui/typeck/issue-87181/tuple-field.stderr b/tests/ui/typeck/issue-87181/tuple-field.stderr new file mode 100644 index 000000000..0a7d30b61 --- /dev/null +++ b/tests/ui/typeck/issue-87181/tuple-field.stderr @@ -0,0 +1,14 @@ +error[E0609]: no field `0` on type `fn(char, u16) -> Foo {Foo}` + --> $DIR/tuple-field.rs:12:15 + | +LL | thing.bar.0; + | ^ + | +help: use parentheses to construct this tuple struct + | +LL | (thing.bar)(/* char */, /* u16 */).0; + | + ++++++++++++++++++++++++ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0609`. diff --git a/tests/ui/typeck/issue-87181/tuple-method.rs b/tests/ui/typeck/issue-87181/tuple-method.rs new file mode 100644 index 000000000..631098443 --- /dev/null +++ b/tests/ui/typeck/issue-87181/tuple-method.rs @@ -0,0 +1,14 @@ +struct Bar<T> { + bar: T +} + +struct Foo(u8, i32); +impl Foo { + fn foo() { } +} + +fn main() { + let thing = Bar { bar: Foo }; + thing.bar.foo(); + //~^ ERROR no method named `foo` found for struct constructor `fn(u8, i32) -> Foo {Foo}` in the current scope [E0599] +} diff --git a/tests/ui/typeck/issue-87181/tuple-method.stderr b/tests/ui/typeck/issue-87181/tuple-method.stderr new file mode 100644 index 000000000..de3dc15a5 --- /dev/null +++ b/tests/ui/typeck/issue-87181/tuple-method.stderr @@ -0,0 +1,9 @@ +error[E0599]: no method named `foo` found for struct constructor `fn(u8, i32) -> Foo {Foo}` in the current scope + --> $DIR/tuple-method.rs:12:15 + | +LL | thing.bar.foo(); + | ^^^ method not found in `fn(u8, i32) -> Foo {Foo}` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0599`. diff --git a/tests/ui/typeck/issue-87771-ice-assign-assign-to-bool.rs b/tests/ui/typeck/issue-87771-ice-assign-assign-to-bool.rs new file mode 100644 index 000000000..751dc8719 --- /dev/null +++ b/tests/ui/typeck/issue-87771-ice-assign-assign-to-bool.rs @@ -0,0 +1,4 @@ +fn main() { + let mut a; + a = a = true; //~ ERROR mismatched types +} diff --git a/tests/ui/typeck/issue-87771-ice-assign-assign-to-bool.stderr b/tests/ui/typeck/issue-87771-ice-assign-assign-to-bool.stderr new file mode 100644 index 000000000..56817ee2c --- /dev/null +++ b/tests/ui/typeck/issue-87771-ice-assign-assign-to-bool.stderr @@ -0,0 +1,11 @@ +error[E0308]: mismatched types + --> $DIR/issue-87771-ice-assign-assign-to-bool.rs:3:9 + | +LL | let mut a; + | ----- expected due to the type of this binding +LL | a = a = true; + | ^^^^^^^^ expected `bool`, found `()` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/typeck/issue-87872-missing-inaccessible-field-literal.rs b/tests/ui/typeck/issue-87872-missing-inaccessible-field-literal.rs new file mode 100644 index 000000000..326e958aa --- /dev/null +++ b/tests/ui/typeck/issue-87872-missing-inaccessible-field-literal.rs @@ -0,0 +1,11 @@ +pub mod foo { + pub struct Foo { + pub you_can_use_this_field: bool, + you_cant_use_this_field: bool, + } +} + +fn main() { + foo::Foo {}; + //~^ ERROR cannot construct `Foo` with struct literal syntax due to private fields +} diff --git a/tests/ui/typeck/issue-87872-missing-inaccessible-field-literal.stderr b/tests/ui/typeck/issue-87872-missing-inaccessible-field-literal.stderr new file mode 100644 index 000000000..f0bd3e0dd --- /dev/null +++ b/tests/ui/typeck/issue-87872-missing-inaccessible-field-literal.stderr @@ -0,0 +1,10 @@ +error: cannot construct `Foo` with struct literal syntax due to private fields + --> $DIR/issue-87872-missing-inaccessible-field-literal.rs:9:5 + | +LL | foo::Foo {}; + | ^^^^^^^^ + | + = note: ... and other private field `you_cant_use_this_field` that was not provided + +error: aborting due to previous error + diff --git a/tests/ui/typeck/issue-87872-missing-inaccessible-field-pattern.rs b/tests/ui/typeck/issue-87872-missing-inaccessible-field-pattern.rs new file mode 100644 index 000000000..d28e17559 --- /dev/null +++ b/tests/ui/typeck/issue-87872-missing-inaccessible-field-pattern.rs @@ -0,0 +1,11 @@ +#![allow(dead_code, unused_variables)] + +pub mod foo { + #[derive(Default)] + pub struct Foo { pub visible: bool, invisible: bool, } +} + +fn main() { + let foo::Foo {} = foo::Foo::default(); + //~^ ERROR pattern does not mention field `visible` and inaccessible fields +} diff --git a/tests/ui/typeck/issue-87872-missing-inaccessible-field-pattern.stderr b/tests/ui/typeck/issue-87872-missing-inaccessible-field-pattern.stderr new file mode 100644 index 000000000..dc3097510 --- /dev/null +++ b/tests/ui/typeck/issue-87872-missing-inaccessible-field-pattern.stderr @@ -0,0 +1,18 @@ +error[E0027]: pattern does not mention field `visible` and inaccessible fields + --> $DIR/issue-87872-missing-inaccessible-field-pattern.rs:9:9 + | +LL | let foo::Foo {} = foo::Foo::default(); + | ^^^^^^^^^^^ missing field `visible` and inaccessible fields + | +help: include the missing field in the pattern and ignore the inaccessible fields + | +LL | let foo::Foo { visible, .. } = foo::Foo::default(); + | ~~~~~~~~~~~~~~~ +help: if you don't care about this missing field, you can explicitly ignore it + | +LL | let foo::Foo { .. } = foo::Foo::default(); + | ~~~~~~ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0027`. diff --git a/tests/ui/typeck/issue-87935-unsized-box-expr.rs b/tests/ui/typeck/issue-87935-unsized-box-expr.rs new file mode 100644 index 000000000..cd2a82074 --- /dev/null +++ b/tests/ui/typeck/issue-87935-unsized-box-expr.rs @@ -0,0 +1,10 @@ +#![feature(box_syntax)] +// Box expression needs to be movable, and hence has to be of a Sized type. +fn main() { + let _x: Box<[u32]> = box { loop {} }; + //~^ ERROR: the size for values of type `[u32]` cannot be known at compilation time + + // Check that a deduced size does not cause issues. + let _y: Box<[u32]> = box []; + let _z: Box<[u32; 0]> = box { loop {} }; +} diff --git a/tests/ui/typeck/issue-87935-unsized-box-expr.stderr b/tests/ui/typeck/issue-87935-unsized-box-expr.stderr new file mode 100644 index 000000000..9ff822352 --- /dev/null +++ b/tests/ui/typeck/issue-87935-unsized-box-expr.stderr @@ -0,0 +1,12 @@ +error[E0277]: the size for values of type `[u32]` cannot be known at compilation time + --> $DIR/issue-87935-unsized-box-expr.rs:4:30 + | +LL | let _x: Box<[u32]> = box { loop {} }; + | ^^^^^^^^^^^ doesn't have a size known at compile-time + | + = help: the trait `Sized` is not implemented for `[u32]` + = note: the type of a box expression must have a statically known size + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/typeck/issue-88609.rs b/tests/ui/typeck/issue-88609.rs new file mode 100644 index 000000000..dc459c885 --- /dev/null +++ b/tests/ui/typeck/issue-88609.rs @@ -0,0 +1,19 @@ +// Regression test for #88609: +// The return type for `main` is not normalized while checking if it implements +// the trait `std::process::Termination`. + +// build-pass + +trait Same { + type Output; +} + +impl<T> Same for T { + type Output = T; +} + +type Unit = <() as Same>::Output; + +fn main() -> Result<Unit, std::io::Error> { + unimplemented!() +} diff --git a/tests/ui/typeck/issue-88643.rs b/tests/ui/typeck/issue-88643.rs new file mode 100644 index 000000000..4435cba02 --- /dev/null +++ b/tests/ui/typeck/issue-88643.rs @@ -0,0 +1,19 @@ +// Regression test for the ICE described in #88643. Specifically: +// https://github.com/rust-lang/rust/issues/88643#issuecomment-913128893 +// and https://github.com/rust-lang/rust/issues/88643#issuecomment-913171935 +// and https://github.com/rust-lang/rust/issues/88643#issuecomment-913765984 + +use std::collections::HashMap; + +pub trait T {} + +static CALLBACKS: HashMap<*const dyn T, dyn FnMut(&mut _) + 'static> = HashMap::new(); +//~^ ERROR: the placeholder `_` is not allowed within types on item signatures for static items [E0121] + +static CALLBACKS2: Vec<dyn Fn(& _)> = Vec::new(); +//~^ ERROR: the placeholder `_` is not allowed within types on item signatures for static items [E0121] + +static CALLBACKS3: Option<dyn Fn(& _)> = None; +//~^ ERROR: the placeholder `_` is not allowed within types on item signatures for static items [E0121] + +fn main() {} diff --git a/tests/ui/typeck/issue-88643.stderr b/tests/ui/typeck/issue-88643.stderr new file mode 100644 index 000000000..d5d596b6f --- /dev/null +++ b/tests/ui/typeck/issue-88643.stderr @@ -0,0 +1,21 @@ +error[E0121]: the placeholder `_` is not allowed within types on item signatures for static items + --> $DIR/issue-88643.rs:10:56 + | +LL | static CALLBACKS: HashMap<*const dyn T, dyn FnMut(&mut _) + 'static> = HashMap::new(); + | ^ not allowed in type signatures + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for static items + --> $DIR/issue-88643.rs:13:33 + | +LL | static CALLBACKS2: Vec<dyn Fn(& _)> = Vec::new(); + | ^ not allowed in type signatures + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for static items + --> $DIR/issue-88643.rs:16:36 + | +LL | static CALLBACKS3: Option<dyn Fn(& _)> = None; + | ^ not allowed in type signatures + +error: aborting due to 3 previous errors + +For more information about this error, try `rustc --explain E0121`. diff --git a/tests/ui/typeck/issue-88803-call-expr-method.fixed b/tests/ui/typeck/issue-88803-call-expr-method.fixed new file mode 100644 index 000000000..19b96ecf3 --- /dev/null +++ b/tests/ui/typeck/issue-88803-call-expr-method.fixed @@ -0,0 +1,9 @@ +// run-rustfix + +fn main() { + let a = Some(42); + println!( + "The value is {}.", + a.unwrap() //~ERROR [E0615] + ); +} diff --git a/tests/ui/typeck/issue-88803-call-expr-method.rs b/tests/ui/typeck/issue-88803-call-expr-method.rs new file mode 100644 index 000000000..a06199466 --- /dev/null +++ b/tests/ui/typeck/issue-88803-call-expr-method.rs @@ -0,0 +1,9 @@ +// run-rustfix + +fn main() { + let a = Some(42); + println!( + "The value is {}.", + (a.unwrap)() //~ERROR [E0615] + ); +} diff --git a/tests/ui/typeck/issue-88803-call-expr-method.stderr b/tests/ui/typeck/issue-88803-call-expr-method.stderr new file mode 100644 index 000000000..645c04b87 --- /dev/null +++ b/tests/ui/typeck/issue-88803-call-expr-method.stderr @@ -0,0 +1,15 @@ +error[E0615]: attempted to take value of method `unwrap` on type `Option<{integer}>` + --> $DIR/issue-88803-call-expr-method.rs:7:12 + | +LL | (a.unwrap)() + | ^^^^^^ method, not a field + | +help: remove wrapping parentheses to call the method + | +LL - (a.unwrap)() +LL + a.unwrap() + | + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0615`. diff --git a/tests/ui/typeck/issue-88844.rs b/tests/ui/typeck/issue-88844.rs new file mode 100644 index 000000000..116c75aab --- /dev/null +++ b/tests/ui/typeck/issue-88844.rs @@ -0,0 +1,14 @@ +// Regression test for #88844. + +struct Struct { value: i32 } +//~^ NOTE: similarly named struct `Struct` defined here + +impl Stuct { +//~^ ERROR: cannot find type `Stuct` in this scope [E0412] +//~| HELP: a struct with a similar name exists + fn new() -> Self { + Self { value: 42 } + } +} + +fn main() {} diff --git a/tests/ui/typeck/issue-88844.stderr b/tests/ui/typeck/issue-88844.stderr new file mode 100644 index 000000000..90bba90be --- /dev/null +++ b/tests/ui/typeck/issue-88844.stderr @@ -0,0 +1,12 @@ +error[E0412]: cannot find type `Stuct` in this scope + --> $DIR/issue-88844.rs:6:6 + | +LL | struct Struct { value: i32 } + | ------------- similarly named struct `Struct` defined here +... +LL | impl Stuct { + | ^^^^^ help: a struct with a similar name exists: `Struct` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0412`. diff --git a/tests/ui/typeck/issue-89044-wrapped-expr-method.fixed b/tests/ui/typeck/issue-89044-wrapped-expr-method.fixed new file mode 100644 index 000000000..0a3086a34 --- /dev/null +++ b/tests/ui/typeck/issue-89044-wrapped-expr-method.fixed @@ -0,0 +1,9 @@ +// run-rustfix + +fn main() { + let a = Some(42); + println!( + "The value is {}.", + (a.unwrap()) //~ERROR [E0615] + ); +} diff --git a/tests/ui/typeck/issue-89044-wrapped-expr-method.rs b/tests/ui/typeck/issue-89044-wrapped-expr-method.rs new file mode 100644 index 000000000..83617e035 --- /dev/null +++ b/tests/ui/typeck/issue-89044-wrapped-expr-method.rs @@ -0,0 +1,9 @@ +// run-rustfix + +fn main() { + let a = Some(42); + println!( + "The value is {}.", + (a.unwrap) //~ERROR [E0615] + ); +} diff --git a/tests/ui/typeck/issue-89044-wrapped-expr-method.stderr b/tests/ui/typeck/issue-89044-wrapped-expr-method.stderr new file mode 100644 index 000000000..6fa0915dc --- /dev/null +++ b/tests/ui/typeck/issue-89044-wrapped-expr-method.stderr @@ -0,0 +1,14 @@ +error[E0615]: attempted to take value of method `unwrap` on type `Option<{integer}>` + --> $DIR/issue-89044-wrapped-expr-method.rs:7:12 + | +LL | (a.unwrap) + | ^^^^^^ method, not a field + | +help: use parentheses to call the method + | +LL | (a.unwrap()) + | ++ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0615`. diff --git a/tests/ui/typeck/issue-89275.rs b/tests/ui/typeck/issue-89275.rs new file mode 100644 index 000000000..b91c00175 --- /dev/null +++ b/tests/ui/typeck/issue-89275.rs @@ -0,0 +1,29 @@ +#![recursion_limit = "5"] // To reduce noise + +//expect mutability error when ambiguous traits are in scope +//and not an overflow error on the span in the main function. + +struct Ratio<T>(T); + +pub trait Pow { + fn pow(self) -> Self; +} + +impl<'a, T> Pow for &'a Ratio<T> +where + &'a T: Pow, +{ + fn pow(self) -> Self { + self + } +} + +fn downcast<'a, W: ?Sized>() -> &'a W { + todo!() +} + +struct Other; + +fn main() { + let other: &mut Other = downcast();//~ERROR 28:29: 28:39: mismatched types [E0308] +} diff --git a/tests/ui/typeck/issue-89275.stderr b/tests/ui/typeck/issue-89275.stderr new file mode 100644 index 000000000..d73e647d2 --- /dev/null +++ b/tests/ui/typeck/issue-89275.stderr @@ -0,0 +1,14 @@ +error[E0308]: mismatched types + --> $DIR/issue-89275.rs:28:29 + | +LL | let other: &mut Other = downcast(); + | ---------- ^^^^^^^^^^ types differ in mutability + | | + | expected due to this + | + = note: expected mutable reference `&mut Other` + found reference `&_` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/typeck/issue-89806.rs b/tests/ui/typeck/issue-89806.rs new file mode 100644 index 000000000..69cec0865 --- /dev/null +++ b/tests/ui/typeck/issue-89806.rs @@ -0,0 +1,3 @@ +fn main() { + 0u8.as_ref(); //~ ERROR no method named `as_ref` found for type `u8` in the current scope +} diff --git a/tests/ui/typeck/issue-89806.stderr b/tests/ui/typeck/issue-89806.stderr new file mode 100644 index 000000000..c36b4967e --- /dev/null +++ b/tests/ui/typeck/issue-89806.stderr @@ -0,0 +1,9 @@ +error[E0599]: no method named `as_ref` found for type `u8` in the current scope + --> $DIR/issue-89806.rs:2:9 + | +LL | 0u8.as_ref(); + | ^^^^^^ method not found in `u8` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0599`. diff --git a/tests/ui/typeck/issue-89856.rs b/tests/ui/typeck/issue-89856.rs new file mode 100644 index 000000000..b021e349e --- /dev/null +++ b/tests/ui/typeck/issue-89856.rs @@ -0,0 +1,8 @@ +fn take_str_maybe(x: Option<&str>) -> Option<&str> { None } + +fn main() { + let string = String::from("Hello, world"); + let option = Some(&string); + take_str_maybe(option); + //~^ ERROR: mismatched types [E0308] +} diff --git a/tests/ui/typeck/issue-89856.stderr b/tests/ui/typeck/issue-89856.stderr new file mode 100644 index 000000000..5fa1ae1a5 --- /dev/null +++ b/tests/ui/typeck/issue-89856.stderr @@ -0,0 +1,23 @@ +error[E0308]: mismatched types + --> $DIR/issue-89856.rs:6:20 + | +LL | take_str_maybe(option); + | -------------- ^^^^^^ expected `str`, found struct `String` + | | + | arguments to this function are incorrect + | + = note: expected enum `Option<&str>` + found enum `Option<&String>` +note: function defined here + --> $DIR/issue-89856.rs:1:4 + | +LL | fn take_str_maybe(x: Option<&str>) -> Option<&str> { None } + | ^^^^^^^^^^^^^^ --------------- +help: try converting the passed type into a `&str` + | +LL | take_str_maybe(option.map(|x| &**x)); + | ++++++++++++++ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/typeck/issue-89935.rs b/tests/ui/typeck/issue-89935.rs new file mode 100644 index 000000000..03f8f09a7 --- /dev/null +++ b/tests/ui/typeck/issue-89935.rs @@ -0,0 +1,18 @@ +// check-pass + +trait Foo: Baz {} +trait Bar {} +trait Baz: Bar { + fn bar(&self); +} + +impl<T: Foo> Bar for T {} +impl<T: Foo> Baz for T { + fn bar(&self) {} +} + +fn accept_foo(x: Box<dyn Foo>) { + x.bar(); +} + +fn main() {} diff --git a/tests/ui/typeck/issue-90101.rs b/tests/ui/typeck/issue-90101.rs new file mode 100644 index 000000000..1954ee6f1 --- /dev/null +++ b/tests/ui/typeck/issue-90101.rs @@ -0,0 +1,8 @@ +use std::path::{Path, PathBuf}; + +fn func(path: impl Into<PathBuf>, code: impl Into<String>) {} + +fn main() { + func(Path::new("hello").to_path_buf().to_string_lossy(), "world") + //~^ ERROR [E0277] +} diff --git a/tests/ui/typeck/issue-90101.stderr b/tests/ui/typeck/issue-90101.stderr new file mode 100644 index 000000000..d2729d853 --- /dev/null +++ b/tests/ui/typeck/issue-90101.stderr @@ -0,0 +1,24 @@ +error[E0277]: the trait bound `PathBuf: From<Cow<'_, str>>` is not satisfied + --> $DIR/issue-90101.rs:6:10 + | +LL | func(Path::new("hello").to_path_buf().to_string_lossy(), "world") + | ---- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `From<Cow<'_, str>>` is not implemented for `PathBuf` + | | + | required by a bound introduced by this call + | + = help: the following other types implement trait `From<T>`: + <PathBuf as From<&T>> + <PathBuf as From<Box<Path>>> + <PathBuf as From<Cow<'a, Path>>> + <PathBuf as From<OsString>> + <PathBuf as From<String>> + = note: required for `Cow<'_, str>` to implement `Into<PathBuf>` +note: required by a bound in `func` + --> $DIR/issue-90101.rs:3:20 + | +LL | fn func(path: impl Into<PathBuf>, code: impl Into<String>) {} + | ^^^^^^^^^^^^^ required by this bound in `func` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/typeck/issue-90164.rs b/tests/ui/typeck/issue-90164.rs new file mode 100644 index 000000000..63350433e --- /dev/null +++ b/tests/ui/typeck/issue-90164.rs @@ -0,0 +1,9 @@ +fn copy<R: Unpin, W>(_: R, _: W) {} + +fn f<T>(r: T) { + let w = (); + copy(r, w); + //~^ ERROR [E0277] +} + +fn main() {} diff --git a/tests/ui/typeck/issue-90164.stderr b/tests/ui/typeck/issue-90164.stderr new file mode 100644 index 000000000..1e2f1bae3 --- /dev/null +++ b/tests/ui/typeck/issue-90164.stderr @@ -0,0 +1,22 @@ +error[E0277]: `T` cannot be unpinned + --> $DIR/issue-90164.rs:5:10 + | +LL | copy(r, w); + | ---- ^ the trait `Unpin` is not implemented for `T` + | | + | required by a bound introduced by this call + | + = note: consider using `Box::pin` +note: required by a bound in `copy` + --> $DIR/issue-90164.rs:1:12 + | +LL | fn copy<R: Unpin, W>(_: R, _: W) {} + | ^^^^^ required by this bound in `copy` +help: consider restricting type parameter `T` + | +LL | fn f<T: std::marker::Unpin>(r: T) { + | ++++++++++++++++++++ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/typeck/issue-90319.rs b/tests/ui/typeck/issue-90319.rs new file mode 100644 index 000000000..57e6ac7cf --- /dev/null +++ b/tests/ui/typeck/issue-90319.rs @@ -0,0 +1,17 @@ +struct Wrapper<T>(T); + +trait Trait { + fn method(&self) {} +} + +impl<'a, T> Trait for Wrapper<&'a T> where Wrapper<T>: Trait {} + +fn get<T>() -> T { + unimplemented!() +} + +fn main() { + let thing = get::<Thing>();//~ERROR cannot find type `Thing` in this scope [E0412] + let wrapper = Wrapper(thing); + Trait::method(&wrapper); +} diff --git a/tests/ui/typeck/issue-90319.stderr b/tests/ui/typeck/issue-90319.stderr new file mode 100644 index 000000000..61549dd70 --- /dev/null +++ b/tests/ui/typeck/issue-90319.stderr @@ -0,0 +1,9 @@ +error[E0412]: cannot find type `Thing` in this scope + --> $DIR/issue-90319.rs:14:23 + | +LL | let thing = get::<Thing>(); + | ^^^^^ not found in this scope + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0412`. diff --git a/tests/ui/typeck/issue-90483-inaccessible-field-adjustment.rs b/tests/ui/typeck/issue-90483-inaccessible-field-adjustment.rs new file mode 100644 index 000000000..74e50d46e --- /dev/null +++ b/tests/ui/typeck/issue-90483-inaccessible-field-adjustment.rs @@ -0,0 +1,14 @@ +// edition:2021 + +mod m { + pub struct S { foo: i32 } + impl S { + pub fn foo(&self) -> i32 { 42 } + } +} + +fn bar(s: &m::S) { + || s.foo() + s.foo; //~ ERROR E0616 +} + +fn main() {} diff --git a/tests/ui/typeck/issue-90483-inaccessible-field-adjustment.stderr b/tests/ui/typeck/issue-90483-inaccessible-field-adjustment.stderr new file mode 100644 index 000000000..02cdc102c --- /dev/null +++ b/tests/ui/typeck/issue-90483-inaccessible-field-adjustment.stderr @@ -0,0 +1,14 @@ +error[E0616]: field `foo` of struct `S` is private + --> $DIR/issue-90483-inaccessible-field-adjustment.rs:11:18 + | +LL | || s.foo() + s.foo; + | ^^^ private field + | +help: a method `foo` also exists, call it with parentheses + | +LL | || s.foo() + s.foo(); + | ++ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0616`. diff --git a/tests/ui/typeck/issue-90804-incorrect-reference-suggestion.rs b/tests/ui/typeck/issue-90804-incorrect-reference-suggestion.rs new file mode 100644 index 000000000..f891a42fc --- /dev/null +++ b/tests/ui/typeck/issue-90804-incorrect-reference-suggestion.rs @@ -0,0 +1,11 @@ +// Do not suggest referencing the parameter to `check` + +trait Marker<T> {} + +impl<T> Marker<i32> for T {} + +pub fn check<T: Marker<u32>>(_: T) {} + +pub fn main() { + check::<()>(()); //~ ERROR [E0277] +} diff --git a/tests/ui/typeck/issue-90804-incorrect-reference-suggestion.stderr b/tests/ui/typeck/issue-90804-incorrect-reference-suggestion.stderr new file mode 100644 index 000000000..08eab0253 --- /dev/null +++ b/tests/ui/typeck/issue-90804-incorrect-reference-suggestion.stderr @@ -0,0 +1,17 @@ +error[E0277]: the trait bound `(): Marker<u32>` is not satisfied + --> $DIR/issue-90804-incorrect-reference-suggestion.rs:10:17 + | +LL | check::<()>(()); + | ----------- ^^ the trait `Marker<u32>` is not implemented for `()` + | | + | required by a bound introduced by this call + | +note: required by a bound in `check` + --> $DIR/issue-90804-incorrect-reference-suggestion.rs:7:17 + | +LL | pub fn check<T: Marker<u32>>(_: T) {} + | ^^^^^^^^^^^ required by this bound in `check` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/typeck/issue-91210-ptr-method.fixed b/tests/ui/typeck/issue-91210-ptr-method.fixed new file mode 100644 index 000000000..94200cce7 --- /dev/null +++ b/tests/ui/typeck/issue-91210-ptr-method.fixed @@ -0,0 +1,15 @@ +// Regression test for issue #91210. + +// run-rustfix + +#![allow(unused)] + +struct Foo { read: i32 } + +unsafe fn blah(x: *mut Foo) { + (*x).read = 4; + //~^ ERROR: attempted to take value of method + //~| HELP: to access the field, dereference first +} + +fn main() {} diff --git a/tests/ui/typeck/issue-91210-ptr-method.rs b/tests/ui/typeck/issue-91210-ptr-method.rs new file mode 100644 index 000000000..ed0ce6eff --- /dev/null +++ b/tests/ui/typeck/issue-91210-ptr-method.rs @@ -0,0 +1,15 @@ +// Regression test for issue #91210. + +// run-rustfix + +#![allow(unused)] + +struct Foo { read: i32 } + +unsafe fn blah(x: *mut Foo) { + x.read = 4; + //~^ ERROR: attempted to take value of method + //~| HELP: to access the field, dereference first +} + +fn main() {} diff --git a/tests/ui/typeck/issue-91210-ptr-method.stderr b/tests/ui/typeck/issue-91210-ptr-method.stderr new file mode 100644 index 000000000..7a0cfb2cf --- /dev/null +++ b/tests/ui/typeck/issue-91210-ptr-method.stderr @@ -0,0 +1,14 @@ +error[E0615]: attempted to take value of method `read` on type `*mut Foo` + --> $DIR/issue-91210-ptr-method.rs:10:7 + | +LL | x.read = 4; + | ^^^^ method, not a field + | +help: to access the field, dereference first + | +LL | (*x).read = 4; + | ++ + + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0615`. diff --git a/tests/ui/typeck/issue-91267.rs b/tests/ui/typeck/issue-91267.rs new file mode 100644 index 000000000..4e39cfab5 --- /dev/null +++ b/tests/ui/typeck/issue-91267.rs @@ -0,0 +1,8 @@ +#![feature(type_ascription)] + +fn main() { + type_ascribe!(0, u8<e<5>=e>) + //~^ ERROR: cannot find type `e` in this scope [E0412] + //~| ERROR: associated type bindings are not allowed here [E0229] + //~| ERROR: mismatched types [E0308] +} diff --git a/tests/ui/typeck/issue-91267.stderr b/tests/ui/typeck/issue-91267.stderr new file mode 100644 index 000000000..72acd9c67 --- /dev/null +++ b/tests/ui/typeck/issue-91267.stderr @@ -0,0 +1,24 @@ +error[E0412]: cannot find type `e` in this scope + --> $DIR/issue-91267.rs:4:30 + | +LL | type_ascribe!(0, u8<e<5>=e>) + | ^ not found in this scope + +error[E0229]: associated type bindings are not allowed here + --> $DIR/issue-91267.rs:4:25 + | +LL | type_ascribe!(0, u8<e<5>=e>) + | ^^^^^^ associated type not allowed here + +error[E0308]: mismatched types + --> $DIR/issue-91267.rs:4:5 + | +LL | fn main() { + | - expected `()` because of default return type +LL | type_ascribe!(0, u8<e<5>=e>) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `()`, found `u8` + +error: aborting due to 3 previous errors + +Some errors have detailed explanations: E0229, E0308, E0412. +For more information about an error, try `rustc --explain E0229`. diff --git a/tests/ui/typeck/issue-91328.fixed b/tests/ui/typeck/issue-91328.fixed new file mode 100644 index 000000000..c0384399a --- /dev/null +++ b/tests/ui/typeck/issue-91328.fixed @@ -0,0 +1,47 @@ +// Regression test for issue #91328. + +// run-rustfix + +#![allow(dead_code)] + +fn foo(r: Result<Vec<i32>, i32>) -> i32 { + match r.as_deref() { + //~^ HELP: consider using `as_deref` here + Ok([a, b]) => a + b, + //~^ ERROR: expected an array or slice + //~| NOTE: pattern cannot match with input type + _ => 42, + } +} + +fn bar(o: Option<Vec<i32>>) -> i32 { + match o.as_deref() { + //~^ HELP: consider using `as_deref` here + Some([a, b]) => a + b, + //~^ ERROR: expected an array or slice + //~| NOTE: pattern cannot match with input type + _ => 42, + } +} + +fn baz(v: Vec<i32>) -> i32 { + match v[..] { + //~^ HELP: consider slicing here + [a, b] => a + b, + //~^ ERROR: expected an array or slice + //~| NOTE: pattern cannot match with input type + _ => 42, + } +} + +fn qux(a: &Option<Box<[i32; 2]>>) -> i32 { + match a.as_deref() { + //~^ HELP: consider using `as_deref` here + Some([a, b]) => a + b, + //~^ ERROR: expected an array or slice + //~| NOTE: pattern cannot match with input type + _ => 42, + } +} + +fn main() {} diff --git a/tests/ui/typeck/issue-91328.rs b/tests/ui/typeck/issue-91328.rs new file mode 100644 index 000000000..63602d26f --- /dev/null +++ b/tests/ui/typeck/issue-91328.rs @@ -0,0 +1,47 @@ +// Regression test for issue #91328. + +// run-rustfix + +#![allow(dead_code)] + +fn foo(r: Result<Vec<i32>, i32>) -> i32 { + match r { + //~^ HELP: consider using `as_deref` here + Ok([a, b]) => a + b, + //~^ ERROR: expected an array or slice + //~| NOTE: pattern cannot match with input type + _ => 42, + } +} + +fn bar(o: Option<Vec<i32>>) -> i32 { + match o { + //~^ HELP: consider using `as_deref` here + Some([a, b]) => a + b, + //~^ ERROR: expected an array or slice + //~| NOTE: pattern cannot match with input type + _ => 42, + } +} + +fn baz(v: Vec<i32>) -> i32 { + match v { + //~^ HELP: consider slicing here + [a, b] => a + b, + //~^ ERROR: expected an array or slice + //~| NOTE: pattern cannot match with input type + _ => 42, + } +} + +fn qux(a: &Option<Box<[i32; 2]>>) -> i32 { + match a { + //~^ HELP: consider using `as_deref` here + Some([a, b]) => a + b, + //~^ ERROR: expected an array or slice + //~| NOTE: pattern cannot match with input type + _ => 42, + } +} + +fn main() {} diff --git a/tests/ui/typeck/issue-91328.stderr b/tests/ui/typeck/issue-91328.stderr new file mode 100644 index 000000000..f2f407bca --- /dev/null +++ b/tests/ui/typeck/issue-91328.stderr @@ -0,0 +1,39 @@ +error[E0529]: expected an array or slice, found `Vec<i32>` + --> $DIR/issue-91328.rs:10:12 + | +LL | match r { + | - help: consider using `as_deref` here: `r.as_deref()` +LL | +LL | Ok([a, b]) => a + b, + | ^^^^^^ pattern cannot match with input type `Vec<i32>` + +error[E0529]: expected an array or slice, found `Vec<i32>` + --> $DIR/issue-91328.rs:20:14 + | +LL | match o { + | - help: consider using `as_deref` here: `o.as_deref()` +LL | +LL | Some([a, b]) => a + b, + | ^^^^^^ pattern cannot match with input type `Vec<i32>` + +error[E0529]: expected an array or slice, found `Vec<i32>` + --> $DIR/issue-91328.rs:30:9 + | +LL | match v { + | - help: consider slicing here: `v[..]` +LL | +LL | [a, b] => a + b, + | ^^^^^^ pattern cannot match with input type `Vec<i32>` + +error[E0529]: expected an array or slice, found `Box<[i32; 2]>` + --> $DIR/issue-91328.rs:40:14 + | +LL | match a { + | - help: consider using `as_deref` here: `a.as_deref()` +LL | +LL | Some([a, b]) => a + b, + | ^^^^^^ pattern cannot match with input type `Box<[i32; 2]>` + +error: aborting due to 4 previous errors + +For more information about this error, try `rustc --explain E0529`. diff --git a/tests/ui/typeck/issue-91334.rs b/tests/ui/typeck/issue-91334.rs new file mode 100644 index 000000000..bf9a5a626 --- /dev/null +++ b/tests/ui/typeck/issue-91334.rs @@ -0,0 +1,10 @@ +// Regression test for the ICE described in issue #91334. + +// error-pattern: this file contains an unclosed delimiter +// error-pattern: expected one of +// error-pattern: mismatched closing delimiter +// error-pattern: mismatched types + +#![feature(generators)] + +fn f(){||yield(((){), diff --git a/tests/ui/typeck/issue-91334.stderr b/tests/ui/typeck/issue-91334.stderr new file mode 100644 index 000000000..8508f7a38 --- /dev/null +++ b/tests/ui/typeck/issue-91334.stderr @@ -0,0 +1,50 @@ +error: this file contains an unclosed delimiter + --> $DIR/issue-91334.rs:10:23 + | +LL | fn f(){||yield(((){), + | - - ^ + | | | + | | unclosed delimiter + | unclosed delimiter + +error: this file contains an unclosed delimiter + --> $DIR/issue-91334.rs:10:23 + | +LL | fn f(){||yield(((){), + | - - ^ + | | | + | | unclosed delimiter + | unclosed delimiter + +error: expected one of `)`, `,`, `.`, `?`, or an operator, found `{` + --> $DIR/issue-91334.rs:10:19 + | +LL | fn f(){||yield(((){), + | ^ + | | + | expected one of `)`, `,`, `.`, `?`, or an operator + | help: missing `,` + +error: mismatched closing delimiter: `)` + --> $DIR/issue-91334.rs:10:19 + | +LL | fn f(){||yield(((){), + | - ^^ mismatched closing delimiter + | | | + | | unclosed delimiter + | closing delimiter possibly meant for this + +error[E0308]: mismatched types + --> $DIR/issue-91334.rs:10:8 + | +LL | fn f(){||yield(((){), + | -^^^^^^^^^^^^^^^ expected `()`, found generator + | | + | help: a return type might be missing here: `-> _` + | + = note: expected unit type `()` + found generator `[generator@$DIR/issue-91334.rs:10:8: 10:10]` + +error: aborting due to 5 previous errors + +For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/typeck/issue-91450-inner-ty-error.rs b/tests/ui/typeck/issue-91450-inner-ty-error.rs new file mode 100644 index 000000000..3c7c990d4 --- /dev/null +++ b/tests/ui/typeck/issue-91450-inner-ty-error.rs @@ -0,0 +1,7 @@ +// Regression test for #91450. +// This test ensures that the compiler does not suggest `Foo<[type error]>` in diagnostic messages. + +fn foo() -> Option<_> {} //~ ERROR: [E0308] +//~^ ERROR: the placeholder `_` is not allowed + +fn main() {} diff --git a/tests/ui/typeck/issue-91450-inner-ty-error.stderr b/tests/ui/typeck/issue-91450-inner-ty-error.stderr new file mode 100644 index 000000000..32f4c8f6f --- /dev/null +++ b/tests/ui/typeck/issue-91450-inner-ty-error.stderr @@ -0,0 +1,21 @@ +error[E0308]: mismatched types + --> $DIR/issue-91450-inner-ty-error.rs:4:13 + | +LL | fn foo() -> Option<_> {} + | --- ^^^^^^^^^ expected enum `Option`, found `()` + | | + | implicitly returns `()` as its body has no tail or `return` expression + | + = note: expected enum `Option<_>` + found unit type `()` + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types + --> $DIR/issue-91450-inner-ty-error.rs:4:20 + | +LL | fn foo() -> Option<_> {} + | ^ not allowed in type signatures + +error: aborting due to 2 previous errors + +Some errors have detailed explanations: E0121, E0308. +For more information about an error, try `rustc --explain E0121`. diff --git a/tests/ui/typeck/issue-91633.rs b/tests/ui/typeck/issue-91633.rs new file mode 100644 index 000000000..331a798dd --- /dev/null +++ b/tests/ui/typeck/issue-91633.rs @@ -0,0 +1,8 @@ +// check-pass +fn f<T> (it: &[T]) +where + [T] : std::ops::Index<usize>, +{ + let _ = &it[0]; +} +fn main(){} diff --git a/tests/ui/typeck/issue-92481.rs b/tests/ui/typeck/issue-92481.rs new file mode 100644 index 000000000..0a6b1843d --- /dev/null +++ b/tests/ui/typeck/issue-92481.rs @@ -0,0 +1,14 @@ +//check-fail + +#![crate_type="lib"] + +fn r({) { + Ok { //~ ERROR mismatched types [E0308] + d..||_=m + } +} +//~^^^^^ ERROR expected parameter name, found `{` +//~| ERROR expected one of `,`, `:`, or `}`, found `..` +//~^^^^^ ERROR cannot find value `d` in this scope [E0425] +//~| ERROR cannot find value `m` in this scope [E0425] +//~| ERROR variant `Result<_, _>::Ok` has no field named `d` [E0559] diff --git a/tests/ui/typeck/issue-92481.stderr b/tests/ui/typeck/issue-92481.stderr new file mode 100644 index 000000000..cd778a649 --- /dev/null +++ b/tests/ui/typeck/issue-92481.stderr @@ -0,0 +1,60 @@ +error: expected parameter name, found `{` + --> $DIR/issue-92481.rs:5:6 + | +LL | fn r({) { + | ^ expected parameter name + +error: expected one of `,`, `:`, or `}`, found `..` + --> $DIR/issue-92481.rs:5:6 + | +LL | fn r({) { + | ^ unclosed delimiter +LL | Ok { +LL | d..||_=m + | -^ + | | + | help: `}` may belong here + +error[E0425]: cannot find value `d` in this scope + --> $DIR/issue-92481.rs:7:9 + | +LL | d..||_=m + | ^ not found in this scope + +error[E0425]: cannot find value `m` in this scope + --> $DIR/issue-92481.rs:7:16 + | +LL | d..||_=m + | ^ not found in this scope + +error[E0559]: variant `Result<_, _>::Ok` has no field named `d` + --> $DIR/issue-92481.rs:7:9 + | +LL | d..||_=m + | ^ field does not exist + --> $SRC_DIR/core/src/result.rs:LL:COL + | + = note: `Result<_, _>::Ok` defined here + | +help: `Result<_, _>::Ok` is a tuple variant, use the appropriate syntax + | +LL | Result<_, _>::Ok(/* fields */) + | + +error[E0308]: mismatched types + --> $DIR/issue-92481.rs:6:5 + | +LL | fn r({) { + | - help: a return type might be missing here: `-> _` +LL | / Ok { +LL | | d..||_=m +LL | | } + | |_____^ expected `()`, found enum `Result` + | + = note: expected unit type `()` + found enum `Result<_, _>` + +error: aborting due to 6 previous errors + +Some errors have detailed explanations: E0308, E0425, E0559. +For more information about an error, try `rustc --explain E0308`. diff --git a/tests/ui/typeck/issue-93486.rs b/tests/ui/typeck/issue-93486.rs new file mode 100644 index 000000000..f8f98d5c1 --- /dev/null +++ b/tests/ui/typeck/issue-93486.rs @@ -0,0 +1,6 @@ +fn main() { + while let 1 = 1 { + vec![].last_mut().unwrap() = 3_u8; + //~^ ERROR invalid left-hand side of assignment + } +} diff --git a/tests/ui/typeck/issue-93486.stderr b/tests/ui/typeck/issue-93486.stderr new file mode 100644 index 000000000..167edc894 --- /dev/null +++ b/tests/ui/typeck/issue-93486.stderr @@ -0,0 +1,16 @@ +error[E0070]: invalid left-hand side of assignment + --> $DIR/issue-93486.rs:3:36 + | +LL | vec![].last_mut().unwrap() = 3_u8; + | -------------------------- ^ + | | + | cannot assign to this expression + | +help: consider dereferencing here to assign to the mutably borrowed value + | +LL | *vec![].last_mut().unwrap() = 3_u8; + | + + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0070`. diff --git a/tests/ui/typeck/issue-96530.rs b/tests/ui/typeck/issue-96530.rs new file mode 100644 index 000000000..4ab93ab49 --- /dev/null +++ b/tests/ui/typeck/issue-96530.rs @@ -0,0 +1,20 @@ +struct Person { + first_name: String, + age: u32, +} + +fn first_woman(man: &Person) -> Person { + Person { + first_name: "Eve".to_string(), + ..man.clone() //~ ERROR: mismatched types + } +} + +fn main() { + let adam = Person { + first_name: "Adam".to_string(), + age: 0, + }; + + let eve = first_woman(&adam); +} diff --git a/tests/ui/typeck/issue-96530.stderr b/tests/ui/typeck/issue-96530.stderr new file mode 100644 index 000000000..4b4568b1d --- /dev/null +++ b/tests/ui/typeck/issue-96530.stderr @@ -0,0 +1,9 @@ +error[E0308]: mismatched types + --> $DIR/issue-96530.rs:9:11 + | +LL | ..man.clone() + | ^^^^^^^^^^^ expected struct `Person`, found `&Person` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/typeck/issue-96738.rs b/tests/ui/typeck/issue-96738.rs new file mode 100644 index 000000000..ce2556f86 --- /dev/null +++ b/tests/ui/typeck/issue-96738.rs @@ -0,0 +1,4 @@ +fn main() { + Some.nonexistent_method(); //~ ERROR: no method named `nonexistent_method` found + Some.nonexistent_field; //~ ERROR: no field `nonexistent_field` +} diff --git a/tests/ui/typeck/issue-96738.stderr b/tests/ui/typeck/issue-96738.stderr new file mode 100644 index 000000000..547cffffa --- /dev/null +++ b/tests/ui/typeck/issue-96738.stderr @@ -0,0 +1,16 @@ +error[E0599]: no method named `nonexistent_method` found for enum constructor `fn(_) -> Option<_> {Option::<_>::Some}` in the current scope + --> $DIR/issue-96738.rs:2:10 + | +LL | Some.nonexistent_method(); + | ^^^^^^^^^^^^^^^^^^ method not found in `fn(_) -> Option<_> {Option::<_>::Some}` + +error[E0609]: no field `nonexistent_field` on type `fn(_) -> Option<_> {Option::<_>::Some}` + --> $DIR/issue-96738.rs:3:10 + | +LL | Some.nonexistent_field; + | ^^^^^^^^^^^^^^^^^ + +error: aborting due to 2 previous errors + +Some errors have detailed explanations: E0599, E0609. +For more information about an error, try `rustc --explain E0599`. diff --git a/tests/ui/typeck/issue-98260.rs b/tests/ui/typeck/issue-98260.rs new file mode 100644 index 000000000..cf48294e1 --- /dev/null +++ b/tests/ui/typeck/issue-98260.rs @@ -0,0 +1,9 @@ +fn main() {} +trait A { + fn a(aa: B) -> Result<_, B> { + //~^ ERROR: the placeholder `_` is not allowed within types on item signatures for return types [E0121] + Ok(()) + } +} + +enum B {} diff --git a/tests/ui/typeck/issue-98260.stderr b/tests/ui/typeck/issue-98260.stderr new file mode 100644 index 000000000..08a1d17e2 --- /dev/null +++ b/tests/ui/typeck/issue-98260.stderr @@ -0,0 +1,12 @@ +error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types + --> $DIR/issue-98260.rs:3:27 + | +LL | fn a(aa: B) -> Result<_, B> { + | -------^---- + | | | + | | not allowed in type signatures + | help: replace with the correct return type: `Result<(), B>` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0121`. diff --git a/tests/ui/typeck/issue-98982.rs b/tests/ui/typeck/issue-98982.rs new file mode 100644 index 000000000..2553824bb --- /dev/null +++ b/tests/ui/typeck/issue-98982.rs @@ -0,0 +1,9 @@ +fn foo() -> i32 { + for i in 0..0 { + //~^ ERROR: mismatched types [E0308] + return i; + } + //~| help: return a value for the case when the loop has zero elements to iterate on, or consider changing the return type to account for that possibility +} + +fn main() {} diff --git a/tests/ui/typeck/issue-98982.stderr b/tests/ui/typeck/issue-98982.stderr new file mode 100644 index 000000000..3c9806ac9 --- /dev/null +++ b/tests/ui/typeck/issue-98982.stderr @@ -0,0 +1,24 @@ +error[E0308]: mismatched types + --> $DIR/issue-98982.rs:2:5 + | +LL | fn foo() -> i32 { + | --- expected `i32` because of return type +LL | / for i in 0..0 { +LL | | +LL | | return i; +LL | | } + | |_____^ expected `i32`, found `()` + | +note: the function expects a value to always be returned, but loops might run zero times + --> $DIR/issue-98982.rs:2:5 + | +LL | for i in 0..0 { + | ^^^^^^^^^^^^^ this might have zero elements to iterate on +LL | +LL | return i; + | -------- if the loop doesn't execute, this value would never get returned + = help: return a value for the case when the loop has zero elements to iterate on, or consider changing the return type to account for that possibility + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/typeck/missing-private-fields-in-struct-literal.rs b/tests/ui/typeck/missing-private-fields-in-struct-literal.rs new file mode 100644 index 000000000..9f1560bfb --- /dev/null +++ b/tests/ui/typeck/missing-private-fields-in-struct-literal.rs @@ -0,0 +1,18 @@ +pub mod m { + pub struct S { + pub visible: bool, + a: (), + b: (), + c: (), + d: (), + e: (), + } +} + +fn main() { + let _ = m::S { //~ ERROR cannot construct `S` with struct literal syntax due to private fields + visible: true, + a: (), + b: (), + }; +} diff --git a/tests/ui/typeck/missing-private-fields-in-struct-literal.stderr b/tests/ui/typeck/missing-private-fields-in-struct-literal.stderr new file mode 100644 index 000000000..234110f31 --- /dev/null +++ b/tests/ui/typeck/missing-private-fields-in-struct-literal.stderr @@ -0,0 +1,15 @@ +error: cannot construct `S` with struct literal syntax due to private fields + --> $DIR/missing-private-fields-in-struct-literal.rs:13:13 + | +LL | let _ = m::S { + | ^^^^ +LL | visible: true, +LL | a: (), + | ----- private field +LL | b: (), + | ----- private field + | + = note: ... and other private fields `c`, `d` and `e` that were not provided + +error: aborting due to previous error + diff --git a/tests/ui/typeck/no-type-for-node-ice.rs b/tests/ui/typeck/no-type-for-node-ice.rs new file mode 100644 index 000000000..d0cfdbf50 --- /dev/null +++ b/tests/ui/typeck/no-type-for-node-ice.rs @@ -0,0 +1,5 @@ +// Related issues: #20401, #20506, #20614, #20752, #20829, #20846, #20885, #20886 + +fn main() { + "".homura[""]; //~ no field `homura` on type `&'static str` +} diff --git a/tests/ui/typeck/no-type-for-node-ice.stderr b/tests/ui/typeck/no-type-for-node-ice.stderr new file mode 100644 index 000000000..b50241fb1 --- /dev/null +++ b/tests/ui/typeck/no-type-for-node-ice.stderr @@ -0,0 +1,9 @@ +error[E0609]: no field `homura` on type `&'static str` + --> $DIR/no-type-for-node-ice.rs:4:8 + | +LL | "".homura[""]; + | ^^^^^^ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0609`. diff --git a/tests/ui/typeck/nonexistent-field-not-ambiguous.rs b/tests/ui/typeck/nonexistent-field-not-ambiguous.rs new file mode 100644 index 000000000..1cd192b78 --- /dev/null +++ b/tests/ui/typeck/nonexistent-field-not-ambiguous.rs @@ -0,0 +1,8 @@ +struct Foo { + val: MissingType, + //~^ ERROR cannot find type `MissingType` in this scope +} + +fn main() { + Foo { val: Default::default() }; +} diff --git a/tests/ui/typeck/nonexistent-field-not-ambiguous.stderr b/tests/ui/typeck/nonexistent-field-not-ambiguous.stderr new file mode 100644 index 000000000..76a2a5f99 --- /dev/null +++ b/tests/ui/typeck/nonexistent-field-not-ambiguous.stderr @@ -0,0 +1,9 @@ +error[E0412]: cannot find type `MissingType` in this scope + --> $DIR/nonexistent-field-not-ambiguous.rs:2:10 + | +LL | val: MissingType, + | ^^^^^^^^^^^ not found in this scope + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0412`. diff --git a/tests/ui/typeck/path-to-method-sugg-unresolved-expr.rs b/tests/ui/typeck/path-to-method-sugg-unresolved-expr.rs new file mode 100644 index 000000000..fb56b3944 --- /dev/null +++ b/tests/ui/typeck/path-to-method-sugg-unresolved-expr.rs @@ -0,0 +1,4 @@ +fn main() { + let page_size = page_size::get(); + //~^ ERROR failed to resolve: use of undeclared crate or module `page_size` +} diff --git a/tests/ui/typeck/path-to-method-sugg-unresolved-expr.stderr b/tests/ui/typeck/path-to-method-sugg-unresolved-expr.stderr new file mode 100644 index 000000000..b01e30be5 --- /dev/null +++ b/tests/ui/typeck/path-to-method-sugg-unresolved-expr.stderr @@ -0,0 +1,9 @@ +error[E0433]: failed to resolve: use of undeclared crate or module `page_size` + --> $DIR/path-to-method-sugg-unresolved-expr.rs:2:21 + | +LL | let page_size = page_size::get(); + | ^^^^^^^^^ use of undeclared crate or module `page_size` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0433`. diff --git a/tests/ui/typeck/point-at-type-param-in-path-expr.rs b/tests/ui/typeck/point-at-type-param-in-path-expr.rs new file mode 100644 index 000000000..9a21536f9 --- /dev/null +++ b/tests/ui/typeck/point-at-type-param-in-path-expr.rs @@ -0,0 +1,6 @@ +fn foo<T: std::fmt::Display>() {} + +fn main() { + let x = foo::<()>; + //~^ ERROR `()` doesn't implement `std::fmt::Display` +} diff --git a/tests/ui/typeck/point-at-type-param-in-path-expr.stderr b/tests/ui/typeck/point-at-type-param-in-path-expr.stderr new file mode 100644 index 000000000..1feaa0508 --- /dev/null +++ b/tests/ui/typeck/point-at-type-param-in-path-expr.stderr @@ -0,0 +1,17 @@ +error[E0277]: `()` doesn't implement `std::fmt::Display` + --> $DIR/point-at-type-param-in-path-expr.rs:4:19 + | +LL | let x = foo::<()>; + | ^^ `()` cannot be formatted with the default formatter + | + = help: the trait `std::fmt::Display` is not implemented for `()` + = note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead +note: required by a bound in `foo` + --> $DIR/point-at-type-param-in-path-expr.rs:1:11 + | +LL | fn foo<T: std::fmt::Display>() {} + | ^^^^^^^^^^^^^^^^^ required by this bound in `foo` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/typeck/point-at-type-parameter-definition.rs b/tests/ui/typeck/point-at-type-parameter-definition.rs new file mode 100644 index 000000000..856c0db08 --- /dev/null +++ b/tests/ui/typeck/point-at-type-parameter-definition.rs @@ -0,0 +1,17 @@ +trait Trait { + fn do_stuff(&self); +} + +struct Hello; + +impl Hello { + fn method(&self) {} +} + +impl<Hello> Trait for Vec<Hello> { + fn do_stuff(&self) { + self[0].method(); //~ ERROR no method named `method` found for type parameter `Hello` in the current scope + } +} + +fn main() {} diff --git a/tests/ui/typeck/point-at-type-parameter-definition.stderr b/tests/ui/typeck/point-at-type-parameter-definition.stderr new file mode 100644 index 000000000..8a6ab6110 --- /dev/null +++ b/tests/ui/typeck/point-at-type-parameter-definition.stderr @@ -0,0 +1,12 @@ +error[E0599]: no method named `method` found for type parameter `Hello` in the current scope + --> $DIR/point-at-type-parameter-definition.rs:13:17 + | +LL | impl<Hello> Trait for Vec<Hello> { + | ----- method `method` not found for this type parameter +LL | fn do_stuff(&self) { +LL | self[0].method(); + | ^^^^^^ method not found in `Hello` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0599`. diff --git a/tests/ui/typeck/prim-with-args.fixed b/tests/ui/typeck/prim-with-args.fixed new file mode 100644 index 000000000..e3f99479a --- /dev/null +++ b/tests/ui/typeck/prim-with-args.fixed @@ -0,0 +1,28 @@ +// run-rustfix +fn main() { + +let _x: isize; //~ ERROR type arguments are not allowed on builtin type +let _x: i8; //~ ERROR type arguments are not allowed on builtin type +let _x: i16; //~ ERROR type arguments are not allowed on builtin type +let _x: i32; //~ ERROR type arguments are not allowed on builtin type +let _x: i64; //~ ERROR type arguments are not allowed on builtin type +let _x: usize; //~ ERROR type arguments are not allowed on builtin type +let _x: u8; //~ ERROR type arguments are not allowed on builtin type +let _x: u16; //~ ERROR type arguments are not allowed on builtin type +let _x: u32; //~ ERROR type arguments are not allowed on builtin type +let _x: u64; //~ ERROR type arguments are not allowed on builtin type +let _x: char; //~ ERROR type arguments are not allowed on builtin type + +let _x: isize; //~ ERROR lifetime arguments are not allowed on builtin type +let _x: i8; //~ ERROR lifetime arguments are not allowed on builtin type +let _x: i16; //~ ERROR lifetime arguments are not allowed on builtin type +let _x: i32; //~ ERROR lifetime arguments are not allowed on builtin type +let _x: i64; //~ ERROR lifetime arguments are not allowed on builtin type +let _x: usize; //~ ERROR lifetime arguments are not allowed on builtin type +let _x: u8; //~ ERROR lifetime arguments are not allowed on builtin type +let _x: u16; //~ ERROR lifetime arguments are not allowed on builtin type +let _x: u32; //~ ERROR lifetime arguments are not allowed on builtin type +let _x: u64; //~ ERROR lifetime arguments are not allowed on builtin type +let _x: char; //~ ERROR lifetime arguments are not allowed on builtin type + +} diff --git a/tests/ui/typeck/prim-with-args.rs b/tests/ui/typeck/prim-with-args.rs new file mode 100644 index 000000000..b10471ecc --- /dev/null +++ b/tests/ui/typeck/prim-with-args.rs @@ -0,0 +1,28 @@ +// run-rustfix +fn main() { + +let _x: isize<isize>; //~ ERROR type arguments are not allowed on builtin type +let _x: i8<isize>; //~ ERROR type arguments are not allowed on builtin type +let _x: i16<isize>; //~ ERROR type arguments are not allowed on builtin type +let _x: i32<isize>; //~ ERROR type arguments are not allowed on builtin type +let _x: i64<isize>; //~ ERROR type arguments are not allowed on builtin type +let _x: usize<isize>; //~ ERROR type arguments are not allowed on builtin type +let _x: u8<isize>; //~ ERROR type arguments are not allowed on builtin type +let _x: u16<isize>; //~ ERROR type arguments are not allowed on builtin type +let _x: u32<isize>; //~ ERROR type arguments are not allowed on builtin type +let _x: u64<isize>; //~ ERROR type arguments are not allowed on builtin type +let _x: char<isize>; //~ ERROR type arguments are not allowed on builtin type + +let _x: isize<'static>; //~ ERROR lifetime arguments are not allowed on builtin type +let _x: i8<'static>; //~ ERROR lifetime arguments are not allowed on builtin type +let _x: i16<'static>; //~ ERROR lifetime arguments are not allowed on builtin type +let _x: i32<'static>; //~ ERROR lifetime arguments are not allowed on builtin type +let _x: i64<'static>; //~ ERROR lifetime arguments are not allowed on builtin type +let _x: usize<'static>; //~ ERROR lifetime arguments are not allowed on builtin type +let _x: u8<'static>; //~ ERROR lifetime arguments are not allowed on builtin type +let _x: u16<'static>; //~ ERROR lifetime arguments are not allowed on builtin type +let _x: u32<'static>; //~ ERROR lifetime arguments are not allowed on builtin type +let _x: u64<'static>; //~ ERROR lifetime arguments are not allowed on builtin type +let _x: char<'static>; //~ ERROR lifetime arguments are not allowed on builtin type + +} diff --git a/tests/ui/typeck/prim-with-args.stderr b/tests/ui/typeck/prim-with-args.stderr new file mode 100644 index 000000000..2ddad5ad7 --- /dev/null +++ b/tests/ui/typeck/prim-with-args.stderr @@ -0,0 +1,311 @@ +error[E0109]: type arguments are not allowed on builtin type `isize` + --> $DIR/prim-with-args.rs:4:15 + | +LL | let _x: isize<isize>; + | ----- ^^^^^ type argument not allowed + | | + | not allowed on builtin type `isize` + | +help: primitive type `isize` doesn't have generic parameters + | +LL - let _x: isize<isize>; +LL + let _x: isize; + | + +error[E0109]: type arguments are not allowed on builtin type `i8` + --> $DIR/prim-with-args.rs:5:12 + | +LL | let _x: i8<isize>; + | -- ^^^^^ type argument not allowed + | | + | not allowed on builtin type `i8` + | +help: primitive type `i8` doesn't have generic parameters + | +LL - let _x: i8<isize>; +LL + let _x: i8; + | + +error[E0109]: type arguments are not allowed on builtin type `i16` + --> $DIR/prim-with-args.rs:6:13 + | +LL | let _x: i16<isize>; + | --- ^^^^^ type argument not allowed + | | + | not allowed on builtin type `i16` + | +help: primitive type `i16` doesn't have generic parameters + | +LL - let _x: i16<isize>; +LL + let _x: i16; + | + +error[E0109]: type arguments are not allowed on builtin type `i32` + --> $DIR/prim-with-args.rs:7:13 + | +LL | let _x: i32<isize>; + | --- ^^^^^ type argument not allowed + | | + | not allowed on builtin type `i32` + | +help: primitive type `i32` doesn't have generic parameters + | +LL - let _x: i32<isize>; +LL + let _x: i32; + | + +error[E0109]: type arguments are not allowed on builtin type `i64` + --> $DIR/prim-with-args.rs:8:13 + | +LL | let _x: i64<isize>; + | --- ^^^^^ type argument not allowed + | | + | not allowed on builtin type `i64` + | +help: primitive type `i64` doesn't have generic parameters + | +LL - let _x: i64<isize>; +LL + let _x: i64; + | + +error[E0109]: type arguments are not allowed on builtin type `usize` + --> $DIR/prim-with-args.rs:9:15 + | +LL | let _x: usize<isize>; + | ----- ^^^^^ type argument not allowed + | | + | not allowed on builtin type `usize` + | +help: primitive type `usize` doesn't have generic parameters + | +LL - let _x: usize<isize>; +LL + let _x: usize; + | + +error[E0109]: type arguments are not allowed on builtin type `u8` + --> $DIR/prim-with-args.rs:10:12 + | +LL | let _x: u8<isize>; + | -- ^^^^^ type argument not allowed + | | + | not allowed on builtin type `u8` + | +help: primitive type `u8` doesn't have generic parameters + | +LL - let _x: u8<isize>; +LL + let _x: u8; + | + +error[E0109]: type arguments are not allowed on builtin type `u16` + --> $DIR/prim-with-args.rs:11:13 + | +LL | let _x: u16<isize>; + | --- ^^^^^ type argument not allowed + | | + | not allowed on builtin type `u16` + | +help: primitive type `u16` doesn't have generic parameters + | +LL - let _x: u16<isize>; +LL + let _x: u16; + | + +error[E0109]: type arguments are not allowed on builtin type `u32` + --> $DIR/prim-with-args.rs:12:13 + | +LL | let _x: u32<isize>; + | --- ^^^^^ type argument not allowed + | | + | not allowed on builtin type `u32` + | +help: primitive type `u32` doesn't have generic parameters + | +LL - let _x: u32<isize>; +LL + let _x: u32; + | + +error[E0109]: type arguments are not allowed on builtin type `u64` + --> $DIR/prim-with-args.rs:13:13 + | +LL | let _x: u64<isize>; + | --- ^^^^^ type argument not allowed + | | + | not allowed on builtin type `u64` + | +help: primitive type `u64` doesn't have generic parameters + | +LL - let _x: u64<isize>; +LL + let _x: u64; + | + +error[E0109]: type arguments are not allowed on builtin type `char` + --> $DIR/prim-with-args.rs:14:14 + | +LL | let _x: char<isize>; + | ---- ^^^^^ type argument not allowed + | | + | not allowed on builtin type `char` + | +help: primitive type `char` doesn't have generic parameters + | +LL - let _x: char<isize>; +LL + let _x: char; + | + +error[E0109]: lifetime arguments are not allowed on builtin type `isize` + --> $DIR/prim-with-args.rs:16:15 + | +LL | let _x: isize<'static>; + | ----- ^^^^^^^ lifetime argument not allowed + | | + | not allowed on builtin type `isize` + | +help: primitive type `isize` doesn't have generic parameters + | +LL - let _x: isize<'static>; +LL + let _x: isize; + | + +error[E0109]: lifetime arguments are not allowed on builtin type `i8` + --> $DIR/prim-with-args.rs:17:12 + | +LL | let _x: i8<'static>; + | -- ^^^^^^^ lifetime argument not allowed + | | + | not allowed on builtin type `i8` + | +help: primitive type `i8` doesn't have generic parameters + | +LL - let _x: i8<'static>; +LL + let _x: i8; + | + +error[E0109]: lifetime arguments are not allowed on builtin type `i16` + --> $DIR/prim-with-args.rs:18:13 + | +LL | let _x: i16<'static>; + | --- ^^^^^^^ lifetime argument not allowed + | | + | not allowed on builtin type `i16` + | +help: primitive type `i16` doesn't have generic parameters + | +LL - let _x: i16<'static>; +LL + let _x: i16; + | + +error[E0109]: lifetime arguments are not allowed on builtin type `i32` + --> $DIR/prim-with-args.rs:19:13 + | +LL | let _x: i32<'static>; + | --- ^^^^^^^ lifetime argument not allowed + | | + | not allowed on builtin type `i32` + | +help: primitive type `i32` doesn't have generic parameters + | +LL - let _x: i32<'static>; +LL + let _x: i32; + | + +error[E0109]: lifetime arguments are not allowed on builtin type `i64` + --> $DIR/prim-with-args.rs:20:13 + | +LL | let _x: i64<'static>; + | --- ^^^^^^^ lifetime argument not allowed + | | + | not allowed on builtin type `i64` + | +help: primitive type `i64` doesn't have generic parameters + | +LL - let _x: i64<'static>; +LL + let _x: i64; + | + +error[E0109]: lifetime arguments are not allowed on builtin type `usize` + --> $DIR/prim-with-args.rs:21:15 + | +LL | let _x: usize<'static>; + | ----- ^^^^^^^ lifetime argument not allowed + | | + | not allowed on builtin type `usize` + | +help: primitive type `usize` doesn't have generic parameters + | +LL - let _x: usize<'static>; +LL + let _x: usize; + | + +error[E0109]: lifetime arguments are not allowed on builtin type `u8` + --> $DIR/prim-with-args.rs:22:12 + | +LL | let _x: u8<'static>; + | -- ^^^^^^^ lifetime argument not allowed + | | + | not allowed on builtin type `u8` + | +help: primitive type `u8` doesn't have generic parameters + | +LL - let _x: u8<'static>; +LL + let _x: u8; + | + +error[E0109]: lifetime arguments are not allowed on builtin type `u16` + --> $DIR/prim-with-args.rs:23:13 + | +LL | let _x: u16<'static>; + | --- ^^^^^^^ lifetime argument not allowed + | | + | not allowed on builtin type `u16` + | +help: primitive type `u16` doesn't have generic parameters + | +LL - let _x: u16<'static>; +LL + let _x: u16; + | + +error[E0109]: lifetime arguments are not allowed on builtin type `u32` + --> $DIR/prim-with-args.rs:24:13 + | +LL | let _x: u32<'static>; + | --- ^^^^^^^ lifetime argument not allowed + | | + | not allowed on builtin type `u32` + | +help: primitive type `u32` doesn't have generic parameters + | +LL - let _x: u32<'static>; +LL + let _x: u32; + | + +error[E0109]: lifetime arguments are not allowed on builtin type `u64` + --> $DIR/prim-with-args.rs:25:13 + | +LL | let _x: u64<'static>; + | --- ^^^^^^^ lifetime argument not allowed + | | + | not allowed on builtin type `u64` + | +help: primitive type `u64` doesn't have generic parameters + | +LL - let _x: u64<'static>; +LL + let _x: u64; + | + +error[E0109]: lifetime arguments are not allowed on builtin type `char` + --> $DIR/prim-with-args.rs:26:14 + | +LL | let _x: char<'static>; + | ---- ^^^^^^^ lifetime argument not allowed + | | + | not allowed on builtin type `char` + | +help: primitive type `char` doesn't have generic parameters + | +LL - let _x: char<'static>; +LL + let _x: char; + | + +error: aborting due to 22 previous errors + +For more information about this error, try `rustc --explain E0109`. diff --git a/tests/ui/typeck/project-cache-issue-37154.rs b/tests/ui/typeck/project-cache-issue-37154.rs new file mode 100644 index 000000000..b10239c22 --- /dev/null +++ b/tests/ui/typeck/project-cache-issue-37154.rs @@ -0,0 +1,21 @@ +// run-pass + +#![allow(dead_code)] +// Regression test for #37154: the problem here was that the cache +// results in a false error because it was caching placeholder results +// even after those placeholder regions had been popped. + +trait Foo { + fn method(&self) {} +} + +struct Wrapper<T>(T); + +impl<T> Foo for Wrapper<T> where for<'a> &'a T: IntoIterator<Item=&'a ()> {} + +fn f(x: Wrapper<Vec<()>>) { + x.method(); // This works. + x.method(); // error: no method named `method` +} + +fn main() { } diff --git a/tests/ui/typeck/quiet-type-err-let-binding.rs b/tests/ui/typeck/quiet-type-err-let-binding.rs new file mode 100644 index 000000000..a6eab536a --- /dev/null +++ b/tests/ui/typeck/quiet-type-err-let-binding.rs @@ -0,0 +1,17 @@ +// fn foo() -> String { +// String::new() +// } + +fn test(s: &str) { + println!("{}", s); +} + +fn test2(s: String) { + println!("{}", s); +} + +fn main() { + let x = foo(); //~ERROR cannot find function `foo` in this scope + test(&x); + test2(x); // Does not complain about `x` being a `&str`. +} diff --git a/tests/ui/typeck/quiet-type-err-let-binding.stderr b/tests/ui/typeck/quiet-type-err-let-binding.stderr new file mode 100644 index 000000000..ad7f85e01 --- /dev/null +++ b/tests/ui/typeck/quiet-type-err-let-binding.stderr @@ -0,0 +1,9 @@ +error[E0425]: cannot find function `foo` in this scope + --> $DIR/quiet-type-err-let-binding.rs:14:13 + | +LL | let x = foo(); + | ^^^ not found in this scope + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0425`. diff --git a/tests/ui/typeck/remove-extra-argument.fixed b/tests/ui/typeck/remove-extra-argument.fixed new file mode 100644 index 000000000..d09306bf7 --- /dev/null +++ b/tests/ui/typeck/remove-extra-argument.fixed @@ -0,0 +1,9 @@ +// run-rustfix +// Check that the HELP suggestion is `l(vec![])` instead of `l($crate::vec::Vec::new())` +fn l(_a: Vec<u8>) {} + +fn main() { + l(vec![]) + //~^ ERROR function takes 1 argument but 2 arguments were supplied + //~| HELP remove the extra argument +} diff --git a/tests/ui/typeck/remove-extra-argument.rs b/tests/ui/typeck/remove-extra-argument.rs new file mode 100644 index 000000000..2181c37ce --- /dev/null +++ b/tests/ui/typeck/remove-extra-argument.rs @@ -0,0 +1,9 @@ +// run-rustfix +// Check that the HELP suggestion is `l(vec![])` instead of `l($crate::vec::Vec::new())` +fn l(_a: Vec<u8>) {} + +fn main() { + l(vec![], vec![]) + //~^ ERROR function takes 1 argument but 2 arguments were supplied + //~| HELP remove the extra argument +} diff --git a/tests/ui/typeck/remove-extra-argument.stderr b/tests/ui/typeck/remove-extra-argument.stderr new file mode 100644 index 000000000..b734bcd4e --- /dev/null +++ b/tests/ui/typeck/remove-extra-argument.stderr @@ -0,0 +1,19 @@ +error[E0061]: this function takes 1 argument but 2 arguments were supplied + --> $DIR/remove-extra-argument.rs:6:5 + | +LL | l(vec![], vec![]) + | ^ ------ argument of type `Vec<_>` unexpected + | +note: function defined here + --> $DIR/remove-extra-argument.rs:3:4 + | +LL | fn l(_a: Vec<u8>) {} + | ^ ----------- +help: remove the extra argument + | +LL | l(vec![]) + | ~~~~~~~~ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0061`. diff --git a/tests/ui/typeck/return_type_containing_closure.rs b/tests/ui/typeck/return_type_containing_closure.rs new file mode 100644 index 000000000..29624e08a --- /dev/null +++ b/tests/ui/typeck/return_type_containing_closure.rs @@ -0,0 +1,10 @@ +#[allow(unused)] +fn foo() { //~ HELP a return type might be missing here + vec!['a'].iter().map(|c| c) + //~^ ERROR mismatched types [E0308] + //~| NOTE expected `()`, found struct `Map` + //~| NOTE expected unit type `()` + //~| HELP consider using a semicolon here +} + +fn main() {} diff --git a/tests/ui/typeck/return_type_containing_closure.stderr b/tests/ui/typeck/return_type_containing_closure.stderr new file mode 100644 index 000000000..101aee395 --- /dev/null +++ b/tests/ui/typeck/return_type_containing_closure.stderr @@ -0,0 +1,20 @@ +error[E0308]: mismatched types + --> $DIR/return_type_containing_closure.rs:3:5 + | +LL | vec!['a'].iter().map(|c| c) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `()`, found struct `Map` + | + = note: expected unit type `()` + found struct `Map<std::slice::Iter<'_, char>, [closure@$DIR/return_type_containing_closure.rs:3:26: 3:29]>` +help: consider using a semicolon here + | +LL | vec!['a'].iter().map(|c| c); + | + +help: a return type might be missing here + | +LL | fn foo() -> _ { + | ++++ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/typeck/slow-lhs-suggestion.rs b/tests/ui/typeck/slow-lhs-suggestion.rs new file mode 100644 index 000000000..80dfd6835 --- /dev/null +++ b/tests/ui/typeck/slow-lhs-suggestion.rs @@ -0,0 +1,26 @@ +fn main() { + 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1; + //~^ ERROR invalid left-hand side of assignment + //~| ERROR invalid left-hand side of assignment + //~| ERROR invalid left-hand side of assignment + //~| ERROR invalid left-hand side of assignment + //~| ERROR invalid left-hand side of assignment + //~| ERROR invalid left-hand side of assignment + //~| ERROR invalid left-hand side of assignment + //~| ERROR invalid left-hand side of assignment + //~| ERROR invalid left-hand side of assignment + //~| ERROR invalid left-hand side of assignment + //~| ERROR invalid left-hand side of assignment + //~| ERROR invalid left-hand side of assignment + //~| ERROR invalid left-hand side of assignment + //~| ERROR invalid left-hand side of assignment + //~| ERROR invalid left-hand side of assignment + //~| ERROR invalid left-hand side of assignment + //~| ERROR invalid left-hand side of assignment + //~| ERROR invalid left-hand side of assignment + //~| ERROR invalid left-hand side of assignment + //~| ERROR invalid left-hand side of assignment + //~| ERROR invalid left-hand side of assignment + //~| ERROR invalid left-hand side of assignment + //~| ERROR invalid left-hand side of assignment +} diff --git a/tests/ui/typeck/slow-lhs-suggestion.stderr b/tests/ui/typeck/slow-lhs-suggestion.stderr new file mode 100644 index 000000000..c5bf795ee --- /dev/null +++ b/tests/ui/typeck/slow-lhs-suggestion.stderr @@ -0,0 +1,187 @@ +error[E0070]: invalid left-hand side of assignment + --> $DIR/slow-lhs-suggestion.rs:2:95 + | +LL | 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1; + | - ^ + | | + | cannot assign to this expression + +error[E0070]: invalid left-hand side of assignment + --> $DIR/slow-lhs-suggestion.rs:2:91 + | +LL | 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1; + | - ^ + | | + | cannot assign to this expression + +error[E0070]: invalid left-hand side of assignment + --> $DIR/slow-lhs-suggestion.rs:2:87 + | +LL | 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1; + | - ^ + | | + | cannot assign to this expression + +error[E0070]: invalid left-hand side of assignment + --> $DIR/slow-lhs-suggestion.rs:2:83 + | +LL | 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1; + | - ^ + | | + | cannot assign to this expression + +error[E0070]: invalid left-hand side of assignment + --> $DIR/slow-lhs-suggestion.rs:2:79 + | +LL | 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1; + | - ^ + | | + | cannot assign to this expression + +error[E0070]: invalid left-hand side of assignment + --> $DIR/slow-lhs-suggestion.rs:2:75 + | +LL | 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1; + | - ^ + | | + | cannot assign to this expression + +error[E0070]: invalid left-hand side of assignment + --> $DIR/slow-lhs-suggestion.rs:2:71 + | +LL | 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1; + | - ^ + | | + | cannot assign to this expression + +error[E0070]: invalid left-hand side of assignment + --> $DIR/slow-lhs-suggestion.rs:2:67 + | +LL | 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1; + | - ^ + | | + | cannot assign to this expression + +error[E0070]: invalid left-hand side of assignment + --> $DIR/slow-lhs-suggestion.rs:2:63 + | +LL | 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1; + | - ^ + | | + | cannot assign to this expression + +error[E0070]: invalid left-hand side of assignment + --> $DIR/slow-lhs-suggestion.rs:2:59 + | +LL | 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1; + | - ^ + | | + | cannot assign to this expression + +error[E0070]: invalid left-hand side of assignment + --> $DIR/slow-lhs-suggestion.rs:2:55 + | +LL | 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1; + | - ^ + | | + | cannot assign to this expression + +error[E0070]: invalid left-hand side of assignment + --> $DIR/slow-lhs-suggestion.rs:2:51 + | +LL | 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1; + | - ^ + | | + | cannot assign to this expression + +error[E0070]: invalid left-hand side of assignment + --> $DIR/slow-lhs-suggestion.rs:2:47 + | +LL | 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1; + | - ^ + | | + | cannot assign to this expression + +error[E0070]: invalid left-hand side of assignment + --> $DIR/slow-lhs-suggestion.rs:2:43 + | +LL | 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1; + | - ^ + | | + | cannot assign to this expression + +error[E0070]: invalid left-hand side of assignment + --> $DIR/slow-lhs-suggestion.rs:2:39 + | +LL | 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1; + | - ^ + | | + | cannot assign to this expression + +error[E0070]: invalid left-hand side of assignment + --> $DIR/slow-lhs-suggestion.rs:2:35 + | +LL | 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1; + | - ^ + | | + | cannot assign to this expression + +error[E0070]: invalid left-hand side of assignment + --> $DIR/slow-lhs-suggestion.rs:2:31 + | +LL | 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1; + | - ^ + | | + | cannot assign to this expression + +error[E0070]: invalid left-hand side of assignment + --> $DIR/slow-lhs-suggestion.rs:2:27 + | +LL | 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1; + | - ^ + | | + | cannot assign to this expression + +error[E0070]: invalid left-hand side of assignment + --> $DIR/slow-lhs-suggestion.rs:2:23 + | +LL | 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1; + | - ^ + | | + | cannot assign to this expression + +error[E0070]: invalid left-hand side of assignment + --> $DIR/slow-lhs-suggestion.rs:2:19 + | +LL | 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1; + | - ^ + | | + | cannot assign to this expression + +error[E0070]: invalid left-hand side of assignment + --> $DIR/slow-lhs-suggestion.rs:2:15 + | +LL | 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1; + | - ^ + | | + | cannot assign to this expression + +error[E0070]: invalid left-hand side of assignment + --> $DIR/slow-lhs-suggestion.rs:2:11 + | +LL | 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1; + | - ^ + | | + | cannot assign to this expression + +error[E0070]: invalid left-hand side of assignment + --> $DIR/slow-lhs-suggestion.rs:2:7 + | +LL | 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1; + | - ^ + | | + | cannot assign to this expression + +error: aborting due to 23 previous errors + +For more information about this error, try `rustc --explain E0070`. diff --git a/tests/ui/typeck/struct-enum-wrong-args.rs b/tests/ui/typeck/struct-enum-wrong-args.rs new file mode 100644 index 000000000..19de4d677 --- /dev/null +++ b/tests/ui/typeck/struct-enum-wrong-args.rs @@ -0,0 +1,14 @@ +// Regression test of #86481. +struct Wrapper(i32); +struct DoubleWrapper(i32, i32); + +fn main() { + let _ = Some(3, 2); //~ ERROR this enum variant takes + let _ = Ok(3, 6, 2); //~ ERROR this enum variant takes + let _ = Ok(); //~ ERROR this enum variant takes + let _ = Wrapper(); //~ ERROR this struct takes + let _ = Wrapper(5, 2); //~ ERROR this struct takes + let _ = DoubleWrapper(); //~ ERROR this struct takes + let _ = DoubleWrapper(5); //~ ERROR this struct takes + let _ = DoubleWrapper(5, 2, 7); //~ ERROR this struct takes +} diff --git a/tests/ui/typeck/struct-enum-wrong-args.stderr b/tests/ui/typeck/struct-enum-wrong-args.stderr new file mode 100644 index 000000000..fbced928a --- /dev/null +++ b/tests/ui/typeck/struct-enum-wrong-args.stderr @@ -0,0 +1,124 @@ +error[E0061]: this enum variant takes 1 argument but 2 arguments were supplied + --> $DIR/struct-enum-wrong-args.rs:6:13 + | +LL | let _ = Some(3, 2); + | ^^^^ - argument of type `{integer}` unexpected + | +note: tuple variant defined here + --> $SRC_DIR/core/src/option.rs:LL:COL +help: remove the extra argument + | +LL | let _ = Some(3); + | ~~~ + +error[E0061]: this enum variant takes 1 argument but 3 arguments were supplied + --> $DIR/struct-enum-wrong-args.rs:7:13 + | +LL | let _ = Ok(3, 6, 2); + | ^^ - - argument of type `{integer}` unexpected + | | + | argument of type `{integer}` unexpected + | +note: tuple variant defined here + --> $SRC_DIR/core/src/result.rs:LL:COL +help: remove the extra arguments + | +LL | let _ = Ok(3); + | ~~~ + +error[E0061]: this enum variant takes 1 argument but 0 arguments were supplied + --> $DIR/struct-enum-wrong-args.rs:8:13 + | +LL | let _ = Ok(); + | ^^-- an argument is missing + | +note: tuple variant defined here + --> $SRC_DIR/core/src/result.rs:LL:COL +help: provide the argument + | +LL | let _ = Ok(/* value */); + | ~~~~~~~~~~~~~ + +error[E0061]: this struct takes 1 argument but 0 arguments were supplied + --> $DIR/struct-enum-wrong-args.rs:9:13 + | +LL | let _ = Wrapper(); + | ^^^^^^^-- an argument of type `i32` is missing + | +note: tuple struct defined here + --> $DIR/struct-enum-wrong-args.rs:2:8 + | +LL | struct Wrapper(i32); + | ^^^^^^^ +help: provide the argument + | +LL | let _ = Wrapper(/* i32 */); + | ~~~~~~~~~~~ + +error[E0061]: this struct takes 1 argument but 2 arguments were supplied + --> $DIR/struct-enum-wrong-args.rs:10:13 + | +LL | let _ = Wrapper(5, 2); + | ^^^^^^^ - argument of type `{integer}` unexpected + | +note: tuple struct defined here + --> $DIR/struct-enum-wrong-args.rs:2:8 + | +LL | struct Wrapper(i32); + | ^^^^^^^ +help: remove the extra argument + | +LL | let _ = Wrapper(5); + | ~~~ + +error[E0061]: this struct takes 2 arguments but 0 arguments were supplied + --> $DIR/struct-enum-wrong-args.rs:11:13 + | +LL | let _ = DoubleWrapper(); + | ^^^^^^^^^^^^^-- two arguments of type `i32` and `i32` are missing + | +note: tuple struct defined here + --> $DIR/struct-enum-wrong-args.rs:3:8 + | +LL | struct DoubleWrapper(i32, i32); + | ^^^^^^^^^^^^^ +help: provide the arguments + | +LL | let _ = DoubleWrapper(/* i32 */, /* i32 */); + | ~~~~~~~~~~~~~~~~~~~~~~ + +error[E0061]: this struct takes 2 arguments but 1 argument was supplied + --> $DIR/struct-enum-wrong-args.rs:12:13 + | +LL | let _ = DoubleWrapper(5); + | ^^^^^^^^^^^^^--- an argument of type `i32` is missing + | +note: tuple struct defined here + --> $DIR/struct-enum-wrong-args.rs:3:8 + | +LL | struct DoubleWrapper(i32, i32); + | ^^^^^^^^^^^^^ +help: provide the argument + | +LL | let _ = DoubleWrapper(5, /* i32 */); + | ~~~~~~~~~~~~~~ + +error[E0061]: this struct takes 2 arguments but 3 arguments were supplied + --> $DIR/struct-enum-wrong-args.rs:13:13 + | +LL | let _ = DoubleWrapper(5, 2, 7); + | ^^^^^^^^^^^^^ - argument of type `{integer}` unexpected + | +note: tuple struct defined here + --> $DIR/struct-enum-wrong-args.rs:3:8 + | +LL | struct DoubleWrapper(i32, i32); + | ^^^^^^^^^^^^^ +help: remove the extra argument + | +LL | let _ = DoubleWrapper(5, 2); + | ~~~~~~ + +error: aborting due to 8 previous errors + +For more information about this error, try `rustc --explain E0061`. diff --git a/tests/ui/typeck/suggest-adding-missing-zero-to-floating-point-number.fixed b/tests/ui/typeck/suggest-adding-missing-zero-to-floating-point-number.fixed new file mode 100644 index 000000000..ba83e7900 --- /dev/null +++ b/tests/ui/typeck/suggest-adding-missing-zero-to-floating-point-number.fixed @@ -0,0 +1,11 @@ +// run-rustfix + +fn main() { + 2.0e1; //~ERROR `{integer}` is a primitive type and therefore doesn't have fields + 2.0E1; //~ERROR `{integer}` is a primitive type and therefore doesn't have fields + 2.0f32; //~ERROR `{integer}` is a primitive type and therefore doesn't have fields + 2.0f64; //~ERROR `{integer}` is a primitive type and therefore doesn't have fields + 2.0e+12; //~ERROR `{integer}` is a primitive type and therefore doesn't have fields + 2.0e-12; //~ERROR `{integer}` is a primitive type and therefore doesn't have fields + 2.0e1f32; //~ERROR `{integer}` is a primitive type and therefore doesn't have fields +} diff --git a/tests/ui/typeck/suggest-adding-missing-zero-to-floating-point-number.rs b/tests/ui/typeck/suggest-adding-missing-zero-to-floating-point-number.rs new file mode 100644 index 000000000..c102447f6 --- /dev/null +++ b/tests/ui/typeck/suggest-adding-missing-zero-to-floating-point-number.rs @@ -0,0 +1,11 @@ +// run-rustfix + +fn main() { + 2.e1; //~ERROR `{integer}` is a primitive type and therefore doesn't have fields + 2.E1; //~ERROR `{integer}` is a primitive type and therefore doesn't have fields + 2.f32; //~ERROR `{integer}` is a primitive type and therefore doesn't have fields + 2.f64; //~ERROR `{integer}` is a primitive type and therefore doesn't have fields + 2.e+12; //~ERROR `{integer}` is a primitive type and therefore doesn't have fields + 2.e-12; //~ERROR `{integer}` is a primitive type and therefore doesn't have fields + 2.e1f32; //~ERROR `{integer}` is a primitive type and therefore doesn't have fields +} diff --git a/tests/ui/typeck/suggest-adding-missing-zero-to-floating-point-number.stderr b/tests/ui/typeck/suggest-adding-missing-zero-to-floating-point-number.stderr new file mode 100644 index 000000000..503015f3b --- /dev/null +++ b/tests/ui/typeck/suggest-adding-missing-zero-to-floating-point-number.stderr @@ -0,0 +1,80 @@ +error[E0610]: `{integer}` is a primitive type and therefore doesn't have fields + --> $DIR/suggest-adding-missing-zero-to-floating-point-number.rs:4:7 + | +LL | 2.e1; + | ^^ + | +help: if intended to be a floating point literal, consider adding a `0` after the period + | +LL | 2.0e1; + | + + +error[E0610]: `{integer}` is a primitive type and therefore doesn't have fields + --> $DIR/suggest-adding-missing-zero-to-floating-point-number.rs:5:7 + | +LL | 2.E1; + | ^^ + | +help: if intended to be a floating point literal, consider adding a `0` after the period + | +LL | 2.0E1; + | + + +error[E0610]: `{integer}` is a primitive type and therefore doesn't have fields + --> $DIR/suggest-adding-missing-zero-to-floating-point-number.rs:6:7 + | +LL | 2.f32; + | ^^^ + | +help: if intended to be a floating point literal, consider adding a `0` after the period + | +LL | 2.0f32; + | + + +error[E0610]: `{integer}` is a primitive type and therefore doesn't have fields + --> $DIR/suggest-adding-missing-zero-to-floating-point-number.rs:7:7 + | +LL | 2.f64; + | ^^^ + | +help: if intended to be a floating point literal, consider adding a `0` after the period + | +LL | 2.0f64; + | + + +error[E0610]: `{integer}` is a primitive type and therefore doesn't have fields + --> $DIR/suggest-adding-missing-zero-to-floating-point-number.rs:8:7 + | +LL | 2.e+12; + | ^ + | +help: if intended to be a floating point literal, consider adding a `0` after the period + | +LL | 2.0e+12; + | + + +error[E0610]: `{integer}` is a primitive type and therefore doesn't have fields + --> $DIR/suggest-adding-missing-zero-to-floating-point-number.rs:9:7 + | +LL | 2.e-12; + | ^ + | +help: if intended to be a floating point literal, consider adding a `0` after the period + | +LL | 2.0e-12; + | + + +error[E0610]: `{integer}` is a primitive type and therefore doesn't have fields + --> $DIR/suggest-adding-missing-zero-to-floating-point-number.rs:10:7 + | +LL | 2.e1f32; + | ^^^^^ + | +help: if intended to be a floating point literal, consider adding a `0` after the period + | +LL | 2.0e1f32; + | + + +error: aborting due to 7 previous errors + +For more information about this error, try `rustc --explain E0610`. diff --git a/tests/ui/typeck/type-placeholder-fn-in-const.rs b/tests/ui/typeck/type-placeholder-fn-in-const.rs new file mode 100644 index 000000000..ab2e2d8c5 --- /dev/null +++ b/tests/ui/typeck/type-placeholder-fn-in-const.rs @@ -0,0 +1,14 @@ +struct MyStruct; + +trait Test { + const TEST: fn() -> _; + //~^ ERROR: the placeholder `_` is not allowed within types on item signatures for functions [E0121] + //~| ERROR: the placeholder `_` is not allowed within types on item signatures for constants [E0121] +} + +impl Test for MyStruct { + const TEST: fn() -> _ = 42; + //~^ ERROR: the placeholder `_` is not allowed within types on item signatures for functions [E0121] +} + +fn main() {} diff --git a/tests/ui/typeck/type-placeholder-fn-in-const.stderr b/tests/ui/typeck/type-placeholder-fn-in-const.stderr new file mode 100644 index 000000000..e7b2e554a --- /dev/null +++ b/tests/ui/typeck/type-placeholder-fn-in-const.stderr @@ -0,0 +1,21 @@ +error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions + --> $DIR/type-placeholder-fn-in-const.rs:4:25 + | +LL | const TEST: fn() -> _; + | ^ not allowed in type signatures + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for constants + --> $DIR/type-placeholder-fn-in-const.rs:4:25 + | +LL | const TEST: fn() -> _; + | ^ not allowed in type signatures + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions + --> $DIR/type-placeholder-fn-in-const.rs:10:25 + | +LL | const TEST: fn() -> _ = 42; + | ^ not allowed in type signatures + +error: aborting due to 3 previous errors + +For more information about this error, try `rustc --explain E0121`. diff --git a/tests/ui/typeck/typeck-builtin-bound-type-parameters.rs b/tests/ui/typeck/typeck-builtin-bound-type-parameters.rs new file mode 100644 index 000000000..c463a8ad0 --- /dev/null +++ b/tests/ui/typeck/typeck-builtin-bound-type-parameters.rs @@ -0,0 +1,17 @@ +fn foo1<T:Copy<U>, U>(x: T) {} +//~^ ERROR this trait takes 0 generic arguments but 1 generic argument was supplied + +trait Trait: Copy<dyn Send> {} +//~^ ERROR this trait takes 0 generic arguments but 1 generic argument was supplied + +struct MyStruct1<T: Copy<T>>; +//~^ ERROR this trait takes 0 generic arguments but 1 generic argument was supplied + +struct MyStruct2<'a, T: Copy<'a>>; +//~^ ERROR this trait takes 0 lifetime arguments but 1 lifetime argument was supplied + +fn foo2<'a, T:Copy<'a, U>, U>(x: T) {} +//~^ ERROR this trait takes 0 lifetime arguments but 1 lifetime argument was supplied +//~| ERROR this trait takes 0 generic arguments but 1 generic argument was supplied + +fn main() { } diff --git a/tests/ui/typeck/typeck-builtin-bound-type-parameters.stderr b/tests/ui/typeck/typeck-builtin-bound-type-parameters.stderr new file mode 100644 index 000000000..331540d1e --- /dev/null +++ b/tests/ui/typeck/typeck-builtin-bound-type-parameters.stderr @@ -0,0 +1,51 @@ +error[E0107]: this trait takes 0 generic arguments but 1 generic argument was supplied + --> $DIR/typeck-builtin-bound-type-parameters.rs:1:11 + | +LL | fn foo1<T:Copy<U>, U>(x: T) {} + | ^^^^--- help: remove these generics + | | + | expected 0 generic arguments + +error[E0107]: this trait takes 0 generic arguments but 1 generic argument was supplied + --> $DIR/typeck-builtin-bound-type-parameters.rs:4:14 + | +LL | trait Trait: Copy<dyn Send> {} + | ^^^^---------- help: remove these generics + | | + | expected 0 generic arguments + +error[E0107]: this trait takes 0 generic arguments but 1 generic argument was supplied + --> $DIR/typeck-builtin-bound-type-parameters.rs:7:21 + | +LL | struct MyStruct1<T: Copy<T>>; + | ^^^^--- help: remove these generics + | | + | expected 0 generic arguments + +error[E0107]: this trait takes 0 lifetime arguments but 1 lifetime argument was supplied + --> $DIR/typeck-builtin-bound-type-parameters.rs:10:25 + | +LL | struct MyStruct2<'a, T: Copy<'a>>; + | ^^^^---- help: remove these generics + | | + | expected 0 lifetime arguments + +error[E0107]: this trait takes 0 lifetime arguments but 1 lifetime argument was supplied + --> $DIR/typeck-builtin-bound-type-parameters.rs:13:15 + | +LL | fn foo2<'a, T:Copy<'a, U>, U>(x: T) {} + | ^^^^ -- help: remove this lifetime argument + | | + | expected 0 lifetime arguments + +error[E0107]: this trait takes 0 generic arguments but 1 generic argument was supplied + --> $DIR/typeck-builtin-bound-type-parameters.rs:13:15 + | +LL | fn foo2<'a, T:Copy<'a, U>, U>(x: T) {} + | ^^^^ - help: remove this generic argument + | | + | expected 0 generic arguments + +error: aborting due to 6 previous errors + +For more information about this error, try `rustc --explain E0107`. diff --git a/tests/ui/typeck/typeck-cast-pointer-to-float.rs b/tests/ui/typeck/typeck-cast-pointer-to-float.rs new file mode 100644 index 000000000..2af7a3cf2 --- /dev/null +++ b/tests/ui/typeck/typeck-cast-pointer-to-float.rs @@ -0,0 +1,5 @@ +fn main() { + let x : i16 = 22; + ((&x) as *const i16) as f32; + //~^ ERROR casting `*const i16` as `f32` is invalid +} diff --git a/tests/ui/typeck/typeck-cast-pointer-to-float.stderr b/tests/ui/typeck/typeck-cast-pointer-to-float.stderr new file mode 100644 index 000000000..81d968454 --- /dev/null +++ b/tests/ui/typeck/typeck-cast-pointer-to-float.stderr @@ -0,0 +1,9 @@ +error[E0606]: casting `*const i16` as `f32` is invalid + --> $DIR/typeck-cast-pointer-to-float.rs:3:5 + | +LL | ((&x) as *const i16) as f32; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0606`. diff --git a/tests/ui/typeck/typeck-closure-to-unsafe-fn-ptr.rs b/tests/ui/typeck/typeck-closure-to-unsafe-fn-ptr.rs new file mode 100644 index 000000000..2530a1e96 --- /dev/null +++ b/tests/ui/typeck/typeck-closure-to-unsafe-fn-ptr.rs @@ -0,0 +1,9 @@ +// run-pass + +unsafe fn call_unsafe(func: unsafe fn() -> ()) -> () { + func() +} + +pub fn main() { + unsafe { call_unsafe(|| {}); } +} diff --git a/tests/ui/typeck/typeck-default-trait-impl-assoc-type.fixed b/tests/ui/typeck/typeck-default-trait-impl-assoc-type.fixed new file mode 100644 index 000000000..a9107f998 --- /dev/null +++ b/tests/ui/typeck/typeck-default-trait-impl-assoc-type.fixed @@ -0,0 +1,17 @@ +// run-rustfix +// Test that we do not consider associated types to be sendable without +// some applicable trait bound (and we don't ICE). +#![allow(dead_code)] + +trait Trait { + type AssocType; + fn dummy(&self) { } +} +fn bar<T:Trait+Send>() where <T as Trait>::AssocType: Send { + is_send::<T::AssocType>(); //~ ERROR E0277 +} + +fn is_send<T:Send>() { +} + +fn main() { } diff --git a/tests/ui/typeck/typeck-default-trait-impl-assoc-type.rs b/tests/ui/typeck/typeck-default-trait-impl-assoc-type.rs new file mode 100644 index 000000000..bafc16577 --- /dev/null +++ b/tests/ui/typeck/typeck-default-trait-impl-assoc-type.rs @@ -0,0 +1,17 @@ +// run-rustfix +// Test that we do not consider associated types to be sendable without +// some applicable trait bound (and we don't ICE). +#![allow(dead_code)] + +trait Trait { + type AssocType; + fn dummy(&self) { } +} +fn bar<T:Trait+Send>() { + is_send::<T::AssocType>(); //~ ERROR E0277 +} + +fn is_send<T:Send>() { +} + +fn main() { } diff --git a/tests/ui/typeck/typeck-default-trait-impl-assoc-type.stderr b/tests/ui/typeck/typeck-default-trait-impl-assoc-type.stderr new file mode 100644 index 000000000..468a14762 --- /dev/null +++ b/tests/ui/typeck/typeck-default-trait-impl-assoc-type.stderr @@ -0,0 +1,20 @@ +error[E0277]: `<T as Trait>::AssocType` cannot be sent between threads safely + --> $DIR/typeck-default-trait-impl-assoc-type.rs:11:15 + | +LL | is_send::<T::AssocType>(); + | ^^^^^^^^^^^^ `<T as Trait>::AssocType` cannot be sent between threads safely + | + = help: the trait `Send` is not implemented for `<T as Trait>::AssocType` +note: required by a bound in `is_send` + --> $DIR/typeck-default-trait-impl-assoc-type.rs:14:14 + | +LL | fn is_send<T:Send>() { + | ^^^^ required by this bound in `is_send` +help: consider further restricting the associated type + | +LL | fn bar<T:Trait+Send>() where <T as Trait>::AssocType: Send { + | +++++++++++++++++++++++++++++++++++ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/typeck/typeck-default-trait-impl-cross-crate-coherence.rs b/tests/ui/typeck/typeck-default-trait-impl-cross-crate-coherence.rs new file mode 100644 index 000000000..cc75cd490 --- /dev/null +++ b/tests/ui/typeck/typeck-default-trait-impl-cross-crate-coherence.rs @@ -0,0 +1,25 @@ +// aux-build:tdticc_coherence_lib.rs +#![allow(suspicious_auto_trait_impls)] + +// Test that we do not consider associated types to be sendable without +// some applicable trait bound (and we don't ICE). + +#![feature(negative_impls)] + +extern crate tdticc_coherence_lib as lib; + +use lib::DefaultedTrait; + +struct A; +impl DefaultedTrait for (A,) { } //~ ERROR E0117 + +struct B; +impl !DefaultedTrait for (B,) { } //~ ERROR E0117 + +struct C; +struct D<T>(T); +impl DefaultedTrait for Box<C> { } //~ ERROR E0321 +impl DefaultedTrait for lib::Something<C> { } //~ ERROR E0117 +impl DefaultedTrait for D<C> { } // OK + +fn main() { } diff --git a/tests/ui/typeck/typeck-default-trait-impl-cross-crate-coherence.stderr b/tests/ui/typeck/typeck-default-trait-impl-cross-crate-coherence.stderr new file mode 100644 index 000000000..fc3778b79 --- /dev/null +++ b/tests/ui/typeck/typeck-default-trait-impl-cross-crate-coherence.stderr @@ -0,0 +1,43 @@ +error[E0117]: only traits defined in the current crate can be implemented for arbitrary types + --> $DIR/typeck-default-trait-impl-cross-crate-coherence.rs:14:1 + | +LL | impl DefaultedTrait for (A,) { } + | ^^^^^^^^^^^^^^^^^^^^^^^^---- + | | | + | | this is not defined in the current crate because tuples are always foreign + | impl doesn't use only types from inside the current crate + | + = note: define and implement a trait or new type instead + +error[E0117]: only traits defined in the current crate can be implemented for arbitrary types + --> $DIR/typeck-default-trait-impl-cross-crate-coherence.rs:17:1 + | +LL | impl !DefaultedTrait for (B,) { } + | ^^^^^^^^^^^^^^^^^^^^^^^^^---- + | | | + | | this is not defined in the current crate because tuples are always foreign + | impl doesn't use only types from inside the current crate + | + = note: define and implement a trait or new type instead + +error[E0321]: cross-crate traits with a default impl, like `DefaultedTrait`, can only be implemented for a struct/enum type defined in the current crate + --> $DIR/typeck-default-trait-impl-cross-crate-coherence.rs:21:1 + | +LL | impl DefaultedTrait for Box<C> { } + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't implement cross-crate trait for type in another crate + +error[E0117]: only traits defined in the current crate can be implemented for types defined outside of the crate + --> $DIR/typeck-default-trait-impl-cross-crate-coherence.rs:22:1 + | +LL | impl DefaultedTrait for lib::Something<C> { } + | ^^^^^^^^^^^^^^^^^^^^^^^^----------------- + | | | + | | `Something` is not defined in the current crate + | impl doesn't use only types from inside the current crate + | + = note: define and implement a trait or new type instead + +error: aborting due to 4 previous errors + +Some errors have detailed explanations: E0117, E0321. +For more information about an error, try `rustc --explain E0117`. diff --git a/tests/ui/typeck/typeck-default-trait-impl-negation-send.rs b/tests/ui/typeck/typeck-default-trait-impl-negation-send.rs new file mode 100644 index 000000000..3a2fc39d4 --- /dev/null +++ b/tests/ui/typeck/typeck-default-trait-impl-negation-send.rs @@ -0,0 +1,21 @@ +#![feature(negative_impls)] + +struct MySendable { + t: *mut u8 +} + +unsafe impl Send for MySendable {} + +struct MyNotSendable { + t: *mut u8 +} + +impl !Send for MyNotSendable {} + +fn is_send<T: Send>() {} + +fn main() { + is_send::<MySendable>(); + is_send::<MyNotSendable>(); + //~^ ERROR `MyNotSendable` cannot be sent between threads safely +} diff --git a/tests/ui/typeck/typeck-default-trait-impl-negation-send.stderr b/tests/ui/typeck/typeck-default-trait-impl-negation-send.stderr new file mode 100644 index 000000000..2ce32990e --- /dev/null +++ b/tests/ui/typeck/typeck-default-trait-impl-negation-send.stderr @@ -0,0 +1,16 @@ +error[E0277]: `MyNotSendable` cannot be sent between threads safely + --> $DIR/typeck-default-trait-impl-negation-send.rs:19:15 + | +LL | is_send::<MyNotSendable>(); + | ^^^^^^^^^^^^^ `MyNotSendable` cannot be sent between threads safely + | + = help: the trait `Send` is not implemented for `MyNotSendable` +note: required by a bound in `is_send` + --> $DIR/typeck-default-trait-impl-negation-send.rs:15:15 + | +LL | fn is_send<T: Send>() {} + | ^^^^ required by this bound in `is_send` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/typeck/typeck-default-trait-impl-negation-sync.rs b/tests/ui/typeck/typeck-default-trait-impl-negation-sync.rs new file mode 100644 index 000000000..b9042188a --- /dev/null +++ b/tests/ui/typeck/typeck-default-trait-impl-negation-sync.rs @@ -0,0 +1,41 @@ +#![feature(negative_impls)] + +struct Managed; +impl !Send for Managed {} +impl !Sync for Managed {} + +use std::cell::UnsafeCell; + +struct MySync { + t: *mut u8 +} + +unsafe impl Sync for MySync {} + +struct MyNotSync { + t: *mut u8 +} + +impl !Sync for MyNotSync {} + +struct MyTypeWUnsafe { + t: UnsafeCell<u8> +} + +struct MyTypeManaged { + t: Managed +} + +fn is_sync<T: Sync>() {} + +fn main() { + is_sync::<MySync>(); + is_sync::<MyNotSync>(); + //~^ ERROR `MyNotSync` cannot be shared between threads safely [E0277] + + is_sync::<MyTypeWUnsafe>(); + //~^ ERROR `UnsafeCell<u8>` cannot be shared between threads safely [E0277] + + is_sync::<MyTypeManaged>(); + //~^ ERROR `Managed` cannot be shared between threads safely [E0277] +} diff --git a/tests/ui/typeck/typeck-default-trait-impl-negation-sync.stderr b/tests/ui/typeck/typeck-default-trait-impl-negation-sync.stderr new file mode 100644 index 000000000..b9fca1a1b --- /dev/null +++ b/tests/ui/typeck/typeck-default-trait-impl-negation-sync.stderr @@ -0,0 +1,52 @@ +error[E0277]: `MyNotSync` cannot be shared between threads safely + --> $DIR/typeck-default-trait-impl-negation-sync.rs:33:15 + | +LL | is_sync::<MyNotSync>(); + | ^^^^^^^^^ `MyNotSync` cannot be shared between threads safely + | + = help: the trait `Sync` is not implemented for `MyNotSync` +note: required by a bound in `is_sync` + --> $DIR/typeck-default-trait-impl-negation-sync.rs:29:15 + | +LL | fn is_sync<T: Sync>() {} + | ^^^^ required by this bound in `is_sync` + +error[E0277]: `UnsafeCell<u8>` cannot be shared between threads safely + --> $DIR/typeck-default-trait-impl-negation-sync.rs:36:15 + | +LL | is_sync::<MyTypeWUnsafe>(); + | ^^^^^^^^^^^^^ `UnsafeCell<u8>` cannot be shared between threads safely + | + = help: within `MyTypeWUnsafe`, the trait `Sync` is not implemented for `UnsafeCell<u8>` +note: required because it appears within the type `MyTypeWUnsafe` + --> $DIR/typeck-default-trait-impl-negation-sync.rs:21:8 + | +LL | struct MyTypeWUnsafe { + | ^^^^^^^^^^^^^ +note: required by a bound in `is_sync` + --> $DIR/typeck-default-trait-impl-negation-sync.rs:29:15 + | +LL | fn is_sync<T: Sync>() {} + | ^^^^ required by this bound in `is_sync` + +error[E0277]: `Managed` cannot be shared between threads safely + --> $DIR/typeck-default-trait-impl-negation-sync.rs:39:15 + | +LL | is_sync::<MyTypeManaged>(); + | ^^^^^^^^^^^^^ `Managed` cannot be shared between threads safely + | + = help: within `MyTypeManaged`, the trait `Sync` is not implemented for `Managed` +note: required because it appears within the type `MyTypeManaged` + --> $DIR/typeck-default-trait-impl-negation-sync.rs:25:8 + | +LL | struct MyTypeManaged { + | ^^^^^^^^^^^^^ +note: required by a bound in `is_sync` + --> $DIR/typeck-default-trait-impl-negation-sync.rs:29:15 + | +LL | fn is_sync<T: Sync>() {} + | ^^^^ required by this bound in `is_sync` + +error: aborting due to 3 previous errors + +For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/typeck/typeck-default-trait-impl-send-param.rs b/tests/ui/typeck/typeck-default-trait-impl-send-param.rs new file mode 100644 index 000000000..7948cd101 --- /dev/null +++ b/tests/ui/typeck/typeck-default-trait-impl-send-param.rs @@ -0,0 +1,11 @@ +// Test that we do not consider parameter types to be sendable without +// an explicit trait bound. + +fn foo<T>() { + is_send::<T>() //~ ERROR E0277 +} + +fn is_send<T:Send>() { +} + +fn main() { } diff --git a/tests/ui/typeck/typeck-default-trait-impl-send-param.stderr b/tests/ui/typeck/typeck-default-trait-impl-send-param.stderr new file mode 100644 index 000000000..887a1ddbb --- /dev/null +++ b/tests/ui/typeck/typeck-default-trait-impl-send-param.stderr @@ -0,0 +1,19 @@ +error[E0277]: `T` cannot be sent between threads safely + --> $DIR/typeck-default-trait-impl-send-param.rs:5:15 + | +LL | is_send::<T>() + | ^ `T` cannot be sent between threads safely + | +note: required by a bound in `is_send` + --> $DIR/typeck-default-trait-impl-send-param.rs:8:14 + | +LL | fn is_send<T:Send>() { + | ^^^^ required by this bound in `is_send` +help: consider restricting type parameter `T` + | +LL | fn foo<T: std::marker::Send>() { + | +++++++++++++++++++ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/typeck/typeck-fn-to-unsafe-fn-ptr.rs b/tests/ui/typeck/typeck-fn-to-unsafe-fn-ptr.rs new file mode 100644 index 000000000..1e954f569 --- /dev/null +++ b/tests/ui/typeck/typeck-fn-to-unsafe-fn-ptr.rs @@ -0,0 +1,12 @@ +// run-pass +// This tests reification from safe function to `unsafe fn` pointer + +fn do_nothing() -> () {} + +unsafe fn call_unsafe(func: unsafe fn() -> ()) -> () { + func() +} + +pub fn main() { + unsafe { call_unsafe(do_nothing); } +} diff --git a/tests/ui/typeck/typeck-unsafe-always-share.rs b/tests/ui/typeck/typeck-unsafe-always-share.rs new file mode 100644 index 000000000..be87ab172 --- /dev/null +++ b/tests/ui/typeck/typeck-unsafe-always-share.rs @@ -0,0 +1,32 @@ +// Verify that UnsafeCell is *always* !Sync regardless if `T` is sync. + +#![feature(negative_impls)] + +use std::cell::UnsafeCell; +use std::marker::Sync; + +struct MySync<T> { + u: UnsafeCell<T> +} + +struct NoSync; +impl !Sync for NoSync {} + +fn test<T: Sync>(s: T) {} + +fn main() { + let us = UnsafeCell::new(MySync{u: UnsafeCell::new(0)}); + test(us); + //~^ ERROR `UnsafeCell<MySync<{integer}>>` cannot be shared between threads safely + + let uns = UnsafeCell::new(NoSync); + test(uns); + //~^ ERROR `UnsafeCell<NoSync>` cannot be shared between threads safely [E0277] + + let ms = MySync{u: uns}; + test(ms); + //~^ ERROR `UnsafeCell<NoSync>` cannot be shared between threads safely [E0277] + + test(NoSync); + //~^ ERROR `NoSync` cannot be shared between threads safely [E0277] +} diff --git a/tests/ui/typeck/typeck-unsafe-always-share.stderr b/tests/ui/typeck/typeck-unsafe-always-share.stderr new file mode 100644 index 000000000..154e50499 --- /dev/null +++ b/tests/ui/typeck/typeck-unsafe-always-share.stderr @@ -0,0 +1,68 @@ +error[E0277]: `UnsafeCell<MySync<{integer}>>` cannot be shared between threads safely + --> $DIR/typeck-unsafe-always-share.rs:19:10 + | +LL | test(us); + | ---- ^^ `UnsafeCell<MySync<{integer}>>` cannot be shared between threads safely + | | + | required by a bound introduced by this call + | + = help: the trait `Sync` is not implemented for `UnsafeCell<MySync<{integer}>>` +note: required by a bound in `test` + --> $DIR/typeck-unsafe-always-share.rs:15:12 + | +LL | fn test<T: Sync>(s: T) {} + | ^^^^ required by this bound in `test` + +error[E0277]: `UnsafeCell<NoSync>` cannot be shared between threads safely + --> $DIR/typeck-unsafe-always-share.rs:23:10 + | +LL | test(uns); + | ---- ^^^ `UnsafeCell<NoSync>` cannot be shared between threads safely + | | + | required by a bound introduced by this call + | + = help: the trait `Sync` is not implemented for `UnsafeCell<NoSync>` +note: required by a bound in `test` + --> $DIR/typeck-unsafe-always-share.rs:15:12 + | +LL | fn test<T: Sync>(s: T) {} + | ^^^^ required by this bound in `test` + +error[E0277]: `UnsafeCell<NoSync>` cannot be shared between threads safely + --> $DIR/typeck-unsafe-always-share.rs:27:10 + | +LL | test(ms); + | ---- ^^ `UnsafeCell<NoSync>` cannot be shared between threads safely + | | + | required by a bound introduced by this call + | + = help: within `MySync<NoSync>`, the trait `Sync` is not implemented for `UnsafeCell<NoSync>` +note: required because it appears within the type `MySync<NoSync>` + --> $DIR/typeck-unsafe-always-share.rs:8:8 + | +LL | struct MySync<T> { + | ^^^^^^ +note: required by a bound in `test` + --> $DIR/typeck-unsafe-always-share.rs:15:12 + | +LL | fn test<T: Sync>(s: T) {} + | ^^^^ required by this bound in `test` + +error[E0277]: `NoSync` cannot be shared between threads safely + --> $DIR/typeck-unsafe-always-share.rs:30:10 + | +LL | test(NoSync); + | ---- ^^^^^^ `NoSync` cannot be shared between threads safely + | | + | required by a bound introduced by this call + | + = help: the trait `Sync` is not implemented for `NoSync` +note: required by a bound in `test` + --> $DIR/typeck-unsafe-always-share.rs:15:12 + | +LL | fn test<T: Sync>(s: T) {} + | ^^^^ required by this bound in `test` + +error: aborting due to 4 previous errors + +For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/typeck/typeck_type_placeholder_1.rs b/tests/ui/typeck/typeck_type_placeholder_1.rs new file mode 100644 index 000000000..ea7aa5285 --- /dev/null +++ b/tests/ui/typeck/typeck_type_placeholder_1.rs @@ -0,0 +1,32 @@ +// run-pass + +#![allow(dead_code)] +// This test checks that the `_` type placeholder works +// correctly for enabling type inference. + + +struct TestStruct { + x: *const isize +} + +unsafe impl Sync for TestStruct {} + +static CONSTEXPR: TestStruct = TestStruct{ x: &413 }; + + +pub fn main() { + let x: Vec<_> = (0..5).collect(); + let expected: &[usize] = &[0,1,2,3,4]; + assert_eq!(x, expected); + + let x = (0..5).collect::<Vec<_>>(); + assert_eq!(x, expected); + + let y: _ = "hello"; + assert_eq!(y.len(), 5); + + let ptr: &usize = &5; + let ptr2 = ptr as *const _; + + assert_eq!(ptr as *const usize as usize, ptr2 as usize); +} diff --git a/tests/ui/typeck/typeck_type_placeholder_item.rs b/tests/ui/typeck/typeck_type_placeholder_item.rs new file mode 100644 index 000000000..b96c52713 --- /dev/null +++ b/tests/ui/typeck/typeck_type_placeholder_item.rs @@ -0,0 +1,230 @@ +// Needed for `type Y = impl Trait<_>` and `type B = _;` +#![feature(associated_type_defaults)] +#![feature(type_alias_impl_trait)] +// This test checks that it is not possible to enable global type +// inference by using the `_` type placeholder. + +fn test() -> _ { 5 } +//~^ ERROR the placeholder `_` is not allowed within types on item signatures for return types + +fn test2() -> (_, _) { (5, 5) } +//~^ ERROR the placeholder `_` is not allowed within types on item signatures for return types + +static TEST3: _ = "test"; +//~^ ERROR the placeholder `_` is not allowed within types on item signatures for static variables + +static TEST4: _ = 145; +//~^ ERROR the placeholder `_` is not allowed within types on item signatures for static variables + +static TEST5: (_, _) = (1, 2); +//~^ ERROR the placeholder `_` is not allowed within types on item signatures for static variables + +fn test6(_: _) { } +//~^ ERROR the placeholder `_` is not allowed within types on item signatures for functions + +fn test6_b<T>(_: _, _: T) { } +//~^ ERROR the placeholder `_` is not allowed within types on item signatures for functions + +fn test6_c<T, K, L, A, B>(_: _, _: (T, K, L, A, B)) { } +//~^ ERROR the placeholder `_` is not allowed within types on item signatures for functions + +fn test7(x: _) { let _x: usize = x; } +//~^ ERROR the placeholder `_` is not allowed within types on item signatures for functions + +fn test8(_f: fn() -> _) { } +//~^ ERROR the placeholder `_` is not allowed within types on item signatures for functions +//~^^ ERROR the placeholder `_` is not allowed within types on item signatures for functions + +struct Test9; + +impl Test9 { + fn test9(&self) -> _ { () } + //~^ ERROR the placeholder `_` is not allowed within types on item signatures for return types + + fn test10(&self, _x : _) { } + //~^ ERROR the placeholder `_` is not allowed within types on item signatures for functions +} + +fn test11(x: &usize) -> &_ { +//~^ ERROR the placeholder `_` is not allowed within types on item signatures for return types + &x +} + +unsafe fn test12(x: *const usize) -> *const *const _ { +//~^ ERROR the placeholder `_` is not allowed within types on item signatures for return types + &x +} + +impl Clone for Test9 { + fn clone(&self) -> _ { Test9 } + //~^ ERROR the placeholder `_` is not allowed within types on item signatures for functions + + fn clone_from(&mut self, other: _) { *self = Test9; } + //~^ ERROR the placeholder `_` is not allowed within types on item signatures for functions +} + +struct Test10 { + a: _, + //~^ ERROR the placeholder `_` is not allowed within types on item signatures for structs + b: (_, _), +} + +pub fn main() { + static A = 42; + //~^ ERROR missing type for `static` item + static B: _ = 42; + //~^ ERROR the placeholder `_` is not allowed within types on item signatures for static variables + static C: Option<_> = Some(42); + //~^ ERROR the placeholder `_` is not allowed within types on item signatures for static variables + fn fn_test() -> _ { 5 } + //~^ ERROR the placeholder `_` is not allowed within types on item signatures for return types + + fn fn_test2() -> (_, _) { (5, 5) } + //~^ ERROR the placeholder `_` is not allowed within types on item signatures for return types + + static FN_TEST3: _ = "test"; + //~^ ERROR the placeholder `_` is not allowed within types on item signatures for static variables + + static FN_TEST4: _ = 145; + //~^ ERROR the placeholder `_` is not allowed within types on item signatures for static variables + + static FN_TEST5: (_, _) = (1, 2); + //~^ ERROR the placeholder `_` is not allowed within types on item signatures for static variables + + fn fn_test6(_: _) { } + //~^ ERROR the placeholder `_` is not allowed within types on item signatures for functions + + fn fn_test7(x: _) { let _x: usize = x; } + //~^ ERROR the placeholder `_` is not allowed within types on item signatures for functions + + fn fn_test8(_f: fn() -> _) { } + //~^ ERROR the placeholder `_` is not allowed within types on item signatures for functions + //~^^ ERROR the placeholder `_` is not allowed within types on item signatures for functions + + struct FnTest9; + + impl FnTest9 { + fn fn_test9(&self) -> _ { () } + //~^ ERROR the placeholder `_` is not allowed within types on item signatures for return types + + fn fn_test10(&self, _x : _) { } + //~^ ERROR the placeholder `_` is not allowed within types on item signatures for functions + } + + impl Clone for FnTest9 { + fn clone(&self) -> _ { FnTest9 } + //~^ ERROR the placeholder `_` is not allowed within types on item signatures for functions + + fn clone_from(&mut self, other: _) { *self = FnTest9; } + //~^ ERROR the placeholder `_` is not allowed within types on item signatures for functions + } + + struct FnTest10 { + a: _, + //~^ ERROR the placeholder `_` is not allowed within types on item signatures for structs + b: (_, _), + } + + fn fn_test11(_: _) -> (_, _) { panic!() } + //~^ ERROR the placeholder `_` is not allowed within types on item signatures for return types + //~| ERROR type annotations needed + + fn fn_test12(x: i32) -> (_, _) { (x, x) } + //~^ ERROR the placeholder `_` is not allowed within types on item signatures for return types + + fn fn_test13(x: _) -> (i32, _) { (x, x) } + //~^ ERROR the placeholder `_` is not allowed within types on item signatures for return types +} + +trait T { + fn method_test1(&self, x: _); + //~^ ERROR the placeholder `_` is not allowed within types on item signatures for functions + fn method_test2(&self, x: _) -> _; + //~^ ERROR the placeholder `_` is not allowed within types on item signatures for functions + fn method_test3(&self) -> _; + //~^ ERROR the placeholder `_` is not allowed within types on item signatures for functions + fn assoc_fn_test1(x: _); + //~^ ERROR the placeholder `_` is not allowed within types on item signatures for functions + fn assoc_fn_test2(x: _) -> _; + //~^ ERROR the placeholder `_` is not allowed within types on item signatures for functions + fn assoc_fn_test3() -> _; + //~^ ERROR the placeholder `_` is not allowed within types on item signatures for functions +} + +struct BadStruct<_>(_); +//~^ ERROR expected identifier, found reserved identifier `_` +//~| ERROR the placeholder `_` is not allowed within types on item signatures for structs +trait BadTrait<_> {} +//~^ ERROR expected identifier, found reserved identifier `_` +impl BadTrait<_> for BadStruct<_> {} +//~^ ERROR the placeholder `_` is not allowed within types on item signatures for implementations + +fn impl_trait() -> impl BadTrait<_> { +//~^ ERROR the placeholder `_` is not allowed within types on item signatures for opaque types + unimplemented!() +} + +struct BadStruct1<_, _>(_); +//~^ ERROR expected identifier, found reserved identifier `_` +//~| ERROR expected identifier, found reserved identifier `_` +//~| ERROR the name `_` is already used +//~| ERROR the placeholder `_` is not allowed within types on item signatures for structs +struct BadStruct2<_, T>(_, T); +//~^ ERROR expected identifier, found reserved identifier `_` +//~| ERROR the placeholder `_` is not allowed within types on item signatures for structs + +type X = Box<_>; +//~^ ERROR the placeholder `_` is not allowed within types on item signatures for type aliases + +struct Struct; +trait Trait<T> {} +impl Trait<usize> for Struct {} +type Y = impl Trait<_>; +//~^ ERROR the placeholder `_` is not allowed within types on item signatures for opaque types +fn foo() -> Y { + Struct +} + +trait Qux { + type A; + type B = _; + //~^ ERROR the placeholder `_` is not allowed within types on item signatures for associated types + const C: _; + //~^ ERROR the placeholder `_` is not allowed within types on item signatures for constants + const D: _ = 42; + //~^ ERROR the placeholder `_` is not allowed within types on item signatures for constants + // type E: _; // FIXME: make the parser propagate the existence of `B` + type F: std::ops::Fn(_); + //~^ ERROR the placeholder `_` is not allowed within types on item signatures for associated types +} +impl Qux for Struct { + type A = _; + //~^ ERROR the placeholder `_` is not allowed within types on item signatures for associated types + type B = _; + //~^ ERROR the placeholder `_` is not allowed within types on item signatures for associated types + const C: _; + //~^ ERROR the placeholder `_` is not allowed within types on item signatures for constants + //~| ERROR associated constant in `impl` without body + const D: _ = 42; + //~^ ERROR the placeholder `_` is not allowed within types on item signatures for constants +} + +fn map<T>(_: fn() -> Option<&'static T>) -> Option<T> { + None +} + +fn value() -> Option<&'static _> { +//~^ ERROR the placeholder `_` is not allowed within types on item signatures for return types + Option::<&'static u8>::None +} + +const _: Option<_> = map(value); +//~^ ERROR the placeholder `_` is not allowed within types on item signatures for constants + +fn evens_squared(n: usize) -> _ { +//~^ ERROR the placeholder `_` is not allowed within types on item signatures for return types + (1..n).filter(|x| x % 2 == 0).map(|x| x * x) +} + +const _: _ = (1..10).filter(|x| x % 2 == 0).map(|x| x * x); +//~^ ERROR the placeholder `_` is not allowed within types on item signatures for constants diff --git a/tests/ui/typeck/typeck_type_placeholder_item.stderr b/tests/ui/typeck/typeck_type_placeholder_item.stderr new file mode 100644 index 000000000..bc02547c6 --- /dev/null +++ b/tests/ui/typeck/typeck_type_placeholder_item.stderr @@ -0,0 +1,663 @@ +error: expected identifier, found reserved identifier `_` + --> $DIR/typeck_type_placeholder_item.rs:154:18 + | +LL | struct BadStruct<_>(_); + | ^ expected identifier, found reserved identifier + +error: expected identifier, found reserved identifier `_` + --> $DIR/typeck_type_placeholder_item.rs:157:16 + | +LL | trait BadTrait<_> {} + | ^ expected identifier, found reserved identifier + +error: expected identifier, found reserved identifier `_` + --> $DIR/typeck_type_placeholder_item.rs:167:19 + | +LL | struct BadStruct1<_, _>(_); + | ^ expected identifier, found reserved identifier + +error: expected identifier, found reserved identifier `_` + --> $DIR/typeck_type_placeholder_item.rs:167:22 + | +LL | struct BadStruct1<_, _>(_); + | ^ expected identifier, found reserved identifier + +error: expected identifier, found reserved identifier `_` + --> $DIR/typeck_type_placeholder_item.rs:172:19 + | +LL | struct BadStruct2<_, T>(_, T); + | ^ expected identifier, found reserved identifier + +error: associated constant in `impl` without body + --> $DIR/typeck_type_placeholder_item.rs:205:5 + | +LL | const C: _; + | ^^^^^^^^^^- + | | + | help: provide a definition for the constant: `= <expr>;` + +error[E0403]: the name `_` is already used for a generic parameter in this item's generic parameters + --> $DIR/typeck_type_placeholder_item.rs:167:22 + | +LL | struct BadStruct1<_, _>(_); + | - ^ already used + | | + | first use of `_` + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types + --> $DIR/typeck_type_placeholder_item.rs:7:14 + | +LL | fn test() -> _ { 5 } + | ^ + | | + | not allowed in type signatures + | help: replace with the correct return type: `i32` + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types + --> $DIR/typeck_type_placeholder_item.rs:10:16 + | +LL | fn test2() -> (_, _) { (5, 5) } + | -^--^- + | || | + | || not allowed in type signatures + | |not allowed in type signatures + | help: replace with the correct return type: `(i32, i32)` + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for static variables + --> $DIR/typeck_type_placeholder_item.rs:13:15 + | +LL | static TEST3: _ = "test"; + | ^ + | | + | not allowed in type signatures + | help: replace with the correct type: `&str` + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for static variables + --> $DIR/typeck_type_placeholder_item.rs:16:15 + | +LL | static TEST4: _ = 145; + | ^ + | | + | not allowed in type signatures + | help: replace with the correct type: `i32` + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for static variables + --> $DIR/typeck_type_placeholder_item.rs:19:15 + | +LL | static TEST5: (_, _) = (1, 2); + | ^^^^^^ not allowed in type signatures + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions + --> $DIR/typeck_type_placeholder_item.rs:22:13 + | +LL | fn test6(_: _) { } + | ^ not allowed in type signatures + | +help: use type parameters instead + | +LL | fn test6<T>(_: T) { } + | +++ ~ + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions + --> $DIR/typeck_type_placeholder_item.rs:25:18 + | +LL | fn test6_b<T>(_: _, _: T) { } + | ^ not allowed in type signatures + | +help: use type parameters instead + | +LL | fn test6_b<T, U>(_: U, _: T) { } + | +++ ~ + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions + --> $DIR/typeck_type_placeholder_item.rs:28:30 + | +LL | fn test6_c<T, K, L, A, B>(_: _, _: (T, K, L, A, B)) { } + | ^ not allowed in type signatures + | +help: use type parameters instead + | +LL | fn test6_c<T, K, L, A, B, U>(_: U, _: (T, K, L, A, B)) { } + | +++ ~ + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions + --> $DIR/typeck_type_placeholder_item.rs:31:13 + | +LL | fn test7(x: _) { let _x: usize = x; } + | ^ not allowed in type signatures + | +help: use type parameters instead + | +LL | fn test7<T>(x: T) { let _x: usize = x; } + | +++ ~ + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions + --> $DIR/typeck_type_placeholder_item.rs:34:22 + | +LL | fn test8(_f: fn() -> _) { } + | ^ + | | + | not allowed in type signatures + | help: use type parameters instead: `T` + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions + --> $DIR/typeck_type_placeholder_item.rs:34:22 + | +LL | fn test8(_f: fn() -> _) { } + | ^ not allowed in type signatures + | +help: use type parameters instead + | +LL | fn test8<T>(_f: fn() -> T) { } + | +++ ~ + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types + --> $DIR/typeck_type_placeholder_item.rs:48:26 + | +LL | fn test11(x: &usize) -> &_ { + | -^ + | || + | |not allowed in type signatures + | help: replace with the correct return type: `&'static &'static usize` + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types + --> $DIR/typeck_type_placeholder_item.rs:53:52 + | +LL | unsafe fn test12(x: *const usize) -> *const *const _ { + | --------------^ + | | | + | | not allowed in type signatures + | help: replace with the correct return type: `*const *const usize` + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for structs + --> $DIR/typeck_type_placeholder_item.rs:67:8 + | +LL | a: _, + | ^ not allowed in type signatures +LL | +LL | b: (_, _), + | ^ ^ not allowed in type signatures + | | + | not allowed in type signatures + | +help: use type parameters instead + | +LL ~ struct Test10<T> { +LL ~ a: T, +LL | +LL ~ b: (T, T), + | + +error: missing type for `static` item + --> $DIR/typeck_type_placeholder_item.rs:73:13 + | +LL | static A = 42; + | ^ help: provide a type for the static variable: `: i32` + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for static variables + --> $DIR/typeck_type_placeholder_item.rs:75:15 + | +LL | static B: _ = 42; + | ^ + | | + | not allowed in type signatures + | help: replace with the correct type: `i32` + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for static variables + --> $DIR/typeck_type_placeholder_item.rs:77:15 + | +LL | static C: Option<_> = Some(42); + | ^^^^^^^^^ not allowed in type signatures + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types + --> $DIR/typeck_type_placeholder_item.rs:79:21 + | +LL | fn fn_test() -> _ { 5 } + | ^ + | | + | not allowed in type signatures + | help: replace with the correct return type: `i32` + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types + --> $DIR/typeck_type_placeholder_item.rs:82:23 + | +LL | fn fn_test2() -> (_, _) { (5, 5) } + | -^--^- + | || | + | || not allowed in type signatures + | |not allowed in type signatures + | help: replace with the correct return type: `(i32, i32)` + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for static variables + --> $DIR/typeck_type_placeholder_item.rs:85:22 + | +LL | static FN_TEST3: _ = "test"; + | ^ + | | + | not allowed in type signatures + | help: replace with the correct type: `&str` + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for static variables + --> $DIR/typeck_type_placeholder_item.rs:88:22 + | +LL | static FN_TEST4: _ = 145; + | ^ + | | + | not allowed in type signatures + | help: replace with the correct type: `i32` + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for static variables + --> $DIR/typeck_type_placeholder_item.rs:91:22 + | +LL | static FN_TEST5: (_, _) = (1, 2); + | ^^^^^^ not allowed in type signatures + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions + --> $DIR/typeck_type_placeholder_item.rs:94:20 + | +LL | fn fn_test6(_: _) { } + | ^ not allowed in type signatures + | +help: use type parameters instead + | +LL | fn fn_test6<T>(_: T) { } + | +++ ~ + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions + --> $DIR/typeck_type_placeholder_item.rs:97:20 + | +LL | fn fn_test7(x: _) { let _x: usize = x; } + | ^ not allowed in type signatures + | +help: use type parameters instead + | +LL | fn fn_test7<T>(x: T) { let _x: usize = x; } + | +++ ~ + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions + --> $DIR/typeck_type_placeholder_item.rs:100:29 + | +LL | fn fn_test8(_f: fn() -> _) { } + | ^ + | | + | not allowed in type signatures + | help: use type parameters instead: `T` + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions + --> $DIR/typeck_type_placeholder_item.rs:100:29 + | +LL | fn fn_test8(_f: fn() -> _) { } + | ^ not allowed in type signatures + | +help: use type parameters instead + | +LL | fn fn_test8<T>(_f: fn() -> T) { } + | +++ ~ + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for structs + --> $DIR/typeck_type_placeholder_item.rs:123:12 + | +LL | a: _, + | ^ not allowed in type signatures +LL | +LL | b: (_, _), + | ^ ^ not allowed in type signatures + | | + | not allowed in type signatures + | +help: use type parameters instead + | +LL ~ struct FnTest10<T> { +LL ~ a: T, +LL | +LL ~ b: (T, T), + | + +error[E0282]: type annotations needed + --> $DIR/typeck_type_placeholder_item.rs:128:18 + | +LL | fn fn_test11(_: _) -> (_, _) { panic!() } + | ^ cannot infer type + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types + --> $DIR/typeck_type_placeholder_item.rs:128:28 + | +LL | fn fn_test11(_: _) -> (_, _) { panic!() } + | ^ ^ not allowed in type signatures + | | + | not allowed in type signatures + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types + --> $DIR/typeck_type_placeholder_item.rs:132:30 + | +LL | fn fn_test12(x: i32) -> (_, _) { (x, x) } + | -^--^- + | || | + | || not allowed in type signatures + | |not allowed in type signatures + | help: replace with the correct return type: `(i32, i32)` + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types + --> $DIR/typeck_type_placeholder_item.rs:135:33 + | +LL | fn fn_test13(x: _) -> (i32, _) { (x, x) } + | ------^- + | | | + | | not allowed in type signatures + | help: replace with the correct return type: `(i32, i32)` + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for structs + --> $DIR/typeck_type_placeholder_item.rs:154:21 + | +LL | struct BadStruct<_>(_); + | ^ not allowed in type signatures + | +help: use type parameters instead + | +LL | struct BadStruct<T>(T); + | ~ ~ + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for implementations + --> $DIR/typeck_type_placeholder_item.rs:159:15 + | +LL | impl BadTrait<_> for BadStruct<_> {} + | ^ ^ not allowed in type signatures + | | + | not allowed in type signatures + | +help: use type parameters instead + | +LL | impl<T> BadTrait<T> for BadStruct<T> {} + | +++ ~ ~ + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for opaque types + --> $DIR/typeck_type_placeholder_item.rs:162:34 + | +LL | fn impl_trait() -> impl BadTrait<_> { + | ^ not allowed in type signatures + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for structs + --> $DIR/typeck_type_placeholder_item.rs:167:25 + | +LL | struct BadStruct1<_, _>(_); + | ^ not allowed in type signatures + | +help: use type parameters instead + | +LL | struct BadStruct1<T, _>(T); + | ~ ~ + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for structs + --> $DIR/typeck_type_placeholder_item.rs:172:25 + | +LL | struct BadStruct2<_, T>(_, T); + | ^ not allowed in type signatures + | +help: use type parameters instead + | +LL | struct BadStruct2<U, T>(U, T); + | ~ ~ + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for type aliases + --> $DIR/typeck_type_placeholder_item.rs:176:14 + | +LL | type X = Box<_>; + | ^ not allowed in type signatures + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for opaque types + --> $DIR/typeck_type_placeholder_item.rs:182:21 + | +LL | type Y = impl Trait<_>; + | ^ not allowed in type signatures + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types + --> $DIR/typeck_type_placeholder_item.rs:216:31 + | +LL | fn value() -> Option<&'static _> { + | ----------------^- + | | | + | | not allowed in type signatures + | help: replace with the correct return type: `Option<&'static u8>` + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for constants + --> $DIR/typeck_type_placeholder_item.rs:221:10 + | +LL | const _: Option<_> = map(value); + | ^^^^^^^^^ + | | + | not allowed in type signatures + | help: replace with the correct type: `Option<u8>` + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types + --> $DIR/typeck_type_placeholder_item.rs:224:31 + | +LL | fn evens_squared(n: usize) -> _ { + | ^ + | | + | not allowed in type signatures + | help: replace with an appropriate return type: `impl Iterator<Item = usize>` + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for constants + --> $DIR/typeck_type_placeholder_item.rs:229:10 + | +LL | const _: _ = (1..10).filter(|x| x % 2 == 0).map(|x| x * x); + | ^ not allowed in type signatures + | +note: however, the inferred type `Map<Filter<Range<i32>, [closure@typeck_type_placeholder_item.rs:229:29]>, [closure@typeck_type_placeholder_item.rs:229:49]>` cannot be named + --> $DIR/typeck_type_placeholder_item.rs:229:14 + | +LL | const _: _ = (1..10).filter(|x| x % 2 == 0).map(|x| x * x); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions + --> $DIR/typeck_type_placeholder_item.rs:140:31 + | +LL | fn method_test1(&self, x: _); + | ^ not allowed in type signatures + | +help: use type parameters instead + | +LL | fn method_test1<T>(&self, x: T); + | +++ ~ + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions + --> $DIR/typeck_type_placeholder_item.rs:142:31 + | +LL | fn method_test2(&self, x: _) -> _; + | ^ ^ not allowed in type signatures + | | + | not allowed in type signatures + | +help: use type parameters instead + | +LL | fn method_test2<T>(&self, x: T) -> T; + | +++ ~ ~ + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions + --> $DIR/typeck_type_placeholder_item.rs:144:31 + | +LL | fn method_test3(&self) -> _; + | ^ not allowed in type signatures + | +help: use type parameters instead + | +LL | fn method_test3<T>(&self) -> T; + | +++ ~ + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions + --> $DIR/typeck_type_placeholder_item.rs:146:26 + | +LL | fn assoc_fn_test1(x: _); + | ^ not allowed in type signatures + | +help: use type parameters instead + | +LL | fn assoc_fn_test1<T>(x: T); + | +++ ~ + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions + --> $DIR/typeck_type_placeholder_item.rs:148:26 + | +LL | fn assoc_fn_test2(x: _) -> _; + | ^ ^ not allowed in type signatures + | | + | not allowed in type signatures + | +help: use type parameters instead + | +LL | fn assoc_fn_test2<T>(x: T) -> T; + | +++ ~ ~ + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions + --> $DIR/typeck_type_placeholder_item.rs:150:28 + | +LL | fn assoc_fn_test3() -> _; + | ^ not allowed in type signatures + | +help: use type parameters instead + | +LL | fn assoc_fn_test3<T>() -> T; + | +++ ~ + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for associated types + --> $DIR/typeck_type_placeholder_item.rs:190:14 + | +LL | type B = _; + | ^ not allowed in type signatures + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for constants + --> $DIR/typeck_type_placeholder_item.rs:192:14 + | +LL | const C: _; + | ^ not allowed in type signatures + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for constants + --> $DIR/typeck_type_placeholder_item.rs:194:14 + | +LL | const D: _ = 42; + | ^ + | | + | not allowed in type signatures + | help: replace with the correct type: `i32` + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for associated types + --> $DIR/typeck_type_placeholder_item.rs:197:26 + | +LL | type F: std::ops::Fn(_); + | ^ not allowed in type signatures + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types + --> $DIR/typeck_type_placeholder_item.rs:41:24 + | +LL | fn test9(&self) -> _ { () } + | ^ + | | + | not allowed in type signatures + | help: replace with the correct return type: `()` + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions + --> $DIR/typeck_type_placeholder_item.rs:44:27 + | +LL | fn test10(&self, _x : _) { } + | ^ not allowed in type signatures + | +help: use type parameters instead + | +LL | fn test10<T>(&self, _x : T) { } + | +++ ~ + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions + --> $DIR/typeck_type_placeholder_item.rs:59:24 + | +LL | fn clone(&self) -> _ { Test9 } + | ^ not allowed in type signatures + | +help: try replacing `_` with the type in the corresponding trait method signature + | +LL | fn clone(&self) -> Test9 { Test9 } + | ~~~~~ + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions + --> $DIR/typeck_type_placeholder_item.rs:62:37 + | +LL | fn clone_from(&mut self, other: _) { *self = Test9; } + | ^ not allowed in type signatures + | +help: try replacing `_` with the type in the corresponding trait method signature + | +LL | fn clone_from(&mut self, other: &Test9) { *self = Test9; } + | ~~~~~~ + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types + --> $DIR/typeck_type_placeholder_item.rs:107:31 + | +LL | fn fn_test9(&self) -> _ { () } + | ^ + | | + | not allowed in type signatures + | help: replace with the correct return type: `()` + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions + --> $DIR/typeck_type_placeholder_item.rs:110:34 + | +LL | fn fn_test10(&self, _x : _) { } + | ^ not allowed in type signatures + | +help: use type parameters instead + | +LL | fn fn_test10<T>(&self, _x : T) { } + | +++ ~ + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions + --> $DIR/typeck_type_placeholder_item.rs:115:28 + | +LL | fn clone(&self) -> _ { FnTest9 } + | ^ not allowed in type signatures + | +help: try replacing `_` with the type in the corresponding trait method signature + | +LL | fn clone(&self) -> FnTest9 { FnTest9 } + | ~~~~~~~ + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions + --> $DIR/typeck_type_placeholder_item.rs:118:41 + | +LL | fn clone_from(&mut self, other: _) { *self = FnTest9; } + | ^ not allowed in type signatures + | +help: try replacing `_` with the type in the corresponding trait method signature + | +LL | fn clone_from(&mut self, other: &FnTest9) { *self = FnTest9; } + | ~~~~~~~~ + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for associated types + --> $DIR/typeck_type_placeholder_item.rs:201:14 + | +LL | type A = _; + | ^ not allowed in type signatures + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for associated types + --> $DIR/typeck_type_placeholder_item.rs:203:14 + | +LL | type B = _; + | ^ not allowed in type signatures + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for constants + --> $DIR/typeck_type_placeholder_item.rs:205:14 + | +LL | const C: _; + | ^ not allowed in type signatures + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for constants + --> $DIR/typeck_type_placeholder_item.rs:208:14 + | +LL | const D: _ = 42; + | ^ + | | + | not allowed in type signatures + | help: replace with the correct type: `i32` + +error: aborting due to 71 previous errors + +Some errors have detailed explanations: E0121, E0282, E0403. +For more information about an error, try `rustc --explain E0121`. diff --git a/tests/ui/typeck/typeck_type_placeholder_item_help.rs b/tests/ui/typeck/typeck_type_placeholder_item_help.rs new file mode 100644 index 000000000..c459d8c3c --- /dev/null +++ b/tests/ui/typeck/typeck_type_placeholder_item_help.rs @@ -0,0 +1,33 @@ +// This test checks that it proper item type will be suggested when +// using the `_` type placeholder. + +fn test1() -> _ { Some(42) } +//~^ ERROR the placeholder `_` is not allowed within types on item signatures for return types + +const TEST2: _ = 42u32; +//~^ ERROR the placeholder `_` is not allowed within types on item signatures for constants + +const TEST3: _ = Some(42); +//~^ ERROR the placeholder `_` is not allowed within types on item signatures for constants + +const TEST4: fn() -> _ = 42; +//~^ ERROR the placeholder `_` is not allowed within types on item signatures for functions +//~| ERROR the placeholder `_` is not allowed within types on item signatures for constant items + +trait Test5 { + const TEST5: _ = 42; + //~^ ERROR the placeholder `_` is not allowed within types on item signatures for constants +} + +struct Test6; + +impl Test6 { + const TEST6: _ = 13; + //~^ ERROR the placeholder `_` is not allowed within types on item signatures for constants +} + +pub fn main() { + let _: Option<usize> = test1(); + let _: f64 = test1(); + let _: Option<i32> = test1(); +} diff --git a/tests/ui/typeck/typeck_type_placeholder_item_help.stderr b/tests/ui/typeck/typeck_type_placeholder_item_help.stderr new file mode 100644 index 000000000..07a5dbd93 --- /dev/null +++ b/tests/ui/typeck/typeck_type_placeholder_item_help.stderr @@ -0,0 +1,60 @@ +error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types + --> $DIR/typeck_type_placeholder_item_help.rs:4:15 + | +LL | fn test1() -> _ { Some(42) } + | ^ + | | + | not allowed in type signatures + | help: replace with the correct return type: `Option<i32>` + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for constants + --> $DIR/typeck_type_placeholder_item_help.rs:7:14 + | +LL | const TEST2: _ = 42u32; + | ^ + | | + | not allowed in type signatures + | help: replace with the correct type: `u32` + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for constants + --> $DIR/typeck_type_placeholder_item_help.rs:10:14 + | +LL | const TEST3: _ = Some(42); + | ^ + | | + | not allowed in type signatures + | help: replace with the correct type: `Option<i32>` + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions + --> $DIR/typeck_type_placeholder_item_help.rs:13:22 + | +LL | const TEST4: fn() -> _ = 42; + | ^ not allowed in type signatures + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for constant items + --> $DIR/typeck_type_placeholder_item_help.rs:13:22 + | +LL | const TEST4: fn() -> _ = 42; + | ^ not allowed in type signatures + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for constants + --> $DIR/typeck_type_placeholder_item_help.rs:18:18 + | +LL | const TEST5: _ = 42; + | ^ + | | + | not allowed in type signatures + | help: replace with the correct type: `i32` + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for constants + --> $DIR/typeck_type_placeholder_item_help.rs:25:18 + | +LL | const TEST6: _ = 13; + | ^ + | | + | not allowed in type signatures + | help: replace with the correct type: `i32` + +error: aborting due to 7 previous errors + +For more information about this error, try `rustc --explain E0121`. diff --git a/tests/ui/typeck/typeck_type_placeholder_lifetime_1.rs b/tests/ui/typeck/typeck_type_placeholder_lifetime_1.rs new file mode 100644 index 000000000..43e46c5b6 --- /dev/null +++ b/tests/ui/typeck/typeck_type_placeholder_lifetime_1.rs @@ -0,0 +1,11 @@ +// This test checks that the `_` type placeholder does not react +// badly if put as a lifetime parameter. + +struct Foo<'a, T:'a> { + r: &'a T +} + +pub fn main() { + let c: Foo<_, _> = Foo { r: &5 }; + //~^ ERROR this struct takes 1 generic argument but 2 generic arguments were supplied +} diff --git a/tests/ui/typeck/typeck_type_placeholder_lifetime_1.stderr b/tests/ui/typeck/typeck_type_placeholder_lifetime_1.stderr new file mode 100644 index 000000000..a89c6b85c --- /dev/null +++ b/tests/ui/typeck/typeck_type_placeholder_lifetime_1.stderr @@ -0,0 +1,17 @@ +error[E0107]: this struct takes 1 generic argument but 2 generic arguments were supplied + --> $DIR/typeck_type_placeholder_lifetime_1.rs:9:12 + | +LL | let c: Foo<_, _> = Foo { r: &5 }; + | ^^^ - help: remove this generic argument + | | + | expected 1 generic argument + | +note: struct defined here, with 1 generic parameter: `T` + --> $DIR/typeck_type_placeholder_lifetime_1.rs:4:8 + | +LL | struct Foo<'a, T:'a> { + | ^^^ - + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0107`. diff --git a/tests/ui/typeck/typeck_type_placeholder_lifetime_2.rs b/tests/ui/typeck/typeck_type_placeholder_lifetime_2.rs new file mode 100644 index 000000000..178b8b122 --- /dev/null +++ b/tests/ui/typeck/typeck_type_placeholder_lifetime_2.rs @@ -0,0 +1,11 @@ +// This test checks that the `_` type placeholder does not react +// badly if put as a lifetime parameter. + +struct Foo<'a, T:'a> { + r: &'a T +} + +pub fn main() { + let c: Foo<_, usize> = Foo { r: &5 }; + //~^ ERROR this struct takes 1 generic argument but 2 generic arguments were supplied +} diff --git a/tests/ui/typeck/typeck_type_placeholder_lifetime_2.stderr b/tests/ui/typeck/typeck_type_placeholder_lifetime_2.stderr new file mode 100644 index 000000000..f30766bdf --- /dev/null +++ b/tests/ui/typeck/typeck_type_placeholder_lifetime_2.stderr @@ -0,0 +1,17 @@ +error[E0107]: this struct takes 1 generic argument but 2 generic arguments were supplied + --> $DIR/typeck_type_placeholder_lifetime_2.rs:9:12 + | +LL | let c: Foo<_, usize> = Foo { r: &5 }; + | ^^^ ----- help: remove this generic argument + | | + | expected 1 generic argument + | +note: struct defined here, with 1 generic parameter: `T` + --> $DIR/typeck_type_placeholder_lifetime_2.rs:4:8 + | +LL | struct Foo<'a, T:'a> { + | ^^^ - + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0107`. diff --git a/tests/ui/typeck/typeck_type_placeholder_mismatch.rs b/tests/ui/typeck/typeck_type_placeholder_mismatch.rs new file mode 100644 index 000000000..2f9cfcf8d --- /dev/null +++ b/tests/ui/typeck/typeck_type_placeholder_mismatch.rs @@ -0,0 +1,27 @@ +// This test checks that genuine type errors with partial +// type hints are understandable. + +use std::marker::PhantomData; + +struct Foo<T>(PhantomData<T>); +struct Bar<U>(PhantomData<U>); + +pub fn main() { +} + +fn test1() { + let x: Foo<_> = Bar::<usize>(PhantomData); + //~^ ERROR mismatched types + //~| expected struct `Foo<_>` + //~| found struct `Bar<usize>` + //~| expected struct `Foo`, found struct `Bar` + let y: Foo<usize> = x; +} + +fn test2() { + let x: Foo<_> = Bar::<usize>(PhantomData); + //~^ ERROR mismatched types + //~| expected struct `Foo<_>` + //~| found struct `Bar<usize>` + //~| expected struct `Foo`, found struct `Bar` +} diff --git a/tests/ui/typeck/typeck_type_placeholder_mismatch.stderr b/tests/ui/typeck/typeck_type_placeholder_mismatch.stderr new file mode 100644 index 000000000..867412a24 --- /dev/null +++ b/tests/ui/typeck/typeck_type_placeholder_mismatch.stderr @@ -0,0 +1,25 @@ +error[E0308]: mismatched types + --> $DIR/typeck_type_placeholder_mismatch.rs:13:21 + | +LL | let x: Foo<_> = Bar::<usize>(PhantomData); + | ------ ^^^^^^^^^^^^^^^^^^^^^^^^^ expected struct `Foo`, found struct `Bar` + | | + | expected due to this + | + = note: expected struct `Foo<_>` + found struct `Bar<usize>` + +error[E0308]: mismatched types + --> $DIR/typeck_type_placeholder_mismatch.rs:22:21 + | +LL | let x: Foo<_> = Bar::<usize>(PhantomData); + | ------ ^^^^^^^^^^^^^^^^^^^^^^^^^ expected struct `Foo`, found struct `Bar` + | | + | expected due to this + | + = note: expected struct `Foo<_>` + found struct `Bar<usize>` + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/typeck/ufcs-type-params.rs b/tests/ui/typeck/ufcs-type-params.rs new file mode 100644 index 000000000..eee2b55b2 --- /dev/null +++ b/tests/ui/typeck/ufcs-type-params.rs @@ -0,0 +1,15 @@ +// run-pass +// pretty-expanded FIXME #23616 + +trait Foo<T> { + fn get(&self) -> T; +} + +impl Foo<i32> for i32 { + fn get(&self) -> i32 { *self } +} + +fn main() { + let x: i32 = 1; + Foo::<i32>::get(&x); +} diff --git a/tests/ui/typeck/unify-return-ty.rs b/tests/ui/typeck/unify-return-ty.rs new file mode 100644 index 000000000..da1d82e89 --- /dev/null +++ b/tests/ui/typeck/unify-return-ty.rs @@ -0,0 +1,16 @@ +// run-pass +// Tests that the tail expr in null() has its type +// unified with the type *T, and so the type variable +// in that type gets resolved. + +// pretty-expanded FIXME #23616 + +use std::mem; + +fn null<T>() -> *const T { + unsafe { + mem::transmute(0_usize) + } +} + +pub fn main() { null::<isize>(); } diff --git a/tests/ui/typeck/while-loop-block-cond.rs b/tests/ui/typeck/while-loop-block-cond.rs new file mode 100644 index 000000000..929759766 --- /dev/null +++ b/tests/ui/typeck/while-loop-block-cond.rs @@ -0,0 +1,4 @@ +fn main() { + while {} {} + //~^ ERROR mismatched types [E0308] +} diff --git a/tests/ui/typeck/while-loop-block-cond.stderr b/tests/ui/typeck/while-loop-block-cond.stderr new file mode 100644 index 000000000..598273af9 --- /dev/null +++ b/tests/ui/typeck/while-loop-block-cond.stderr @@ -0,0 +1,9 @@ +error[E0308]: mismatched types + --> $DIR/while-loop-block-cond.rs:2:11 + | +LL | while {} {} + | ^^ expected `bool`, found `()` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0308`. |