3 #![feature(box_patterns, stmt_expr_attributes, yeet_expr)]
7 ellipsis_inclusive_range_patterns,
8 irrefutable_let_patterns,
13 #![deny(unused_parens)]
15 fn lint_on_top_level() {
16 let (a) = 0; //~ ERROR unnecessary parentheses around pattern
17 for (a) in 0..1 {} //~ ERROR unnecessary parentheses around pattern
18 if let (a) = 0 {} //~ ERROR unnecessary parentheses around pattern
19 while let (a) = 0 {} //~ ERROR unnecessary parentheses around pattern
20 fn foo((a): u8) {} //~ ERROR unnecessary parentheses around pattern
21 let _ = |(a): u8| 0; //~ ERROR unnecessary parentheses around pattern
25 let _x = #[allow(dead_code)] (1 + 2);
28 fn _no_lint_yeet() -> Result<(), ()> {
29 #[allow(unreachable_code)]
35 // Don't lint in these cases (#64106).
36 fn or_patterns_no_lint() {
38 box (0 | 1) => {} // Should not lint as `box 0 | 1` binds as `(box 0) | 1`.
43 x @ (0 | 1) => {} // Should not lint as `x @ 0 | 1` binds as `(x @ 0) | 1`.
47 if let &(0 | 1) = &0 {} // Should also not lint.
48 if let &mut (0 | 1) = &mut 0 {} // Same.
50 fn foo((Ok(a) | Err(a)): Result<u8, u8>) {} // Doesn't parse if we remove parens for now.
52 let _ = |(Ok(a) | Err(a)): Result<u8, u8>| 1; // `|Ok(a) | Err(a)| 1` parses as bit-or.
55 fn or_patterns_will_lint() {
56 if let (0 | 1) = 0 {} //~ ERROR unnecessary parentheses around pattern
57 if let ((0 | 1),) = (0,) {} //~ ERROR unnecessary parentheses around pattern
58 if let [(0 | 1)] = [0] {} //~ ERROR unnecessary parentheses around pattern
59 if let 0 | (1 | 2) = 0 {} //~ ERROR unnecessary parentheses around pattern
61 if let TS((0 | 1)) = TS(0) {} //~ ERROR unnecessary parentheses around pattern
63 if let NS { f: (0 | 1) } = (NS { f: 0 }) {} //~ ERROR unnecessary parentheses around pattern
66 // Don't lint on `&(mut x)` because `&mut x` means something else (#55342).
67 fn deref_mut_binding_no_lint() {
73 (_) => {} //~ ERROR unnecessary parentheses around pattern
74 (y) => {} //~ ERROR unnecessary parentheses around pattern
75 (ref r) => {} //~ ERROR unnecessary parentheses around pattern
76 (e @ 1...2) => {} //~ ERROR unnecessary parentheses around pattern
77 (1...2) => {} // Non ambiguous range pattern should not warn
78 e @ (3...4) => {} // Non ambiguous range pattern should not warn
82 (e @ &(1...2)) => {} //~ ERROR unnecessary parentheses around pattern
83 &(_) => {} //~ ERROR unnecessary parentheses around pattern
84 e @ &(1...2) => {} // Ambiguous range pattern should not warn
85 &(1...2) => {} // Ambiguous range pattern should not warn
89 e @ &(1...2) | e @ &(3...4) => {} // Complex ambiguous pattern should not warn
94 (_) => {} //~ ERROR unnecessary parentheses around pattern
95 (y) => {} //~ ERROR unnecessary parentheses around pattern
96 (ref r) => {} //~ ERROR unnecessary parentheses around pattern
97 (e @ 1..=2) => {} //~ ERROR unnecessary parentheses around pattern
98 (1..=2) => {} // Non ambiguous range pattern should not warn
99 e @ (3..=4) => {} // Non ambiguous range pattern should not warn
103 (e @ &(1..=2)) => {} //~ ERROR unnecessary parentheses around pattern
104 &(_) => {} //~ ERROR unnecessary parentheses around pattern
105 e @ &(1..=2) => {} // Ambiguous range pattern should not warn
106 &(1..=2) => {} // Ambiguous range pattern should not warn
110 e @ &(1..=2) | e @ &(3..=4) => {} // Complex ambiguous pattern should not warn