Skip to content
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

Merged
merged 2 commits into from
Apr 12, 2021
Merged

Issue 81508 fix #83669

merged 2 commits into from
Apr 12, 2021

Conversation

kwj2104
Copy link
Contributor

@kwj2104 kwj2104 commented Mar 30, 2021

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.

@rust-highfive
Copy link
Collaborator

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.

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Mar 30, 2021
@rust-log-analyzer

This comment has been minimized.

Copy link
Member

@JohnTitor JohnTitor left a 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?

{
suggestion = Some((
vec![(path_span, format!("{}", ident))],
String::from("try using variable instead of path"),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO:

Suggested change
String::from("try using variable instead of path"),
String::from("try using the similarly named variable instead"),

Copy link
Contributor Author

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.

@kwj2104 kwj2104 force-pushed the issue-81508-fix branch 3 times, most recently from 1756fc1 to 0761396 Compare March 30, 2021 16:29
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@JohnTitor
Copy link
Member

(Note that you messed up the submodules, you should drop them from the commits.)

@rust-log-analyzer

This comment has been minimized.

@JohnTitor
Copy link
Member

Okay, thanks for rebasing, the last thing I'd like to ask is to squash commits into one, could you?

@kwj2104 kwj2104 force-pushed the issue-81508-fix branch 3 times, most recently from 9fedee9 to b58a7c2 Compare March 31, 2021 15:06
| ^^^-----
| |
| use of undeclared type `Foo`
| help: try using the similarly named variable instead: `Foo`
Copy link
Member

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

Copy link
Contributor Author

@kwj2104 kwj2104 Mar 31, 2021

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

Copy link
Member

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!

Copy link
Contributor Author

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`

@rust-log-analyzer

This comment has been minimized.

Copy link
Member

@varkor varkor left a 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.

compiler/rustc_resolve/src/lib.rs Outdated Show resolved Hide resolved
compiler/rustc_resolve/src/lib.rs Outdated Show resolved Hide resolved
compiler/rustc_resolve/src/late.rs Outdated Show resolved Hide resolved
compiler/rustc_resolve/src/lib.rs Outdated Show resolved Hide resolved
compiler/rustc_resolve/src/lib.rs Outdated Show resolved Hide resolved
compiler/rustc_resolve/src/lib.rs Outdated Show resolved Hide resolved
compiler/rustc_resolve/src/lib.rs Outdated Show resolved Hide resolved
compiler/rustc_resolve/src/lib.rs Outdated Show resolved Hide resolved
compiler/rustc_resolve/src/lib.rs Outdated Show resolved Hide resolved
@varkor
Copy link
Member

varkor commented Apr 11, 2021

Thanks @kwj2104: this looks great!

@bors r+

@bors
Copy link
Contributor

bors commented Apr 11, 2021

📌 Commit f51f25a has been approved by varkor

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 11, 2021
bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 12, 2021
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
@bors bors merged commit b6780b3 into rust-lang:master Apr 12, 2021
@bors
Copy link
Contributor

bors commented Apr 12, 2021

⌛ Testing commit f51f25a with merge e41f378...

@rustbot rustbot added this to the 1.53.0 milestone Apr 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Confusing diagnostic when improperly using constant as type.
7 participants