enum type instead of variant suggestion unification
Weirdly, we were deciding between a help note and a structured suggestion based on whether the import candidate span was a dummy—but we weren't using that span in any case! The dummy-ness of the span (which appears to be a matter of this-crate vs. other-crate definition) isn't the right criterion by which we should decide whether it's germane to mention that "there is an enum variant"; instead, let's use the someness of `def` (which is used as the `has_unexpected_resolution` argument to `error_code`). Since `import_candidate_to_paths` has no other callers, we are free to stop returning the span and rename the function. By using `span_suggestions_`, we leverage the max-suggestions output limit already built in to the emitter, thus resolving #56028. In the matter of message wording, "you can" is redundant (and perhaps too informal); prefer the imperative.
This commit is contained in:
parent
2d3e909e4e
commit
3986c96448
9 changed files with 122 additions and 54 deletions
|
|
@ -0,0 +1,13 @@
|
|||
enum PutDown { Set }
|
||||
enum AffixHeart { Set }
|
||||
enum CauseToBe { Set }
|
||||
enum Determine { Set }
|
||||
enum TableDishesAction { Set }
|
||||
enum Solidify { Set }
|
||||
enum UnorderedCollection { Set }
|
||||
|
||||
fn setup() -> Set { Set }
|
||||
|
||||
fn main() {
|
||||
setup();
|
||||
}
|
||||
|
|
@ -0,0 +1,38 @@
|
|||
error[E0412]: cannot find type `Set` in this scope
|
||||
--> $DIR/issue-56028-there-is-an-enum-variant.rs:9:15
|
||||
|
|
||||
LL | fn setup() -> Set { Set }
|
||||
| ^^^ not found in this scope
|
||||
help: there is an enum variant `AffixHeart::Set` and 7 others; try using the variant's enum
|
||||
|
|
||||
LL | fn setup() -> AffixHeart { Set }
|
||||
| ^^^^^^^^^^
|
||||
LL | fn setup() -> CauseToBe { Set }
|
||||
| ^^^^^^^^^
|
||||
LL | fn setup() -> Determine { Set }
|
||||
| ^^^^^^^^^
|
||||
LL | fn setup() -> PutDown { Set }
|
||||
| ^^^^^^^
|
||||
and 3 other candidates
|
||||
|
||||
error[E0425]: cannot find value `Set` in this scope
|
||||
--> $DIR/issue-56028-there-is-an-enum-variant.rs:9:21
|
||||
|
|
||||
LL | fn setup() -> Set { Set }
|
||||
| ^^^ not found in this scope
|
||||
help: possible candidates are found in other modules, you can import them into scope
|
||||
|
|
||||
LL | use AffixHeart::Set;
|
||||
|
|
||||
LL | use CauseToBe::Set;
|
||||
|
|
||||
LL | use Determine::Set;
|
||||
|
|
||||
LL | use PutDown::Set;
|
||||
|
|
||||
and 3 other candidates
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
Some errors occurred: E0412, E0425.
|
||||
For more information about an error, try `rustc --explain E0412`.
|
||||
|
|
@ -5,7 +5,7 @@ LL | fn foo(x: Foo::Bar) {} //~ ERROR expected type, found variant `Foo::Bar`
|
|||
| ^^^^^^^^
|
||||
| |
|
||||
| not a type
|
||||
| help: you can try using the variant's enum: `Foo`
|
||||
| help: try using the variant's enum: `Foo`
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ LL | fn new() -> NoResult<MyEnum, String> {
|
|||
| --------^^^^^^^^^^^^^^^^
|
||||
| |
|
||||
| did you mean `Result`?
|
||||
| help: you can try using the variant's enum: `foo::MyEnum`
|
||||
| help: try using the variant's enum: `foo::MyEnum`
|
||||
|
||||
error[E0573]: expected type, found variant `Result`
|
||||
--> $DIR/issue-17546.rs:32:17
|
||||
|
|
@ -48,7 +48,7 @@ LL | fn newer() -> NoResult<foo::MyEnum, String> {
|
|||
| --------^^^^^^^^^^^^^^^^^^^^^
|
||||
| |
|
||||
| did you mean `Result`?
|
||||
| help: you can try using the variant's enum: `foo::MyEnum`
|
||||
| help: try using the variant's enum: `foo::MyEnum`
|
||||
|
||||
error: aborting due to 4 previous errors
|
||||
|
||||
|
|
|
|||
|
|
@ -2,9 +2,10 @@ error[E0573]: expected type, found variant `foo::Foo::FooV`
|
|||
--> $DIR/issue-30535.rs:16:8
|
||||
|
|
||||
LL | _: foo::Foo::FooV //~ ERROR expected type, found variant `foo::Foo::FooV`
|
||||
| ^^^^^^^^^^^^^^ not a type
|
||||
|
|
||||
= help: there is an enum variant `foo::Foo::FooV`, try using `foo::Foo`?
|
||||
| ^^^^^^^^^^^^^^
|
||||
| |
|
||||
| not a type
|
||||
| help: try using the variant's enum: `foo::Foo`
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
|
|||
|
|
@ -2,19 +2,21 @@ error[E0412]: cannot find type `Foo` in this scope
|
|||
--> $DIR/issue-35075.rs:12:12
|
||||
|
|
||||
LL | inner: Foo<T> //~ ERROR cannot find type `Foo` in this scope
|
||||
| ^^^---
|
||||
| |
|
||||
| not found in this scope
|
||||
| help: you can try using the variant's enum: `Baz`
|
||||
| ^^^ not found in this scope
|
||||
help: there is an enum variant `Baz::Foo`; try using the variant's enum
|
||||
|
|
||||
LL | inner: Baz //~ ERROR cannot find type `Foo` in this scope
|
||||
| ^^^
|
||||
|
||||
error[E0412]: cannot find type `Foo` in this scope
|
||||
--> $DIR/issue-35075.rs:16:9
|
||||
|
|
||||
LL | Foo(Foo<T>) //~ ERROR cannot find type `Foo` in this scope
|
||||
| ^^^---
|
||||
| |
|
||||
| not found in this scope
|
||||
| help: you can try using the variant's enum: `Baz`
|
||||
| ^^^ not found in this scope
|
||||
help: there is an enum variant `Baz::Foo`; try using the variant's enum
|
||||
|
|
||||
LL | Foo(Baz) //~ ERROR cannot find type `Foo` in this scope
|
||||
| ^^^
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
|
|
|
|||
|
|
@ -2,10 +2,11 @@ error[E0412]: cannot find type `Apple` in this scope
|
|||
--> $DIR/issue-35675.rs:17:29
|
||||
|
|
||||
LL | fn should_return_fruit() -> Apple {
|
||||
| ^^^^^ not found in this scope
|
||||
help: there is an enum variant `Fruit::Apple`; try using the variant's enum
|
||||
|
|
||||
LL | fn should_return_fruit() -> Fruit {
|
||||
| ^^^^^
|
||||
| |
|
||||
| not found in this scope
|
||||
| help: you can try using the variant's enum: `Fruit`
|
||||
|
||||
error[E0425]: cannot find function `Apple` in this scope
|
||||
--> $DIR/issue-35675.rs:19:5
|
||||
|
|
@ -24,7 +25,7 @@ LL | fn should_return_fruit_too() -> Fruit::Apple {
|
|||
| ^^^^^^^^^^^^
|
||||
| |
|
||||
| not a type
|
||||
| help: you can try using the variant's enum: `Fruit`
|
||||
| help: try using the variant's enum: `Fruit`
|
||||
|
||||
error[E0425]: cannot find function `Apple` in this scope
|
||||
--> $DIR/issue-35675.rs:25:5
|
||||
|
|
@ -41,27 +42,34 @@ error[E0573]: expected type, found variant `Ok`
|
|||
|
|
||||
LL | fn foo() -> Ok {
|
||||
| ^^ not a type
|
||||
help: try using the variant's enum
|
||||
|
|
||||
= help: there is an enum variant `std::prelude::v1::Ok`, try using `std::prelude::v1`?
|
||||
= help: there is an enum variant `std::result::Result::Ok`, try using `std::result::Result`?
|
||||
LL | fn foo() -> std::prelude::v1 {
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
LL | fn foo() -> std::result::Result {
|
||||
| ^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error[E0412]: cannot find type `Variant3` in this scope
|
||||
--> $DIR/issue-35675.rs:34:13
|
||||
|
|
||||
LL | fn bar() -> Variant3 {
|
||||
| ^^^^^^^^
|
||||
| |
|
||||
| not found in this scope
|
||||
| help: you can try using the variant's enum: `x::Enum`
|
||||
| ^^^^^^^^ not found in this scope
|
||||
help: there is an enum variant `x::Enum::Variant3`; try using the variant's enum
|
||||
|
|
||||
LL | fn bar() -> x::Enum {
|
||||
| ^^^^^^^
|
||||
|
||||
error[E0573]: expected type, found variant `Some`
|
||||
--> $DIR/issue-35675.rs:38:13
|
||||
|
|
||||
LL | fn qux() -> Some {
|
||||
| ^^^^ not a type
|
||||
help: try using the variant's enum
|
||||
|
|
||||
= help: there is an enum variant `std::prelude::v1::Option::Some`, try using `std::prelude::v1::Option`?
|
||||
= help: there is an enum variant `std::prelude::v1::Some`, try using `std::prelude::v1`?
|
||||
LL | fn qux() -> std::prelude::v1::Option {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
LL | fn qux() -> std::prelude::v1 {
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 7 previous errors
|
||||
|
||||
|
|
|
|||
|
|
@ -3,28 +3,24 @@ error[E0573]: expected type, found variant `Ty::A`
|
|||
|
|
||||
LL | B(Ty::A),
|
||||
| ^^^^^ not a type
|
||||
help: you can try using the variant's enum
|
||||
|
|
||||
LL | B(Ty),
|
||||
| ^^
|
||||
help: you can try using the variant's enum
|
||||
help: try using the variant's enum
|
||||
|
|
||||
LL | B(E),
|
||||
| ^
|
||||
LL | B(Ty),
|
||||
| ^^
|
||||
|
||||
error[E0573]: expected type, found variant `E::A`
|
||||
--> $DIR/variant-used-as-type.rs:27:6
|
||||
|
|
||||
LL | impl E::A {}
|
||||
| ^^^^ not a type
|
||||
help: you can try using the variant's enum
|
||||
|
|
||||
LL | impl Ty {}
|
||||
| ^^
|
||||
help: you can try using the variant's enum
|
||||
help: try using the variant's enum
|
||||
|
|
||||
LL | impl E {}
|
||||
| ^
|
||||
LL | impl Ty {}
|
||||
| ^^
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue