]>
Commit | Line | Data |
---|---|---|
f035d41b XL |
1 | // run-rustfix |
2 | ||
3 | #![deny(unused_parens)] | |
4 | #![allow(while_true)] // for rustfix | |
5 | ||
6 | #[derive(Eq, PartialEq)] | |
7 | struct X { y: bool } | |
8 | impl X { | |
9 | fn foo(&self, conjunct: bool) -> bool { self.y && conjunct } | |
10 | } | |
11 | ||
12 | fn foo() -> isize { | |
13 | return 1; //~ ERROR unnecessary parentheses around `return` value | |
14 | } | |
15 | fn bar(y: bool) -> X { | |
16 | return X { y }; //~ ERROR unnecessary parentheses around `return` value | |
17 | } | |
18 | ||
19 | pub fn unused_parens_around_return_type() -> u32 { //~ ERROR unnecessary parentheses around type | |
20 | panic!() | |
21 | } | |
22 | ||
23 | pub fn unused_parens_around_block_return() -> u32 { | |
24 | let _foo = { | |
25 | 5 //~ ERROR unnecessary parentheses around block return value | |
26 | }; | |
27 | 5 //~ ERROR unnecessary parentheses around block return value | |
28 | } | |
29 | ||
30 | pub trait Trait { | |
31 | fn test(&self); | |
32 | } | |
33 | ||
34 | pub fn passes_unused_parens_lint() -> &'static (dyn Trait) { | |
35 | panic!() | |
36 | } | |
37 | ||
fe692bf9 FG |
38 | pub fn parens_with_keyword(e: &[()]) -> i32 { |
39 | if true {} //~ ERROR unnecessary parentheses around `if` | |
40 | while true {} //~ ERROR unnecessary parentheses around `while` | |
41 | for _ in e {} //~ ERROR unnecessary parentheses around `for` | |
42 | match 1 { _ => ()} //~ ERROR unnecessary parentheses around `match` | |
43 | return 1; //~ ERROR unnecessary parentheses around `return` value | |
44 | } | |
45 | ||
f035d41b XL |
46 | macro_rules! baz { |
47 | ($($foo:expr),+) => { | |
48 | ($($foo),*) | |
49 | } | |
50 | } | |
51 | ||
52 | pub const CONST_ITEM: usize = 10; //~ ERROR unnecessary parentheses around assigned value | |
53 | pub static STATIC_ITEM: usize = 10; //~ ERROR unnecessary parentheses around assigned value | |
54 | ||
55 | fn main() { | |
56 | foo(); | |
57 | bar(true); //~ ERROR unnecessary parentheses around function argument | |
58 | ||
59 | if true {} //~ ERROR unnecessary parentheses around `if` condition | |
60 | while true {} //~ ERROR unnecessary parentheses around `while` condition | |
61 | match true { //~ ERROR unnecessary parentheses around `match` scrutinee expression | |
62 | _ => {} | |
63 | } | |
64 | if let 1 = 1 {} //~ ERROR unnecessary parentheses around `let` scrutinee expression | |
65 | while let 1 = 2 {} //~ ERROR unnecessary parentheses around `let` scrutinee expression | |
66 | let v = X { y: false }; | |
67 | // struct lits needs parens, so these shouldn't warn. | |
68 | if (v == X { y: true }) {} | |
69 | if (X { y: true } == v) {} | |
70 | if (X { y: false }.y) {} | |
29967ef6 XL |
71 | // this shouldn't warn, because the parens are necessary to disambiguate let chains |
72 | if let true = (true && false) {} | |
f035d41b XL |
73 | |
74 | while (X { y: false }.foo(true)) {} | |
75 | while (true | X { y: false }.y) {} | |
76 | ||
77 | match (X { y: false }) { | |
78 | _ => {} | |
79 | } | |
80 | ||
81 | X { y: false }.foo(true); //~ ERROR unnecessary parentheses around method argument | |
82 | ||
83 | let mut _a = 0; //~ ERROR unnecessary parentheses around assigned value | |
84 | _a = 0; //~ ERROR unnecessary parentheses around assigned value | |
85 | _a += 1; //~ ERROR unnecessary parentheses around assigned value | |
86 | ||
ed00b5ec FG |
87 | let mut _a = 3; //~ ERROR unnecessary parentheses around pattern |
88 | let mut _a = 3; //~ ERROR unnecessary parentheses around pattern | |
89 | let mut _a = 3; //~ ERROR unnecessary parentheses around pattern | |
90 | ||
91 | let _a = 3; //~ ERROR unnecessary parentheses around pattern | |
92 | let _a = 3; //~ ERROR unnecessary parentheses around pattern | |
93 | let _a = 3; //~ ERROR unnecessary parentheses around pattern | |
94 | ||
f035d41b XL |
95 | let _a = baz!(3, 4); |
96 | let _b = baz!(3); | |
97 | } |