]> git.lizzy.rs Git - rust.git/blob - src/test/ui/lint/lint-unnecessary-parens.rs
Rollup merge of #62310 - GuillaumeGomez:add-missing-doc-links-boxed, r=Centril
[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     //~^ WARN denote infinite loops with
23     match (true) { //~ ERROR unnecessary parentheses around `match` head expression
24         _ => {}
25     }
26     if let 1 = (1) {} //~ ERROR unnecessary parentheses around `let` head expression
27     while let 1 = (2) {} //~ ERROR unnecessary parentheses around `let` head expression
28     let v = X { y: false };
29     // struct lits needs parens, so these shouldn't warn.
30     if (v == X { y: true }) {}
31     if (X { y: true } == v) {}
32     if (X { y: false }.y) {}
33
34     while (X { y: false }.foo(true)) {}
35     while (true | X { y: false }.y) {}
36
37     match (X { y: false }) {
38         _ => {}
39     }
40
41     X { y: false }.foo((true)); //~ ERROR unnecessary parentheses around method argument
42
43     let mut _a = (0); //~ ERROR unnecessary parentheses around assigned value
44     _a = (0); //~ ERROR unnecessary parentheses around assigned value
45     _a += (1); //~ ERROR unnecessary parentheses around assigned value
46 }