Auto merge of #74005 - estebank:type-ascription-redux, r=petrochenkov

Clean up errors in typeck and resolve

* Tweak ordering of suggestions
* Do not suggest similarly named enclosing item
* Point at item definition in foreign crates
* Add missing primary label

CC #34255.
This commit is contained in:
bors 2020-08-10 23:50:39 +00:00
commit 3bb5a863c8
26 changed files with 230 additions and 151 deletions

View file

@ -2,10 +2,7 @@ error[E0573]: expected type, found const parameter `C`
--> $DIR/struct-with-invalid-const-param.rs:4:23
|
LL | struct S<const C: u8>(C);
| ----------------------^--
| | |
| | help: a struct with a similar name exists: `S`
| similarly named struct `S` defined here
| ^ not a type
warning: the feature `const_generics` is incomplete and may not be safe to use and/or cause compiler crashes
--> $DIR/struct-with-invalid-const-param.rs:1:12

View file

@ -12,14 +12,14 @@ LL | let e1 = Empty1;
LL | pub struct XEmpty2;
| ------------------- similarly named unit struct `XEmpty2` defined here
|
help: a unit struct with a similar name exists
|
LL | let e1 = XEmpty2;
| ^^^^^^^
help: use struct literal syntax instead
|
LL | let e1 = Empty1 {};
| ^^^^^^^^^
help: a unit struct with a similar name exists
|
LL | let e1 = XEmpty2;
| ^^^^^^^
error[E0423]: expected function, tuple struct or tuple variant, found struct `Empty1`
--> $DIR/empty-struct-braces-expr.rs:16:14
@ -29,15 +29,20 @@ LL | struct Empty1 {}
...
LL | let e1 = Empty1();
| ^^^^^^^^
|
::: $DIR/auxiliary/empty-struct.rs:2:1
|
help: a unit struct with a similar name exists
LL | pub struct XEmpty2;
| ------------------- similarly named unit struct `XEmpty2` defined here
|
LL | let e1 = XEmpty2();
| ^^^^^^^
help: use struct literal syntax instead
|
LL | let e1 = Empty1 {};
| ^^^^^^^^^
help: a unit struct with a similar name exists
|
LL | let e1 = XEmpty2();
| ^^^^^^^
error[E0423]: expected value, found struct variant `E::Empty3`
--> $DIR/empty-struct-braces-expr.rs:18:14
@ -63,34 +68,43 @@ error[E0423]: expected value, found struct `XEmpty1`
LL | let xe1 = XEmpty1;
| ^^^^^^^
|
::: $DIR/auxiliary/empty-struct.rs:2:1
::: $DIR/auxiliary/empty-struct.rs:1:1
|
LL | pub struct XEmpty1 {}
| ------------------ `XEmpty1` defined here
LL | pub struct XEmpty2;
| ------------------- similarly named unit struct `XEmpty2` defined here
|
help: a unit struct with a similar name exists
|
LL | let xe1 = XEmpty2;
| ^^^^^^^
help: use struct literal syntax instead
|
LL | let xe1 = XEmpty1 {};
| ^^^^^^^^^^
help: a unit struct with a similar name exists
|
LL | let xe1 = XEmpty2;
| ^^^^^^^
error[E0423]: expected function, tuple struct or tuple variant, found struct `XEmpty1`
--> $DIR/empty-struct-braces-expr.rs:23:15
|
LL | let xe1 = XEmpty1();
| ^^^^^^^^^
|
::: $DIR/auxiliary/empty-struct.rs:1:1
|
help: a unit struct with a similar name exists
LL | pub struct XEmpty1 {}
| ------------------ `XEmpty1` defined here
LL | pub struct XEmpty2;
| ------------------- similarly named unit struct `XEmpty2` defined here
|
LL | let xe1 = XEmpty2();
| ^^^^^^^
help: use struct literal syntax instead
|
LL | let xe1 = XEmpty1 {};
| ^^^^^^^^^^
help: a unit struct with a similar name exists
|
LL | let xe1 = XEmpty2();
| ^^^^^^^
error[E0599]: no variant or associated item named `Empty3` found for enum `empty_struct::XE` in the current scope
--> $DIR/empty-struct-braces-expr.rs:25:19

View file

@ -13,19 +13,21 @@ error[E0532]: expected unit struct, unit variant or constant, found struct varia
LL | XE::XEmpty3 => ()
| ^^^^^^^^^^^
|
::: $DIR/auxiliary/empty-struct.rs:7:5
::: $DIR/auxiliary/empty-struct.rs:6:5
|
LL | XEmpty3 {},
| ------- `XE::XEmpty3` defined here
LL | XEmpty4,
| ------- similarly named unit variant `XEmpty4` defined here
|
help: a unit variant with a similar name exists
|
LL | XE::XEmpty4 => ()
| ^^^^^^^
help: use struct pattern syntax instead
|
LL | XE::XEmpty3 { /* fields */ } => ()
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
help: a unit variant with a similar name exists
|
LL | XE::XEmpty4 => ()
| ^^^^^^^
error: aborting due to 2 previous errors

View file

@ -6,30 +6,43 @@ LL | struct Empty1 {}
...
LL | Empty1() => ()
| ^^^^^^^^
|
::: $DIR/auxiliary/empty-struct.rs:3:1
|
help: a tuple struct with a similar name exists
LL | pub struct XEmpty6();
| --------------------- similarly named tuple struct `XEmpty6` defined here
|
LL | XEmpty6() => ()
| ^^^^^^^
help: use struct pattern syntax instead
|
LL | Empty1 {} => ()
| ^^^^^^^^^
help: a tuple struct with a similar name exists
|
LL | XEmpty6() => ()
| ^^^^^^^
error[E0532]: expected tuple struct or tuple variant, found struct `XEmpty1`
--> $DIR/empty-struct-braces-pat-2.rs:18:9
|
LL | XEmpty1() => ()
| ^^^^^^^^^
|
::: $DIR/auxiliary/empty-struct.rs:1:1
|
help: a tuple struct with a similar name exists
LL | pub struct XEmpty1 {}
| ------------------ `XEmpty1` defined here
LL | pub struct XEmpty2;
LL | pub struct XEmpty6();
| --------------------- similarly named tuple struct `XEmpty6` defined here
|
LL | XEmpty6() => ()
| ^^^^^^^
help: use struct pattern syntax instead
|
LL | XEmpty1 {} => ()
| ^^^^^^^^^^
help: a tuple struct with a similar name exists
|
LL | XEmpty6() => ()
| ^^^^^^^
error[E0532]: expected tuple struct or tuple variant, found struct `Empty1`
--> $DIR/empty-struct-braces-pat-2.rs:21:9
@ -39,30 +52,43 @@ LL | struct Empty1 {}
...
LL | Empty1(..) => ()
| ^^^^^^^^^^
|
::: $DIR/auxiliary/empty-struct.rs:3:1
|
help: a tuple struct with a similar name exists
LL | pub struct XEmpty6();
| --------------------- similarly named tuple struct `XEmpty6` defined here
|
LL | XEmpty6(..) => ()
| ^^^^^^^
help: use struct pattern syntax instead
|
LL | Empty1 {} => ()
| ^^^^^^^^^
help: a tuple struct with a similar name exists
|
LL | XEmpty6(..) => ()
| ^^^^^^^
error[E0532]: expected tuple struct or tuple variant, found struct `XEmpty1`
--> $DIR/empty-struct-braces-pat-2.rs:24:9
|
LL | XEmpty1(..) => ()
| ^^^^^^^^^^^
|
::: $DIR/auxiliary/empty-struct.rs:1:1
|
help: a tuple struct with a similar name exists
LL | pub struct XEmpty1 {}
| ------------------ `XEmpty1` defined here
LL | pub struct XEmpty2;
LL | pub struct XEmpty6();
| --------------------- similarly named tuple struct `XEmpty6` defined here
|
LL | XEmpty6(..) => ()
| ^^^^^^^
help: use struct pattern syntax instead
|
LL | XEmpty1 {} => ()
| ^^^^^^^^^^
help: a tuple struct with a similar name exists
|
LL | XEmpty6(..) => ()
| ^^^^^^^
error: aborting due to 4 previous errors

View file

@ -12,15 +12,23 @@ error[E0532]: expected tuple struct or tuple variant, found struct variant `XE::
|
LL | XE::XEmpty3() => ()
| ^^^^^^^^^^^^^
|
::: $DIR/auxiliary/empty-struct.rs:6:5
|
help: a tuple variant with a similar name exists
LL | XEmpty3 {},
| ------- `XE::XEmpty3` defined here
LL | XEmpty4,
LL | XEmpty5(),
| --------- similarly named tuple variant `XEmpty5` defined here
|
LL | XE::XEmpty5() => ()
| ^^^^^^^
help: use struct pattern syntax instead
|
LL | XE::XEmpty3 { /* fields */ } => ()
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
help: a tuple variant with a similar name exists
|
LL | XE::XEmpty5() => ()
| ^^^^^^^
error[E0532]: expected tuple struct or tuple variant, found struct variant `E::Empty3`
--> $DIR/empty-struct-braces-pat-3.rs:25:9
@ -36,15 +44,23 @@ error[E0532]: expected tuple struct or tuple variant, found struct variant `XE::
|
LL | XE::XEmpty3(..) => ()
| ^^^^^^^^^^^^^^^
|
::: $DIR/auxiliary/empty-struct.rs:6:5
|
help: a tuple variant with a similar name exists
LL | XEmpty3 {},
| ------- `XE::XEmpty3` defined here
LL | XEmpty4,
LL | XEmpty5(),
| --------- similarly named tuple variant `XEmpty5` defined here
|
LL | XE::XEmpty5(..) => ()
| ^^^^^^^
help: use struct pattern syntax instead
|
LL | XE::XEmpty3 { /* fields */ } => ()
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
help: a tuple variant with a similar name exists
|
LL | XE::XEmpty5(..) => ()
| ^^^^^^^
error: aborting due to 4 previous errors

View file

@ -38,6 +38,8 @@ LL | XE::XEmpty5 => (),
|
LL | XEmpty4,
| ------- similarly named unit variant `XEmpty4` defined here
LL | XEmpty5(),
| --------- `XE::XEmpty5` defined here
error: aborting due to 4 previous errors

View file

@ -34,21 +34,24 @@ LL | struct Foo { a: bool };
LL |
LL | let f = Foo();
| ^^^^^
...
LL | fn foo() {
| -------- similarly named function `foo` defined here
|
help: a function with a similar name exists
|
LL | let f = foo();
| ^^^
help: use struct literal syntax instead
|
LL | let f = Foo { a: val };
| ^^^^^^^^^^^^^^
help: a function with a similar name exists
|
LL | let f = foo();
| ^^^
error[E0423]: expected value, found struct `T`
--> $DIR/E0423.rs:14:8
|
LL | if T {} == T {} { println!("Ok"); }
| ^
| ^ not a value
|
help: surround the struct literal with parentheses
|

View file

@ -8,7 +8,7 @@ error[E0423]: expected value, found macro `semitransparent`
--> $DIR/rustc-macro-transparency.rs:29:5
|
LL | semitransparent;
| ^^^^^^^^^^^^^^^
| ^^^^^^^^^^^^^^^ not a value
|
help: use `!` to invoke the macro
|
@ -19,7 +19,7 @@ error[E0423]: expected value, found macro `opaque`
--> $DIR/rustc-macro-transparency.rs:30:5
|
LL | opaque;
| ^^^^^^
| ^^^^^^ not a value
|
help: use `!` to invoke the macro
|

View file

@ -1,10 +1,8 @@
error[E0425]: cannot find function `g` in this scope
--> $DIR/issue-31845.rs:7:12
|
LL | fn h() {
| ------ similarly named function `h` defined here
LL | g();
| ^ help: a function with a similar name exists: `h`
| ^ not found in this scope
error: aborting due to previous error

View file

@ -5,16 +5,7 @@ LL | struct X {}
| ----------- `X` defined here
LL |
LL | const Y: X = X("ö");
| ^^^^^^
|
help: a constant with a similar name exists
|
LL | const Y: X = Y("ö");
| ^
help: use struct literal syntax instead
|
LL | const Y: X = X {};
| ^^^^
| ^^^^^^ help: use struct literal syntax instead: `X {}`
error: aborting due to previous error

View file

@ -53,14 +53,14 @@ LL | TV(),
LL | check(m7::V);
| ^^^^^
|
help: a tuple variant with a similar name exists
|
LL | check(m7::TV);
| ^^
help: use struct literal syntax instead
|
LL | check(m7::V {});
| ^^^^^^^^
help: a tuple variant with a similar name exists
|
LL | check(m7::TV);
| ^^
help: consider importing one of these items instead
|
LL | use m8::V;
@ -74,19 +74,21 @@ error[E0423]: expected value, found struct variant `xm7::V`
LL | check(xm7::V);
| ^^^^^^
|
::: $DIR/auxiliary/namespace-mix.rs:7:9
::: $DIR/auxiliary/namespace-mix.rs:6:9
|
LL | V {},
| - `xm7::V` defined here
LL | TV(),
| ---- similarly named tuple variant `TV` defined here
|
help: a tuple variant with a similar name exists
|
LL | check(xm7::TV);
| ^^
help: use struct literal syntax instead
|
LL | check(xm7::V { /* fields */ });
| ^^^^^^^^^^^^^^^^^^^^^^^
help: a tuple variant with a similar name exists
|
LL | check(xm7::TV);
| ^^
help: consider importing one of these items instead
|
LL | use m8::V;

View file

@ -1,10 +1,8 @@
error[E0423]: expected function, tuple struct or tuple variant, found struct `S`
--> $DIR/legacy-ctor-visibility.rs:9:13
|
LL | fn f() {
| ------ similarly named function `f` defined here
LL | S(10);
| ^ help: a function with a similar name exists: `f`
| ^
error: aborting due to previous error

View file

@ -44,12 +44,8 @@ error[E0412]: cannot find type `Y` in this scope
--> $DIR/attributes-on-modules-fail.rs:10:14
|
LL | type A = Y;
| ---------^- similarly named type alias `A` defined here
| ^ not found in this scope
|
help: a type alias with a similar name exists
|
LL | type A = A;
| ^
help: consider importing this struct
|
LL | use Y;
@ -59,12 +55,8 @@ error[E0412]: cannot find type `X` in this scope
--> $DIR/attributes-on-modules-fail.rs:14:10
|
LL | type A = X;
| ---------^- similarly named type alias `A` defined here
| ^ not found in this scope
|
help: a type alias with a similar name exists
|
LL | type A = A;
| ^
help: consider importing this struct
|
LL | use m::X;

View file

@ -12,6 +12,11 @@ error[E0423]: expected value, found struct variant `issue_19452_aux::Homura::Mad
|
LL | let homura = issue_19452_aux::Homura::Madoka;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use struct literal syntax instead: `issue_19452_aux::Homura::Madoka { /* fields */ }`
|
::: $DIR/auxiliary/issue-19452-aux.rs:2:5
|
LL | Madoka { age: u32 }
| ------ `issue_19452_aux::Homura::Madoka` defined here
error: aborting due to 2 previous errors

View file

@ -7,14 +7,14 @@ LL | struct Handle {}
LL | handle: Handle
| ^^^^^^
|
help: a local variable with a similar name exists
|
LL | handle: handle
| ^^^^^^
help: use struct literal syntax instead
|
LL | handle: Handle {}
| ^^^^^^^^^
help: a local variable with a similar name exists
|
LL | handle: handle
| ^^^^^^
error: aborting due to previous error

View file

@ -16,16 +16,9 @@ LL | m::Z::Unit;
error[E0423]: expected value, found enum `Z`
--> $DIR/privacy-enum-ctor.rs:25:9
|
LL | fn f() {
| ------ similarly named function `f` defined here
...
LL | Z;
| ^
|
help: a function with a similar name exists
|
LL | f;
| ^
help: try using one of the enum's variants
|
LL | m::Z::Fn;
@ -55,10 +48,6 @@ LL | fn f() {
LL | let _: E = m::E;
| ^^^^
|
help: a function with a similar name exists
|
LL | let _: E = m::f;
| ^
help: try using one of the enum's variants
|
LL | let _: E = E::Fn;
@ -67,6 +56,10 @@ LL | let _: E = E::Struct;
| ^^^^^^^^^
LL | let _: E = E::Unit;
| ^^^^^^^
help: a function with a similar name exists
|
LL | let _: E = m::f;
| ^
help: consider importing one of these items instead
|
LL | use std::f32::consts::E;

View file

@ -2,7 +2,7 @@ error[E0423]: expected function, found macro `assert`
--> $DIR/resolve-hint-macro.rs:2:5
|
LL | assert(true);
| ^^^^^^
| ^^^^^^ not a function
|
help: use `!` to invoke the macro
|

View file

@ -31,14 +31,14 @@ LL | pub const I: i32 = 1;
LL | a::b.J
| ^^^^
|
help: a constant with a similar name exists
|
LL | a::I.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
@ -68,14 +68,14 @@ LL | pub const I: i32 = 1;
LL | a::b.f()
| ^^^^
|
help: a constant with a similar name exists
|
LL | a::I.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

View file

@ -46,7 +46,7 @@ error[E0423]: expected value, found struct variant `E::V`
--> $DIR/struct-literal-variant-in-if.rs:10:13
|
LL | if x == E::V { field } {}
| ^^^^
| ^^^^ not a value
|
help: surround the struct literal with parentheses
|

View file

@ -9,14 +9,14 @@ LL | B { a: usize },
LL | let _: E = E::B;
| ^^^^
|
help: a tuple variant with a similar name exists
|
LL | let _: E = E::A;
| ^
help: use struct literal syntax instead
|
LL | let _: E = E::B { a: val };
| ^^^^^^^^^^^^^^^
help: a tuple variant with a similar name exists
|
LL | let _: E = E::A;
| ^
error[E0308]: mismatched types
--> $DIR/fn-or-tuple-struct-without-args.rs:29:20

View file

@ -11,7 +11,7 @@ error[E0574]: expected struct, variant or union type, found macro `try`
--> $DIR/try-block-in-edition2015.rs:4:33
|
LL | let try_result: Option<_> = try {
| ^^^
| ^^^ not a struct, variant or union type
|
= note: if you want the `try` keyword, you need to be in the 2018 edition
help: use `!` to invoke the macro

View file

@ -4,10 +4,7 @@ error[E0573]: expected type, found function `f`
LL | f() :
| - help: maybe you meant to write `;` here
LL | f();
| ^^^
| |
| not a type
| expecting a type here because of type ascription
| ^^^ expecting a type here because of type ascription
error: aborting due to previous error

View file

@ -2,10 +2,7 @@ error[E0412]: cannot find type `B` in this scope
--> $DIR/ui-testing-optout.rs:4:10
|
4 | type A = B;
| ---------^-
| | |
| | help: a type alias with a similar name exists: `A`
| similarly named type alias `A` defined here
| ^ not found in this scope
error[E0412]: cannot find type `D` in this scope
--> $DIR/ui-testing-optout.rs:7:10

View file

@ -3,6 +3,11 @@ error[E0423]: expected value, found struct `xcrate_unit_struct::StructWithFields
|
LL | let _ = xcrate_unit_struct::StructWithFields;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use struct literal syntax instead: `xcrate_unit_struct::StructWithFields { foo: val }`
|
::: $DIR/auxiliary/xcrate_unit_struct.rs:20:1
|
LL | pub struct StructWithFields {
| --------------------------- `xcrate_unit_struct::StructWithFields` defined here
error: aborting due to previous error