From 090c228873c8109e82857145f71f34c0ccdf28dd Mon Sep 17 00:00:00 2001 From: cocodery Date: Wed, 3 Jan 2024 22:12:27 +0800 Subject: [PATCH 1/2] Fix/Issue11932: assert* in multi-condition after unrolling will cause lint emit warning --- clippy_lints/src/booleans.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/clippy_lints/src/booleans.rs b/clippy_lints/src/booleans.rs index e11f83f22603..2d0af1017d58 100644 --- a/clippy_lints/src/booleans.rs +++ b/clippy_lints/src/booleans.rs @@ -502,6 +502,8 @@ impl<'a, 'tcx> Visitor<'tcx> for NotSimplificationVisitor<'a, 'tcx> { && !inner.span.from_expansion() && let Some(suggestion) = simplify_not(self.cx, inner) && self.cx.tcx.lint_level_at_node(NONMINIMAL_BOOL, expr.hir_id).0 != Level::Allow + && let Some(snippet) = snippet_opt(self.cx, expr.span) + && !snippet.contains("assert") { span_lint_and_sugg( self.cx, From bd6e9202b47ec68841d58b1574361e09c5d7775b Mon Sep 17 00:00:00 2001 From: cocodery Date: Sat, 6 Jan 2024 14:12:41 +0800 Subject: [PATCH 2/2] modify check that any macros will be ingored in this lint, and add test --- clippy_lints/src/booleans.rs | 3 +-- tests/ui/nonminimal_bool.rs | 11 +++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/clippy_lints/src/booleans.rs b/clippy_lints/src/booleans.rs index 2d0af1017d58..2d1c250ace90 100644 --- a/clippy_lints/src/booleans.rs +++ b/clippy_lints/src/booleans.rs @@ -499,11 +499,10 @@ struct NotSimplificationVisitor<'a, 'tcx> { impl<'a, 'tcx> Visitor<'tcx> for NotSimplificationVisitor<'a, 'tcx> { fn visit_expr(&mut self, expr: &'tcx Expr<'_>) { if let ExprKind::Unary(UnOp::Not, inner) = &expr.kind + && !expr.span.from_expansion() && !inner.span.from_expansion() && let Some(suggestion) = simplify_not(self.cx, inner) && self.cx.tcx.lint_level_at_node(NONMINIMAL_BOOL, expr.hir_id).0 != Level::Allow - && let Some(snippet) = snippet_opt(self.cx, expr.span) - && !snippet.contains("assert") { span_lint_and_sugg( self.cx, diff --git a/tests/ui/nonminimal_bool.rs b/tests/ui/nonminimal_bool.rs index 4d48ef14d31c..f7c3df7066f7 100644 --- a/tests/ui/nonminimal_bool.rs +++ b/tests/ui/nonminimal_bool.rs @@ -145,3 +145,14 @@ fn issue10836() { // Should not lint let _: bool = !!Foo(true); } + +fn issue11932() { + let x: i32 = unimplemented!(); + + #[allow(clippy::nonminimal_bool)] + let _ = x % 2 == 0 || { + // Should not lint + assert!(x > 0); + x % 3 == 0 + }; +}