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

cargo fix fails on non_shorthand_field_patterns #66434

Closed
moxian opened this issue Nov 15, 2019 · 3 comments · Fixed by #67500
Closed

cargo fix fails on non_shorthand_field_patterns #66434

moxian opened this issue Nov 15, 2019 · 3 comments · Fixed by #67500
Labels
A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` C-bug Category: This is a bug. D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@moxian
Copy link
Contributor

moxian commented Nov 15, 2019

Code:

#![allow(unused_variables)]
#![allow(dead_code)]
#![allow(unused_mut)]
// #![allow(non_shorthand_field_patterns)]  // uncommenting this removes the bug

struct Some {
    inner: Vec<i32>
}

fn stuff(x: Some){
    let Some {
        inner: inner,
    } =  x;
}


fn main() {
}

cargo fix output:

PS D:\work\trash\repros\some-palette> cargo fix --allow-dirty
    Checking some-palette v0.1.0 (D:\work\trash\repros\some-palette)
warning: failed to automatically apply fixes suggested by rustc to crate `some_palette`

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

  * src\main.rs

This likely indicates a bug in either rustc or cargo itself,
and we would appreciate a bug report! You're likely to see
a number of compiler warnings after this message which cargo
attempted to fix but failed. If you could open an issue at
https://github.com/rust-lang/rust/issues
quoting the full output of this command we'd be very appreciative!
Note that you may be able to make some more progress in the near-term
fixing code with the `--broken-code` flag

The following errors were reported:
error: expected `,`
  --> src\main.rs:12:9
   |
12 |         inner inner,
   |         ^^^^^

error: aborting due to previous error

Original diagnostics will follow.

warning: the `inner:` in this pattern is redundant
  --> src\main.rs:12:9
   |
12 |         inner: inner,
   |         ------^^^^^^
   |         |
   |         help: remove this
   |
   = note: `#[warn(non_shorthand_field_patterns)]` on by default

warning: the `inner:` in this pattern is redundant
  --> src\main.rs:12:9
   |
12 |         inner: inner,
   |         ------^^^^^^
   |         |
   |         help: remove this
   |
   = note: `#[warn(non_shorthand_field_patterns)]` on by default

    Finished dev [unoptimized + debuginfo] target(s) in 0.43s

Note that inner inner in the attempted fix is incorrect syntax (it ate a colon).

Github helpfully suggests that #65924 might be related. Edit: it probably actually isn't.

Version info:

> cargo --version
cargo 1.40.0-beta (5da4b4d47 2019-10-28)
> rustc --version
rustc 1.40.0-beta.1 (76b40532a 2019-11-05)
@csmoe

This comment has been minimized.

@csmoe csmoe closed this as completed Nov 15, 2019
@moxian

This comment has been minimized.

@ehuss
Copy link
Contributor

ehuss commented Nov 15, 2019

This is the correct place to file the issue, it is a bug in rustc.

The issue is that the non_shorthand_field_patterns lint is providing a bad suggestion. Either the span needs to encompass the entire binding, or the suggested text needs to be the empty string.

@ehuss ehuss reopened this Nov 15, 2019
@jonas-schievink jonas-schievink added A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` C-bug Category: This is a bug. 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. labels Nov 15, 2019
@estebank estebank added the E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. label Nov 19, 2019
Centril added a commit to Centril/rust that referenced this issue Dec 22, 2019
…rns, r=Centril

Tweak non_shorthand_field_patterns' suggestion

Fixes rust-lang#66434

r? @estebank
@bors bors closed this as completed in c355463 Dec 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` C-bug Category: This is a bug. D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. 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.

5 participants