Skip to content

unused_parens doesn't fire for match arms #92751

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

Closed
clarfonthey opened this issue Jan 11, 2022 · 1 comment · Fixed by #100093
Closed

unused_parens doesn't fire for match arms #92751

clarfonthey opened this issue Jan 11, 2022 · 1 comment · Fixed by #100093
Assignees
Labels
C-bug Category: This is a bug.

Comments

@clarfonthey
Copy link
Contributor

clarfonthey commented Jan 11, 2022

Minimal example:

pub fn broken(x: Option<()>) -> i32 {
    match x {
        Some(()) => (1),
        None => (2),
    }
}

pub fn works(x: Option<()>) -> i32 {
    if x.is_none() {
        (2)
    } else {
        (1)
    }
}

I would expect that the unused_parens lint fire for the broken function, but it does not. Compare this to the works function, where it does. This can potentially show up when refactoring a function, e.g. if converting to the above from:

pub fn broken(x: Option<()>) -> i32 {
    match x {
        Some(()) => do_something_with(1),
        None => do_something_with(2),
    }
}

This could arguably be a formatting issue, as some people might like to split things on multiple lines like:

=> (
   some_long_expr
)

However, we don't do this for other cases where unused_parens is added. Take, for example:

if (
    some_long_expr
) {
   // ...
}

This still triggers the unused_parens lint.

This is a particularly weird case because users will often separate out the match arm into a block if it gets long, e.g.:

=> {
    some_long_expr
}

But not with parentheses. I think that for the case of parentheses, the precedent should go with removing them.

@clarfonthey clarfonthey added the C-bug Category: This is a bug. label Jan 11, 2022
@wcampbell0x2a
Copy link
Contributor

@rustbot claim

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants