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

Rustc suggests incorrect fixes (#[warn(unused_parens)]) #117380

Closed
he-thinks opened this issue Oct 30, 2023 · 1 comment · Fixed by #117395
Closed

Rustc suggests incorrect fixes (#[warn(unused_parens)]) #117380

he-thinks opened this issue Oct 30, 2023 · 1 comment · Fixed by #117395
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints 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

@he-thinks
Copy link

he-thinks commented Oct 30, 2023

Code

fn main() {
    let(mut _x): i8 = 0;
    let( mut _x): i8 = 0;
    let(_x): i8 = 0;
}

Current output

warning: unnecessary parentheses around pattern
 --> src/main.rs:2:8
  |
2 |     let(mut _x): i8 = 0;
  |        ^      ^
  |
  = note: `#[warn(unused_parens)]` on by default
help: remove these parentheses
  |
2 -     let(mut _x): i8 = 0;
2       letmut _x: i8 = 0;
  |

warning: unnecessary parentheses around pattern
 --> src/main.rs:3:8
  |
3 |     let( mut _x): i8 = 0;
  |        ^^      ^
  |
help: remove these parentheses
  |
3 -     let( mut _x): i8 = 0;
3       letmut _x: i8 = 0;
  |

warning: unnecessary parentheses around pattern
 --> src/main.rs:4:8
  |
4 |     let(_x): i8 = 0;
  |        ^  ^
  |
help: remove these parentheses
  |
4 -     let(_x): i8 = 0;
4       let_x: i8 = 0;
  |

Desired output

warning: unnecessary parentheses around pattern
 --> src/main.rs:2:8
  |
2 |     let(mut _x): i8 = 0;
  |        ^      ^
  |
  = note: `#[warn(unused_parens)]` on by default
help: remove these parentheses
  |
2 -     let(mut _x): i8 = 0;
2       let mut _x: i8 = 0;
  |

warning: unnecessary parentheses around pattern
 --> src/main.rs:3:8
  |
3 |     let( mut _x): i8 = 0;
  |        ^^      ^
  |
help: remove these parentheses
  |
3 -     let( mut _x): i8 = 0;
3       let mut _x: i8 = 0;
  |

warning: unnecessary parentheses around pattern
 --> src/main.rs:4:8
  |
4 |     let(_x): i8 = 0;
  |        ^  ^
  |
help: remove these parentheses
  |
4 -     let(_x): i8 = 0;
4       let _x: i8 = 0;
  |

Rationale and extra context

Rustc suggests incorrect fixes for #[warn(unused_parens)] for these patterns.

Other cases

No response

Anything else?

Rustc version:

rustc 1.75.0-nightly (e5cfc5547 2023-10-28)
binary: rustc
commit-hash: e5cfc55477eceed1317a02189fdf77a4a98f2124
commit-date: 2023-10-28
host: x86_64-pc-windows-gnu
release: 1.75.0-nightly
LLVM version: 17.0.3

(the same issue with the stable 1.73.0 rustc).

@he-thinks he-thinks 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 Oct 30, 2023
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Oct 30, 2023
@gurry
Copy link
Contributor

gurry commented Oct 30, 2023

@rustbot claim

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Oct 30, 2023
…Nilstrieb

Fix missing leading space in suggestion

For a local pattern with no space between `let` and `(` e.g.:
```rust
  let(_a) = 3;
```
we were previously suggesting this illegal code:
```rust
  let_a = 3;
```
After this change the suggestion will instead be:
```rust
  let _a = 3;
```
Fixes rust-lang#117380
@saethlin saethlin added D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Oct 30, 2023
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Oct 30, 2023
…Nilstrieb

Fix missing leading space in suggestion

For a local pattern with no space between `let` and `(` e.g.:
```rust
  let(_a) = 3;
```
we were previously suggesting this illegal code:
```rust
  let_a = 3;
```
After this change the suggestion will instead be:
```rust
  let _a = 3;
```
Fixes rust-lang#117380
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this issue Oct 30, 2023
…Nilstrieb

Fix missing leading space in suggestion

For a local pattern with no space between `let` and `(` e.g.:
```rust
  let(_a) = 3;
```
we were previously suggesting this illegal code:
```rust
  let_a = 3;
```
After this change the suggestion will instead be:
```rust
  let _a = 3;
```
Fixes rust-lang#117380
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this issue Oct 30, 2023
…Nilstrieb

Fix missing leading space in suggestion

For a local pattern with no space between `let` and `(` e.g.:
```rust
  let(_a) = 3;
```
we were previously suggesting this illegal code:
```rust
  let_a = 3;
```
After this change the suggestion will instead be:
```rust
  let _a = 3;
```
Fixes rust-lang#117380
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Oct 30, 2023
Rollup merge of rust-lang#117395 - gurry:117380-wrong-parent-sugg, r=Nilstrieb

Fix missing leading space in suggestion

For a local pattern with no space between `let` and `(` e.g.:
```rust
  let(_a) = 3;
```
we were previously suggesting this illegal code:
```rust
  let_a = 3;
```
After this change the suggestion will instead be:
```rust
  let _a = 3;
```
Fixes rust-lang#117380
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints 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.

4 participants