diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:06:31 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:06:31 +0000 |
commit | 2ff14448863ac1a1dd9533461708e29aae170c2d (patch) | |
tree | 85b9fea2bbfe3f06473cfa381eed11f273b57c5c /src/test/ui/suggestions | |
parent | Adding debian version 1.64.0+dfsg1-1. (diff) | |
download | rustc-2ff14448863ac1a1dd9533461708e29aae170c2d.tar.xz rustc-2ff14448863ac1a1dd9533461708e29aae170c2d.zip |
Adding debian version 1.65.0+dfsg1-2.debian/1.65.0+dfsg1-2
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/test/ui/suggestions')
101 files changed, 1321 insertions, 290 deletions
diff --git a/src/test/ui/suggestions/args-instead-of-tuple-errors.stderr b/src/test/ui/suggestions/args-instead-of-tuple-errors.stderr index 805c75f46..0a91c442d 100644 --- a/src/test/ui/suggestions/args-instead-of-tuple-errors.stderr +++ b/src/test/ui/suggestions/args-instead-of-tuple-errors.stderr @@ -2,10 +2,13 @@ error[E0061]: this enum variant takes 1 argument but 2 arguments were supplied --> $DIR/args-instead-of-tuple-errors.rs:6:34 | LL | let _: Option<(i32, bool)> = Some(1, 2); - | ^^^^ - - argument of type `{integer}` unexpected - | | - | expected tuple, found integer + | ^^^^ - argument of type `{integer}` unexpected | +note: expected tuple, found integer + --> $DIR/args-instead-of-tuple-errors.rs:6:39 + | +LL | let _: Option<(i32, bool)> = Some(1, 2); + | ^ = note: expected tuple `(i32, bool)` found type `{integer}` note: tuple variant defined here @@ -16,16 +19,19 @@ LL | Some(#[stable(feature = "rust1", since = "1.0.0")] T), help: remove the extra argument | LL | let _: Option<(i32, bool)> = Some(/* (i32, bool) */); - | ~~~~~~~~~~~~~~~~~~~~~~~ + | ~~~~~~~~~~~~~~~~~~~ error[E0061]: this function takes 1 argument but 2 arguments were supplied --> $DIR/args-instead-of-tuple-errors.rs:8:5 | LL | int_bool(1, 2); - | ^^^^^^^^ - - argument of type `{integer}` unexpected - | | - | expected tuple, found integer + | ^^^^^^^^ - argument of type `{integer}` unexpected | +note: expected tuple, found integer + --> $DIR/args-instead-of-tuple-errors.rs:8:14 + | +LL | int_bool(1, 2); + | ^ = note: expected tuple `(i32, bool)` found type `{integer}` note: function defined here @@ -36,7 +42,7 @@ LL | fn int_bool(_: (i32, bool)) { help: remove the extra argument | LL | int_bool(/* (i32, bool) */); - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~ + | ~~~~~~~~~~~~~~~~~~~ error[E0061]: this enum variant takes 1 argument but 0 arguments were supplied --> $DIR/args-instead-of-tuple-errors.rs:11:28 @@ -52,7 +58,7 @@ LL | Some(#[stable(feature = "rust1", since = "1.0.0")] T), help: provide the argument | LL | let _: Option<(i8,)> = Some(/* (i8,) */); - | ~~~~~~~~~~~~~~~~~ + | ~~~~~~~~~~~~~ error[E0308]: mismatched types --> $DIR/args-instead-of-tuple-errors.rs:14:34 diff --git a/src/test/ui/suggestions/args-instead-of-tuple.stderr b/src/test/ui/suggestions/args-instead-of-tuple.stderr index 2448a5149..20f9e5259 100644 --- a/src/test/ui/suggestions/args-instead-of-tuple.stderr +++ b/src/test/ui/suggestions/args-instead-of-tuple.stderr @@ -44,7 +44,7 @@ LL | Some(#[stable(feature = "rust1", since = "1.0.0")] T), help: provide the argument | LL | let _: Option<()> = Some(()); - | ~~~~~~~~ + | ~~~~ error[E0308]: mismatched types --> $DIR/args-instead-of-tuple.rs:14:34 diff --git a/src/test/ui/suggestions/as-ref-2.fixed b/src/test/ui/suggestions/as-ref-2.fixed deleted file mode 100644 index 13bbb233f..000000000 --- a/src/test/ui/suggestions/as-ref-2.fixed +++ /dev/null @@ -1,13 +0,0 @@ -// run-rustfix - -struct Struct; - -fn bar(_: &Struct) -> Struct { - Struct -} - -fn main() { - let foo = Some(Struct); - let _x: Option<Struct> = foo.as_ref().map(|s| bar(&s)); - let _y = foo; //~ERROR use of moved value: `foo` -} diff --git a/src/test/ui/suggestions/as-ref-2.rs b/src/test/ui/suggestions/as-ref-2.rs index 74d61cdd9..b22f409b4 100644 --- a/src/test/ui/suggestions/as-ref-2.rs +++ b/src/test/ui/suggestions/as-ref-2.rs @@ -1,5 +1,3 @@ -// run-rustfix - struct Struct; fn bar(_: &Struct) -> Struct { diff --git a/src/test/ui/suggestions/as-ref-2.stderr b/src/test/ui/suggestions/as-ref-2.stderr index 3c9d0f72a..e15e45d86 100644 --- a/src/test/ui/suggestions/as-ref-2.stderr +++ b/src/test/ui/suggestions/as-ref-2.stderr @@ -1,10 +1,12 @@ error[E0382]: use of moved value: `foo` - --> $DIR/as-ref-2.rs:12:14 + --> $DIR/as-ref-2.rs:10:14 | LL | let foo = Some(Struct); | --- move occurs because `foo` has type `Option<Struct>`, which does not implement the `Copy` trait LL | let _x: Option<Struct> = foo.map(|s| bar(&s)); - | ---------------- `foo` moved due to this method call + | --- ---------------- `foo` moved due to this method call + | | + | help: consider calling `.as_ref()` or `.as_mut()` to borrow the type's contents LL | let _y = foo; | ^^^ value used here after move | @@ -13,10 +15,6 @@ note: this function takes ownership of the receiver `self`, which moves `foo` | LL | pub const fn map<U, F>(self, f: F) -> Option<U> | ^^^^ -help: consider calling `.as_ref()` to borrow the type's contents - | -LL | let _x: Option<Struct> = foo.as_ref().map(|s| bar(&s)); - | +++++++++ error: aborting due to previous error diff --git a/src/test/ui/suggestions/as-ref.rs b/src/test/ui/suggestions/as-ref.rs index 46d946153..a05353441 100644 --- a/src/test/ui/suggestions/as-ref.rs +++ b/src/test/ui/suggestions/as-ref.rs @@ -17,4 +17,11 @@ fn main() { // note: do not suggest because of `E: usize` let x: &Result<usize, usize> = &Ok(3); let y: Result<&usize, usize> = x; //~ ERROR mismatched types [E0308] + + let multiple_ref_opt = &&Some(Foo); + multiple_ref_opt.map(|arg| takes_ref(arg)); //~ ERROR mismatched types [E0308] + multiple_ref_opt.and_then(|arg| Some(takes_ref(arg))); //~ ERROR mismatched types [E0308] + let multiple_ref_result = &&Ok(Foo); + multiple_ref_result.map(|arg| takes_ref(arg)); //~ ERROR mismatched types [E0308] + multiple_ref_result.and_then(|arg| Ok(takes_ref(arg))); //~ ERROR mismatched types [E0308] } diff --git a/src/test/ui/suggestions/as-ref.stderr b/src/test/ui/suggestions/as-ref.stderr index 1efd1b317..deafa9f48 100644 --- a/src/test/ui/suggestions/as-ref.stderr +++ b/src/test/ui/suggestions/as-ref.stderr @@ -97,6 +97,66 @@ LL | let y: Result<&usize, usize> = x; = note: expected enum `Result<&usize, usize>` found reference `&Result<usize, usize>` -error: aborting due to 7 previous errors +error[E0308]: mismatched types + --> $DIR/as-ref.rs:22:42 + | +LL | multiple_ref_opt.map(|arg| takes_ref(arg)); + | --- --------- ^^^ expected `&Foo`, found struct `Foo` + | | | + | | arguments to this function are incorrect + | help: consider using `as_ref` instead: `as_ref().map` + | +note: function defined here + --> $DIR/as-ref.rs:3:4 + | +LL | fn takes_ref(_: &Foo) {} + | ^^^^^^^^^ ------- + +error[E0308]: mismatched types + --> $DIR/as-ref.rs:23:52 + | +LL | multiple_ref_opt.and_then(|arg| Some(takes_ref(arg))); + | -------- --------- ^^^ expected `&Foo`, found struct `Foo` + | | | + | | arguments to this function are incorrect + | help: consider using `as_ref` instead: `as_ref().and_then` + | +note: function defined here + --> $DIR/as-ref.rs:3:4 + | +LL | fn takes_ref(_: &Foo) {} + | ^^^^^^^^^ ------- + +error[E0308]: mismatched types + --> $DIR/as-ref.rs:25:45 + | +LL | multiple_ref_result.map(|arg| takes_ref(arg)); + | --- --------- ^^^ expected `&Foo`, found struct `Foo` + | | | + | | arguments to this function are incorrect + | help: consider using `as_ref` instead: `as_ref().map` + | +note: function defined here + --> $DIR/as-ref.rs:3:4 + | +LL | fn takes_ref(_: &Foo) {} + | ^^^^^^^^^ ------- + +error[E0308]: mismatched types + --> $DIR/as-ref.rs:26:53 + | +LL | multiple_ref_result.and_then(|arg| Ok(takes_ref(arg))); + | -------- --------- ^^^ expected `&Foo`, found struct `Foo` + | | | + | | arguments to this function are incorrect + | help: consider using `as_ref` instead: `as_ref().and_then` + | +note: function defined here + --> $DIR/as-ref.rs:3:4 + | +LL | fn takes_ref(_: &Foo) {} + | ^^^^^^^^^ ------- + +error: aborting due to 11 previous errors For more information about this error, try `rustc --explain E0308`. diff --git a/src/test/ui/suggestions/assoc-const-as-field.stderr b/src/test/ui/suggestions/assoc-const-as-field.stderr index 5e746ecb2..78e5634b2 100644 --- a/src/test/ui/suggestions/assoc-const-as-field.stderr +++ b/src/test/ui/suggestions/assoc-const-as-field.stderr @@ -2,9 +2,7 @@ error[E0423]: expected value, found struct `Mod::Foo` --> $DIR/assoc-const-as-field.rs:11:9 | LL | foo(Mod::Foo.Bar); - | ^^^^^^^^---- - | | - | help: use the path separator to refer to an item: `Mod::Foo::Bar` + | ^^^^^^^^- help: use the path separator to refer to an item: `::` error: aborting due to previous error diff --git a/src/test/ui/suggestions/async-fn-ctor-passed-as-arg-where-it-should-have-been-called.stderr b/src/test/ui/suggestions/async-fn-ctor-passed-as-arg-where-it-should-have-been-called.stderr index c7d420e0a..bfd506c9f 100644 --- a/src/test/ui/suggestions/async-fn-ctor-passed-as-arg-where-it-should-have-been-called.stderr +++ b/src/test/ui/suggestions/async-fn-ctor-passed-as-arg-where-it-should-have-been-called.stderr @@ -9,7 +9,7 @@ LL | bar(foo); | | | required by a bound introduced by this call | - = help: the trait `Future` is not implemented for `fn() -> impl Future<Output = ()> {foo}` + = help: the trait `Future` is not implemented for fn item `fn() -> impl Future<Output = ()> {foo}` = note: fn() -> impl Future<Output = ()> {foo} must be a future or must implement `IntoFuture` to be awaited note: required by a bound in `bar` --> $DIR/async-fn-ctor-passed-as-arg-where-it-should-have-been-called.rs:7:16 @@ -31,7 +31,7 @@ LL | bar(async_closure); | | | required by a bound introduced by this call | - = help: the trait `Future` is not implemented for `[closure@$DIR/async-fn-ctor-passed-as-arg-where-it-should-have-been-called.rs:11:25: 11:33]` + = help: the trait `Future` is not implemented for closure `[closure@$DIR/async-fn-ctor-passed-as-arg-where-it-should-have-been-called.rs:11:25: 11:33]` = note: [closure@$DIR/async-fn-ctor-passed-as-arg-where-it-should-have-been-called.rs:11:25: 11:33] must be a future or must implement `IntoFuture` to be awaited note: required by a bound in `bar` --> $DIR/async-fn-ctor-passed-as-arg-where-it-should-have-been-called.rs:7:16 diff --git a/src/test/ui/suggestions/bool_typo_err_suggest.rs b/src/test/ui/suggestions/bool_typo_err_suggest.rs new file mode 100644 index 000000000..deab0fb05 --- /dev/null +++ b/src/test/ui/suggestions/bool_typo_err_suggest.rs @@ -0,0 +1,12 @@ +// Suggest the boolean value instead of emit a generic error that the value +// True is not in the scope. + +fn main() { + let x = True; + //~^ ERROR cannot find value `True` in this scope + //~| HELP you may want to use a bool value instead + + let y = False; + //~^ ERROR cannot find value `False` in this scope + //~| HELP you may want to use a bool value instead +} diff --git a/src/test/ui/suggestions/bool_typo_err_suggest.stderr b/src/test/ui/suggestions/bool_typo_err_suggest.stderr new file mode 100644 index 000000000..52bde07ca --- /dev/null +++ b/src/test/ui/suggestions/bool_typo_err_suggest.stderr @@ -0,0 +1,25 @@ +error[E0425]: cannot find value `True` in this scope + --> $DIR/bool_typo_err_suggest.rs:5:13 + | +LL | let x = True; + | ^^^^ not found in this scope + | +help: you may want to use a bool value instead + | +LL | let x = true; + | ~~~~ + +error[E0425]: cannot find value `False` in this scope + --> $DIR/bool_typo_err_suggest.rs:9:13 + | +LL | let y = False; + | ^^^^^ not found in this scope + | +help: you may want to use a bool value instead + | +LL | let y = false; + | ~~~~~ + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0425`. diff --git a/src/test/ui/suggestions/call-boxed.rs b/src/test/ui/suggestions/call-boxed.rs new file mode 100644 index 000000000..d19e4596a --- /dev/null +++ b/src/test/ui/suggestions/call-boxed.rs @@ -0,0 +1,7 @@ +fn main() { + let mut x = 1i32; + let y = Box::new(|| 1); + x = y; + //~^ ERROR mismatched types + //~| HELP use parentheses to call this closure +} diff --git a/src/test/ui/suggestions/call-boxed.stderr b/src/test/ui/suggestions/call-boxed.stderr new file mode 100644 index 000000000..9b619ac9a --- /dev/null +++ b/src/test/ui/suggestions/call-boxed.stderr @@ -0,0 +1,20 @@ +error[E0308]: mismatched types + --> $DIR/call-boxed.rs:4:9 + | +LL | let mut x = 1i32; + | ---- expected due to this value +LL | let y = Box::new(|| 1); + | -- the found closure +LL | x = y; + | ^ expected `i32`, found struct `Box` + | + = note: expected type `i32` + found struct `Box<[closure@$DIR/call-boxed.rs:3:22: 3:24]>` +help: use parentheses to call this closure + | +LL | x = y(); + | ++ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0308`. diff --git a/src/test/ui/suggestions/call-on-missing.rs b/src/test/ui/suggestions/call-on-missing.rs new file mode 100644 index 000000000..25ced84dd --- /dev/null +++ b/src/test/ui/suggestions/call-on-missing.rs @@ -0,0 +1,39 @@ +struct Foo { i: i32 } + +impl Foo { + fn bar(&self) {} +} + +fn foo() -> Foo { + Foo { i: 1 } +} + +fn main() { + foo.bar(); + //~^ ERROR no method named `bar` + //~| HELP use parentheses to call this function + + foo.i; + //~^ ERROR no field `i` + //~| HELP use parentheses to call this function + + let callable = Box::new(|| Foo { i: 1 }) as Box<dyn Fn() -> Foo>; + + callable.bar(); + //~^ ERROR no method named `bar` + //~| HELP use parentheses to call this trait object + + callable.i; + //~^ ERROR no field `i` + //~| HELP use parentheses to call this trait object +} + +fn type_param<T: Fn() -> Foo>(t: T) { + t.bar(); + //~^ ERROR no method named `bar` + //~| HELP use parentheses to call this type parameter + + t.i; + //~^ ERROR no field `i` + //~| HELP use parentheses to call this type parameter +} diff --git a/src/test/ui/suggestions/call-on-missing.stderr b/src/test/ui/suggestions/call-on-missing.stderr new file mode 100644 index 000000000..ca9abc7e9 --- /dev/null +++ b/src/test/ui/suggestions/call-on-missing.stderr @@ -0,0 +1,75 @@ +error[E0599]: no method named `bar` found for fn item `fn() -> Foo {foo}` in the current scope + --> $DIR/call-on-missing.rs:12:9 + | +LL | foo.bar(); + | ^^^ method not found in `fn() -> Foo {foo}` + | +help: use parentheses to call this function + | +LL | foo().bar(); + | ++ + +error[E0609]: no field `i` on type `fn() -> Foo {foo}` + --> $DIR/call-on-missing.rs:16:9 + | +LL | foo.i; + | ^ + | +help: use parentheses to call this function + | +LL | foo().i; + | ++ + +error[E0599]: no method named `bar` found for struct `Box<dyn Fn() -> Foo>` in the current scope + --> $DIR/call-on-missing.rs:22:14 + | +LL | callable.bar(); + | ^^^ method not found in `Box<dyn Fn() -> Foo>` + | +help: use parentheses to call this trait object + | +LL | callable().bar(); + | ++ + +error[E0609]: no field `i` on type `Box<dyn Fn() -> Foo>` + --> $DIR/call-on-missing.rs:26:14 + | +LL | callable.i; + | ^ unknown field + | +help: use parentheses to call this trait object + | +LL | callable().i; + | ++ + +error[E0599]: no method named `bar` found for type parameter `T` in the current scope + --> $DIR/call-on-missing.rs:32:7 + | +LL | fn type_param<T: Fn() -> Foo>(t: T) { + | - method `bar` not found for this type parameter +LL | t.bar(); + | ^^^ method not found in `T` + | +help: use parentheses to call this type parameter + | +LL | t().bar(); + | ++ + +error[E0609]: no field `i` on type `T` + --> $DIR/call-on-missing.rs:36:7 + | +LL | fn type_param<T: Fn() -> Foo>(t: T) { + | - type parameter 'T' declared here +... +LL | t.i; + | ^ + | +help: use parentheses to call this type parameter + | +LL | t().i; + | ++ + +error: aborting due to 6 previous errors + +Some errors have detailed explanations: E0599, E0609. +For more information about an error, try `rustc --explain E0599`. diff --git a/src/test/ui/suggestions/const-no-type.rs b/src/test/ui/suggestions/const-no-type.rs index 6f46cfdf0..c6fdcdadb 100644 --- a/src/test/ui/suggestions/const-no-type.rs +++ b/src/test/ui/suggestions/const-no-type.rs @@ -14,38 +14,38 @@ fn main() {} const C2 = 42; //~^ ERROR missing type for `const` item //~| HELP provide a type for the item -//~| SUGGESTION C2: <type> +//~| SUGGESTION : <type> #[cfg(FALSE)] static S2 = "abc"; //~^ ERROR missing type for `static` item //~| HELP provide a type for the item -//~| SUGGESTION S2: <type> +//~| SUGGESTION : <type> #[cfg(FALSE)] static mut SM2 = "abc"; //~^ ERROR missing type for `static mut` item //~| HELP provide a type for the item -//~| SUGGESTION SM2: <type> +//~| SUGGESTION : <type> // These will, so the diagnostics should be stolen by typeck: const C = 42; //~^ ERROR missing type for `const` item //~| HELP provide a type for the constant -//~| SUGGESTION C: i32 +//~| SUGGESTION : i32 const D = &&42; //~^ ERROR missing type for `const` item //~| HELP provide a type for the constant -//~| SUGGESTION D: &&i32 +//~| SUGGESTION : &&i32 static S = Vec::<String>::new(); //~^ ERROR missing type for `static` item //~| HELP provide a type for the static variable -//~| SUGGESTION S: Vec<String> +//~| SUGGESTION : Vec<String> static mut SM = "abc"; //~^ ERROR missing type for `static mut` item //~| HELP provide a type for the static variable -//~| SUGGESTION &str +//~| SUGGESTION : &str diff --git a/src/test/ui/suggestions/const-no-type.stderr b/src/test/ui/suggestions/const-no-type.stderr index 3b0fd6337..bd703992f 100644 --- a/src/test/ui/suggestions/const-no-type.stderr +++ b/src/test/ui/suggestions/const-no-type.stderr @@ -1,44 +1,44 @@ error: missing type for `const` item - --> $DIR/const-no-type.rs:33:7 + --> $DIR/const-no-type.rs:33:8 | LL | const C = 42; - | ^ help: provide a type for the constant: `C: i32` + | ^ help: provide a type for the constant: `: i32` error: missing type for `const` item - --> $DIR/const-no-type.rs:38:7 + --> $DIR/const-no-type.rs:38:8 | LL | const D = &&42; - | ^ help: provide a type for the constant: `D: &&i32` + | ^ help: provide a type for the constant: `: &&i32` error: missing type for `static` item - --> $DIR/const-no-type.rs:43:8 + --> $DIR/const-no-type.rs:43:9 | LL | static S = Vec::<String>::new(); - | ^ help: provide a type for the static variable: `S: Vec<String>` + | ^ help: provide a type for the static variable: `: Vec<String>` error: missing type for `static mut` item - --> $DIR/const-no-type.rs:48:12 + --> $DIR/const-no-type.rs:48:14 | LL | static mut SM = "abc"; - | ^^ help: provide a type for the static variable: `SM: &str` + | ^ help: provide a type for the static variable: `: &str` error: missing type for `const` item - --> $DIR/const-no-type.rs:14:7 + --> $DIR/const-no-type.rs:14:9 | LL | const C2 = 42; - | ^^ help: provide a type for the item: `C2: <type>` + | ^ help: provide a type for the item: `: <type>` error: missing type for `static` item - --> $DIR/const-no-type.rs:20:8 + --> $DIR/const-no-type.rs:20:10 | LL | static S2 = "abc"; - | ^^ help: provide a type for the item: `S2: <type>` + | ^ help: provide a type for the item: `: <type>` error: missing type for `static mut` item - --> $DIR/const-no-type.rs:26:12 + --> $DIR/const-no-type.rs:26:15 | LL | static mut SM2 = "abc"; - | ^^^ help: provide a type for the item: `SM2: <type>` + | ^ help: provide a type for the item: `: <type>` error: aborting due to 7 previous errors diff --git a/src/test/ui/suggestions/copied-and-cloned.fixed b/src/test/ui/suggestions/copied-and-cloned.fixed new file mode 100644 index 000000000..f801403fe --- /dev/null +++ b/src/test/ui/suggestions/copied-and-cloned.fixed @@ -0,0 +1,23 @@ +// run-rustfix + +fn expect<T>(_: T) {} + +fn main() { + let x = Some(&()); + expect::<Option<()>>(x.copied()); + //~^ ERROR mismatched types + //~| HELP use `Option::copied` to copy the value inside the `Option` + let x = Ok(&()); + expect::<Result<(), ()>>(x.copied()); + //~^ ERROR mismatched types + //~| HELP use `Result::copied` to copy the value inside the `Result` + let s = String::new(); + let x = Some(&s); + expect::<Option<String>>(x.cloned()); + //~^ ERROR mismatched types + //~| HELP use `Option::cloned` to clone the value inside the `Option` + let x = Ok(&s); + expect::<Result<String, ()>>(x.cloned()); + //~^ ERROR mismatched types + //~| HELP use `Result::cloned` to clone the value inside the `Result` +} diff --git a/src/test/ui/suggestions/copied-and-cloned.rs b/src/test/ui/suggestions/copied-and-cloned.rs new file mode 100644 index 000000000..640450b76 --- /dev/null +++ b/src/test/ui/suggestions/copied-and-cloned.rs @@ -0,0 +1,23 @@ +// run-rustfix + +fn expect<T>(_: T) {} + +fn main() { + let x = Some(&()); + expect::<Option<()>>(x); + //~^ ERROR mismatched types + //~| HELP use `Option::copied` to copy the value inside the `Option` + let x = Ok(&()); + expect::<Result<(), ()>>(x); + //~^ ERROR mismatched types + //~| HELP use `Result::copied` to copy the value inside the `Result` + let s = String::new(); + let x = Some(&s); + expect::<Option<String>>(x); + //~^ ERROR mismatched types + //~| HELP use `Option::cloned` to clone the value inside the `Option` + let x = Ok(&s); + expect::<Result<String, ()>>(x); + //~^ ERROR mismatched types + //~| HELP use `Result::cloned` to clone the value inside the `Result` +} diff --git a/src/test/ui/suggestions/copied-and-cloned.stderr b/src/test/ui/suggestions/copied-and-cloned.stderr new file mode 100644 index 000000000..a6336281b --- /dev/null +++ b/src/test/ui/suggestions/copied-and-cloned.stderr @@ -0,0 +1,83 @@ +error[E0308]: mismatched types + --> $DIR/copied-and-cloned.rs:7:26 + | +LL | expect::<Option<()>>(x); + | -------------------- ^ expected `()`, found `&()` + | | + | arguments to this function are incorrect + | + = note: expected enum `Option<()>` + found enum `Option<&()>` +note: function defined here + --> $DIR/copied-and-cloned.rs:3:4 + | +LL | fn expect<T>(_: T) {} + | ^^^^^^ ---- +help: use `Option::copied` to copy the value inside the `Option` + | +LL | expect::<Option<()>>(x.copied()); + | +++++++++ + +error[E0308]: mismatched types + --> $DIR/copied-and-cloned.rs:11:30 + | +LL | expect::<Result<(), ()>>(x); + | ------------------------ ^ expected `()`, found `&()` + | | + | arguments to this function are incorrect + | + = note: expected enum `Result<(), ()>` + found enum `Result<&(), _>` +note: function defined here + --> $DIR/copied-and-cloned.rs:3:4 + | +LL | fn expect<T>(_: T) {} + | ^^^^^^ ---- +help: use `Result::copied` to copy the value inside the `Result` + | +LL | expect::<Result<(), ()>>(x.copied()); + | +++++++++ + +error[E0308]: mismatched types + --> $DIR/copied-and-cloned.rs:16:30 + | +LL | expect::<Option<String>>(x); + | ------------------------ ^ expected struct `String`, found `&String` + | | + | arguments to this function are incorrect + | + = note: expected enum `Option<String>` + found enum `Option<&String>` +note: function defined here + --> $DIR/copied-and-cloned.rs:3:4 + | +LL | fn expect<T>(_: T) {} + | ^^^^^^ ---- +help: use `Option::cloned` to clone the value inside the `Option` + | +LL | expect::<Option<String>>(x.cloned()); + | +++++++++ + +error[E0308]: mismatched types + --> $DIR/copied-and-cloned.rs:20:34 + | +LL | expect::<Result<String, ()>>(x); + | ---------------------------- ^ expected struct `String`, found `&String` + | | + | arguments to this function are incorrect + | + = note: expected enum `Result<String, ()>` + found enum `Result<&String, _>` +note: function defined here + --> $DIR/copied-and-cloned.rs:3:4 + | +LL | fn expect<T>(_: T) {} + | ^^^^^^ ---- +help: use `Result::cloned` to clone the value inside the `Result` + | +LL | expect::<Result<String, ()>>(x.cloned()); + | +++++++++ + +error: aborting due to 4 previous errors + +For more information about this error, try `rustc --explain E0308`. diff --git a/src/test/ui/suggestions/deref-path-method.rs b/src/test/ui/suggestions/deref-path-method.rs new file mode 100644 index 000000000..0281cdb6b --- /dev/null +++ b/src/test/ui/suggestions/deref-path-method.rs @@ -0,0 +1,6 @@ +fn main() { + let vec = Vec::new(); + Vec::contains(&vec, &0); + //~^ ERROR no function or associated item named `contains` found for struct `Vec<_, _>` in the current scope + //~| HELP the function `contains` is implemented on `[_]` +} diff --git a/src/test/ui/suggestions/deref-path-method.stderr b/src/test/ui/suggestions/deref-path-method.stderr new file mode 100644 index 000000000..1cc37d611 --- /dev/null +++ b/src/test/ui/suggestions/deref-path-method.stderr @@ -0,0 +1,14 @@ +error[E0599]: no function or associated item named `contains` found for struct `Vec<_, _>` in the current scope + --> $DIR/deref-path-method.rs:3:10 + | +LL | Vec::contains(&vec, &0); + | ^^^^^^^^ function or associated item not found in `Vec<_, _>` + | +help: the function `contains` is implemented on `[_]` + | +LL | <[_]>::contains(&vec, &0); + | ~~~~~ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0599`. diff --git a/src/test/ui/suggestions/derive-clone-for-eq.stderr b/src/test/ui/suggestions/derive-clone-for-eq.stderr index 55a23c031..0645f0cdd 100644 --- a/src/test/ui/suggestions/derive-clone-for-eq.stderr +++ b/src/test/ui/suggestions/derive-clone-for-eq.stderr @@ -4,7 +4,7 @@ error[E0277]: the trait bound `T: Clone` is not satisfied LL | #[derive(Clone, Eq)] | ^^ the trait `Clone` is not implemented for `T` | -note: required because of the requirements on the impl of `PartialEq` for `Struct<T>` +note: required for `Struct<T>` to implement `PartialEq` --> $DIR/derive-clone-for-eq.rs:9:19 | LL | impl<T: Clone, U> PartialEq<U> for Struct<T> diff --git a/src/test/ui/suggestions/derive-macro-missing-bounds.stderr b/src/test/ui/suggestions/derive-macro-missing-bounds.stderr index 4186dc7cb..b9f773965 100644 --- a/src/test/ui/suggestions/derive-macro-missing-bounds.stderr +++ b/src/test/ui/suggestions/derive-macro-missing-bounds.stderr @@ -26,13 +26,13 @@ LL | #[derive(Debug)] LL | struct Outer<T>(Inner<T>); | ^^^^^^^^ the trait `c::Trait` is not implemented for `T` | -note: required because of the requirements on the impl of `Debug` for `c::Inner<T>` +note: required for `c::Inner<T>` to implement `Debug` --> $DIR/derive-macro-missing-bounds.rs:34:28 | LL | impl<T: Debug + Trait> Debug for Inner<T> { | ^^^^^ ^^^^^^^^ = note: 1 redundant requirement hidden - = note: required because of the requirements on the impl of `Debug` for `&c::Inner<T>` + = note: required for `&c::Inner<T>` to implement `Debug` = note: required for the cast from `&c::Inner<T>` to the object type `dyn Debug` = note: this error originates in the derive macro `Debug` (in Nightly builds, run with -Z macro-backtrace for more info) help: consider restricting type parameter `T` @@ -48,13 +48,13 @@ LL | #[derive(Debug)] LL | struct Outer<T>(Inner<T>); | ^^^^^^^^ the trait `d::Trait` is not implemented for `T` | -note: required because of the requirements on the impl of `Debug` for `d::Inner<T>` +note: required for `d::Inner<T>` to implement `Debug` --> $DIR/derive-macro-missing-bounds.rs:49:13 | LL | impl<T> Debug for Inner<T> where T: Debug, T: Trait { | ^^^^^ ^^^^^^^^ = note: 1 redundant requirement hidden - = note: required because of the requirements on the impl of `Debug` for `&d::Inner<T>` + = note: required for `&d::Inner<T>` to implement `Debug` = note: required for the cast from `&d::Inner<T>` to the object type `dyn Debug` = note: this error originates in the derive macro `Debug` (in Nightly builds, run with -Z macro-backtrace for more info) help: consider restricting type parameter `T` @@ -70,13 +70,13 @@ LL | #[derive(Debug)] LL | struct Outer<T>(Inner<T>); | ^^^^^^^^ the trait `e::Trait` is not implemented for `T` | -note: required because of the requirements on the impl of `Debug` for `e::Inner<T>` +note: required for `e::Inner<T>` to implement `Debug` --> $DIR/derive-macro-missing-bounds.rs:64:13 | LL | impl<T> Debug for Inner<T> where T: Debug + Trait { | ^^^^^ ^^^^^^^^ = note: 1 redundant requirement hidden - = note: required because of the requirements on the impl of `Debug` for `&e::Inner<T>` + = note: required for `&e::Inner<T>` to implement `Debug` = note: required for the cast from `&e::Inner<T>` to the object type `dyn Debug` = note: this error originates in the derive macro `Debug` (in Nightly builds, run with -Z macro-backtrace for more info) help: consider restricting type parameter `T` @@ -92,13 +92,13 @@ LL | #[derive(Debug)] LL | struct Outer<T>(Inner<T>); | ^^^^^^^^ the trait `f::Trait` is not implemented for `T` | -note: required because of the requirements on the impl of `Debug` for `f::Inner<T>` +note: required for `f::Inner<T>` to implement `Debug` --> $DIR/derive-macro-missing-bounds.rs:79:20 | LL | impl<T: Debug> Debug for Inner<T> where T: Trait { | ^^^^^ ^^^^^^^^ = note: 1 redundant requirement hidden - = note: required because of the requirements on the impl of `Debug` for `&f::Inner<T>` + = note: required for `&f::Inner<T>` to implement `Debug` = note: required for the cast from `&f::Inner<T>` to the object type `dyn Debug` = note: this error originates in the derive macro `Debug` (in Nightly builds, run with -Z macro-backtrace for more info) help: consider restricting type parameter `T` diff --git a/src/test/ui/suggestions/dont-suggest-pin-array-dot-set.stderr b/src/test/ui/suggestions/dont-suggest-pin-array-dot-set.stderr index 677aa031b..c66da3ea6 100644 --- a/src/test/ui/suggestions/dont-suggest-pin-array-dot-set.stderr +++ b/src/test/ui/suggestions/dont-suggest-pin-array-dot-set.stderr @@ -2,7 +2,7 @@ error[E0599]: no method named `set` found for array `[u8; 1]` in the current sco --> $DIR/dont-suggest-pin-array-dot-set.rs:14:7 | LL | a.set(0, 3); - | ^^^ help: there is an associated function with a similar name: `get` + | ^^^ help: there is a method with a similar name: `get` error: aborting due to previous error diff --git a/src/test/ui/suggestions/dont-try-removing-the-field.rs b/src/test/ui/suggestions/dont-try-removing-the-field.rs new file mode 100644 index 000000000..948aa2b94 --- /dev/null +++ b/src/test/ui/suggestions/dont-try-removing-the-field.rs @@ -0,0 +1,17 @@ +// run-pass + +#![allow(dead_code)] + +struct Foo { + foo: i32, + bar: i32, + baz: (), +} + +fn use_foo(x: Foo) -> (i32, i32) { + let Foo { foo, bar, baz } = x; //~ WARNING unused variable: `baz` + //~| help: try ignoring the field + return (foo, bar); +} + +fn main() {} diff --git a/src/test/ui/suggestions/dont-try-removing-the-field.stderr b/src/test/ui/suggestions/dont-try-removing-the-field.stderr new file mode 100644 index 000000000..263171a4a --- /dev/null +++ b/src/test/ui/suggestions/dont-try-removing-the-field.stderr @@ -0,0 +1,10 @@ +warning: unused variable: `baz` + --> $DIR/dont-try-removing-the-field.rs:12:25 + | +LL | let Foo { foo, bar, baz } = x; + | ^^^ help: try ignoring the field: `baz: _` + | + = note: `#[warn(unused_variables)]` on by default + +warning: 1 warning emitted + diff --git a/src/test/ui/suggestions/expected-boxed-future-isnt-pinned.stderr b/src/test/ui/suggestions/expected-boxed-future-isnt-pinned.stderr index 71facf57e..77cef485f 100644 --- a/src/test/ui/suggestions/expected-boxed-future-isnt-pinned.stderr +++ b/src/test/ui/suggestions/expected-boxed-future-isnt-pinned.stderr @@ -46,10 +46,12 @@ LL | pub const fn new(pointer: P) -> Pin<P> { | ^^^ error[E0277]: `dyn Future<Output = i32> + Send` cannot be unpinned - --> $DIR/expected-boxed-future-isnt-pinned.rs:19:5 + --> $DIR/expected-boxed-future-isnt-pinned.rs:19:14 | LL | Pin::new(x) - | ^^^^^^^^ the trait `Unpin` is not implemented for `dyn Future<Output = i32> + Send` + | -------- ^ the trait `Unpin` is not implemented for `dyn Future<Output = i32> + Send` + | | + | required by a bound introduced by this call | = note: consider using `Box::pin` note: required by a bound in `Pin::<P>::new` @@ -59,10 +61,12 @@ LL | impl<P: Deref<Target: Unpin>> Pin<P> { | ^^^^^ required by this bound in `Pin::<P>::new` error[E0277]: `dyn Future<Output = i32> + Send` cannot be unpinned - --> $DIR/expected-boxed-future-isnt-pinned.rs:24:5 + --> $DIR/expected-boxed-future-isnt-pinned.rs:24:14 | LL | Pin::new(Box::new(x)) - | ^^^^^^^^ the trait `Unpin` is not implemented for `dyn Future<Output = i32> + Send` + | -------- ^^^^^^^^^^^ the trait `Unpin` is not implemented for `dyn Future<Output = i32> + Send` + | | + | required by a bound introduced by this call | = note: consider using `Box::pin` note: required by a bound in `Pin::<P>::new` @@ -87,7 +91,7 @@ LL | pub const fn from_generator<T>(gen: T) -> impl Future<Output = T::Return> | ------------------------------- the found opaque type | = note: expected struct `Pin<Box<(dyn Future<Output = i32> + Send + 'static)>>` - found opaque type `impl Future` + found opaque type `impl Future<Output = {integer}>` help: you need to pin and box this expression | LL ~ Box::pin(async { diff --git a/src/test/ui/suggestions/field-access-considering-privacy.rs b/src/test/ui/suggestions/field-access-considering-privacy.rs new file mode 100644 index 000000000..3de06b214 --- /dev/null +++ b/src/test/ui/suggestions/field-access-considering-privacy.rs @@ -0,0 +1,35 @@ +use a::TyCtxt; + +mod a { + use std::ops::Deref; + pub struct TyCtxt<'tcx> { + gcx: &'tcx GlobalCtxt<'tcx>, + } + + impl<'tcx> Deref for TyCtxt<'tcx> { + type Target = &'tcx GlobalCtxt<'tcx>; + + fn deref(&self) -> &Self::Target { + &self.gcx + } + } + + pub struct GlobalCtxt<'tcx> { + pub sess: &'tcx Session, + _t: &'tcx (), + } + + pub struct Session { + pub opts: (), + } +} + +mod b { + fn foo<'tcx>(tcx: crate::TyCtxt<'tcx>) { + tcx.opts; + //~^ ERROR no field `opts` on type `TyCtxt<'tcx>` + //~| HELP one of the expressions' fields has a field of the same name + } +} + +fn main() {} diff --git a/src/test/ui/suggestions/field-access-considering-privacy.stderr b/src/test/ui/suggestions/field-access-considering-privacy.stderr new file mode 100644 index 000000000..cbf6f3d10 --- /dev/null +++ b/src/test/ui/suggestions/field-access-considering-privacy.stderr @@ -0,0 +1,14 @@ +error[E0609]: no field `opts` on type `TyCtxt<'tcx>` + --> $DIR/field-access-considering-privacy.rs:29:13 + | +LL | tcx.opts; + | ^^^^ unknown field + | +help: one of the expressions' fields has a field of the same name + | +LL | tcx.sess.opts; + | +++++ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0609`. diff --git a/src/test/ui/suggestions/fn-ctor-passed-as-arg-where-it-should-have-been-called.stderr b/src/test/ui/suggestions/fn-ctor-passed-as-arg-where-it-should-have-been-called.stderr index fb0a6f70b..fe603b675 100644 --- a/src/test/ui/suggestions/fn-ctor-passed-as-arg-where-it-should-have-been-called.stderr +++ b/src/test/ui/suggestions/fn-ctor-passed-as-arg-where-it-should-have-been-called.stderr @@ -5,7 +5,7 @@ LL | fn foo() -> impl T<O=()> { S } | --- consider calling this function ... LL | bar(foo); - | --- ^^^ the trait `T` is not implemented for `fn() -> impl T<O = ()> {foo}` + | --- ^^^ the trait `T` is not implemented for fn item `fn() -> impl T<O = ()> {foo}` | | | required by a bound introduced by this call | @@ -25,7 +25,7 @@ error[E0277]: the trait bound `[closure@$DIR/fn-ctor-passed-as-arg-where-it-shou LL | let closure = || S; | -- consider calling this closure LL | bar(closure); - | --- ^^^^^^^ the trait `T` is not implemented for `[closure@$DIR/fn-ctor-passed-as-arg-where-it-should-have-been-called.rs:18:19: 18:21]` + | --- ^^^^^^^ the trait `T` is not implemented for closure `[closure@$DIR/fn-ctor-passed-as-arg-where-it-should-have-been-called.rs:18:19: 18:21]` | | | required by a bound introduced by this call | diff --git a/src/test/ui/suggestions/fn-or-tuple-struct-without-args.stderr b/src/test/ui/suggestions/fn-or-tuple-struct-without-args.stderr index e75ce0da8..3c7b895e3 100644 --- a/src/test/ui/suggestions/fn-or-tuple-struct-without-args.stderr +++ b/src/test/ui/suggestions/fn-or-tuple-struct-without-args.stderr @@ -33,8 +33,8 @@ LL | let _: usize = foo; found fn item `fn(usize, usize) -> usize {foo}` help: use parentheses to call this function | -LL | let _: usize = foo(_, _); - | ++++++ +LL | let _: usize = foo(/* usize */, /* usize */); + | ++++++++++++++++++++++++++ error[E0308]: mismatched types --> $DIR/fn-or-tuple-struct-without-args.rs:30:16 @@ -51,8 +51,8 @@ LL | let _: S = S; found fn item `fn(usize, usize) -> S {S}` help: use parentheses to instantiate this tuple struct | -LL | let _: S = S(_, _); - | ++++++ +LL | let _: S = S(/* usize */, /* usize */); + | ++++++++++++++++++++++++++ error[E0308]: mismatched types --> $DIR/fn-or-tuple-struct-without-args.rs:31:20 @@ -103,10 +103,10 @@ LL | let _: usize = T::baz; | = note: expected type `usize` found fn item `fn(usize, usize) -> usize {<_ as T>::baz}` -help: use parentheses to call this function +help: use parentheses to call this associated function | -LL | let _: usize = T::baz(_, _); - | ++++++ +LL | let _: usize = T::baz(/* usize */, /* usize */); + | ++++++++++++++++++++++++++ error[E0308]: mismatched types --> $DIR/fn-or-tuple-struct-without-args.rs:34:20 @@ -121,10 +121,10 @@ LL | let _: usize = T::bat; | = note: expected type `usize` found fn item `fn(usize) -> usize {<_ as T>::bat}` -help: use parentheses to call this function +help: use parentheses to call this associated function | -LL | let _: usize = T::bat(_); - | +++ +LL | let _: usize = T::bat(/* usize */); + | +++++++++++++ error[E0308]: mismatched types --> $DIR/fn-or-tuple-struct-without-args.rs:35:16 @@ -141,8 +141,8 @@ LL | let _: E = E::A; found fn item `fn(usize) -> E {E::A}` help: use parentheses to instantiate this tuple variant | -LL | let _: E = E::A(_); - | +++ +LL | let _: E = E::A(/* usize */); + | +++++++++++++ error[E0308]: mismatched types --> $DIR/fn-or-tuple-struct-without-args.rs:37:20 @@ -157,10 +157,10 @@ LL | let _: usize = X::baz; | = note: expected type `usize` found fn item `fn(usize, usize) -> usize {<X as T>::baz}` -help: use parentheses to call this function +help: use parentheses to call this associated function | -LL | let _: usize = X::baz(_, _); - | ++++++ +LL | let _: usize = X::baz(/* usize */, /* usize */); + | ++++++++++++++++++++++++++ error[E0308]: mismatched types --> $DIR/fn-or-tuple-struct-without-args.rs:38:20 @@ -175,10 +175,10 @@ LL | let _: usize = X::bat; | = note: expected type `usize` found fn item `fn(usize) -> usize {<X as T>::bat}` -help: use parentheses to call this function +help: use parentheses to call this associated function | -LL | let _: usize = X::bat(_); - | +++ +LL | let _: usize = X::bat(/* usize */); + | +++++++++++++ error[E0308]: mismatched types --> $DIR/fn-or-tuple-struct-without-args.rs:39:20 @@ -193,10 +193,10 @@ LL | let _: usize = X::bax; | = note: expected type `usize` found fn item `fn(usize) -> usize {<X as T>::bax}` -help: use parentheses to call this function +help: use parentheses to call this associated function | -LL | let _: usize = X::bax(_); - | +++ +LL | let _: usize = X::bax(/* usize */); + | +++++++++++++ error[E0308]: mismatched types --> $DIR/fn-or-tuple-struct-without-args.rs:40:20 @@ -211,10 +211,10 @@ LL | let _: usize = X::bach; | = note: expected type `usize` found fn item `fn(usize) -> usize {<X as T>::bach}` -help: use parentheses to call this function +help: use parentheses to call this associated function | -LL | let _: usize = X::bach(_); - | +++ +LL | let _: usize = X::bach(/* usize */); + | +++++++++++++ error[E0308]: mismatched types --> $DIR/fn-or-tuple-struct-without-args.rs:41:20 @@ -229,10 +229,10 @@ LL | let _: usize = X::ban; | = note: expected type `usize` found fn item `for<'r> fn(&'r X) -> usize {<X as T>::ban}` -help: use parentheses to call this function +help: use parentheses to call this associated function | -LL | let _: usize = X::ban(_); - | +++ +LL | let _: usize = X::ban(/* &X */); + | ++++++++++ error[E0308]: mismatched types --> $DIR/fn-or-tuple-struct-without-args.rs:42:20 @@ -247,10 +247,10 @@ LL | let _: usize = X::bal; | = note: expected type `usize` found fn item `for<'r> fn(&'r X) -> usize {<X as T>::bal}` -help: use parentheses to call this function +help: use parentheses to call this associated function | -LL | let _: usize = X::bal(_); - | +++ +LL | let _: usize = X::bal(/* &X */); + | ++++++++++ error[E0615]: attempted to take value of method `ban` on type `X` --> $DIR/fn-or-tuple-struct-without-args.rs:43:22 diff --git a/src/test/ui/suggestions/imm-ref-trait-object-literal-bound-regions.stderr b/src/test/ui/suggestions/imm-ref-trait-object-literal-bound-regions.stderr index ba6af8f15..864ab0535 100644 --- a/src/test/ui/suggestions/imm-ref-trait-object-literal-bound-regions.stderr +++ b/src/test/ui/suggestions/imm-ref-trait-object-literal-bound-regions.stderr @@ -1,8 +1,10 @@ error[E0277]: the trait bound `for<'b> &'b S: Trait` is not satisfied - --> $DIR/imm-ref-trait-object-literal-bound-regions.rs:17:5 + --> $DIR/imm-ref-trait-object-literal-bound-regions.rs:17:14 | LL | foo::<S>(s); - | ^^^^^^^^ the trait `for<'b> Trait` is not implemented for `&'b S` + | -------- ^ the trait `for<'b> Trait` is not implemented for `&'b S` + | | + | required by a bound introduced by this call | = help: the trait `Trait` is implemented for `&'a mut S` = note: `for<'b> Trait` is implemented for `&'b mut S`, but not for `&'b S` diff --git a/src/test/ui/suggestions/imm-ref-trait-object-literal.stderr b/src/test/ui/suggestions/imm-ref-trait-object-literal.stderr index 5f3f62a7b..e01102e38 100644 --- a/src/test/ui/suggestions/imm-ref-trait-object-literal.stderr +++ b/src/test/ui/suggestions/imm-ref-trait-object-literal.stderr @@ -21,7 +21,7 @@ error[E0277]: the trait bound `S: Trait` is not satisfied --> $DIR/imm-ref-trait-object-literal.rs:13:7 | LL | foo(s); - | --- ^ expected an implementor of trait `Trait` + | --- ^ the trait `Trait` is not implemented for `S` | | | required by a bound introduced by this call | diff --git a/src/test/ui/suggestions/into-str.stderr b/src/test/ui/suggestions/into-str.stderr index 8ae5c8479..a56a2a188 100644 --- a/src/test/ui/suggestions/into-str.stderr +++ b/src/test/ui/suggestions/into-str.stderr @@ -14,7 +14,7 @@ LL | foo(String::new()); <String as From<Box<str>>> <String as From<Cow<'a, str>>> <String as From<char>> - = note: required because of the requirements on the impl of `Into<&str>` for `String` + = note: required for `String` to implement `Into<&str>` note: required by a bound in `foo` --> $DIR/into-str.rs:1:31 | diff --git a/src/test/ui/suggestions/issue-101421.rs b/src/test/ui/suggestions/issue-101421.rs new file mode 100644 index 000000000..b615997d1 --- /dev/null +++ b/src/test/ui/suggestions/issue-101421.rs @@ -0,0 +1,12 @@ +pub trait Ice { + fn f(&self, _: ()); +} + +impl Ice for () { + fn f(&self, _: ()) {} +} + +fn main() { + ().f::<()>(()); + //~^ ERROR this associated function takes 0 generic arguments but 1 generic argument was supplied +} diff --git a/src/test/ui/suggestions/issue-101421.stderr b/src/test/ui/suggestions/issue-101421.stderr new file mode 100644 index 000000000..f8e1efb88 --- /dev/null +++ b/src/test/ui/suggestions/issue-101421.stderr @@ -0,0 +1,17 @@ +error[E0107]: this associated function takes 0 generic arguments but 1 generic argument was supplied + --> $DIR/issue-101421.rs:10:8 + | +LL | ().f::<()>(()); + | ^------ help: remove these generics + | | + | expected 0 generic arguments + | +note: associated function defined here, with 0 generic parameters + --> $DIR/issue-101421.rs:2:8 + | +LL | fn f(&self, _: ()); + | ^ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0107`. diff --git a/src/test/ui/suggestions/issue-101465.rs b/src/test/ui/suggestions/issue-101465.rs new file mode 100644 index 000000000..8e42e2c22 --- /dev/null +++ b/src/test/ui/suggestions/issue-101465.rs @@ -0,0 +1,25 @@ +#![feature(trait_alias)] + +struct B; +struct C; + +trait Tr {} + +impl Tr for B {} +impl Tr for C {} + +trait Tr2<S> = Into<S>; + +fn foo2<T: Tr2<()>>() {} + +fn foo() -> impl Tr { + let x = foo2::<_>(); + + match true { + true => B, + false => C, + //~^ `match` arms have incompatible types + } +} + +fn main() {} diff --git a/src/test/ui/suggestions/issue-101465.stderr b/src/test/ui/suggestions/issue-101465.stderr new file mode 100644 index 000000000..e2ca77712 --- /dev/null +++ b/src/test/ui/suggestions/issue-101465.stderr @@ -0,0 +1,25 @@ +error[E0308]: `match` arms have incompatible types + --> $DIR/issue-101465.rs:20:18 + | +LL | / match true { +LL | | true => B, + | | - this is found to be of type `B` +LL | | false => C, + | | ^ expected struct `B`, found struct `C` +LL | | +LL | | } + | |_____- `match` arms have incompatible types + | +help: you could change the return type to be a boxed trait object + | +LL | fn foo() -> Box<dyn Tr> { + | ~~~~~~~ + +help: if you change the return type to expect trait objects, box the returned expressions + | +LL ~ true => Box::new(B), +LL ~ false => Box::new(C), + | + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0308`. diff --git a/src/test/ui/suggestions/issue-101984.rs b/src/test/ui/suggestions/issue-101984.rs new file mode 100644 index 000000000..5f7ecb77e --- /dev/null +++ b/src/test/ui/suggestions/issue-101984.rs @@ -0,0 +1,27 @@ +use std::marker::PhantomData; + +type Component = fn(&()); + +struct Wrapper { + router: Router<(Component, Box<Self>)>, +} + +struct Match<C>(PhantomData<C>); + +struct Router<T>(PhantomData<T>); + +impl<T> Router<T> { + pub fn at(&self) -> Result<Match<&T>, ()> { + todo!() + } +} + +impl Wrapper { + fn at(&self, path: &str) -> Result<(Component, Box<Self>), ()> { + let (cmp, router) = self.router.at()?; + //~^ ERROR mismatched types + todo!() + } +} + +fn main() {} diff --git a/src/test/ui/suggestions/issue-101984.stderr b/src/test/ui/suggestions/issue-101984.stderr new file mode 100644 index 000000000..c744c62d1 --- /dev/null +++ b/src/test/ui/suggestions/issue-101984.stderr @@ -0,0 +1,14 @@ +error[E0308]: mismatched types + --> $DIR/issue-101984.rs:21:13 + | +LL | let (cmp, router) = self.router.at()?; + | ^^^^^^^^^^^^^ ----------------- this expression has type `Match<&(for<'r> fn(&'r ()), Box<Wrapper>)>` + | | + | expected struct `Match`, found tuple + | + = note: expected struct `Match<&(for<'r> fn(&'r ()), Box<Wrapper>)>` + found tuple `(_, _)` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0308`. diff --git a/src/test/ui/suggestions/issue-61963.stderr b/src/test/ui/suggestions/issue-61963.stderr index c0d776e59..a788cab6e 100644 --- a/src/test/ui/suggestions/issue-61963.stderr +++ b/src/test/ui/suggestions/issue-61963.stderr @@ -13,9 +13,8 @@ LL | #![deny(bare_trait_objects)] = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html> help: use `dyn` | -LL - bar: Box<Bar>, -LL + bar: Box<dyn Bar>, - | +LL | bar: Box<dyn Bar>, + | +++ error: trait objects without an explicit `dyn` are deprecated --> $DIR/issue-61963.rs:18:1 @@ -27,9 +26,8 @@ LL | pub struct Foo { = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html> help: use `dyn` | -LL - pub struct Foo { -LL + dyn pub struct Foo { - | +LL | dyn pub struct Foo { + | +++ error: trait objects without an explicit `dyn` are deprecated --> $DIR/issue-61963.rs:28:14 @@ -41,9 +39,8 @@ LL | bar: Box<Bar>, = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html> help: use `dyn` | -LL - bar: Box<Bar>, -LL + bar: Box<dyn Bar>, - | +LL | bar: Box<dyn Bar>, + | +++ error: trait objects without an explicit `dyn` are deprecated --> $DIR/issue-61963.rs:28:14 @@ -55,9 +52,8 @@ LL | bar: Box<Bar>, = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html> help: use `dyn` | -LL - bar: Box<Bar>, -LL + bar: Box<dyn Bar>, - | +LL | bar: Box<dyn Bar>, + | +++ error: trait objects without an explicit `dyn` are deprecated --> $DIR/issue-61963.rs:18:1 @@ -69,9 +65,8 @@ LL | pub struct Foo { = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html> help: use `dyn` | -LL - pub struct Foo { -LL + dyn pub struct Foo { - | +LL | dyn pub struct Foo { + | +++ error: trait objects without an explicit `dyn` are deprecated --> $DIR/issue-61963.rs:18:1 @@ -83,9 +78,8 @@ LL | pub struct Foo { = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html> help: use `dyn` | -LL - pub struct Foo { -LL + dyn pub struct Foo { - | +LL | dyn pub struct Foo { + | +++ error: trait objects without an explicit `dyn` are deprecated --> $DIR/issue-61963.rs:18:1 @@ -97,9 +91,8 @@ LL | pub struct Foo { = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html> help: use `dyn` | -LL - pub struct Foo { -LL + dyn pub struct Foo { - | +LL | dyn pub struct Foo { + | +++ error: aborting due to 7 previous errors diff --git a/src/test/ui/suggestions/issue-62843.stderr b/src/test/ui/suggestions/issue-62843.stderr index bc1c69406..62f0943d4 100644 --- a/src/test/ui/suggestions/issue-62843.stderr +++ b/src/test/ui/suggestions/issue-62843.stderr @@ -2,12 +2,12 @@ error[E0277]: expected a `FnMut<(char,)>` closure, found `String` --> $DIR/issue-62843.rs:4:32 | LL | println!("{:?}", line.find(pattern)); - | ---- ^^^^^^^ expected an implementor of trait `Pattern<'_>` + | ---- ^^^^^^^ the trait `Pattern<'_>` is not implemented for `String` | | | required by a bound introduced by this call | = note: the trait bound `String: Pattern<'_>` is not satisfied - = note: required because of the requirements on the impl of `Pattern<'_>` for `String` + = note: required for `String` to implement `Pattern<'_>` note: required by a bound in `core::str::<impl str>::find` --> $SRC_DIR/core/src/str/mod.rs:LL:COL | diff --git a/src/test/ui/suggestions/issue-71394-no-from-impl.stderr b/src/test/ui/suggestions/issue-71394-no-from-impl.stderr index 383f40d47..684db23e1 100644 --- a/src/test/ui/suggestions/issue-71394-no-from-impl.stderr +++ b/src/test/ui/suggestions/issue-71394-no-from-impl.stderr @@ -1,13 +1,15 @@ error[E0277]: the trait bound `&[i8]: From<&[u8]>` is not satisfied - --> $DIR/issue-71394-no-from-impl.rs:3:25 + --> $DIR/issue-71394-no-from-impl.rs:3:20 | LL | let _: &[i8] = data.into(); - | ^^^^ the trait `From<&[u8]>` is not implemented for `&[i8]` + | ^^^^ ---- required by a bound introduced by this call + | | + | the trait `From<&[u8]>` is not implemented for `&[i8]` | = help: the following other types implement trait `From<T>`: <[T; LANES] as From<Simd<T, LANES>>> <[bool; LANES] as From<Mask<T, LANES>>> - = note: required because of the requirements on the impl of `Into<&[i8]>` for `&[u8]` + = note: required for `&[u8]` to implement `Into<&[i8]>` error: aborting due to previous error diff --git a/src/test/ui/suggestions/issue-84973-2.stderr b/src/test/ui/suggestions/issue-84973-2.stderr index 2c54ea672..513bf28fb 100644 --- a/src/test/ui/suggestions/issue-84973-2.stderr +++ b/src/test/ui/suggestions/issue-84973-2.stderr @@ -2,7 +2,7 @@ error[E0277]: the trait bound `i32: Tr` is not satisfied --> $DIR/issue-84973-2.rs:11:9 | LL | foo(a); - | --- ^ expected an implementor of trait `Tr` + | --- ^ the trait `Tr` is not implemented for `i32` | | | required by a bound introduced by this call | diff --git a/src/test/ui/suggestions/issue-84973-blacklist.stderr b/src/test/ui/suggestions/issue-84973-blacklist.stderr index ae0d3efca..c20cc8164 100644 --- a/src/test/ui/suggestions/issue-84973-blacklist.stderr +++ b/src/test/ui/suggestions/issue-84973-blacklist.stderr @@ -31,10 +31,12 @@ LL | #[derive(Clone)] | error[E0277]: `[static generator@$DIR/issue-84973-blacklist.rs:17:13: 17:22]` cannot be unpinned - --> $DIR/issue-84973-blacklist.rs:17:5 + --> $DIR/issue-84973-blacklist.rs:17:13 | LL | f_unpin(static || { yield; }); - | ^^^^^^^ the trait `Unpin` is not implemented for `[static generator@$DIR/issue-84973-blacklist.rs:17:13: 17:22]` + | ------- ^^^^^^^^^^^^^^^^^^^^ the trait `Unpin` is not implemented for `[static generator@$DIR/issue-84973-blacklist.rs:17:13: 17:22]` + | | + | required by a bound introduced by this call | = note: consider using `Box::pin` note: required by a bound in `f_unpin` diff --git a/src/test/ui/suggestions/issue-84973-negative.stderr b/src/test/ui/suggestions/issue-84973-negative.stderr index 15559d4ae..ce838bce0 100644 --- a/src/test/ui/suggestions/issue-84973-negative.stderr +++ b/src/test/ui/suggestions/issue-84973-negative.stderr @@ -17,7 +17,7 @@ error[E0277]: the trait bound `f32: Tr` is not satisfied --> $DIR/issue-84973-negative.rs:11:9 | LL | bar(b); - | --- ^ expected an implementor of trait `Tr` + | --- ^ the trait `Tr` is not implemented for `f32` | | | required by a bound introduced by this call | diff --git a/src/test/ui/suggestions/issue-84973.stderr b/src/test/ui/suggestions/issue-84973.stderr index 24c989ec3..ae2bf5aac 100644 --- a/src/test/ui/suggestions/issue-84973.stderr +++ b/src/test/ui/suggestions/issue-84973.stderr @@ -2,7 +2,7 @@ error[E0277]: the trait bound `Fancy: SomeTrait` is not satisfied --> $DIR/issue-84973.rs:6:24 | LL | let o = Other::new(f); - | ---------- ^ expected an implementor of trait `SomeTrait` + | ---------- ^ the trait `SomeTrait` is not implemented for `Fancy` | | | required by a bound introduced by this call | diff --git a/src/test/ui/suggestions/issue-85347.rs b/src/test/ui/suggestions/issue-85347.rs index f08e38689..02b5fb618 100644 --- a/src/test/ui/suggestions/issue-85347.rs +++ b/src/test/ui/suggestions/issue-85347.rs @@ -1,9 +1,8 @@ -#![allow(incomplete_features)] -#![feature(generic_associated_types)] use std::ops::Deref; trait Foo { type Bar<'a>: Deref<Target = <Self>::Bar<Target = Self>>; //~^ ERROR this associated type takes 1 lifetime argument but 0 lifetime arguments were supplied + //~| ERROR associated type bindings are not allowed here //~| HELP add missing } diff --git a/src/test/ui/suggestions/issue-85347.stderr b/src/test/ui/suggestions/issue-85347.stderr index fccd2ef8d..17c1b7dc4 100644 --- a/src/test/ui/suggestions/issue-85347.stderr +++ b/src/test/ui/suggestions/issue-85347.stderr @@ -1,11 +1,11 @@ error[E0107]: this associated type takes 1 lifetime argument but 0 lifetime arguments were supplied - --> $DIR/issue-85347.rs:5:42 + --> $DIR/issue-85347.rs:3:42 | LL | type Bar<'a>: Deref<Target = <Self>::Bar<Target = Self>>; | ^^^ expected 1 lifetime argument | note: associated type defined here, with 1 lifetime parameter: `'a` - --> $DIR/issue-85347.rs:5:10 + --> $DIR/issue-85347.rs:3:10 | LL | type Bar<'a>: Deref<Target = <Self>::Bar<Target = Self>>; | ^^^ -- @@ -14,6 +14,13 @@ help: add missing lifetime argument LL | type Bar<'a>: Deref<Target = <Self>::Bar<'a, Target = Self>>; | +++ -error: aborting due to previous error +error[E0229]: associated type bindings are not allowed here + --> $DIR/issue-85347.rs:3:46 + | +LL | type Bar<'a>: Deref<Target = <Self>::Bar<Target = Self>>; + | ^^^^^^^^^^^^^ associated type not allowed here + +error: aborting due to 2 previous errors -For more information about this error, try `rustc --explain E0107`. +Some errors have detailed explanations: E0107, E0229. +For more information about an error, try `rustc --explain E0107`. diff --git a/src/test/ui/suggestions/issue-89064.rs b/src/test/ui/suggestions/issue-89064.rs new file mode 100644 index 000000000..fa5fc899d --- /dev/null +++ b/src/test/ui/suggestions/issue-89064.rs @@ -0,0 +1,35 @@ +use std::convert::TryInto; + +trait A<T> { + fn foo() {} +} + +trait B<T, U> { + fn bar() {} +} + +struct S; + +impl<T> A<T> for S {} +impl<T, U> B<T, U> for S {} + +fn main() { + let _ = A::foo::<S>(); + //~^ ERROR + //~| HELP remove these generics + //~| HELP consider moving this generic argument + + let _ = B::bar::<S, S>(); + //~^ ERROR + //~| HELP remove these generics + //~| HELP consider moving these generic arguments + + let _ = A::<S>::foo::<S>(); + //~^ ERROR + //~| HELP remove these generics + + let _ = 42.into::<Option<_>>(); + //~^ ERROR + //~| HELP remove these generics + //~| HELP consider moving this generic argument +} diff --git a/src/test/ui/suggestions/issue-89064.stderr b/src/test/ui/suggestions/issue-89064.stderr new file mode 100644 index 000000000..8b2a38816 --- /dev/null +++ b/src/test/ui/suggestions/issue-89064.stderr @@ -0,0 +1,82 @@ +error[E0107]: this associated function takes 0 generic arguments but 1 generic argument was supplied + --> $DIR/issue-89064.rs:17:16 + | +LL | let _ = A::foo::<S>(); + | ^^^ expected 0 generic arguments + | +note: associated function defined here, with 0 generic parameters + --> $DIR/issue-89064.rs:4:8 + | +LL | fn foo() {} + | ^^^ +help: consider moving this generic argument to the `A` trait, which takes up to 1 argument + | +LL - let _ = A::foo::<S>(); +LL + let _ = A::<S>::foo(); + | +help: remove these generics + | +LL - let _ = A::foo::<S>(); +LL + let _ = A::foo(); + | + +error[E0107]: this associated function takes 0 generic arguments but 2 generic arguments were supplied + --> $DIR/issue-89064.rs:22:16 + | +LL | let _ = B::bar::<S, S>(); + | ^^^ expected 0 generic arguments + | +note: associated function defined here, with 0 generic parameters + --> $DIR/issue-89064.rs:8:8 + | +LL | fn bar() {} + | ^^^ +help: consider moving these generic arguments to the `B` trait, which takes up to 2 arguments + | +LL - let _ = B::bar::<S, S>(); +LL + let _ = B::<S, S>::bar(); + | +help: remove these generics + | +LL - let _ = B::bar::<S, S>(); +LL + let _ = B::bar(); + | + +error[E0107]: this associated function takes 0 generic arguments but 1 generic argument was supplied + --> $DIR/issue-89064.rs:27:21 + | +LL | let _ = A::<S>::foo::<S>(); + | ^^^----- help: remove these generics + | | + | expected 0 generic arguments + | +note: associated function defined here, with 0 generic parameters + --> $DIR/issue-89064.rs:4:8 + | +LL | fn foo() {} + | ^^^ + +error[E0107]: this associated function takes 0 generic arguments but 1 generic argument was supplied + --> $DIR/issue-89064.rs:31:16 + | +LL | let _ = 42.into::<Option<_>>(); + | ^^^^ expected 0 generic arguments + | +note: associated function defined here, with 0 generic parameters + --> $SRC_DIR/core/src/convert/mod.rs:LL:COL + | +LL | fn into(self) -> T; + | ^^^^ +help: consider moving this generic argument to the `Into` trait, which takes up to 1 argument + | +LL | let _ = Into::<Option<_>>::into(42); + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~ +help: remove these generics + | +LL - let _ = 42.into::<Option<_>>(); +LL + let _ = 42.into(); + | + +error: aborting due to 4 previous errors + +For more information about this error, try `rustc --explain E0107`. diff --git a/src/test/ui/suggestions/issue-96223.stderr b/src/test/ui/suggestions/issue-96223.stderr index 513725d99..72a9a739a 100644 --- a/src/test/ui/suggestions/issue-96223.stderr +++ b/src/test/ui/suggestions/issue-96223.stderr @@ -7,12 +7,12 @@ LL | icey_bounds(&p); | required by a bound introduced by this call | = help: the trait `Foo<'de>` is implemented for `Baz<T>` -note: required because of the requirements on the impl of `for<'de> Foo<'de>` for `Baz<EmptyBis<'de>>` +note: required for `Baz<EmptyBis<'de>>` to implement `for<'de> Foo<'de>` --> $DIR/issue-96223.rs:16:14 | LL | impl<'de, T> Foo<'de> for Baz<T> where T: Foo<'de> {} | ^^^^^^^^ ^^^^^^ -note: required because of the requirements on the impl of `Dummy<EmptyMarker>` for `Empty` +note: required for `Empty` to implement `Dummy<EmptyMarker>` --> $DIR/issue-96223.rs:20:9 | LL | impl<M> Dummy<M> for Empty diff --git a/src/test/ui/suggestions/issue-96555.stderr b/src/test/ui/suggestions/issue-96555.stderr index a1a603cf2..9a8a183dc 100644 --- a/src/test/ui/suggestions/issue-96555.stderr +++ b/src/test/ui/suggestions/issue-96555.stderr @@ -8,7 +8,7 @@ LL | m::f1().await; | = help: the trait `Future` is not implemented for `()` = note: () must be a future or must implement `IntoFuture` to be awaited - = note: required because of the requirements on the impl of `IntoFuture` for `()` + = note: required for `()` to implement `IntoFuture` help: remove the `.await` | LL - m::f1().await; @@ -29,7 +29,7 @@ LL | m::f2().await; | = help: the trait `Future` is not implemented for `()` = note: () must be a future or must implement `IntoFuture` to be awaited - = note: required because of the requirements on the impl of `IntoFuture` for `()` + = note: required for `()` to implement `IntoFuture` help: remove the `.await` | LL - m::f2().await; @@ -50,7 +50,7 @@ LL | m::f3().await; | = help: the trait `Future` is not implemented for `()` = note: () must be a future or must implement `IntoFuture` to be awaited - = note: required because of the requirements on the impl of `IntoFuture` for `()` + = note: required for `()` to implement `IntoFuture` help: remove the `.await` | LL - m::f3().await; diff --git a/src/test/ui/suggestions/issue-97677.fixed b/src/test/ui/suggestions/issue-97677.fixed index 73ca9f97b..1e7569fa4 100644 --- a/src/test/ui/suggestions/issue-97677.fixed +++ b/src/test/ui/suggestions/issue-97677.fixed @@ -1,6 +1,6 @@ // run-rustfix -fn add_ten<N: std::ops::Add<i32, Output=N>>(n: N) -> N { +fn add_ten<N: std::ops::Add<i32, Output = N>>(n: N) -> N { n + 10 //~^ ERROR cannot add `{integer}` to `N` } diff --git a/src/test/ui/suggestions/issue-97677.stderr b/src/test/ui/suggestions/issue-97677.stderr index 069b184ac..575d79267 100644 --- a/src/test/ui/suggestions/issue-97677.stderr +++ b/src/test/ui/suggestions/issue-97677.stderr @@ -8,8 +8,8 @@ LL | n + 10 | help: consider restricting type parameter `N` | -LL | fn add_ten<N: std::ops::Add<i32, Output=N>>(n: N) -> N { - | ++++++++++++++++++++++++++++++ +LL | fn add_ten<N: std::ops::Add<i32, Output = N>>(n: N) -> N { + | ++++++++++++++++++++++++++++++++ error: aborting due to previous error diff --git a/src/test/ui/suggestions/lifetimes/missing-lifetimes-in-signature-2.stderr b/src/test/ui/suggestions/lifetimes/missing-lifetimes-in-signature-2.stderr index 0212c2d71..e5d2ead6a 100644 --- a/src/test/ui/suggestions/lifetimes/missing-lifetimes-in-signature-2.stderr +++ b/src/test/ui/suggestions/lifetimes/missing-lifetimes-in-signature-2.stderr @@ -22,8 +22,8 @@ LL | | }); | |______^ help: consider adding an explicit lifetime bound... | -LL | fn func<T: Test + 'a>(foo: &Foo, t: T) { - | ++++ +LL | fn func<'a, T: Test + 'a>(foo: &Foo, t: T) { + | +++ ++++ error: aborting due to previous error diff --git a/src/test/ui/suggestions/lifetimes/missing-lifetimes-in-signature.stderr b/src/test/ui/suggestions/lifetimes/missing-lifetimes-in-signature.stderr index 0d749f04b..ed1b91676 100644 --- a/src/test/ui/suggestions/lifetimes/missing-lifetimes-in-signature.stderr +++ b/src/test/ui/suggestions/lifetimes/missing-lifetimes-in-signature.stderr @@ -47,8 +47,10 @@ LL | | } | |_____^ help: consider adding an explicit lifetime bound... | -LL | G: Get<T> + 'a, - | ++++ +LL ~ fn bar<'a, G, T>(g: G, dest: &mut T) -> impl FnOnce() + '_ +LL | where +LL ~ G: Get<T> + 'a, + | error[E0311]: the parameter type `G` may not live long enough --> $DIR/missing-lifetimes-in-signature.rs:52:5 @@ -74,8 +76,8 @@ LL | | } | |_____^ help: consider adding an explicit lifetime bound... | -LL | fn qux<'a, G: 'a + 'b, T>(g: G, dest: &mut T) -> impl FnOnce() + '_ - | ++++ +LL | fn qux<'b, 'a, G: 'a + 'b, T>(g: G, dest: &mut T) -> impl FnOnce() + '_ + | +++ ++++ error[E0311]: the parameter type `G` may not live long enough --> $DIR/missing-lifetimes-in-signature.rs:61:9 @@ -101,8 +103,8 @@ LL | | } | |_________^ help: consider adding an explicit lifetime bound... | -LL | fn qux<'b, G: Get<T> + 'b + 'c, T>(g: G, dest: &mut T) -> impl FnOnce() + '_ { - | ++++ +LL | fn qux<'c, 'b, G: Get<T> + 'b + 'c, T>(g: G, dest: &mut T) -> impl FnOnce() + '_ { + | +++ ++++ error[E0311]: the parameter type `G` may not live long enough --> $DIR/missing-lifetimes-in-signature.rs:73:5 @@ -130,8 +132,8 @@ LL | | } | |_____^ help: consider adding an explicit lifetime bound... | -LL | fn bat<'a, G: 'a + 'b, T>(g: G, dest: &mut T) -> impl FnOnce() + '_ + 'a - | ++++ +LL | fn bat<'b, 'a, G: 'a + 'b, T>(g: G, dest: &mut T) -> impl FnOnce() + '_ + 'a + | +++ ++++ error[E0621]: explicit lifetime required in the type of `dest` --> $DIR/missing-lifetimes-in-signature.rs:73:5 diff --git a/src/test/ui/suggestions/many-type-ascription.rs b/src/test/ui/suggestions/many-type-ascription.rs new file mode 100644 index 000000000..31ac556b9 --- /dev/null +++ b/src/test/ui/suggestions/many-type-ascription.rs @@ -0,0 +1,4 @@ +fn main() { + let _ = 0: i32; //~ ERROR: type ascription is experimental + let _ = 0: i32; // (error only emitted once) +} diff --git a/src/test/ui/suggestions/many-type-ascription.stderr b/src/test/ui/suggestions/many-type-ascription.stderr new file mode 100644 index 000000000..3706bbae9 --- /dev/null +++ b/src/test/ui/suggestions/many-type-ascription.stderr @@ -0,0 +1,12 @@ +error[E0658]: type ascription is experimental + --> $DIR/many-type-ascription.rs:2:13 + | +LL | let _ = 0: i32; + | ^^^^^^ + | + = note: see issue #23416 <https://github.com/rust-lang/rust/issues/23416> for more information + = help: add `#![feature(type_ascription)]` to the crate attributes to enable + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0658`. diff --git a/src/test/ui/suggestions/move-generic-to-trait-in-method-with-params.rs b/src/test/ui/suggestions/move-generic-to-trait-in-method-with-params.rs new file mode 100644 index 000000000..2f540060a --- /dev/null +++ b/src/test/ui/suggestions/move-generic-to-trait-in-method-with-params.rs @@ -0,0 +1,18 @@ +// Generalizes the suggestion introduced in #100838 + +trait Foo<T> { + fn bar(&self, _: T); +} + +impl Foo<i32> for i32 { + fn bar(&self, x: i32) { + println!("{}", self + x); + } +} + +fn main() { + 1.bar::<i32>(0); + //~^ ERROR this associated function takes 0 generic arguments but 1 generic argument was supplied + //~| HELP consider moving this generic argument to the `Foo` trait, which takes up to 1 argument + //~| HELP remove these generics +} diff --git a/src/test/ui/suggestions/move-generic-to-trait-in-method-with-params.stderr b/src/test/ui/suggestions/move-generic-to-trait-in-method-with-params.stderr new file mode 100644 index 000000000..9557220f6 --- /dev/null +++ b/src/test/ui/suggestions/move-generic-to-trait-in-method-with-params.stderr @@ -0,0 +1,24 @@ +error[E0107]: this associated function takes 0 generic arguments but 1 generic argument was supplied + --> $DIR/move-generic-to-trait-in-method-with-params.rs:14:7 + | +LL | 1.bar::<i32>(0); + | ^^^ expected 0 generic arguments + | +note: associated function defined here, with 0 generic parameters + --> $DIR/move-generic-to-trait-in-method-with-params.rs:4:8 + | +LL | fn bar(&self, _: T); + | ^^^ +help: consider moving this generic argument to the `Foo` trait, which takes up to 1 argument + | +LL | Foo::<i32>::bar(1, 0); + | ~~~~~~~~~~~~~~~~~~~~~ +help: remove these generics + | +LL - 1.bar::<i32>(0); +LL + 1.bar(0); + | + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0107`. diff --git a/src/test/ui/suggestions/option-content-move.fixed b/src/test/ui/suggestions/option-content-move.fixed deleted file mode 100644 index ba16bcc8a..000000000 --- a/src/test/ui/suggestions/option-content-move.fixed +++ /dev/null @@ -1,39 +0,0 @@ -//run-rustfix - -pub struct LipogramCorpora { - selections: Vec<(char, Option<String>)>, -} - -impl LipogramCorpora { - pub fn validate_all(&mut self) -> Result<(), char> { - for selection in &self.selections { - if selection.1.is_some() { - if selection.1.as_ref().unwrap().contains(selection.0) { - //~^ ERROR cannot move out of `selection.1` - return Err(selection.0); - } - } - } - Ok(()) - } -} - -pub struct LipogramCorpora2 { - selections: Vec<(char, Result<String, String>)>, -} - -impl LipogramCorpora2 { - pub fn validate_all(&mut self) -> Result<(), char> { - for selection in &self.selections { - if selection.1.is_ok() { - if selection.1.as_ref().unwrap().contains(selection.0) { - //~^ ERROR cannot move out of `selection.1` - return Err(selection.0); - } - } - } - Ok(()) - } -} - -fn main() {} diff --git a/src/test/ui/suggestions/option-content-move.rs b/src/test/ui/suggestions/option-content-move.rs index ef38f114e..46c895b95 100644 --- a/src/test/ui/suggestions/option-content-move.rs +++ b/src/test/ui/suggestions/option-content-move.rs @@ -1,5 +1,3 @@ -//run-rustfix - pub struct LipogramCorpora { selections: Vec<(char, Option<String>)>, } diff --git a/src/test/ui/suggestions/option-content-move.stderr b/src/test/ui/suggestions/option-content-move.stderr index fccfbe1d7..a6f1ebc97 100644 --- a/src/test/ui/suggestions/option-content-move.stderr +++ b/src/test/ui/suggestions/option-content-move.stderr @@ -1,9 +1,10 @@ error[E0507]: cannot move out of `selection.1` which is behind a shared reference - --> $DIR/option-content-move.rs:11:20 + --> $DIR/option-content-move.rs:9:20 | LL | if selection.1.unwrap().contains(selection.0) { | ^^^^^^^^^^^ -------- `selection.1` moved due to this method call | | + | help: consider calling `.as_ref()` or `.as_mut()` to borrow the type's contents | move occurs because `selection.1` has type `Option<String>`, which does not implement the `Copy` trait | note: this function takes ownership of the receiver `self`, which moves `selection.1` @@ -11,17 +12,14 @@ note: this function takes ownership of the receiver `self`, which moves `selecti | LL | pub const fn unwrap(self) -> T { | ^^^^ -help: consider calling `.as_ref()` to borrow the type's contents - | -LL | if selection.1.as_ref().unwrap().contains(selection.0) { - | +++++++++ error[E0507]: cannot move out of `selection.1` which is behind a shared reference - --> $DIR/option-content-move.rs:29:20 + --> $DIR/option-content-move.rs:27:20 | LL | if selection.1.unwrap().contains(selection.0) { | ^^^^^^^^^^^ -------- `selection.1` moved due to this method call | | + | help: consider calling `.as_ref()` or `.as_mut()` to borrow the type's contents | move occurs because `selection.1` has type `Result<String, String>`, which does not implement the `Copy` trait | note: this function takes ownership of the receiver `self`, which moves `selection.1` @@ -29,10 +27,6 @@ note: this function takes ownership of the receiver `self`, which moves `selecti | LL | pub fn unwrap(self) -> T | ^^^^ -help: consider calling `.as_ref()` to borrow the type's contents - | -LL | if selection.1.as_ref().unwrap().contains(selection.0) { - | +++++++++ error: aborting due to 2 previous errors diff --git a/src/test/ui/suggestions/restrict-type-not-param.rs b/src/test/ui/suggestions/restrict-type-not-param.rs new file mode 100644 index 000000000..60f5ba45c --- /dev/null +++ b/src/test/ui/suggestions/restrict-type-not-param.rs @@ -0,0 +1,12 @@ +use std::ops::Add; + +struct Wrapper<T>(T); + +trait Foo {} + +fn qux<T>(a: Wrapper<T>, b: T) -> T { + a + b + //~^ ERROR cannot add `T` to `Wrapper<T>` +} + +fn main() {} diff --git a/src/test/ui/suggestions/restrict-type-not-param.stderr b/src/test/ui/suggestions/restrict-type-not-param.stderr new file mode 100644 index 000000000..e7d9c5ecb --- /dev/null +++ b/src/test/ui/suggestions/restrict-type-not-param.stderr @@ -0,0 +1,26 @@ +error[E0369]: cannot add `T` to `Wrapper<T>` + --> $DIR/restrict-type-not-param.rs:8:7 + | +LL | a + b + | - ^ - T + | | + | Wrapper<T> + | +note: an implementation of `Add<_>` might be missing for `Wrapper<T>` + --> $DIR/restrict-type-not-param.rs:3:1 + | +LL | struct Wrapper<T>(T); + | ^^^^^^^^^^^^^^^^^ must implement `Add<_>` +note: the following trait must be implemented + --> $SRC_DIR/core/src/ops/arith.rs:LL:COL + | +LL | pub trait Add<Rhs = Self> { + | ^^^^^^^^^^^^^^^^^^^^^^^^^ +help: consider introducing a `where` clause, but there might be an alternative better way to express this requirement + | +LL | fn qux<T>(a: Wrapper<T>, b: T) -> T where Wrapper<T>: Add<T, Output = T> { + | ++++++++++++++++++++++++++++++++++++ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0369`. diff --git a/src/test/ui/suggestions/return-closures.rs b/src/test/ui/suggestions/return-closures.rs new file mode 100644 index 000000000..86c7c1537 --- /dev/null +++ b/src/test/ui/suggestions/return-closures.rs @@ -0,0 +1,13 @@ +fn foo() { + //~^ HELP try adding a return type + |x: &i32| 1i32 + //~^ ERROR mismatched types +} + +fn bar(i: impl Sized) { + //~^ HELP a return type might be missing here + || i + //~^ ERROR mismatched types +} + +fn main() {} diff --git a/src/test/ui/suggestions/return-closures.stderr b/src/test/ui/suggestions/return-closures.stderr new file mode 100644 index 000000000..e273793ea --- /dev/null +++ b/src/test/ui/suggestions/return-closures.stderr @@ -0,0 +1,27 @@ +error[E0308]: mismatched types + --> $DIR/return-closures.rs:3:5 + | +LL | fn foo() { + | - help: try adding a return type: `-> impl for<'r> Fn(&'r i32) -> i32` +LL | +LL | |x: &i32| 1i32 + | ^^^^^^^^^^^^^^ expected `()`, found closure + | + = note: expected unit type `()` + found closure `[closure@$DIR/return-closures.rs:3:5: 3:14]` + +error[E0308]: mismatched types + --> $DIR/return-closures.rs:9:5 + | +LL | fn bar(i: impl Sized) { + | - help: a return type might be missing here: `-> _` +LL | +LL | || i + | ^^^^ expected `()`, found closure + | + = note: expected unit type `()` + found closure `[closure@$DIR/return-closures.rs:9:5: 9:7]` + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0308`. diff --git a/src/test/ui/suggestions/return-cycle-2.rs b/src/test/ui/suggestions/return-cycle-2.rs new file mode 100644 index 000000000..d6d24be1b --- /dev/null +++ b/src/test/ui/suggestions/return-cycle-2.rs @@ -0,0 +1,14 @@ +use std::marker::PhantomData; + +struct Token<T>(PhantomData<T>); + +impl<T> Token<T> { + fn as_ref(_: i32, _: i32) -> _ { + //~^ ERROR the placeholder `_` is not allowed within types on item signatures for return types + //~| NOTE not allowed in type signatures + //~| HELP replace with the correct return type + Token(PhantomData::<&T>) + } +} + +fn main() {} diff --git a/src/test/ui/suggestions/return-cycle-2.stderr b/src/test/ui/suggestions/return-cycle-2.stderr new file mode 100644 index 000000000..3a1a0f7f4 --- /dev/null +++ b/src/test/ui/suggestions/return-cycle-2.stderr @@ -0,0 +1,12 @@ +error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types + --> $DIR/return-cycle-2.rs:6:34 + | +LL | fn as_ref(_: i32, _: i32) -> _ { + | ^ + | | + | not allowed in type signatures + | help: replace with the correct return type: `Token<&'static T>` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0121`. diff --git a/src/test/ui/suggestions/return-cycle.rs b/src/test/ui/suggestions/return-cycle.rs new file mode 100644 index 000000000..60b80e35a --- /dev/null +++ b/src/test/ui/suggestions/return-cycle.rs @@ -0,0 +1,14 @@ +use std::marker::PhantomData; + +struct Token<T>(PhantomData<T>); + +impl<T> Token<T> { + fn new() -> _ { + //~^ ERROR the placeholder `_` is not allowed within types on item signatures for return types + //~| NOTE not allowed in type signatures + //~| HELP replace with the correct return type + Token(PhantomData::<()>) + } +} + +fn main() {} diff --git a/src/test/ui/suggestions/return-cycle.stderr b/src/test/ui/suggestions/return-cycle.stderr new file mode 100644 index 000000000..63fa9e040 --- /dev/null +++ b/src/test/ui/suggestions/return-cycle.stderr @@ -0,0 +1,12 @@ +error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types + --> $DIR/return-cycle.rs:6:17 + | +LL | fn new() -> _ { + | ^ + | | + | not allowed in type signatures + | help: replace with the correct return type: `Token<()>` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0121`. diff --git a/src/test/ui/suggestions/slice-issue-87994.stderr b/src/test/ui/suggestions/slice-issue-87994.stderr index fd2a44f9a..84ecd749b 100644 --- a/src/test/ui/suggestions/slice-issue-87994.stderr +++ b/src/test/ui/suggestions/slice-issue-87994.stderr @@ -2,10 +2,10 @@ error[E0277]: the size for values of type `[i32]` cannot be known at compilation --> $DIR/slice-issue-87994.rs:3:12 | LL | for _ in v[1..] { - | ^^^^^^ expected an implementor of trait `IntoIterator` + | ^^^^^^ the trait `IntoIterator` is not implemented for `[i32]` | = note: the trait bound `[i32]: IntoIterator` is not satisfied - = note: required because of the requirements on the impl of `IntoIterator` for `[i32]` + = note: required for `[i32]` to implement `IntoIterator` help: consider borrowing here | LL | for _ in &v[1..] { @@ -17,10 +17,10 @@ error[E0277]: `[i32]` is not an iterator --> $DIR/slice-issue-87994.rs:3:12 | LL | for _ in v[1..] { - | ^^^^^^ expected an implementor of trait `IntoIterator` + | ^^^^^^ the trait `IntoIterator` is not implemented for `[i32]` | = note: the trait bound `[i32]: IntoIterator` is not satisfied - = note: required because of the requirements on the impl of `IntoIterator` for `[i32]` + = note: required for `[i32]` to implement `IntoIterator` help: consider borrowing here | LL | for _ in &v[1..] { @@ -32,10 +32,10 @@ error[E0277]: the size for values of type `[K]` cannot be known at compilation t --> $DIR/slice-issue-87994.rs:11:13 | LL | for i2 in v2[1..] { - | ^^^^^^^ expected an implementor of trait `IntoIterator` + | ^^^^^^^ the trait `IntoIterator` is not implemented for `[K]` | = note: the trait bound `[K]: IntoIterator` is not satisfied - = note: required because of the requirements on the impl of `IntoIterator` for `[K]` + = note: required for `[K]` to implement `IntoIterator` help: consider borrowing here | LL | for i2 in &v2[1..] { @@ -47,10 +47,10 @@ error[E0277]: `[K]` is not an iterator --> $DIR/slice-issue-87994.rs:11:13 | LL | for i2 in v2[1..] { - | ^^^^^^^ expected an implementor of trait `IntoIterator` + | ^^^^^^^ the trait `IntoIterator` is not implemented for `[K]` | = note: the trait bound `[K]: IntoIterator` is not satisfied - = note: required because of the requirements on the impl of `IntoIterator` for `[K]` + = note: required for `[K]` to implement `IntoIterator` help: consider borrowing here | LL | for i2 in &v2[1..] { diff --git a/src/test/ui/suggestions/sugg_with_positional_args_and_debug_fmt.rs b/src/test/ui/suggestions/sugg_with_positional_args_and_debug_fmt.rs new file mode 100644 index 000000000..21ab6830b --- /dev/null +++ b/src/test/ui/suggestions/sugg_with_positional_args_and_debug_fmt.rs @@ -0,0 +1,10 @@ +// When build the suggesttion take in consideration the `:?` +// https://github.com/rust-lang/rust/issues/100648 +#![deny(warnings)] + +fn main () { + println!("hello {:?}", world = "world"); + //~^ ERROR named argument `world` is not used by name + //~| HELP use the named argument by name to avoid ambiguity + //~| SUGGESTION world +} diff --git a/src/test/ui/suggestions/sugg_with_positional_args_and_debug_fmt.stderr b/src/test/ui/suggestions/sugg_with_positional_args_and_debug_fmt.stderr new file mode 100644 index 000000000..850f69f2d --- /dev/null +++ b/src/test/ui/suggestions/sugg_with_positional_args_and_debug_fmt.stderr @@ -0,0 +1,21 @@ +error: named argument `world` is not used by name + --> $DIR/sugg_with_positional_args_and_debug_fmt.rs:6:28 + | +LL | println!("hello {:?}", world = "world"); + | ---- ^^^^^ this named argument is referred to by position in formatting string + | | + | this formatting argument uses named argument `world` by position + | +note: the lint level is defined here + --> $DIR/sugg_with_positional_args_and_debug_fmt.rs:3:9 + | +LL | #![deny(warnings)] + | ^^^^^^^^ + = note: `#[deny(named_arguments_used_positionally)]` implied by `#[deny(warnings)]` +help: use the named argument by name to avoid ambiguity + | +LL | println!("hello {world:?}", world = "world"); + | +++++ + +error: aborting due to previous error + diff --git a/src/test/ui/suggestions/suggest-adding-reference-to-trait-assoc-item.fixed b/src/test/ui/suggestions/suggest-adding-reference-to-trait-assoc-item.fixed new file mode 100644 index 000000000..e9b8a9caa --- /dev/null +++ b/src/test/ui/suggestions/suggest-adding-reference-to-trait-assoc-item.fixed @@ -0,0 +1,15 @@ +// run-rustfix +#![allow(unused_variables)] + +fn foo(foo: &mut usize) { + todo!() +} + +fn bar(bar: &usize) { + todo!() +} + +fn main() { + foo(&mut Default::default()); //~ the trait bound `&mut usize: Default` is not satisfied + bar(&Default::default()); //~ the trait bound `&usize: Default` is not satisfied +} diff --git a/src/test/ui/suggestions/suggest-adding-reference-to-trait-assoc-item.rs b/src/test/ui/suggestions/suggest-adding-reference-to-trait-assoc-item.rs new file mode 100644 index 000000000..5fae21ccc --- /dev/null +++ b/src/test/ui/suggestions/suggest-adding-reference-to-trait-assoc-item.rs @@ -0,0 +1,15 @@ +// run-rustfix +#![allow(unused_variables)] + +fn foo(foo: &mut usize) { + todo!() +} + +fn bar(bar: &usize) { + todo!() +} + +fn main() { + foo(Default::default()); //~ the trait bound `&mut usize: Default` is not satisfied + bar(Default::default()); //~ the trait bound `&usize: Default` is not satisfied +} diff --git a/src/test/ui/suggestions/suggest-adding-reference-to-trait-assoc-item.stderr b/src/test/ui/suggestions/suggest-adding-reference-to-trait-assoc-item.stderr new file mode 100644 index 000000000..125a8b44f --- /dev/null +++ b/src/test/ui/suggestions/suggest-adding-reference-to-trait-assoc-item.stderr @@ -0,0 +1,25 @@ +error[E0277]: the trait bound `&mut usize: Default` is not satisfied + --> $DIR/suggest-adding-reference-to-trait-assoc-item.rs:13:9 + | +LL | foo(Default::default()); + | ^^^^^^^^^^^^^^^^ the trait `Default` is not implemented for `&mut usize` + | +help: consider mutably borrowing here + | +LL | foo(&mut Default::default()); + | ++++ + +error[E0277]: the trait bound `&usize: Default` is not satisfied + --> $DIR/suggest-adding-reference-to-trait-assoc-item.rs:14:9 + | +LL | bar(Default::default()); + | ^^^^^^^^^^^^^^^^ the trait `Default` is not implemented for `&usize` + | +help: consider borrowing here + | +LL | bar(&Default::default()); + | + + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/suggestions/suggest-blanket-impl-local-trait.rs b/src/test/ui/suggestions/suggest-blanket-impl-local-trait.rs index 7cf536f79..14fef1b52 100644 --- a/src/test/ui/suggestions/suggest-blanket-impl-local-trait.rs +++ b/src/test/ui/suggestions/suggest-blanket-impl-local-trait.rs @@ -1,5 +1,5 @@ // Ensure that the compiler include the blanklet implementation suggestion -// when inside a `impl` statment are used two local traits. +// when inside a `impl` statement are used two local traits. // // edition:2021 use std::fmt; diff --git a/src/test/ui/suggestions/suggest-blanket-impl-local-trait.stderr b/src/test/ui/suggestions/suggest-blanket-impl-local-trait.stderr index d739a8272..398caa98b 100644 --- a/src/test/ui/suggestions/suggest-blanket-impl-local-trait.stderr +++ b/src/test/ui/suggestions/suggest-blanket-impl-local-trait.stderr @@ -6,9 +6,8 @@ LL | impl LocalTraitTwo for LocalTraitOne {} | help: add `dyn` keyword before this trait | -LL - impl LocalTraitTwo for LocalTraitOne {} -LL + impl LocalTraitTwo for dyn LocalTraitOne {} - | +LL | impl LocalTraitTwo for dyn LocalTraitOne {} + | +++ help: alternatively use a blanket implementation to implement `LocalTraitTwo` for all types that also implement `LocalTraitOne` | LL | impl<T: LocalTraitOne> LocalTraitTwo for T {} @@ -22,9 +21,8 @@ LL | impl fmt::Display for LocalTraitOne { | help: add `dyn` keyword before this trait | -LL - impl fmt::Display for LocalTraitOne { -LL + impl fmt::Display for dyn LocalTraitOne { - | +LL | impl fmt::Display for dyn LocalTraitOne { + | +++ error[E0782]: trait objects must include the `dyn` keyword --> $DIR/suggest-blanket-impl-local-trait.rs:26:23 @@ -34,9 +32,8 @@ LL | impl fmt::Display for LocalTraitTwo + Send { | help: add `dyn` keyword before this trait | -LL - impl fmt::Display for LocalTraitTwo + Send { -LL + impl fmt::Display for dyn LocalTraitTwo + Send { - | +LL | impl fmt::Display for dyn LocalTraitTwo + Send { + | +++ error[E0782]: trait objects must include the `dyn` keyword --> $DIR/suggest-blanket-impl-local-trait.rs:34:24 @@ -46,9 +43,8 @@ LL | impl LocalTraitOne for fmt::Display {} | help: add `dyn` keyword before this trait | -LL - impl LocalTraitOne for fmt::Display {} -LL + impl LocalTraitOne for dyn fmt::Display {} - | +LL | impl LocalTraitOne for dyn fmt::Display {} + | +++ help: alternatively use a blanket implementation to implement `LocalTraitOne` for all types that also implement `fmt::Display` | LL | impl<T: fmt::Display> LocalTraitOne for T {} @@ -62,9 +58,8 @@ LL | impl LocalTraitOne for fmt::Display + Send {} | help: add `dyn` keyword before this trait | -LL - impl LocalTraitOne for fmt::Display + Send {} -LL + impl LocalTraitOne for dyn fmt::Display + Send {} - | +LL | impl LocalTraitOne for dyn fmt::Display + Send {} + | +++ help: alternatively use a blanket implementation to implement `LocalTraitOne` for all types that also implement `fmt::Display + Send` | LL | impl<T: fmt::Display + Send> LocalTraitOne for T {} @@ -78,9 +73,8 @@ LL | impl<E> GenericTrait<E> for LocalTraitOne {} | help: add `dyn` keyword before this trait | -LL - impl<E> GenericTrait<E> for LocalTraitOne {} -LL + impl<E> GenericTrait<E> for dyn LocalTraitOne {} - | +LL | impl<E> GenericTrait<E> for dyn LocalTraitOne {} + | +++ help: alternatively use a blanket implementation to implement `GenericTrait<E>` for all types that also implement `LocalTraitOne` | LL | impl<E, T: LocalTraitOne> GenericTrait<E> for T {} @@ -94,9 +88,8 @@ LL | impl<T, E> GenericTraitTwo<E> for GenericTrait<T> {} | help: add `dyn` keyword before this trait | -LL - impl<T, E> GenericTraitTwo<E> for GenericTrait<T> {} -LL + impl<T, E> GenericTraitTwo<E> for dyn GenericTrait<T> {} - | +LL | impl<T, E> GenericTraitTwo<E> for dyn GenericTrait<T> {} + | +++ help: alternatively use a blanket implementation to implement `GenericTraitTwo<E>` for all types that also implement `GenericTrait<T>` | LL | impl<T, E, U: GenericTrait<T>> GenericTraitTwo<E> for U {} diff --git a/src/test/ui/suggestions/suggest-borrow-to-dyn-object.stderr b/src/test/ui/suggestions/suggest-borrow-to-dyn-object.stderr index 6b6e40613..6ce9bfd9d 100644 --- a/src/test/ui/suggestions/suggest-borrow-to-dyn-object.stderr +++ b/src/test/ui/suggestions/suggest-borrow-to-dyn-object.stderr @@ -2,9 +2,7 @@ error[E0277]: the size for values of type `[u8]` cannot be known at compilation --> $DIR/suggest-borrow-to-dyn-object.rs:12:11 | LL | check(s); - | ----- ^ doesn't have a size known at compile-time - | | - | required by a bound introduced by this call + | ^ doesn't have a size known at compile-time | = help: within `OsStr`, the trait `Sized` is not implemented for `[u8]` = note: required because it appears within the type `OsStr` diff --git a/src/test/ui/suggestions/suggest-dereferencing-index.stderr b/src/test/ui/suggestions/suggest-dereferencing-index.stderr index c8b87af7b..147dc9234 100644 --- a/src/test/ui/suggestions/suggest-dereferencing-index.stderr +++ b/src/test/ui/suggestions/suggest-dereferencing-index.stderr @@ -6,7 +6,7 @@ LL | let one_item_please: i32 = [1, 2, 3][i]; | = help: the trait `SliceIndex<[{integer}]>` is not implemented for `&usize` = help: the trait `SliceIndex<[T]>` is implemented for `usize` - = note: required because of the requirements on the impl of `Index<&usize>` for `[{integer}]` + = note: required for `[{integer}]` to implement `Index<&usize>` help: dereference this index | LL | let one_item_please: i32 = [1, 2, 3][*i]; diff --git a/src/test/ui/suggestions/suggest-imm-mut-trait-implementations.stderr b/src/test/ui/suggestions/suggest-imm-mut-trait-implementations.stderr index 6583cabe1..f2eb651ea 100644 --- a/src/test/ui/suggestions/suggest-imm-mut-trait-implementations.stderr +++ b/src/test/ui/suggestions/suggest-imm-mut-trait-implementations.stderr @@ -2,7 +2,7 @@ error[E0277]: the trait bound `A: Trait` is not satisfied --> $DIR/suggest-imm-mut-trait-implementations.rs:20:9 | LL | foo(a); - | --- ^ expected an implementor of trait `Trait` + | --- ^ the trait `Trait` is not implemented for `A` | | | required by a bound introduced by this call | @@ -22,7 +22,7 @@ error[E0277]: the trait bound `B: Trait` is not satisfied --> $DIR/suggest-imm-mut-trait-implementations.rs:21:9 | LL | foo(b); - | --- ^ expected an implementor of trait `Trait` + | --- ^ the trait `Trait` is not implemented for `B` | | | required by a bound introduced by this call | @@ -40,7 +40,7 @@ error[E0277]: the trait bound `C: Trait` is not satisfied --> $DIR/suggest-imm-mut-trait-implementations.rs:22:9 | LL | foo(c); - | --- ^ expected an implementor of trait `Trait` + | --- ^ the trait `Trait` is not implemented for `C` | | | required by a bound introduced by this call | diff --git a/src/test/ui/suggestions/suggest-methods.stderr b/src/test/ui/suggestions/suggest-methods.stderr index 97d7e6696..03cb9c779 100644 --- a/src/test/ui/suggestions/suggest-methods.stderr +++ b/src/test/ui/suggestions/suggest-methods.stderr @@ -5,25 +5,25 @@ LL | struct Foo; | ---------- method `bat` not found for this struct ... LL | f.bat(1.0); - | ^^^ help: there is an associated function with a similar name: `bar` + | ^^^ help: there is a method with a similar name: `bar` error[E0599]: no method named `is_emtpy` found for struct `String` in the current scope --> $DIR/suggest-methods.rs:21:15 | LL | let _ = s.is_emtpy(); - | ^^^^^^^^ help: there is an associated function with a similar name: `is_empty` + | ^^^^^^^^ help: there is a method with a similar name: `is_empty` error[E0599]: no method named `count_eos` found for type `u32` in the current scope --> $DIR/suggest-methods.rs:25:19 | LL | let _ = 63u32.count_eos(); - | ^^^^^^^^^ help: there is an associated function with a similar name: `count_zeros` + | ^^^^^^^^^ help: there is a method with a similar name: `count_zeros` error[E0599]: no method named `count_o` found for type `u32` in the current scope --> $DIR/suggest-methods.rs:28:19 | LL | let _ = 63u32.count_o(); - | ^^^^^^^ help: there is an associated function with a similar name: `count_ones` + | ^^^^^^^ help: there is a method with a similar name: `count_ones` error: aborting due to 4 previous errors diff --git a/src/test/ui/suggestions/suggest-move-lifetimes.stderr b/src/test/ui/suggestions/suggest-move-lifetimes.stderr index f52631cae..b1a49447d 100644 --- a/src/test/ui/suggestions/suggest-move-lifetimes.stderr +++ b/src/test/ui/suggestions/suggest-move-lifetimes.stderr @@ -1,22 +1,22 @@ -error: lifetime parameters must be declared prior to type parameters +error: lifetime parameters must be declared prior to type and const parameters --> $DIR/suggest-move-lifetimes.rs:1:13 | LL | struct A<T, 'a> { | ----^^- help: reorder the parameters: lifetimes, then consts and types: `<'a, T>` -error: lifetime parameters must be declared prior to type parameters +error: lifetime parameters must be declared prior to type and const parameters --> $DIR/suggest-move-lifetimes.rs:5:13 | LL | struct B<T, 'a, U> { | ----^^---- help: reorder the parameters: lifetimes, then consts and types: `<'a, T, U>` -error: lifetime parameters must be declared prior to type parameters +error: lifetime parameters must be declared prior to type and const parameters --> $DIR/suggest-move-lifetimes.rs:10:16 | LL | struct C<T, U, 'a> { | -------^^- help: reorder the parameters: lifetimes, then consts and types: `<'a, T, U>` -error: lifetime parameters must be declared prior to type parameters +error: lifetime parameters must be declared prior to type and const parameters --> $DIR/suggest-move-lifetimes.rs:15:16 | LL | struct D<T, U, 'a, 'b, V, 'c> { diff --git a/src/test/ui/suggestions/suggest-move-types.stderr b/src/test/ui/suggestions/suggest-move-types.stderr index 1a6032db0..b222e8142 100644 --- a/src/test/ui/suggestions/suggest-move-types.stderr +++ b/src/test/ui/suggestions/suggest-move-types.stderr @@ -121,7 +121,7 @@ LL | struct Cl<'a, 'b, 'c, T, U, V, M: ThreeWithLifetime<T, 'a, A=(), B=(), C=() | ^^ | = note: lifetime arguments must be provided before type arguments - = help: reorder the arguments: lifetimes, then types: `<'a, 'b, 'c, T, U, V>` + = help: reorder the arguments: lifetimes, then type and consts: `<'a, 'b, 'c, T, U, V>` error[E0747]: lifetime provided when a type was expected --> $DIR/suggest-move-types.rs:82:56 @@ -130,7 +130,7 @@ LL | struct Dl<'a, 'b, 'c, T, U, V, M: ThreeWithLifetime<T, 'a, A=(), B=(), U, ' | ^^ | = note: lifetime arguments must be provided before type arguments - = help: reorder the arguments: lifetimes, then types: `<'a, 'b, 'c, T, U, V>` + = help: reorder the arguments: lifetimes, then type and consts: `<'a, 'b, 'c, T, U, V>` error: aborting due to 12 previous errors diff --git a/src/test/ui/suggestions/suggest-ref-macro.stderr b/src/test/ui/suggestions/suggest-ref-macro.stderr index 84cbc9357..17de49fbd 100644 --- a/src/test/ui/suggestions/suggest-ref-macro.stderr +++ b/src/test/ui/suggestions/suggest-ref-macro.stderr @@ -10,14 +10,8 @@ LL | #[hello] note: function defined here --> $DIR/suggest-ref-macro.rs:8:1 | -LL | #[hello] - | _-^^^^^^^ -LL | | fn abc() {} -LL | | -LL | | fn x(_: &mut i32) {} -LL | | -LL | | macro_rules! bla { - | |_____________- +LL | #[hello] + | ^^^^^^^^ = note: this error originates in the attribute macro `hello` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0308]: mismatched types diff --git a/src/test/ui/suggestions/suggest-remove-refs-1.stderr b/src/test/ui/suggestions/suggest-remove-refs-1.stderr index 1083b2f97..1a843f3f5 100644 --- a/src/test/ui/suggestions/suggest-remove-refs-1.stderr +++ b/src/test/ui/suggestions/suggest-remove-refs-1.stderr @@ -8,7 +8,7 @@ LL | for (i, _) in &v.iter().enumerate() { | help: consider removing the leading `&`-reference | = help: the trait `Iterator` is not implemented for `&Enumerate<std::slice::Iter<'_, {integer}>>` - = note: required because of the requirements on the impl of `IntoIterator` for `&Enumerate<std::slice::Iter<'_, {integer}>>` + = note: required for `&Enumerate<std::slice::Iter<'_, {integer}>>` to implement `IntoIterator` error: aborting due to previous error diff --git a/src/test/ui/suggestions/suggest-remove-refs-2.stderr b/src/test/ui/suggestions/suggest-remove-refs-2.stderr index 197b19a1b..f39361d52 100644 --- a/src/test/ui/suggestions/suggest-remove-refs-2.stderr +++ b/src/test/ui/suggestions/suggest-remove-refs-2.stderr @@ -8,7 +8,7 @@ LL | for (i, _) in & & & & &v.iter().enumerate() { | help: consider removing 5 leading `&`-references | = help: the trait `Iterator` is not implemented for `&&&&&Enumerate<std::slice::Iter<'_, {integer}>>` - = note: required because of the requirements on the impl of `IntoIterator` for `&&&&&Enumerate<std::slice::Iter<'_, {integer}>>` + = note: required for `&&&&&Enumerate<std::slice::Iter<'_, {integer}>>` to implement `IntoIterator` error: aborting due to previous error diff --git a/src/test/ui/suggestions/suggest-remove-refs-3.stderr b/src/test/ui/suggestions/suggest-remove-refs-3.stderr index bb0cceac1..4d0732427 100644 --- a/src/test/ui/suggestions/suggest-remove-refs-3.stderr +++ b/src/test/ui/suggestions/suggest-remove-refs-3.stderr @@ -12,7 +12,7 @@ LL | | .enumerate() { | |_____________________^ `&&&&&Enumerate<std::slice::Iter<'_, {integer}>>` is not an iterator | = help: the trait `Iterator` is not implemented for `&&&&&Enumerate<std::slice::Iter<'_, {integer}>>` - = note: required because of the requirements on the impl of `IntoIterator` for `&&&&&Enumerate<std::slice::Iter<'_, {integer}>>` + = note: required for `&&&&&Enumerate<std::slice::Iter<'_, {integer}>>` to implement `IntoIterator` error: aborting due to previous error diff --git a/src/test/ui/suggestions/suggest-swapping-self-ty-and-trait-edition-2021.stderr b/src/test/ui/suggestions/suggest-swapping-self-ty-and-trait-edition-2021.stderr index fc880d6b8..87e716436 100644 --- a/src/test/ui/suggestions/suggest-swapping-self-ty-and-trait-edition-2021.stderr +++ b/src/test/ui/suggestions/suggest-swapping-self-ty-and-trait-edition-2021.stderr @@ -39,9 +39,8 @@ LL | impl<'a, T> Struct<T> for Trait<'a, T> {} | help: add `dyn` keyword before this trait | -LL - impl<'a, T> Struct<T> for Trait<'a, T> {} -LL + impl<'a, T> Struct<T> for dyn Trait<'a, T> {} - | +LL | impl<'a, T> Struct<T> for dyn Trait<'a, T> {} + | +++ error: aborting due to 4 previous errors diff --git a/src/test/ui/suggestions/suggest-swapping-self-ty-and-trait.stderr b/src/test/ui/suggestions/suggest-swapping-self-ty-and-trait.stderr index f5143762d..f716e6c17 100644 --- a/src/test/ui/suggestions/suggest-swapping-self-ty-and-trait.stderr +++ b/src/test/ui/suggestions/suggest-swapping-self-ty-and-trait.stderr @@ -42,9 +42,8 @@ LL | impl<'a, T> Struct<T> for Trait<'a, T> {} = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html> help: use `dyn` | -LL - impl<'a, T> Struct<T> for Trait<'a, T> {} -LL + impl<'a, T> Struct<T> for dyn Trait<'a, T> {} - | +LL | impl<'a, T> Struct<T> for dyn Trait<'a, T> {} + | +++ error: aborting due to 3 previous errors; 1 warning emitted diff --git a/src/test/ui/suggestions/too-many-field-suggestions.rs b/src/test/ui/suggestions/too-many-field-suggestions.rs new file mode 100644 index 000000000..905f9502c --- /dev/null +++ b/src/test/ui/suggestions/too-many-field-suggestions.rs @@ -0,0 +1,29 @@ +struct Thing { + a0: Foo, + a1: Foo, + a2: Foo, + a3: Foo, + a4: Foo, + a5: Foo, + a6: Foo, + a7: Foo, + a8: Foo, + a9: Foo, +} + +struct Foo { + field: Field, +} + +struct Field; + +impl Foo { + fn bar(&self) {} +} + +fn bar(t: Thing) { + t.bar(); //~ ERROR no method named `bar` found for struct `Thing` + t.field; //~ ERROR no field `field` on type `Thing` +} + +fn main() {} diff --git a/src/test/ui/suggestions/too-many-field-suggestions.stderr b/src/test/ui/suggestions/too-many-field-suggestions.stderr new file mode 100644 index 000000000..63ad6fdb1 --- /dev/null +++ b/src/test/ui/suggestions/too-many-field-suggestions.stderr @@ -0,0 +1,44 @@ +error[E0599]: no method named `bar` found for struct `Thing` in the current scope + --> $DIR/too-many-field-suggestions.rs:25:7 + | +LL | struct Thing { + | ------------ method `bar` not found for this struct +... +LL | t.bar(); + | ^^^ method not found in `Thing` + | +help: some of the expressions' fields have a method of the same name + | +LL | t.a0.bar(); + | +++ +LL | t.a1.bar(); + | +++ +LL | t.a2.bar(); + | +++ +LL | t.a3.bar(); + | +++ + and 6 other candidates + +error[E0609]: no field `field` on type `Thing` + --> $DIR/too-many-field-suggestions.rs:26:7 + | +LL | t.field; + | ^^^^^ unknown field + | + = note: available fields are: `a0`, `a1`, `a2`, `a3`, `a4` ... and 5 others +help: some of the expressions' fields have a field of the same name + | +LL | t.a0.field; + | +++ +LL | t.a1.field; + | +++ +LL | t.a2.field; + | +++ +LL | t.a3.field; + | +++ + and 6 other candidates + +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/src/test/ui/suggestions/try-removing-the-field.rs b/src/test/ui/suggestions/try-removing-the-field.rs new file mode 100644 index 000000000..9d0573ca2 --- /dev/null +++ b/src/test/ui/suggestions/try-removing-the-field.rs @@ -0,0 +1,17 @@ +// run-pass + +#![allow(dead_code)] + +struct Foo { + foo: i32, + bar: (), + baz: (), +} + +fn use_foo(x: Foo) -> i32 { + let Foo { foo, bar, .. } = x; //~ WARNING unused variable: `bar` + //~| help: try removing the field + return foo; +} + +fn main() {} diff --git a/src/test/ui/suggestions/try-removing-the-field.stderr b/src/test/ui/suggestions/try-removing-the-field.stderr new file mode 100644 index 000000000..448a2c3d2 --- /dev/null +++ b/src/test/ui/suggestions/try-removing-the-field.stderr @@ -0,0 +1,12 @@ +warning: unused variable: `bar` + --> $DIR/try-removing-the-field.rs:12:20 + | +LL | let Foo { foo, bar, .. } = x; + | ^^^- + | | + | help: try removing the field + | + = note: `#[warn(unused_variables)]` on by default + +warning: 1 warning emitted + diff --git a/src/test/ui/suggestions/type-ascription-and-other-error.rs b/src/test/ui/suggestions/type-ascription-and-other-error.rs new file mode 100644 index 000000000..99ab2f3c8 --- /dev/null +++ b/src/test/ui/suggestions/type-ascription-and-other-error.rs @@ -0,0 +1,6 @@ +fn main() { + not rust; //~ ERROR + let _ = 0: i32; // (error hidden by existing error) + #[cfg(FALSE)] + let _ = 0: i32; // (warning hidden by existing error) +} diff --git a/src/test/ui/suggestions/type-ascription-and-other-error.stderr b/src/test/ui/suggestions/type-ascription-and-other-error.stderr new file mode 100644 index 000000000..eadf634bb --- /dev/null +++ b/src/test/ui/suggestions/type-ascription-and-other-error.stderr @@ -0,0 +1,8 @@ +error: expected one of `!`, `.`, `::`, `;`, `?`, `{`, `}`, or an operator, found `rust` + --> $DIR/type-ascription-and-other-error.rs:2:9 + | +LL | not rust; + | ^^^^ expected one of 8 possible tokens + +error: aborting due to previous error + diff --git a/src/test/ui/suggestions/unnamable-types.stderr b/src/test/ui/suggestions/unnamable-types.stderr index de64269d1..ede3ebfa7 100644 --- a/src/test/ui/suggestions/unnamable-types.stderr +++ b/src/test/ui/suggestions/unnamable-types.stderr @@ -1,8 +1,8 @@ error: missing type for `const` item - --> $DIR/unnamable-types.rs:6:7 + --> $DIR/unnamable-types.rs:6:8 | LL | const A = 5; - | ^ help: provide a type for the constant: `A: i32` + | ^ help: provide a type for the constant: `: i32` error[E0121]: the placeholder `_` is not allowed within types on item signatures for static variables --> $DIR/unnamable-types.rs:10:11 @@ -26,10 +26,10 @@ LL | const C: _ = || 42; | ^^^^^ error: missing type for `const` item - --> $DIR/unnamable-types.rs:23:7 + --> $DIR/unnamable-types.rs:23:8 | LL | const D = S { t: { let i = 0; move || -> i32 { i } } }; - | ^ + | ^ | note: however, the inferred type `S<[closure@$DIR/unnamable-types.rs:23:31: 23:45]>` cannot be named --> $DIR/unnamable-types.rs:23:11 @@ -38,22 +38,22 @@ LL | const D = S { t: { let i = 0; move || -> i32 { i } } }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: missing type for `const` item - --> $DIR/unnamable-types.rs:29:7 + --> $DIR/unnamable-types.rs:29:8 | LL | const E = foo; - | ^ help: provide a type for the constant: `E: fn() -> i32` + | ^ help: provide a type for the constant: `: fn() -> i32` error: missing type for `const` item - --> $DIR/unnamable-types.rs:32:7 + --> $DIR/unnamable-types.rs:32:8 | LL | const F = S { t: foo }; - | ^ help: provide a type for the constant: `F: S<fn() -> i32>` + | ^ help: provide a type for the constant: `: S<fn() -> i32>` error: missing type for `const` item - --> $DIR/unnamable-types.rs:37:7 + --> $DIR/unnamable-types.rs:37:8 | LL | const G = || -> i32 { yield 0; return 1; }; - | ^ + | ^ | note: however, the inferred type `[generator@$DIR/unnamable-types.rs:37:11: 37:20]` cannot be named --> $DIR/unnamable-types.rs:37:11 diff --git a/src/test/ui/suggestions/use-type-argument-instead-of-assoc-type.stderr b/src/test/ui/suggestions/use-type-argument-instead-of-assoc-type.stderr index 7038a572b..75b919232 100644 --- a/src/test/ui/suggestions/use-type-argument-instead-of-assoc-type.stderr +++ b/src/test/ui/suggestions/use-type-argument-instead-of-assoc-type.stderr @@ -12,7 +12,7 @@ LL | pub trait T<X, Y> { help: replace the generic bounds with the associated types | LL | i: Box<dyn T<usize, usize, A = usize, C = usize, B=usize>>, - | ~~~~~~~~~ ~~~~~~~~~ + | +++ +++ error[E0191]: the value of the associated types `A` (from trait `T`), `C` (from trait `T`) must be specified --> $DIR/use-type-argument-instead-of-assoc-type.rs:7:16 |