diff options
| author | bors <bors@rust-lang.org> | 2024-01-27 17:44:24 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2024-01-27 17:44:24 +0000 |
| commit | 276ce3936bd7621f0cfda08fa070056dd6f43efb (patch) | |
| tree | 469fa464bcc7653701071fe7925d437b65f95754 | |
| parent | 18e1f25a9f503de065fbe5cbc328954e0ae112cd (diff) | |
| parent | bd6e9202b47ec68841d58b1574361e09c5d7775b (diff) | |
| download | rust-276ce3936bd7621f0cfda08fa070056dd6f43efb.tar.gz rust-276ce3936bd7621f0cfda08fa070056dd6f43efb.zip | |
Auto merge of #12083 - cocodery:fix/issue11932, r=Alexendoo
Fix/Issue11932: assert* in multi-condition after unrolling will cause lint `nonminimal_bool` emit warning fixes [Issue#11932](https://github.com/rust-lang/rust-clippy/issues/11932) After `assert`, `assert_eq`, `assert_ne`, etc, assert family marcos unrolling in multi-condition expressions, lint `nonminimal_bool` will recognize whole expression as a entirety, analyze each simple condition expr of them, and check whether can simplify them. But `assert` itself is a entirety to programmers, we don't need to lint on `assert`. This commit add check whether lint snippet contains `assert` when try to warning to an expression. changelog: [`nonminimal_bool`] add check for condition expression
| -rw-r--r-- | clippy_lints/src/booleans.rs | 1 | ||||
| -rw-r--r-- | tests/ui/nonminimal_bool.rs | 11 |
2 files changed, 12 insertions, 0 deletions
diff --git a/clippy_lints/src/booleans.rs b/clippy_lints/src/booleans.rs index e11f83f2260..2d1c250ace9 100644 --- a/clippy_lints/src/booleans.rs +++ b/clippy_lints/src/booleans.rs @@ -499,6 +499,7 @@ 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 diff --git a/tests/ui/nonminimal_bool.rs b/tests/ui/nonminimal_bool.rs index 4d48ef14d31..f7c3df7066f 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 + }; +} |
