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

unused_parens reported on complex enum struct-variant literal in match scrutinee expression is actually necessary #113459

Closed
jieyouxu opened this issue Jul 7, 2023 · 0 comments · Fixed by #113679
Assignees
Labels
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.

Comments

@jieyouxu
Copy link
Member

jieyouxu commented Jul 7, 2023

Code

#![allow(dead_code)]

enum State {
    Waiting { start_at: u64 }
}

fn main() {
    match (&mut State::Waiting { start_at: 0u64 }) {
        _ => {}
    }
}

Current output

warning: unnecessary parentheses around `match` scrutinee expression
 --> src/main.rs:8:11
  |
8 |     match (&mut State::Waiting { start_at: 0u64 }) {
  |           ^                                      ^
  |
  = note: `#[warn(unused_parens)]` on by default
help: remove these parentheses
  |
8 -     match (&mut State::Waiting { start_at: 0u64 }) {
8 +     match &mut State::Waiting { start_at: 0u64 } {
  |

Desired output

No `unused_parens` warning.

Rationale and extra context

The unused_parens lint should not fire in this case because the parentheses are actually necessary. Otherwise, following the help to "remove these parentheses" will cause a compilation error.

error: struct literals are not allowed here
 --> src/main.rs:8:16
  |
8 |     match &mut State::Waiting { start_at: 0u64 } {
  |                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
help: surround the struct literal with parentheses
  |
8 |     match &mut (State::Waiting { start_at: 0u64 }) {
  |                +                                 +

Although, following help from the error after applying the suggestion from the unused_parens lint does lead to valid code.

Other cases

No response

Anything else?

No response

@jieyouxu jieyouxu 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 Jul 7, 2023
@jieyouxu jieyouxu changed the title unused_parens reported on complex struct literal in match scrutinee expression is actually necessary unused_parens reported on complex enum struct-variant literal in match scrutinee expression is actually necessary Jul 7, 2023
@chenyukang chenyukang self-assigned this Jul 14, 2023
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Aug 3, 2023
… r=cjgillot

Match scrutinee need necessary parentheses for structs

Fixes rust-lang#113459
@bors bors closed this as completed in d7e7510 Aug 15, 2023
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 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.

2 participants