-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Issue 81508 fix #83669
Issue 81508 fix #83669
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @varkor (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
This comment has been minimized.
This comment has been minimized.
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.
Also, could you rebase instead of merging as per https://rustc-dev-guide.rust-lang.org/git.html#no-merge-policy?
compiler/rustc_resolve/src/lib.rs
Outdated
{ | ||
suggestion = Some(( | ||
vec![(path_span, format!("{}", ident))], | ||
String::from("try using variable instead of path"), |
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.
IMO:
String::from("try using variable instead of path"), | |
String::from("try using the similarly named variable instead"), |
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.
Thanks for the feedback - I've made the wording edits and rebased.
1756fc1
to
0761396
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
0f996c0
to
9d17adf
Compare
This comment has been minimized.
This comment has been minimized.
(Note that you messed up the submodules, you should drop them from the commits.) |
199f495
to
4aedf0b
Compare
This comment has been minimized.
This comment has been minimized.
Okay, thanks for rebasing, the last thing I'd like to ask is to squash commits into one, could you? |
9fedee9
to
b58a7c2
Compare
| ^^^----- | ||
| | | ||
| use of undeclared type `Foo` | ||
| help: try using the similarly named variable instead: `Foo` |
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.
I think this message is confusing, because it seems to suggest using Foo
, which the user is already doing. I think we should instead point to the declaration of Foo
and say something like:
`Foo` is defined here, but is not a type
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.
This makes sense. So we're on the same page, I'm imagining (for the example above):
error[E0433]: failed to resolve: use of undeclared type `Baz`
--> main.rs:4:20
|
4 | println!("{}", Baz::Bar);
| ^^^-----
| |
| use of undeclared type `Baz`
|
help: Baz is defined but not a type
|
3 | let Baz: &str = "";
| ^^^
error: aborting due to previous error
EDIT: Think I found a path forward
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.
@kwj2104: yes, that looks like the sort of thing I had in mind!
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.
New format for errors now points to declaration line:
error[E0433]: failed to resolve: use of undeclared type `Baz`
--> $DIR/issue-81508.rs:11:20
|
LL | let Baz: &str = "";
| --- help: Baz is defined here, but is not a type
LL |
LL | println!("{}", Baz::Bar);
| ^^^ use of undeclared type `Baz`
This comment has been minimized.
This comment has been minimized.
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.
This is looking pretty good now! Most of my comments are very minor.
📌 Commit f51f25a has been approved by |
Rollup of 7 pull requests Successful merges: - rust-lang#83669 (Issue 81508 fix) - rust-lang#84014 (Improve trait/impl method discrepancy errors) - rust-lang#84059 (Bump libc dependency of std to 0.2.93) - rust-lang#84067 (clean up example on read_to_string) - rust-lang#84079 (Improve test for `rustdoc::bare_urls` lint) - rust-lang#84094 (Remove FixedSizeArray) - rust-lang#84101 (rustdoc: Move crate loader to collect_intra_doc_links::early ) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
Fix #81508
Problem: When variable name is used incorrectly as path, error and warning point to undeclared/unused name, when in fact the name is used, just incorrectly (should be used as a variable, not part of a path).
Summary for fix: When path resolution errs, diagnostics checks for variables in
ValueNS
that have the same name (e.g., variable rather than path named Foo), and adds additional suggestion that user may actually intend to use the variable name rather than a path.The fix does not suppress or otherwise change the warning that results. I did not find a straightforward way in the code to modify this, but would love to make changes here as well with any guidance.