fork/rust
git clone https://git.julia.blue/fork/rust
3bcad65fbf6
master
1// run-rustfix 2 3#![deny(unused_parens)] 4#![allow(while_true)] // for rustfix 5 6#[derive(Eq, PartialEq)] 7struct X { y: bool } 8impl X { 9 fn foo(&self, conjunct: bool) -> bool { self.y && conjunct } 10} 11 12fn foo() -> isize { 13 return 1; //~ ERROR unnecessary parentheses around `return` value 14} 15fn bar(y: bool) -> X { 16 return X { y }; //~ ERROR unnecessary parentheses around `return` value 17} 18 19pub fn unused_parens_around_return_type() -> u32 { //~ ERROR unnecessary parentheses around type 20 panic!() 21} 22 23pub 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 30pub trait Trait { 31 fn test(&self); 32} 33 34pub fn passes_unused_parens_lint() -> &'static (dyn Trait) { 35 panic!() 36} 37 38pub 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 46macro_rules! baz { 47 ($($foo:expr),+) => { 48 ($($foo),*) 49 } 50} 51 52pub const CONST_ITEM: usize = 10; //~ ERROR unnecessary parentheses around assigned value 53pub static STATIC_ITEM: usize = 10; //~ ERROR unnecessary parentheses around assigned value 54 55fn 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) {} 71 // this shouldn't warn, because the parens are necessary to disambiguate let chains 72 if let true = (true && false) {} 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 87 let _a = baz!(3, 4); 88 let _b = baz!(3); 89}