Skip to content

Commit ca462d3

Browse files
authored
Rollup merge of #75359 - lcnr:unused-delims-trim, r=oli-obk
unused_delims: trim expr improves rustfix output.
2 parents 0a8d4db + 66db8e5 commit ca462d3

File tree

5 files changed

+26
-24
lines changed

5 files changed

+26
-24
lines changed

src/librustc_lint/unused.rs

+19-17
Original file line numberDiff line numberDiff line change
@@ -481,25 +481,27 @@ trait UnusedDelimLint {
481481
let mut err = lint.build(&span_msg);
482482
let mut ate_left_paren = false;
483483
let mut ate_right_paren = false;
484-
let parens_removed = pattern.trim_matches(|c| match c {
485-
'(' | '{' => {
486-
if ate_left_paren {
487-
false
488-
} else {
489-
ate_left_paren = true;
490-
true
484+
let parens_removed = pattern
485+
.trim_matches(|c| match c {
486+
'(' | '{' => {
487+
if ate_left_paren {
488+
false
489+
} else {
490+
ate_left_paren = true;
491+
true
492+
}
491493
}
492-
}
493-
')' | '}' => {
494-
if ate_right_paren {
495-
false
496-
} else {
497-
ate_right_paren = true;
498-
true
494+
')' | '}' => {
495+
if ate_right_paren {
496+
false
497+
} else {
498+
ate_right_paren = true;
499+
true
500+
}
499501
}
500-
}
501-
_ => false,
502-
});
502+
_ => false,
503+
})
504+
.trim();
503505

504506
let replace = {
505507
let mut replace = if keep_space.0 {

src/test/ui/const-generics/unused_braces.fixed

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ struct A<const N: usize>;
1010

1111
fn main() {
1212
let _: A<7>; // ok
13-
let _: A< 7 >; //~ WARN unnecessary braces
13+
let _: A<7>; //~ WARN unnecessary braces
1414
let _: A<{ 3 + 5 }>; // ok
1515
}

src/test/ui/lint/unused_braces.fixed

+4-4
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,18 @@ fn main() {
2323
}
2424
}
2525

26-
if true {
26+
if true {
2727
//~^ WARN unnecessary braces
2828
}
2929

30-
while false {
30+
while false {
3131
//~^ WARN unnecessary braces
3232
}
3333

34-
let _: [u8; 3 ];
34+
let _: [u8; 3];
3535
//~^ WARN unnecessary braces
3636

37-
consume( 7 );
37+
consume(7);
3838
//~^ WARN unnecessary braces
3939

4040
// Do not emit lint for multiline blocks.

src/test/ui/lint/unused_braces_borrow.fixed

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@ fn main() {
2121
};
2222

2323
consume(&{ a.b });
24-
consume( a.b );
24+
consume(a.b);
2525
//~^ WARN unnecessary braces
2626
}

src/test/ui/try-block/try-block-unused-delims.fixed

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ fn main() {
1111
consume(try {});
1212
//~^ WARN unnecessary parentheses
1313

14-
consume( try {} );
14+
consume(try {});
1515
//~^ WARN unnecessary braces
1616

1717
match try {} {

0 commit comments

Comments
 (0)