Rollup merge of #150882 - issue-149594, r=JonathanBrouwer

Supress unused_parens lint for guard patterns

Fixes rust-lang/rust#149594
This commit is contained in:
Matthias Krüger 2026-01-10 08:34:08 +01:00 committed by GitHub
commit e7b08033a2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 16 additions and 1 deletions

View file

@ -1190,6 +1190,8 @@ impl UnusedParens {
// `&(a..=b)`, there is a recursive `check_pat` on `a` and `b`, but we will assume
// that if there are unnecessary parens they serve a purpose of readability.
PatKind::Range(..) => return,
// Parentheses may be necessary to disambiguate precedence in guard patterns.
PatKind::Guard(..) => return,
// Avoid `p0 | .. | pn` if we should.
PatKind::Or(..) if avoid_or => return,
// Avoid `mut x` and `mut x @ p` if we should:

View file

@ -0,0 +1,13 @@
//! Guard patterns require parentheses to disambiguate precedence
//!
//! Regression test for https://github.com/rust-lang/rust/issues/149594
//@ check-pass
#![feature(guard_patterns)]
#![expect(incomplete_features)]
#![warn(unused_parens)]
fn main() {
let (_ if false) = ();
}

View file

@ -2,7 +2,7 @@
//
//@ check-pass
#![feature(guard_patterns, never_type)]
#![expect(incomplete_features, unused_parens)]
#![expect(incomplete_features)]
#![deny(unreachable_code)]
fn main() {