]> git.lizzy.rs Git - rust.git/blob - tests/ui/lint/lint-unnecessary-parens.fixed
Auto merge of #106884 - clubby789:fieldless-enum-debug, r=michaelwoerister
[rust.git] / tests / ui / lint / lint-unnecessary-parens.fixed
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
38 macro_rules! baz {
39     ($($foo:expr),+) => {
40         ($($foo),*)
41     }
42 }
43
44 pub const CONST_ITEM: usize = 10; //~ ERROR unnecessary parentheses around assigned value
45 pub static STATIC_ITEM: usize = 10; //~ ERROR unnecessary parentheses around assigned value
46
47 fn main() {
48     foo();
49     bar(true); //~ ERROR unnecessary parentheses around function argument
50
51     if true {} //~ ERROR unnecessary parentheses around `if` condition
52     while true {} //~ ERROR unnecessary parentheses around `while` condition
53     match true { //~ ERROR unnecessary parentheses around `match` scrutinee expression
54         _ => {}
55     }
56     if let 1 = 1 {} //~ ERROR unnecessary parentheses around `let` scrutinee expression
57     while let 1 = 2 {} //~ ERROR unnecessary parentheses around `let` scrutinee expression
58     let v = X { y: false };
59     // struct lits needs parens, so these shouldn't warn.
60     if (v == X { y: true }) {}
61     if (X { y: true } == v) {}
62     if (X { y: false }.y) {}
63     // this shouldn't warn, because the parens are necessary to disambiguate let chains
64     if let true = (true && false) {}
65
66     while (X { y: false }.foo(true)) {}
67     while (true | X { y: false }.y) {}
68
69     match (X { y: false }) {
70         _ => {}
71     }
72
73     X { y: false }.foo(true); //~ ERROR unnecessary parentheses around method argument
74
75     let mut _a = 0; //~ ERROR unnecessary parentheses around assigned value
76     _a = 0; //~ ERROR unnecessary parentheses around assigned value
77     _a += 1; //~ ERROR unnecessary parentheses around assigned value
78
79     let _a = baz!(3, 4);
80     let _b = baz!(3);
81 }