Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unused_delims: trim expr #75359

Merged
merged 1 commit into from
Aug 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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