-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Add hints for the case of confusing enum with its variants #45942
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
r? @estebank |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks good to me, could you add a couple of ui tests?
src/librustc_resolve/lib.rs
Outdated
of the following variants?\n{}", | ||
variants.iter() | ||
.map(|suggestion| format!("- `{}`", | ||
path_names_to_string(suggestion))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpick, move indentation one char to the left
src/librustc_resolve/lib.rs
Outdated
(Def::Enum(..), PathSource::TupleStruct) => { | ||
if let Some(variants) = this.collect_enum_variants(def) { | ||
err.note(&format!("did you mean to use one \ | ||
of the following variants?\n{}", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpick, move indentation one char to the left
97fbe48
to
21c580e
Compare
@estebank Could you, please, give me more guidance? I don't really know where is the place for the ui tests, and how to write them. |
@Menschenkindlein you can add a new file to |
@Menschenkindlein You can find a bit more of an explanation in COMPILER_TESTS.md, but what you have to do is pretty much what @oli-obk explained. After you've ran |
I added some tests. It looks like it doesn't work in tests. When I created a separate project and tested the feature, it worked. Somehow it manages to suggest an empty list of variants. By the way, is it a reasonable idea to add a suggestion of a variant in other places where they can be used, e.g. when they are used as constructors? |
Hi @estebank, looks like @Menschenkindlein needs some help from you! 😃 |
I assumed that one |
@Menschenkindlein it is slightly odd if you're finding more than one module per |
93b0c6c
to
39f848e
Compare
There indeed were two |
Awesome @Menschenkindlein! I really like this feature! r=me once you've fixed
|
I don't think they are fixable. These are order issues depending on HashMap randomness. You can turn them into compile-fail tests, since they don't care about order or the full message.
Should work |
If both modules can appear, you could add a custom normalization rule that maps // normalize-stderr: "std::prelude::v1::Option" -> "std::option::Option" |
I implemented |
@bors r+ |
📌 Commit a3686c6 has been approved by |
I'm not sure if that solves it. This error is emitted during resolve, right? So we aren't fully resolved yet, thus the paths in find_module can't necessarily find the correct module. I had a similar issue and solved it by storing the information necessary to produce the diagnostic and emit the error after resolve is finished. There's several of these delayed diagnostics in resolve. |
☀️ Test successful - status-appveyor, status-travis |
@estebank Thank you for patiently guiding me to the completion of this pull request! |
A solution for #43871. When one uses an enum in a place that accepts variants (e.g.,
Option(result)
instead ofSome(result)
), suggest one of this enum's variants.cc @estebank