Skip to content

Wrong fix is suggested when renamed is unused in MyStruct { y: renamed } #82488

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
poliorcetics opened this issue Feb 24, 2021 · 0 comments · Fixed by #82506
Closed

Wrong fix is suggested when renamed is unused in MyStruct { y: renamed } #82488

poliorcetics opened this issue Feb 24, 2021 · 0 comments · Fixed by #82506
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. D-incorrect Diagnostics: A diagnostic that is giving misleading or incorrect information. D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@poliorcetics
Copy link
Contributor

poliorcetics commented Feb 24, 2021

Given the following code (playground link):

struct Point {
    x: u32,
    y: u32
}

fn process_point(Point { x, y: renamed }: Point) {
    /* ... */
}

The current warning output is (ignoring non-relevant parts):

warning: unused variable: `renamed`
 --> src/lib.rs:6:32
  |
6 | fn process_point(Point { x, y: renamed }: Point) {
  |                                ^^^^^^^ help: try ignoring the field: `renamed: _`

Ideally the output should look like:

  |
6 | fn process_point(Point { x, y: renamed }: Point) {
  |                                ^^^^^^^ help: try ignoring the field: `y: _`

because using y: renamed: _ does not work (of course).

Using cargo fix is broken by this too, I got the following message (removing the big message about making a bug report to remove clutter):

✖ cg fix --allow-no-vcs  
    Checking playground v0.1.0 (/Users/alexis/Projects/rust/playground)
warning: failed to automatically apply fixes suggested by rustc to crate `playground`

after fixes were automatically applied the compiler reported errors within these files:

  * src/main.rs

The following errors were reported:
error: expected `,`
  --> src/main.rs:18:46
   |
18 |     fn process_point(Point { x: _, y: renamed: _ }: Point) { /* ... */ }
   |                      -----                   ^
   |                      |
   |                      while parsing the fields for this pattern

error: aborting due to previous error

...

@rustbot label A-diagnostics C-bug D-incorrect D-invalid-suggestion

@poliorcetics poliorcetics added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Feb 24, 2021
@rustbot rustbot added C-bug Category: This is a bug. D-incorrect Diagnostics: A diagnostic that is giving misleading or incorrect information. D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. labels Feb 24, 2021
@estebank estebank added the A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. label Feb 25, 2021
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this issue Feb 26, 2021
Properly account for non-shorthand pattern field in unused variable lint

Fix rust-lang#82488
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this issue Feb 26, 2021
Properly account for non-shorthand pattern field in unused variable lint

Fix rust-lang#82488
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this issue Feb 26, 2021
Properly account for non-shorthand pattern field in unused variable lint

Fix rust-lang#82488
@bors bors closed this as completed in fb24a10 Feb 26, 2021
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. D-incorrect Diagnostics: A diagnostic that is giving misleading or incorrect information. D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants