unused_delims: trim expr

This commit is contained in:
Bastian Kauschke 2020-08-10 12:04:51 +02:00
parent 13290e83a6
commit 66db8e52d7
5 changed files with 26 additions and 24 deletions

View File

@ -481,25 +481,27 @@ trait UnusedDelimLint {
let mut err = lint.build(&span_msg);
let mut ate_left_paren = false;
let mut ate_right_paren = false;
let parens_removed = pattern.trim_matches(|c| match c {
'(' | '{' => {
if ate_left_paren {
false
} else {
ate_left_paren = true;
true
let parens_removed = pattern
.trim_matches(|c| match c {
'(' | '{' => {
if ate_left_paren {
false
} else {
ate_left_paren = true;
true
}
}
}
')' | '}' => {
if ate_right_paren {
false
} else {
ate_right_paren = true;
true
')' | '}' => {
if ate_right_paren {
false
} else {
ate_right_paren = true;
true
}
}
}
_ => false,
});
_ => false,
})
.trim();
let replace = {
let mut replace = if keep_space.0 {

View File

@ -10,6 +10,6 @@ struct A<const N: usize>;
fn main() {
let _: A<7>; // ok
let _: A< 7 >; //~ WARN unnecessary braces
let _: A<7>; //~ WARN unnecessary braces
let _: A<{ 3 + 5 }>; // ok
}

View File

@ -23,18 +23,18 @@ fn main() {
}
}
if true {
if true {
//~^ WARN unnecessary braces
}
while false {
while false {
//~^ WARN unnecessary braces
}
let _: [u8; 3 ];
let _: [u8; 3];
//~^ WARN unnecessary braces
consume( 7 );
consume(7);
//~^ WARN unnecessary braces
// Do not emit lint for multiline blocks.

View File

@ -21,6 +21,6 @@ fn main() {
};
consume(&{ a.b });
consume( a.b );
consume(a.b);
//~^ WARN unnecessary braces
}

View File

@ -11,7 +11,7 @@ fn main() {
consume(try {});
//~^ WARN unnecessary parentheses
consume( try {} );
consume(try {});
//~^ WARN unnecessary braces
match try {} {