Skip to content

Commit

Permalink
unused_delims: trim expr
Browse files Browse the repository at this point in the history
  • Loading branch information
lcnr committed Aug 10, 2020
1 parent 13290e8 commit 66db8e5
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
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
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
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
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
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 66db8e5

Please sign in to comment.