File tree Expand file tree Collapse file tree 2 files changed +13
-3
lines changed Expand file tree Collapse file tree 2 files changed +13
-3
lines changed Original file line number Diff line number Diff line change @@ -494,7 +494,17 @@ impl<T: Display> Display for ParenHelper<T> {
494494/// operators have the same
495495/// precedence.
496496pub fn make_unop ( op : & str , expr : Sugg < ' _ > ) -> Sugg < ' static > {
497- Sugg :: MaybeParen ( format ! ( "{op}{}" , expr. maybe_paren( ) ) . into ( ) )
497+ // If the `expr` starts with `op` already, do not add wrap it in
498+ // parentheses.
499+ let expr = if let Sugg :: MaybeParen ( ref sugg) = expr
500+ && !has_enclosing_paren ( sugg)
501+ && sugg. starts_with ( op)
502+ {
503+ expr
504+ } else {
505+ expr. maybe_paren ( )
506+ } ;
507+ Sugg :: MaybeParen ( format ! ( "{op}{expr}" ) . into ( ) )
498508}
499509
500510/// Builds the string for `<lhs> <op> <rhs>` adding parenthesis when necessary.
Original file line number Diff line number Diff line change @@ -179,7 +179,7 @@ error: inequality checks against true can be replaced by a negation
179179 --> tests/ui/nonminimal_bool.rs:186:8
180180 |
181181LL | if !b != true {}
182- | ^^^^^^^^^^ help: try simplifying it as shown: `!(!b) `
182+ | ^^^^^^^^^^ help: try simplifying it as shown: `!!b `
183183
184184error: this boolean expression can be simplified
185185 --> tests/ui/nonminimal_bool.rs:189:8
@@ -209,7 +209,7 @@ error: inequality checks against true can be replaced by a negation
209209 --> tests/ui/nonminimal_bool.rs:193:8
210210 |
211211LL | if true != !b {}
212- | ^^^^^^^^^^ help: try simplifying it as shown: `!(!b) `
212+ | ^^^^^^^^^^ help: try simplifying it as shown: `!!b `
213213
214214error: this boolean expression can be simplified
215215 --> tests/ui/nonminimal_bool.rs:196:8
You can’t perform that action at this time.
0 commit comments