Skip to content

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

Closed
@kennytm

Description

@kennytm

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)

Metadata

Metadata

Labels

A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.C-bugCategory: This is a bug.F-postfix_match`#![feature(postfix_match)]`S-has-mcveStatus: A Minimal Complete and Verifiable Example has been found for this issueT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions