Skip to content

Commit

Permalink
Rollup merge of #75359 - lcnr:unused-delims-trim, r=oli-obk
Browse files Browse the repository at this point in the history
unused_delims: trim expr

improves rustfix output.
  • Loading branch information
JohnTitor authored Aug 11, 2020
2 parents 0a8d4db + 66db8e5 commit ca462d3
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 24 deletions.
36 changes: 19 additions & 17 deletions src/librustc_lint/unused.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/const-generics/unused_braces.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
8 changes: 4 additions & 4 deletions src/test/ui/lint/unused_braces.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/lint/unused_braces_borrow.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ fn main() {
};

consume(&{ a.b });
consume( a.b );
consume(a.b);
//~^ WARN unnecessary braces
}
2 changes: 1 addition & 1 deletion src/test/ui/try-block/try-block-unused-delims.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ fn main() {
consume(try {});
//~^ WARN unnecessary parentheses

consume( try {} );
consume(try {});
//~^ WARN unnecessary braces

match try {} {
Expand Down

0 comments on commit ca462d3

Please sign in to comment.