2020-07-02 00:32:12 -05:00
|
|
|
// run-rustfix
|
|
|
|
|
2014-10-27 17:37:07 -05:00
|
|
|
#![deny(unused_parens)]
|
2020-07-02 00:32:12 -05:00
|
|
|
#![allow(while_true)] // for rustfix
|
2014-01-18 21:57:47 -06:00
|
|
|
|
2014-12-30 22:32:49 -06:00
|
|
|
#[derive(Eq, PartialEq)]
|
2014-06-24 18:00:46 -05:00
|
|
|
struct X { y: bool }
|
|
|
|
impl X {
|
2017-12-23 21:28:33 -06:00
|
|
|
fn foo(&self, conjunct: bool) -> bool { self.y && conjunct }
|
2014-06-24 18:00:46 -05:00
|
|
|
}
|
|
|
|
|
2015-01-08 04:54:35 -06:00
|
|
|
fn foo() -> isize {
|
2015-01-31 10:23:42 -06:00
|
|
|
return (1); //~ ERROR unnecessary parentheses around `return` value
|
2014-01-18 21:57:47 -06:00
|
|
|
}
|
2017-12-23 21:28:33 -06:00
|
|
|
fn bar(y: bool) -> X {
|
|
|
|
return (X { y }); //~ ERROR unnecessary parentheses around `return` value
|
2014-06-24 18:00:46 -05:00
|
|
|
}
|
2014-01-18 21:57:47 -06:00
|
|
|
|
2020-07-02 00:32:12 -05:00
|
|
|
pub fn unused_parens_around_return_type() -> (u32) { //~ ERROR unnecessary parentheses around type
|
2019-10-04 00:56:57 -05:00
|
|
|
panic!()
|
|
|
|
}
|
|
|
|
|
2020-07-02 00:32:12 -05:00
|
|
|
pub fn unused_parens_around_block_return() -> u32 {
|
|
|
|
let _foo = {
|
2020-01-22 23:42:35 -06:00
|
|
|
(5) //~ ERROR unnecessary parentheses around block return value
|
|
|
|
};
|
|
|
|
(5) //~ ERROR unnecessary parentheses around block return value
|
|
|
|
}
|
|
|
|
|
2020-07-02 00:32:12 -05:00
|
|
|
pub trait Trait {
|
2019-10-04 00:56:57 -05:00
|
|
|
fn test(&self);
|
|
|
|
}
|
|
|
|
|
2020-07-02 00:32:12 -05:00
|
|
|
pub fn passes_unused_parens_lint() -> &'static (dyn Trait) {
|
2019-10-04 00:56:57 -05:00
|
|
|
panic!()
|
|
|
|
}
|
|
|
|
|
2023-06-05 09:25:00 -05:00
|
|
|
pub fn parens_with_keyword(e: &[()]) -> i32 {
|
|
|
|
if(true) {} //~ ERROR unnecessary parentheses around `if`
|
|
|
|
while(true) {} //~ ERROR unnecessary parentheses around `while`
|
|
|
|
for _ in(e) {} //~ ERROR unnecessary parentheses around `for`
|
|
|
|
match(1) { _ => ()} //~ ERROR unnecessary parentheses around `match`
|
|
|
|
return(1); //~ ERROR unnecessary parentheses around `return` value
|
|
|
|
}
|
|
|
|
|
2019-12-03 05:35:09 -06:00
|
|
|
macro_rules! baz {
|
|
|
|
($($foo:expr),+) => {
|
|
|
|
($($foo),*)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-02 00:32:12 -05:00
|
|
|
pub const CONST_ITEM: usize = (10); //~ ERROR unnecessary parentheses around assigned value
|
|
|
|
pub static STATIC_ITEM: usize = (10); //~ ERROR unnecessary parentheses around assigned value
|
2020-02-01 17:30:52 -06:00
|
|
|
|
2014-01-18 21:57:47 -06:00
|
|
|
fn main() {
|
|
|
|
foo();
|
2017-12-23 21:28:33 -06:00
|
|
|
bar((true)); //~ ERROR unnecessary parentheses around function argument
|
2014-01-18 21:57:47 -06:00
|
|
|
|
|
|
|
if (true) {} //~ ERROR unnecessary parentheses around `if` condition
|
|
|
|
while (true) {} //~ ERROR unnecessary parentheses around `while` condition
|
2020-03-31 11:42:54 -05:00
|
|
|
match (true) { //~ ERROR unnecessary parentheses around `match` scrutinee expression
|
2014-01-18 21:57:47 -06:00
|
|
|
_ => {}
|
|
|
|
}
|
2020-03-31 11:42:54 -05:00
|
|
|
if let 1 = (1) {} //~ ERROR unnecessary parentheses around `let` scrutinee expression
|
|
|
|
while let 1 = (2) {} //~ ERROR unnecessary parentheses around `let` scrutinee expression
|
2014-06-24 18:00:46 -05:00
|
|
|
let v = X { y: false };
|
|
|
|
// struct lits needs parens, so these shouldn't warn.
|
|
|
|
if (v == X { y: true }) {}
|
|
|
|
if (X { y: true } == v) {}
|
|
|
|
if (X { y: false }.y) {}
|
2020-10-13 18:13:48 -05:00
|
|
|
// this shouldn't warn, because the parens are necessary to disambiguate let chains
|
|
|
|
if let true = (true && false) {}
|
2014-06-24 18:00:46 -05:00
|
|
|
|
2017-12-23 21:28:33 -06:00
|
|
|
while (X { y: false }.foo(true)) {}
|
2014-06-24 18:00:46 -05:00
|
|
|
while (true | X { y: false }.y) {}
|
|
|
|
|
|
|
|
match (X { y: false }) {
|
|
|
|
_ => {}
|
|
|
|
}
|
|
|
|
|
2017-12-23 21:28:33 -06:00
|
|
|
X { y: false }.foo((true)); //~ ERROR unnecessary parentheses around method argument
|
|
|
|
|
2015-01-31 10:23:42 -06:00
|
|
|
let mut _a = (0); //~ ERROR unnecessary parentheses around assigned value
|
|
|
|
_a = (0); //~ ERROR unnecessary parentheses around assigned value
|
|
|
|
_a += (1); //~ ERROR unnecessary parentheses around assigned value
|
2019-12-03 05:35:09 -06:00
|
|
|
|
2023-10-30 08:34:55 -05:00
|
|
|
let(mut _a) = 3; //~ ERROR unnecessary parentheses around pattern
|
|
|
|
let (mut _a) = 3; //~ ERROR unnecessary parentheses around pattern
|
|
|
|
let( mut _a) = 3; //~ ERROR unnecessary parentheses around pattern
|
|
|
|
|
|
|
|
let(_a) = 3; //~ ERROR unnecessary parentheses around pattern
|
|
|
|
let (_a) = 3; //~ ERROR unnecessary parentheses around pattern
|
|
|
|
let( _a) = 3; //~ ERROR unnecessary parentheses around pattern
|
|
|
|
|
2019-12-03 05:35:09 -06:00
|
|
|
let _a = baz!(3, 4);
|
|
|
|
let _b = baz!(3);
|
2014-01-18 21:57:47 -06:00
|
|
|
}
|