From 66db8e52d7e75e20048af38d137db2fbe4aa9201 Mon Sep 17 00:00:00 2001 From: Bastian Kauschke Date: Mon, 10 Aug 2020 12:04:51 +0200 Subject: [PATCH] unused_delims: trim expr --- src/librustc_lint/unused.rs | 36 ++++++++++--------- .../ui/const-generics/unused_braces.fixed | 2 +- src/test/ui/lint/unused_braces.fixed | 8 ++--- src/test/ui/lint/unused_braces_borrow.fixed | 2 +- .../try-block/try-block-unused-delims.fixed | 2 +- 5 files changed, 26 insertions(+), 24 deletions(-) diff --git a/src/librustc_lint/unused.rs b/src/librustc_lint/unused.rs index 5de9a16e098..ecc8a192f18 100644 --- a/src/librustc_lint/unused.rs +++ b/src/librustc_lint/unused.rs @@ -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 { diff --git a/src/test/ui/const-generics/unused_braces.fixed b/src/test/ui/const-generics/unused_braces.fixed index 5c2b9267af5..836f26efc96 100644 --- a/src/test/ui/const-generics/unused_braces.fixed +++ b/src/test/ui/const-generics/unused_braces.fixed @@ -10,6 +10,6 @@ struct A; fn main() { let _: A<7>; // ok - let _: A< 7 >; //~ WARN unnecessary braces + let _: A<7>; //~ WARN unnecessary braces let _: A<{ 3 + 5 }>; // ok } diff --git a/src/test/ui/lint/unused_braces.fixed b/src/test/ui/lint/unused_braces.fixed index c0225911c6e..1a88d985dd8 100644 --- a/src/test/ui/lint/unused_braces.fixed +++ b/src/test/ui/lint/unused_braces.fixed @@ -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. diff --git a/src/test/ui/lint/unused_braces_borrow.fixed b/src/test/ui/lint/unused_braces_borrow.fixed index 25950334549..583506f891d 100644 --- a/src/test/ui/lint/unused_braces_borrow.fixed +++ b/src/test/ui/lint/unused_braces_borrow.fixed @@ -21,6 +21,6 @@ fn main() { }; consume(&{ a.b }); - consume( a.b ); + consume(a.b); //~^ WARN unnecessary braces } diff --git a/src/test/ui/try-block/try-block-unused-delims.fixed b/src/test/ui/try-block/try-block-unused-delims.fixed index c8b03c20068..756081738c3 100644 --- a/src/test/ui/try-block/try-block-unused-delims.fixed +++ b/src/test/ui/try-block/try-block-unused-delims.fixed @@ -11,7 +11,7 @@ fn main() { consume(try {}); //~^ WARN unnecessary parentheses - consume( try {} ); + consume(try {}); //~^ WARN unnecessary braces match try {} {