Supress unused_parens lint for guard patterns

This commit is contained in:
Alan Egerton 2026-01-09 16:15:39 +00:00
parent 4586feb998
commit 2a3932295e
No known key found for this signature in database
GPG key ID: 3D7EA7527916B438
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() {