diff options
Diffstat (limited to 'src/test/ui/resolve')
21 files changed, 492 insertions, 107 deletions
diff --git a/src/test/ui/resolve/bad-type-env-capture.stderr b/src/test/ui/resolve/bad-type-env-capture.stderr index 6f24c0d86..b6282c2d0 100644 --- a/src/test/ui/resolve/bad-type-env-capture.stderr +++ b/src/test/ui/resolve/bad-type-env-capture.stderr @@ -4,9 +4,9 @@ error[E0401]: can't use generic parameters from outer function LL | fn foo<T>() { | - type parameter from outer function LL | fn bar(b: T) { } - | --- ^ use of generic parameter from outer function - | | - | help: try using a local generic parameter instead: `bar<T>` + | - ^ use of generic parameter from outer function + | | + | help: try using a local generic parameter instead: `<T>` error: aborting due to previous error diff --git a/src/test/ui/resolve/issue-100365.rs b/src/test/ui/resolve/issue-100365.rs new file mode 100644 index 000000000..1d8835036 --- /dev/null +++ b/src/test/ui/resolve/issue-100365.rs @@ -0,0 +1,50 @@ +fn main() { + let addr = Into::<std::net::IpAddr>.into([127, 0, 0, 1]); + //~^ ERROR expected value, found trait `Into` + //~| HELP use the path separator + + let _ = Into.into(()); + //~^ ERROR expected value, found trait `Into` + //~| HELP use the path separator + + let _ = Into::<()>.into; + //~^ ERROR expected value, found trait `Into` + //~| HELP use the path separator +} + +macro_rules! Trait { + () => { + ::std::iter::Iterator + //~^ ERROR expected value, found trait `std::iter::Iterator` + //~| ERROR expected value, found trait `std::iter::Iterator` + }; +} + +macro_rules! create { + () => { + Into::<String>.into("") + //~^ ERROR expected value, found trait `Into` + //~| HELP use the path separator + }; +} + +fn interaction_with_macros() { + // + // Note that if the receiver is a macro call, we do not want to suggest to replace + // `.` with `::` as that would be a syntax error. + // Since the receiver is a trait and not a type, we cannot suggest to surround + // it with angle brackets. It would be interpreted as a trait object type void of + // `dyn` which is most likely not what the user intended to write. + // `<_ as Trait!()>::` is also not an option as it's equally syntactically invalid. + // + + Trait!().map(std::convert::identity); // no `help` here! + + Trait!().map; // no `help` here! + + // + // Ensure that the suggestion is shown for expressions inside of macro definitions. + // + + let _ = create!(); +} diff --git a/src/test/ui/resolve/issue-100365.stderr b/src/test/ui/resolve/issue-100365.stderr new file mode 100644 index 000000000..372d77266 --- /dev/null +++ b/src/test/ui/resolve/issue-100365.stderr @@ -0,0 +1,54 @@ +error[E0423]: expected value, found trait `Into` + --> $DIR/issue-100365.rs:2:16 + | +LL | let addr = Into::<std::net::IpAddr>.into([127, 0, 0, 1]); + | ^^^^^^^^^^^^^^^^^^^^^^^^- help: use the path separator to refer to an item: `::` + +error[E0423]: expected value, found trait `Into` + --> $DIR/issue-100365.rs:6:13 + | +LL | let _ = Into.into(()); + | ^^^^- help: use the path separator to refer to an item: `::` + +error[E0423]: expected value, found trait `Into` + --> $DIR/issue-100365.rs:10:13 + | +LL | let _ = Into::<()>.into; + | ^^^^^^^^^^- help: use the path separator to refer to an item: `::` + +error[E0423]: expected value, found trait `std::iter::Iterator` + --> $DIR/issue-100365.rs:17:9 + | +LL | ::std::iter::Iterator + | ^^^^^^^^^^^^^^^^^^^^^ not a value +... +LL | Trait!().map(std::convert::identity); // no `help` here! + | -------- in this macro invocation + | + = note: this error originates in the macro `Trait` (in Nightly builds, run with -Z macro-backtrace for more info) + +error[E0423]: expected value, found trait `std::iter::Iterator` + --> $DIR/issue-100365.rs:17:9 + | +LL | ::std::iter::Iterator + | ^^^^^^^^^^^^^^^^^^^^^ not a value +... +LL | Trait!().map; // no `help` here! + | -------- in this macro invocation + | + = note: this error originates in the macro `Trait` (in Nightly builds, run with -Z macro-backtrace for more info) + +error[E0423]: expected value, found trait `Into` + --> $DIR/issue-100365.rs:25:9 + | +LL | Into::<String>.into("") + | ^^^^^^^^^^^^^^- help: use the path separator to refer to an item: `::` +... +LL | let _ = create!(); + | --------- in this macro invocation + | + = note: this error originates in the macro `create` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: aborting due to 6 previous errors + +For more information about this error, try `rustc --explain E0423`. diff --git a/src/test/ui/resolve/issue-22692.rs b/src/test/ui/resolve/issue-22692.rs index 1d8f44222..31a762614 100644 --- a/src/test/ui/resolve/issue-22692.rs +++ b/src/test/ui/resolve/issue-22692.rs @@ -1,3 +1,60 @@ fn main() { - let _ = String.new(); //~ ERROR expected value, found struct `String` + let _ = String.new(); + //~^ ERROR expected value, found struct `String` + //~| HELP use the path separator + + let _ = String.default; + //~^ ERROR expected value, found struct `String` + //~| HELP use the path separator + + let _ = Vec::<()>.with_capacity(1); + //~^ ERROR expected value, found struct `Vec` + //~| HELP use the path separator +} + +macro_rules! Type { + () => { + ::std::cell::Cell + //~^ ERROR expected value, found struct `std::cell::Cell` + //~| ERROR expected value, found struct `std::cell::Cell` + //~| ERROR expected value, found struct `std::cell::Cell` + }; +} + +macro_rules! create { + (type method) => { + Vec.new() + //~^ ERROR expected value, found struct `Vec` + //~| HELP use the path separator + }; + (type field) => { + Vec.new + //~^ ERROR expected value, found struct `Vec` + //~| HELP use the path separator + }; + (macro method) => { + Type!().new(0) + //~^ HELP use the path separator + }; +} + +fn interaction_with_macros() { + // + // Verify that we do not only suggest to replace `.` with `::` if the receiver is a + // macro call but that we also correctly suggest to surround it with angle brackets. + // + + Type!().get(); + //~^ HELP use the path separator + + Type! {}.get; + //~^ HELP use the path separator + + // + // Ensure that the suggestion is shown for expressions inside of macro definitions. + // + + let _ = create!(type method); + let _ = create!(type field); + let _ = create!(macro method); } diff --git a/src/test/ui/resolve/issue-22692.stderr b/src/test/ui/resolve/issue-22692.stderr index e076419f6..6962aa161 100644 --- a/src/test/ui/resolve/issue-22692.stderr +++ b/src/test/ui/resolve/issue-22692.stderr @@ -2,10 +2,87 @@ error[E0423]: expected value, found struct `String` --> $DIR/issue-22692.rs:2:13 | LL | let _ = String.new(); - | ^^^^^^---- - | | - | help: use the path separator to refer to an item: `String::new` + | ^^^^^^- help: use the path separator to refer to an item: `::` -error: aborting due to previous error +error[E0423]: expected value, found struct `String` + --> $DIR/issue-22692.rs:6:13 + | +LL | let _ = String.default; + | ^^^^^^- help: use the path separator to refer to an item: `::` + +error[E0423]: expected value, found struct `Vec` + --> $DIR/issue-22692.rs:10:13 + | +LL | let _ = Vec::<()>.with_capacity(1); + | ^^^^^^^^^- help: use the path separator to refer to an item: `::` + +error[E0423]: expected value, found struct `std::cell::Cell` + --> $DIR/issue-22692.rs:17:9 + | +LL | ::std::cell::Cell + | ^^^^^^^^^^^^^^^^^ +... +LL | Type!().get(); + | ------- in this macro invocation + | + = note: this error originates in the macro `Type` (in Nightly builds, run with -Z macro-backtrace for more info) +help: use the path separator to refer to an item + | +LL | <Type!()>::get(); + | ~~~~~~~~~~~ + +error[E0423]: expected value, found struct `std::cell::Cell` + --> $DIR/issue-22692.rs:17:9 + | +LL | ::std::cell::Cell + | ^^^^^^^^^^^^^^^^^ +... +LL | Type! {}.get; + | -------- in this macro invocation + | + = note: this error originates in the macro `Type` (in Nightly builds, run with -Z macro-backtrace for more info) +help: use the path separator to refer to an item + | +LL | <Type! {}>::get; + | ~~~~~~~~~~~~ + +error[E0423]: expected value, found struct `Vec` + --> $DIR/issue-22692.rs:26:9 + | +LL | Vec.new() + | ^^^- help: use the path separator to refer to an item: `::` +... +LL | let _ = create!(type method); + | -------------------- in this macro invocation + | + = note: this error originates in the macro `create` (in Nightly builds, run with -Z macro-backtrace for more info) + +error[E0423]: expected value, found struct `Vec` + --> $DIR/issue-22692.rs:31:9 + | +LL | Vec.new + | ^^^- help: use the path separator to refer to an item: `::` +... +LL | let _ = create!(type field); + | ------------------- in this macro invocation + | + = note: this error originates in the macro `create` (in Nightly builds, run with -Z macro-backtrace for more info) + +error[E0423]: expected value, found struct `std::cell::Cell` + --> $DIR/issue-22692.rs:17:9 + | +LL | ::std::cell::Cell + | ^^^^^^^^^^^^^^^^^ +... +LL | let _ = create!(macro method); + | --------------------- in this macro invocation + | + = note: this error originates in the macro `Type` which comes from the expansion of the macro `create` (in Nightly builds, run with -Z macro-backtrace for more info) +help: use the path separator to refer to an item + | +LL | <Type!()>::new(0) + | ~~~~~~~~~~~ + +error: aborting due to 8 previous errors For more information about this error, try `rustc --explain E0423`. diff --git a/src/test/ui/resolve/issue-3021-c.stderr b/src/test/ui/resolve/issue-3021-c.stderr index 8764ac8a8..5176efc3a 100644 --- a/src/test/ui/resolve/issue-3021-c.stderr +++ b/src/test/ui/resolve/issue-3021-c.stderr @@ -3,22 +3,22 @@ error[E0401]: can't use generic parameters from outer function | LL | fn siphash<T>() { | - type parameter from outer function -... +LL | +LL | trait U { + | - help: try using a local generic parameter instead: `<T>` LL | fn g(&self, x: T) -> T; - | - ^ use of generic parameter from outer function - | | - | help: try using a local generic parameter instead: `g<T>` + | ^ use of generic parameter from outer function error[E0401]: can't use generic parameters from outer function --> $DIR/issue-3021-c.rs:4:30 | LL | fn siphash<T>() { | - type parameter from outer function -... +LL | +LL | trait U { + | - help: try using a local generic parameter instead: `<T>` LL | fn g(&self, x: T) -> T; - | - ^ use of generic parameter from outer function - | | - | help: try using a local generic parameter instead: `g<T>` + | ^ use of generic parameter from outer function error: aborting due to 2 previous errors diff --git a/src/test/ui/resolve/issue-70736-async-fn-no-body-def-collector.rs b/src/test/ui/resolve/issue-70736-async-fn-no-body-def-collector.rs index aaf0f7eae..49462f52f 100644 --- a/src/test/ui/resolve/issue-70736-async-fn-no-body-def-collector.rs +++ b/src/test/ui/resolve/issue-70736-async-fn-no-body-def-collector.rs @@ -14,7 +14,6 @@ trait B { impl B for A { async fn associated(); //~ ERROR without body //~^ ERROR cannot be declared `async` - //~| ERROR has an incompatible type for trait } fn main() {} diff --git a/src/test/ui/resolve/issue-70736-async-fn-no-body-def-collector.stderr b/src/test/ui/resolve/issue-70736-async-fn-no-body-def-collector.stderr index d3214458e..55c3b66f1 100644 --- a/src/test/ui/resolve/issue-70736-async-fn-no-body-def-collector.stderr +++ b/src/test/ui/resolve/issue-70736-async-fn-no-body-def-collector.stderr @@ -14,17 +14,6 @@ LL | async fn inherent(); | | | help: provide a definition for the function: `{ <body> }` -error[E0706]: functions in traits cannot be declared `async` - --> $DIR/issue-70736-async-fn-no-body-def-collector.rs:11:5 - | -LL | async fn associated(); - | -----^^^^^^^^^^^^^^^^^ - | | - | `async` because of this - | - = note: `async` trait functions are not currently supported - = note: consider using the `async-trait` crate: https://crates.io/crates/async-trait - error: associated function in `impl` without body --> $DIR/issue-70736-async-fn-no-body-def-collector.rs:15:5 | @@ -34,7 +23,7 @@ LL | async fn associated(); | help: provide a definition for the function: `{ <body> }` error[E0706]: functions in traits cannot be declared `async` - --> $DIR/issue-70736-async-fn-no-body-def-collector.rs:15:5 + --> $DIR/issue-70736-async-fn-no-body-def-collector.rs:11:5 | LL | async fn associated(); | -----^^^^^^^^^^^^^^^^^ @@ -43,26 +32,22 @@ LL | async fn associated(); | = note: `async` trait functions are not currently supported = note: consider using the `async-trait` crate: https://crates.io/crates/async-trait + = note: see issue #91611 <https://github.com/rust-lang/rust/issues/91611> for more information + = help: add `#![feature(return_position_impl_trait_in_trait)]` to the crate attributes to enable -error[E0053]: method `associated` has an incompatible type for trait - --> $DIR/issue-70736-async-fn-no-body-def-collector.rs:15:26 +error[E0706]: functions in traits cannot be declared `async` + --> $DIR/issue-70736-async-fn-no-body-def-collector.rs:15:5 | LL | async fn associated(); - | ^ - | | - | checked the `Output` of this `async fn`, found opaque type - | expected `()`, found opaque type - | - = note: while checking the return type of the `async fn` -note: type in trait - --> $DIR/issue-70736-async-fn-no-body-def-collector.rs:11:26 + | -----^^^^^^^^^^^^^^^^^ + | | + | `async` because of this | -LL | async fn associated(); - | ^ - = note: expected fn pointer `fn()` - found fn pointer `fn() -> impl Future<Output = ()>` + = note: `async` trait functions are not currently supported + = note: consider using the `async-trait` crate: https://crates.io/crates/async-trait + = note: see issue #91611 <https://github.com/rust-lang/rust/issues/91611> for more information + = help: add `#![feature(return_position_impl_trait_in_trait)]` to the crate attributes to enable -error: aborting due to 6 previous errors +error: aborting due to 5 previous errors -Some errors have detailed explanations: E0053, E0706. -For more information about an error, try `rustc --explain E0053`. +For more information about this error, try `rustc --explain E0706`. diff --git a/src/test/ui/resolve/issue-73427.rs b/src/test/ui/resolve/issue-73427.rs index 3c62782a8..5c2459a59 100644 --- a/src/test/ui/resolve/issue-73427.rs +++ b/src/test/ui/resolve/issue-73427.rs @@ -22,6 +22,10 @@ enum D { Unit, } +enum E { + TupleWithFields(()), +} + fn main() { // Only variants without fields are suggested (and others mentioned in a note) where an enum // is used rather than a variant. @@ -34,6 +38,8 @@ fn main() { //~^ ERROR expected value, found enum `C` D.foo(); //~^ ERROR expected value, found enum `D` + E.foo(); + //~^ ERROR expected value, found enum `E` // Only tuple variants are suggested in calls or tuple struct pattern matching. diff --git a/src/test/ui/resolve/issue-73427.stderr b/src/test/ui/resolve/issue-73427.stderr index 59bb98a34..a2ca46f0c 100644 --- a/src/test/ui/resolve/issue-73427.stderr +++ b/src/test/ui/resolve/issue-73427.stderr @@ -1,5 +1,5 @@ error[E0423]: expected value, found enum `A` - --> $DIR/issue-73427.rs:29:5 + --> $DIR/issue-73427.rs:33:5 | LL | A.foo(); | ^ @@ -23,7 +23,7 @@ LL | (A::Tuple()).foo(); | ~~~~~~~~~~~~ LL | A::Unit.foo(); | ~~~~~~~ -help: the following enum variants are available +help: alternatively, the following enum variants are also available | LL | (A::StructWithFields { /* fields */ }).foo(); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -31,7 +31,7 @@ LL | (A::TupleWithFields(/* fields */)).foo(); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error[E0423]: expected value, found enum `B` - --> $DIR/issue-73427.rs:31:5 + --> $DIR/issue-73427.rs:35:5 | LL | B.foo(); | ^ @@ -52,7 +52,7 @@ LL | (B::TupleWithFields(/* fields */)).foo(); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error[E0423]: expected value, found enum `C` - --> $DIR/issue-73427.rs:33:5 + --> $DIR/issue-73427.rs:37:5 | LL | C.foo(); | ^ @@ -70,7 +70,7 @@ help: you might have meant to use the following enum variant | LL | C::Unit.foo(); | ~~~~~~~ -help: the following enum variants are available +help: alternatively, the following enum variants are also available | LL | (C::StructWithFields { /* fields */ }).foo(); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -78,7 +78,7 @@ LL | (C::TupleWithFields(/* fields */)).foo(); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error[E0423]: expected value, found enum `D` - --> $DIR/issue-73427.rs:35:5 + --> $DIR/issue-73427.rs:39:5 | LL | D.foo(); | ^ @@ -95,13 +95,37 @@ help: you might have meant to use the following enum variant | LL | D::Unit.foo(); | ~~~~~~~ -help: the following enum variant is available +help: alternatively, the following enum variant is available | LL | (D::TupleWithFields(/* fields */)).foo(); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +error[E0423]: expected value, found enum `E` + --> $DIR/issue-73427.rs:41:5 + | +LL | E.foo(); + | ^ + | +note: the enum is defined here + --> $DIR/issue-73427.rs:25:1 + | +LL | / enum E { +LL | | TupleWithFields(()), +LL | | } + | |_^ +help: the following enum variant is available + | +LL | (E::TupleWithFields(/* fields */)).foo(); + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +help: consider importing one of these items instead + | +LL | use std::f32::consts::E; + | +LL | use std::f64::consts::E; + | + error[E0423]: expected function, tuple struct or tuple variant, found enum `A` - --> $DIR/issue-73427.rs:40:13 + --> $DIR/issue-73427.rs:46:13 | LL | let x = A(3); | ^ @@ -126,7 +150,7 @@ LL | let x = A::TupleWithFields(3); | ~~~~~~~~~~~~~~~~~~ error[E0532]: expected tuple struct or tuple variant, found enum `A` - --> $DIR/issue-73427.rs:42:12 + --> $DIR/issue-73427.rs:48:12 | LL | if let A(3) = x { } | ^ @@ -150,7 +174,7 @@ LL | if let A::Tuple(3) = x { } LL | if let A::TupleWithFields(3) = x { } | ~~~~~~~~~~~~~~~~~~ -error: aborting due to 6 previous errors +error: aborting due to 7 previous errors Some errors have detailed explanations: E0423, E0532. For more information about an error, try `rustc --explain E0423`. diff --git a/src/test/ui/resolve/point-at-type-parameter-shadowing-another-type.rs b/src/test/ui/resolve/point-at-type-parameter-shadowing-another-type.rs new file mode 100644 index 000000000..bd496875e --- /dev/null +++ b/src/test/ui/resolve/point-at-type-parameter-shadowing-another-type.rs @@ -0,0 +1,21 @@ +trait Foo<T> { + fn foo(&self, name: T) -> usize; +} + +struct Bar { + baz: Baz, +} + +struct Baz { + num: usize, +} + +impl<Baz> Foo<Baz> for Bar { + fn foo(&self, _name: Baz) -> usize { + match self.baz { + Baz { num } => num, //~ ERROR expected struct, variant or union type, found type parameter `Baz` + } + } +} + +fn main() {} diff --git a/src/test/ui/resolve/point-at-type-parameter-shadowing-another-type.stderr b/src/test/ui/resolve/point-at-type-parameter-shadowing-another-type.stderr new file mode 100644 index 000000000..af9f4612a --- /dev/null +++ b/src/test/ui/resolve/point-at-type-parameter-shadowing-another-type.stderr @@ -0,0 +1,12 @@ +error[E0574]: expected struct, variant or union type, found type parameter `Baz` + --> $DIR/point-at-type-parameter-shadowing-another-type.rs:16:13 + | +LL | impl<Baz> Foo<Baz> for Bar { + | --- found this type parameter +... +LL | Baz { num } => num, + | ^^^ not a struct, variant or union type + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0574`. diff --git a/src/test/ui/resolve/privacy-enum-ctor.stderr b/src/test/ui/resolve/privacy-enum-ctor.stderr index f885ac215..a369dc6db 100644 --- a/src/test/ui/resolve/privacy-enum-ctor.stderr +++ b/src/test/ui/resolve/privacy-enum-ctor.stderr @@ -19,7 +19,7 @@ help: you might have meant to use the following enum variant | LL | m::Z::Unit; | ~~~~~~~~~~ -help: the following enum variants are available +help: alternatively, the following enum variants are also available | LL | (m::Z::Fn(/* fields */)); | ~~~~~~~~~~~~~~~~~~~~~~~~ @@ -47,7 +47,7 @@ help: you might have meant to use the following enum variant | LL | m::Z::Unit; | ~~~~~~~~~~ -help: the following enum variants are available +help: alternatively, the following enum variants are also available | LL | (m::Z::Fn(/* fields */)); | ~~~~~~~~~~~~~~~~~~~~~~~~ @@ -89,7 +89,7 @@ help: you might have meant to use the following enum variant | LL | let _: E = E::Unit; | ~~~~~~~ -help: the following enum variants are available +help: alternatively, the following enum variants are also available | LL | let _: E = (E::Fn(/* fields */)); | ~~~~~~~~~~~~~~~~~~~~~ @@ -143,7 +143,7 @@ help: you might have meant to use the following enum variant | LL | let _: E = E::Unit; | ~~~~~~~ -help: the following enum variants are available +help: alternatively, the following enum variants are also available | LL | let _: E = (E::Fn(/* fields */)); | ~~~~~~~~~~~~~~~~~~~~~ @@ -203,7 +203,7 @@ help: you might have meant to use the following enum variant | LL | let _: Z = m::Z::Unit; | ~~~~~~~~~~ -help: the following enum variants are available +help: alternatively, the following enum variants are also available | LL | let _: Z = (m::Z::Fn(/* fields */)); | ~~~~~~~~~~~~~~~~~~~~~~~~ @@ -329,8 +329,8 @@ LL | let _: Z = Z::Fn; found fn item `fn(u8) -> Z {Z::Fn}` help: use parentheses to instantiate this tuple variant | -LL | let _: Z = Z::Fn(_); - | +++ +LL | let _: Z = Z::Fn(/* u8 */); + | ++++++++++ error[E0618]: expected function, found enum variant `Z::Unit` --> $DIR/privacy-enum-ctor.rs:31:17 @@ -364,8 +364,8 @@ LL | let _: E = m::E::Fn; found fn item `fn(u8) -> E {E::Fn}` help: use parentheses to instantiate this tuple variant | -LL | let _: E = m::E::Fn(_); - | +++ +LL | let _: E = m::E::Fn(/* u8 */); + | ++++++++++ error[E0618]: expected function, found enum variant `m::E::Unit` --> $DIR/privacy-enum-ctor.rs:47:16 @@ -399,8 +399,8 @@ LL | let _: E = E::Fn; found fn item `fn(u8) -> E {E::Fn}` help: use parentheses to instantiate this tuple variant | -LL | let _: E = E::Fn(_); - | +++ +LL | let _: E = E::Fn(/* u8 */); + | ++++++++++ error[E0618]: expected function, found enum variant `E::Unit` --> $DIR/privacy-enum-ctor.rs:55:16 diff --git a/src/test/ui/resolve/resolve-inconsistent-binding-mode.stderr b/src/test/ui/resolve/resolve-inconsistent-binding-mode.stderr index 96c1869b4..c805c9eb1 100644 --- a/src/test/ui/resolve/resolve-inconsistent-binding-mode.stderr +++ b/src/test/ui/resolve/resolve-inconsistent-binding-mode.stderr @@ -31,6 +31,10 @@ LL | Opts::A(ref i) | Opts::B(i) => {} | first introduced with type `&isize` here | = note: in the same arm, a binding must have the same type in all alternatives +help: consider adding `ref` + | +LL | Opts::A(ref i) | Opts::B(ref i) => {} + | +++ error[E0308]: mismatched types --> $DIR/resolve-inconsistent-binding-mode.rs:18:34 @@ -43,6 +47,10 @@ LL | Opts::A(ref i) | Opts::B(i) => {} | first introduced with type `&isize` here | = note: in the same arm, a binding must have the same type in all alternatives +help: consider adding `ref` + | +LL | Opts::A(ref i) | Opts::B(ref i) => {} + | +++ error[E0308]: mismatched types --> $DIR/resolve-inconsistent-binding-mode.rs:27:38 diff --git a/src/test/ui/resolve/resolve-inconsistent-names.rs b/src/test/ui/resolve/resolve-inconsistent-names.rs index 989d2d452..9a40b2034 100644 --- a/src/test/ui/resolve/resolve-inconsistent-names.rs +++ b/src/test/ui/resolve/resolve-inconsistent-names.rs @@ -23,6 +23,7 @@ fn main() { //~| ERROR mismatched types //~| ERROR variable `c` is not bound in all patterns //~| HELP if you meant to match on unit variant `E::A`, use the full path in the pattern + //~| HELP consider removing `ref` } let z = (10, 20); diff --git a/src/test/ui/resolve/resolve-inconsistent-names.stderr b/src/test/ui/resolve/resolve-inconsistent-names.stderr index 9de191f7d..773c9f6cd 100644 --- a/src/test/ui/resolve/resolve-inconsistent-names.stderr +++ b/src/test/ui/resolve/resolve-inconsistent-names.stderr @@ -55,7 +55,7 @@ LL | (A, B) | (ref B, c) | (c, A) => () | first binding error[E0408]: variable `CONST1` is not bound in all patterns - --> $DIR/resolve-inconsistent-names.rs:30:23 + --> $DIR/resolve-inconsistent-names.rs:31:23 | LL | (CONST1, _) | (_, Const2) => () | ------ ^^^^^^^^^^^ pattern doesn't bind `CONST1` @@ -69,7 +69,7 @@ LL | const CONST1: usize = 10; | ^^^^^^^^^^^^^^^^^^^^^^^^^ not accessible error[E0408]: variable `Const2` is not bound in all patterns - --> $DIR/resolve-inconsistent-names.rs:30:9 + --> $DIR/resolve-inconsistent-names.rs:31:9 | LL | (CONST1, _) | (_, Const2) => () | ^^^^^^^^^^^ ------ variable not in all patterns @@ -92,6 +92,11 @@ LL | (A, B) | (ref B, c) | (c, A) => () | first introduced with type `E` here | = note: in the same arm, a binding must have the same type in all alternatives +help: consider removing `ref` + | +LL - (A, B) | (ref B, c) | (c, A) => () +LL + (A, B) | (B, c) | (c, A) => () + | error: aborting due to 9 previous errors diff --git a/src/test/ui/resolve/resolve-primitive-fallback.stderr b/src/test/ui/resolve/resolve-primitive-fallback.stderr index f0eb1a4f4..6d5d5bad9 100644 --- a/src/test/ui/resolve/resolve-primitive-fallback.stderr +++ b/src/test/ui/resolve/resolve-primitive-fallback.stderr @@ -34,7 +34,7 @@ LL | pub const fn size_of<T>() -> usize { help: remove the extra argument | LL | std::mem::size_of(); - | ~~~~~~~~~~~~~~~~~~~ + | ~~ error: aborting due to 3 previous errors diff --git a/src/test/ui/resolve/resolve-type-param-in-item-in-trait.stderr b/src/test/ui/resolve/resolve-type-param-in-item-in-trait.stderr index 10a703ee0..0a6d1cc3b 100644 --- a/src/test/ui/resolve/resolve-type-param-in-item-in-trait.stderr +++ b/src/test/ui/resolve/resolve-type-param-in-item-in-trait.stderr @@ -4,8 +4,8 @@ error[E0401]: can't use generic parameters from outer function LL | trait TraitA<A> { | - type parameter from outer function LL | fn outer(&self) { - | ----- try adding a local generic parameter in this method instead LL | enum Foo<B> { + | - help: try using a local generic parameter instead: `A,` LL | Variance(A) | ^ use of generic parameter from outer function @@ -15,9 +15,10 @@ error[E0401]: can't use generic parameters from outer function LL | trait TraitB<A> { | - type parameter from outer function LL | fn outer(&self) { - | ----- try adding a local generic parameter in this method instead LL | struct Foo<B>(A); - | ^ use of generic parameter from outer function + | - ^ use of generic parameter from outer function + | | + | help: try using a local generic parameter instead: `A,` error[E0401]: can't use generic parameters from outer function --> $DIR/resolve-type-param-in-item-in-trait.rs:23:28 @@ -25,9 +26,10 @@ error[E0401]: can't use generic parameters from outer function LL | trait TraitC<A> { | - type parameter from outer function LL | fn outer(&self) { - | ----- try adding a local generic parameter in this method instead LL | struct Foo<B> { a: A } - | ^ use of generic parameter from outer function + | - ^ use of generic parameter from outer function + | | + | help: try using a local generic parameter instead: `A,` error[E0401]: can't use generic parameters from outer function --> $DIR/resolve-type-param-in-item-in-trait.rs:30:22 @@ -36,9 +38,9 @@ LL | trait TraitD<A> { | - type parameter from outer function LL | fn outer(&self) { LL | fn foo<B>(a: A) { } - | ------ ^ use of generic parameter from outer function - | | - | help: try using a local generic parameter instead: `foo<B, A>` + | - ^ use of generic parameter from outer function + | | + | help: try using a local generic parameter instead: `A,` error: aborting due to 4 previous errors diff --git a/src/test/ui/resolve/suggest-path-for-tuple-struct.stderr b/src/test/ui/resolve/suggest-path-for-tuple-struct.stderr index 957045ca7..4764cf2db 100644 --- a/src/test/ui/resolve/suggest-path-for-tuple-struct.stderr +++ b/src/test/ui/resolve/suggest-path-for-tuple-struct.stderr @@ -2,17 +2,13 @@ error[E0423]: expected value, found struct `SomeTupleStruct` --> $DIR/suggest-path-for-tuple-struct.rs:22:13 | LL | let _ = SomeTupleStruct.new(); - | ^^^^^^^^^^^^^^^---- - | | - | help: use the path separator to refer to an item: `SomeTupleStruct::new` + | ^^^^^^^^^^^^^^^- help: use the path separator to refer to an item: `::` error[E0423]: expected value, found struct `SomeRegularStruct` --> $DIR/suggest-path-for-tuple-struct.rs:24:13 | LL | let _ = SomeRegularStruct.new(); - | ^^^^^^^^^^^^^^^^^---- - | | - | help: use the path separator to refer to an item: `SomeRegularStruct::new` + | ^^^^^^^^^^^^^^^^^- help: use the path separator to refer to an item: `::` error: aborting due to 2 previous errors diff --git a/src/test/ui/resolve/suggest-path-instead-of-mod-dot-item.rs b/src/test/ui/resolve/suggest-path-instead-of-mod-dot-item.rs index 204a27240..d5d6b13d6 100644 --- a/src/test/ui/resolve/suggest-path-instead-of-mod-dot-item.rs +++ b/src/test/ui/resolve/suggest-path-instead-of-mod-dot-item.rs @@ -16,44 +16,96 @@ pub mod a { fn h1() -> i32 { a.I //~^ ERROR expected value, found module `a` + //~| HELP use the path separator } fn h2() -> i32 { a.g() //~^ ERROR expected value, found module `a` + //~| HELP use the path separator } fn h3() -> i32 { a.b.J //~^ ERROR expected value, found module `a` + //~| HELP use the path separator } fn h4() -> i32 { a::b.J //~^ ERROR expected value, found module `a::b` + //~| HELP a constant with a similar name exists + //~| HELP use the path separator } fn h5() { a.b.f(); //~^ ERROR expected value, found module `a` + //~| HELP use the path separator let v = Vec::new(); v.push(a::b); //~^ ERROR expected value, found module `a::b` + //~| HELP a constant with a similar name exists } fn h6() -> i32 { a::b.f() //~^ ERROR expected value, found module `a::b` + //~| HELP a constant with a similar name exists + //~| HELP use the path separator } fn h7() { a::b //~^ ERROR expected value, found module `a::b` + //~| HELP a constant with a similar name exists } fn h8() -> i32 { a::b() //~^ ERROR expected function, found module `a::b` + //~| HELP a constant with a similar name exists +} + +macro_rules! module { + () => { + a + //~^ ERROR expected value, found module `a` + //~| ERROR expected value, found module `a` + }; +} + +macro_rules! create { + (method) => { + a.f() + //~^ ERROR expected value, found module `a` + //~| HELP use the path separator + }; + (field) => { + a.f + //~^ ERROR expected value, found module `a` + //~| HELP use the path separator + }; +} + +fn h9() { + // + // Note that if the receiver is a macro call, we do not want to suggest to replace + // `.` with `::` as that would be a syntax error. + // Since the receiver is a module and not a type, we cannot suggest to surround + // it with angle brackets. + // + + module!().g::<()>(); // no `help` here! + + module!().g; // no `help` here! + + // + // Ensure that the suggestion is shown for expressions inside of macro definitions. + // + + let _ = create!(method); + let _ = create!(field); } fn main() {} diff --git a/src/test/ui/resolve/suggest-path-instead-of-mod-dot-item.stderr b/src/test/ui/resolve/suggest-path-instead-of-mod-dot-item.stderr index 54b242123..a4ce0deeb 100644 --- a/src/test/ui/resolve/suggest-path-instead-of-mod-dot-item.stderr +++ b/src/test/ui/resolve/suggest-path-instead-of-mod-dot-item.stderr @@ -2,28 +2,22 @@ error[E0423]: expected value, found module `a` --> $DIR/suggest-path-instead-of-mod-dot-item.rs:17:5 | LL | a.I - | ^-- - | | - | help: use the path separator to refer to an item: `a::I` + | ^- help: use the path separator to refer to an item: `::` error[E0423]: expected value, found module `a` - --> $DIR/suggest-path-instead-of-mod-dot-item.rs:22:5 + --> $DIR/suggest-path-instead-of-mod-dot-item.rs:23:5 | LL | a.g() - | ^-- - | | - | help: use the path separator to refer to an item: `a::g` + | ^- help: use the path separator to refer to an item: `::` error[E0423]: expected value, found module `a` - --> $DIR/suggest-path-instead-of-mod-dot-item.rs:27:5 + --> $DIR/suggest-path-instead-of-mod-dot-item.rs:29:5 | LL | a.b.J - | ^-- - | | - | help: use the path separator to refer to an item: `a::b` + | ^- help: use the path separator to refer to an item: `::` error[E0423]: expected value, found module `a::b` - --> $DIR/suggest-path-instead-of-mod-dot-item.rs:32:5 + --> $DIR/suggest-path-instead-of-mod-dot-item.rs:35:5 | LL | pub const I: i32 = 1; | --------------------- similarly named constant `I` defined here @@ -34,22 +28,20 @@ LL | a::b.J help: use the path separator to refer to an item | LL | a::b::J - | + | ~~ help: a constant with a similar name exists | LL | a::I.J | ~ error[E0423]: expected value, found module `a` - --> $DIR/suggest-path-instead-of-mod-dot-item.rs:37:5 + --> $DIR/suggest-path-instead-of-mod-dot-item.rs:42:5 | LL | a.b.f(); - | ^-- - | | - | help: use the path separator to refer to an item: `a::b` + | ^- help: use the path separator to refer to an item: `::` error[E0423]: expected value, found module `a::b` - --> $DIR/suggest-path-instead-of-mod-dot-item.rs:40:12 + --> $DIR/suggest-path-instead-of-mod-dot-item.rs:46:12 | LL | pub const I: i32 = 1; | --------------------- similarly named constant `I` defined here @@ -60,7 +52,7 @@ LL | v.push(a::b); | help: a constant with a similar name exists: `I` error[E0423]: expected value, found module `a::b` - --> $DIR/suggest-path-instead-of-mod-dot-item.rs:45:5 + --> $DIR/suggest-path-instead-of-mod-dot-item.rs:52:5 | LL | pub const I: i32 = 1; | --------------------- similarly named constant `I` defined here @@ -71,14 +63,14 @@ LL | a::b.f() help: use the path separator to refer to an item | LL | a::b::f() - | ~~~~~~~ + | ~~ help: a constant with a similar name exists | LL | a::I.f() | ~ error[E0423]: expected value, found module `a::b` - --> $DIR/suggest-path-instead-of-mod-dot-item.rs:50:5 + --> $DIR/suggest-path-instead-of-mod-dot-item.rs:59:5 | LL | pub const I: i32 = 1; | --------------------- similarly named constant `I` defined here @@ -89,7 +81,7 @@ LL | a::b | help: a constant with a similar name exists: `I` error[E0423]: expected function, found module `a::b` - --> $DIR/suggest-path-instead-of-mod-dot-item.rs:55:5 + --> $DIR/suggest-path-instead-of-mod-dot-item.rs:65:5 | LL | pub const I: i32 = 1; | --------------------- similarly named constant `I` defined here @@ -99,6 +91,50 @@ LL | a::b() | | | help: a constant with a similar name exists: `I` -error: aborting due to 9 previous errors +error[E0423]: expected value, found module `a` + --> $DIR/suggest-path-instead-of-mod-dot-item.rs:72:9 + | +LL | a + | ^ not a value +... +LL | module!().g::<()>(); // no `help` here! + | --------- in this macro invocation + | + = note: this error originates in the macro `module` (in Nightly builds, run with -Z macro-backtrace for more info) + +error[E0423]: expected value, found module `a` + --> $DIR/suggest-path-instead-of-mod-dot-item.rs:72:9 + | +LL | a + | ^ not a value +... +LL | module!().g; // no `help` here! + | --------- in this macro invocation + | + = note: this error originates in the macro `module` (in Nightly builds, run with -Z macro-backtrace for more info) + +error[E0423]: expected value, found module `a` + --> $DIR/suggest-path-instead-of-mod-dot-item.rs:80:9 + | +LL | a.f() + | ^- help: use the path separator to refer to an item: `::` +... +LL | let _ = create!(method); + | --------------- in this macro invocation + | + = note: this error originates in the macro `create` (in Nightly builds, run with -Z macro-backtrace for more info) + +error[E0423]: expected value, found module `a` + --> $DIR/suggest-path-instead-of-mod-dot-item.rs:85:9 + | +LL | a.f + | ^- help: use the path separator to refer to an item: `::` +... +LL | let _ = create!(field); + | -------------- in this macro invocation + | + = note: this error originates in the macro `create` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: aborting due to 13 previous errors For more information about this error, try `rustc --explain E0423`. |