Skip to content

Parens around guard patterns wrongly assumed unnecessary #149594

@WaffleLapkin

Description

@WaffleLapkin

I tried this code:

#![feature(guard_patterns)]
#![expect(incomplete_features)]

fn main() {
    let (_ if false) = ();
}

I expected to see this happen: no warnings.

Instead, this happened: unused parens warning:

warning: unnecessary parentheses around pattern
 --> src/main.rs:5:9
  |
5 |     let (_ if false) = ();
  |         ^          ^
  |
  = note: `#[warn(unused_parens)]` (part of `#[warn(unused)]`) on by default
help: remove these parentheses
  |
5 -     let (_ if false) = ();
5 +     let _ if false = ();
  |

Note that removing parentheses makes the code not compile:

error: expected one of `:`, `;`, `=`, or `|`, found keyword `if`
 --> src/main.rs:5:11
  |
5 |     let _ if false = ();
  |           ^^ expected one of `:`, `;`, `=`, or `|`

Meta

rustc version:

1.93.0-nightly (2025-12-02 646a3f8c15baefb98dc6)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.C-bugCategory: This is a bug.F-guard_patterns`#![feature(guard_patterns)]`L-unused_parensLint: unused_parensT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.requires-incomplete-featuresThis issue requires the use of incomplete features.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions