Skip to content

Commit ebfa809

Browse files
use maybe_par to add parenthesis
1 parent 6bcd0b9 commit ebfa809

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

clippy_lints/src/booleans.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,20 @@ fn check_simplify_not(cx: &LateContext<'_>, msrv: &Msrv, expr: &Expr<'_>) {
203203
&& let Some(suggestion) = simplify_not(cx, msrv, inner)
204204
&& cx.tcx.lint_level_at_node(NONMINIMAL_BOOL, expr.hir_id).0 != Level::Allow
205205
{
206+
use clippy_utils::sugg::{Sugg, has_enclosing_paren};
207+
let maybe_par = if let Some(sug) = Sugg::hir_opt(cx, inner) {
208+
match sug.maybe_par() {
209+
Sugg::MaybeParen(str) | Sugg::NonParen(str) => has_enclosing_paren(str),
210+
_ => false,
211+
}
212+
} else {
213+
false
214+
};
215+
let suggestion = if maybe_par {
216+
format!("({suggestion})")
217+
} else {
218+
suggestion
219+
};
206220
span_lint_and_sugg(
207221
cx,
208222
NONMINIMAL_BOOL,

0 commit comments

Comments
 (0)