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

Improve renaming suggestion for names with leading underscores #125795

Merged

Conversation

lucasscharenbroch
Copy link
Contributor

Fixes #125650

Before:

error[E0425]: cannot find value `p` in this scope
 --> test.rs:2:13
  |
2 |     let _ = p;
  |             ^
  |
help: a local variable with a similar name exists, consider renaming `_p` into `p`
  |
1 | fn a(p: i32) {
  |      ~

After:

error[E0425]: cannot find value `p` in this scope
 --> test.rs:2:13
  |
1 | fn a(_p: i32) {
  |      -- `_p` defined here
2 |     let _ = p;
  |             ^
  |
help: the leading underscore in `_p` marks it as unused, consider renaming it to `p`
  |
1 | fn a(p: i32) {
  |      ~

This change doesn't exactly conform to what was proposed in the issue:

  1. I've kept the suggested code instead of solely replacing it with the label
  2. I've removed the "...similar name exists..." message instead of relocating to the usage span
  3. You could argue that it still isn't completely clear that the change is referring to the definition (not the usage), but I'm not sure how to do this without playing down the fact that the error was caused by the usage of an undefined name.

@rustbot
Copy link
Collaborator

rustbot commented May 31, 2024

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @compiler-errors (or someone else) some time within the next two weeks.

Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (S-waiting-on-review and S-waiting-on-author) stays updated, invoking these commands when appropriate:

  • @rustbot author: the review is finished, PR author should check the comments and take action accordingly
  • @rustbot review: the author is ready for a review, this PR will be queued again in the reviewer's queue

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels May 31, 2024
@compiler-errors
Copy link
Member

@bors r+

@bors
Copy link
Contributor

bors commented Jun 4, 2024

📌 Commit 9af9674 has been approved by compiler-errors

It is now in the queue for this repository.

@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 Jun 4, 2024
bors added a commit to rust-lang-ci/rust that referenced this pull request Jun 4, 2024
…mpiler-errors

Rollup of 8 pull requests

Successful merges:

 - rust-lang#125667 (Silence follow-up errors directly based on error types and regions)
 - rust-lang#125717 (Refactor `#[diagnostic::do_not_recommend]` support)
 - rust-lang#125795 (Improve renaming suggestion for names with leading underscores)
 - rust-lang#125865 (Fix ICE caused by ignoring EffectVars in type inference)
 - rust-lang#125953 (Streamline `nested` calls.)
 - rust-lang#125959 (Reduce `pub` exposure in `rustc_mir_build`)
 - rust-lang#125967 (Split smir `Const` into `TyConst` and `MirConst`)
 - rust-lang#125968 (Store the types of `ty::Expr` arguments in the `ty::Expr`)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 7e5528f into rust-lang:master Jun 4, 2024
6 checks passed
@rustbot rustbot added this to the 1.80.0 milestone Jun 4, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Jun 4, 2024
Rollup merge of rust-lang#125795 - lucasscharenbroch:undescore-prefix-suggestion, r=compiler-errors

Improve renaming suggestion for names with leading underscores

Fixes rust-lang#125650

Before:
```
error[E0425]: cannot find value `p` in this scope
 --> test.rs:2:13
  |
2 |     let _ = p;
  |             ^
  |
help: a local variable with a similar name exists, consider renaming `_p` into `p`
  |
1 | fn a(p: i32) {
  |      ~
```

After:
```
error[E0425]: cannot find value `p` in this scope
 --> test.rs:2:13
  |
1 | fn a(_p: i32) {
  |      -- `_p` defined here
2 |     let _ = p;
  |             ^
  |
help: the leading underscore in `_p` marks it as unused, consider renaming it to `p`
  |
1 | fn a(p: i32) {
  |      ~
```

This change doesn't exactly conform to what was proposed in the issue:

1. I've kept the suggested code instead of solely replacing it with the label
2. I've removed the "...similar name exists..." message instead of relocating to the usage span
3. You could argue that it still isn't completely clear that the change is referring to the definition (not the usage), but I'm not sure how to do this without playing down the fact that the error was caused by the usage of an undefined name.
@lucasscharenbroch lucasscharenbroch deleted the undescore-prefix-suggestion branch June 4, 2024 17:44
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. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Confusing compiler suggestion with type/variable with underscore prefix
4 participants