Rollup merge of #75359 - lcnr:unused-delims-trim, r=oli-obk

unused_delims: trim expr

improves rustfix output.
This commit is contained in:
Yuki Okushi 2020-08-11 16:23:57 +09:00 committed by GitHub
commit ca462d36ff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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 {} {