]> git.lizzy.rs Git - rust.git/blob - src/test/ui/lint/lint-unnecessary-parens.rs
d684616565f8ea44843f685883444d5583562367
[rust.git] / src / test / ui / lint / lint-unnecessary-parens.rs
1 #![deny(unused_parens)]
2
3 #[derive(Eq, PartialEq)]
4 struct X { y: bool }
5 impl X {
6     fn foo(&self, conjunct: bool) -> bool { self.y && conjunct }
7 }
8
9 fn foo() -> isize {
10     return (1); //~ ERROR unnecessary parentheses around `return` value
11 }
12 fn bar(y: bool) -> X {
13     return (X { y }); //~ ERROR unnecessary parentheses around `return` value
14 }
15
16 fn main() {
17     foo();
18     bar((true)); //~ ERROR unnecessary parentheses around function argument
19
20     if (true) {} //~ ERROR unnecessary parentheses around `if` condition
21     while (true) {} //~ ERROR unnecessary parentheses around `while` condition
22     match (true) { //~ ERROR unnecessary parentheses around `match` head expression
23         _ => {}
24     }
25     if let 1 = (1) {} //~ ERROR unnecessary parentheses around `let` scrutinee
26     while let 1 = (2) {} //~ ERROR unnecessary parentheses around `let` scrutinee
27     let v = X { y: false };
28     // struct lits needs parens, so these shouldn't warn.
29     if (v == X { y: true }) {}
30     if (X { y: true } == v) {}
31     if (X { y: false }.y) {}
32
33     while (X { y: false }.foo(true)) {}
34     while (true | X { y: false }.y) {}
35
36     match (X { y: false }) {
37         _ => {}
38     }
39
40     X { y: false }.foo((true)); //~ ERROR unnecessary parentheses around method argument
41
42     let mut _a = (0); //~ ERROR unnecessary parentheses around assigned value
43     _a = (0); //~ ERROR unnecessary parentheses around assigned value
44     _a += (1); //~ ERROR unnecessary parentheses around assigned value
45 }