1 #![feature(box_patterns, stmt_expr_attributes)]
3 #![feature(or_patterns)]
5 #![allow(ellipsis_inclusive_range_patterns)]
6 #![allow(unreachable_patterns)]
7 #![allow(unused_variables)]
8 #![deny(unused_parens)]
10 fn lint_on_top_level() {
11 let (a) = 0; //~ ERROR unnecessary parentheses around pattern
12 for (a) in 0..1 {} //~ ERROR unnecessary parentheses around pattern
13 if let (a) = 0 {} //~ ERROR unnecessary parentheses around pattern
14 while let (a) = 0 {} //~ ERROR unnecessary parentheses around pattern
15 fn foo((a): u8) {} //~ ERROR unnecessary parentheses around pattern
16 let _ = |(a): u8| 0; //~ ERROR unnecessary parentheses around pattern
20 let _x = #[allow(dead_code)] (1 + 2);
23 // Don't lint in these cases (#64106).
24 fn or_patterns_no_lint() {
26 box (0 | 1) => {} // Should not lint as `box 0 | 1` binds as `(box 0) | 1`.
31 x @ (0 | 1) => {} // Should not lint as `x @ 0 | 1` binds as `(x @ 0) | 1`.
35 if let &(0 | 1) = &0 {} // Should also not lint.
36 if let &mut (0 | 1) = &mut 0 {} // Same.
38 fn foo((Ok(a) | Err(a)): Result<u8, u8>) {} // Doesn't parse if we remove parens for now.
40 let _ = |(Ok(a) | Err(a)): Result<u8, u8>| 1; // `|Ok(a) | Err(a)| 1` parses as bit-or.
43 fn or_patterns_will_lint() {
44 if let (0 | 1) = 0 {} //~ ERROR unnecessary parentheses around pattern
45 if let ((0 | 1),) = (0,) {} //~ ERROR unnecessary parentheses around pattern
46 if let [(0 | 1)] = [0] {} //~ ERROR unnecessary parentheses around pattern
47 if let 0 | (1 | 2) = 0 {} //~ ERROR unnecessary parentheses around pattern
49 if let TS((0 | 1)) = TS(0) {} //~ ERROR unnecessary parentheses around pattern
51 if let NS { f: (0 | 1) } = (NS { f: 0 }) {} //~ ERROR unnecessary parentheses around pattern
54 // Don't lint on `&(mut x)` because `&mut x` means something else (#55342).
55 fn deref_mut_binding_no_lint() {
61 (_) => {} //~ ERROR unnecessary parentheses around pattern
62 (y) => {} //~ ERROR unnecessary parentheses around pattern
63 (ref r) => {} //~ ERROR unnecessary parentheses around pattern
64 (e @ 1...2) => {} //~ ERROR unnecessary parentheses around pattern
65 (1...2) => {} // Non ambiguous range pattern should not warn
66 e @ (3...4) => {} // Non ambiguous range pattern should not warn
70 (e @ &(1...2)) => {} //~ ERROR unnecessary parentheses around pattern
71 &(_) => {} //~ ERROR unnecessary parentheses around pattern
72 e @ &(1...2) => {} // Ambiguous range pattern should not warn
73 &(1...2) => {} // Ambiguous range pattern should not warn
77 e @ &(1...2) | e @ &(3...4) => {} // Complex ambiguous pattern should not warn
82 (_) => {} //~ ERROR unnecessary parentheses around pattern
83 (y) => {} //~ ERROR unnecessary parentheses around pattern
84 (ref r) => {} //~ ERROR unnecessary parentheses around pattern
85 (e @ 1..=2) => {} //~ ERROR unnecessary parentheses around pattern
86 (1..=2) => {} // Non ambiguous range pattern should not warn
87 e @ (3..=4) => {} // Non ambiguous range pattern should not warn
91 (e @ &(1..=2)) => {} //~ ERROR unnecessary parentheses around pattern
92 &(_) => {} //~ ERROR unnecessary parentheses around pattern
93 e @ &(1..=2) => {} // Ambiguous range pattern should not warn
94 &(1..=2) => {} // Ambiguous range pattern should not warn
98 e @ &(1..=2) | e @ &(3..=4) => {} // Complex ambiguous pattern should not warn