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

Postfix match: Unexpected unused_parens warning when LHS contained parenthesis #123064

Closed
kennytm opened this issue Mar 25, 2024 · 0 comments · Fixed by #123096
Closed

Postfix match: Unexpected unused_parens warning when LHS contained parenthesis #123064

kennytm opened this issue Mar 25, 2024 · 0 comments · Fixed by #123096
Assignees
Labels
A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. F-postfix_match `#![feature(postfix_match)]` S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@kennytm
Copy link
Member

kennytm commented Mar 25, 2024

cc #121618.

I tried this code:

#![feature(postfix_match)]
fn main() {
    (&1).match { a => a };
    (1 + 2).match { b => b };
}

I expected to see this happen: no warnings

Instead, this happened:

warning: unnecessary parentheses around `match` scrutinee expression
 --> src/main.rs:3:5
  |
3 |     (&1).match { a => a };
  |     ^  ^
  |
  = note: `#[warn(unused_parens)]` on by default
help: remove these parentheses
  |
3 -     (&1).match { a => a };
3 +     &1.match { a => a };
  |

warning: unnecessary parentheses around `match` scrutinee expression
 --> src/main.rs:4:5
  |
4 |     (1 + 2).match { b => b };
  |     ^     ^
  |
help: remove these parentheses
  |
4 -     (1 + 2).match { b => b };
4 +     1 + 2.match { b => b };
  |

warning: `playground` (bin "playground") generated 2 warnings (run `cargo fix --bin "playground"` to apply 2 suggestions)

Meta

rustc --version --verbose:

1.79.0-nightly (2024-03-24 0824b300eb0dae5d9ed5)
@kennytm kennytm added the C-bug Category: This is a bug. label Mar 25, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Mar 25, 2024
@jieyouxu jieyouxu added F-postfix_match `#![feature(postfix_match)]` 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. S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Mar 25, 2024
@fmease fmease added A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. and removed A-diagnostics Area: Messages for errors, warnings, and lints labels Mar 25, 2024
@compiler-errors compiler-errors self-assigned this Mar 26, 2024
@bors bors closed this as completed in 69cfe80 Mar 28, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Mar 28, 2024
Rollup merge of rust-lang#123096 - compiler-errors:postfix-match-parens, r=fmease

Don't check match scrutinee of postfix match for unused parens

We only check the scrutinees of block-like constructs and a few others (return/index/assign/method calls). Just don't do it for postfix match at all.

Fixes rust-lang#123064

r? fmease
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. C-bug Category: This is a bug. F-postfix_match `#![feature(postfix_match)]` S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this 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