Skip to content

Commit 276ce39

Browse files
committedJan 27, 2024
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](rust-lang/rust-clippy#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
2 parents 18e1f25 + bd6e920 commit 276ce39

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed
 

Diff for: ‎clippy_lints/src/booleans.rs

+1
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,7 @@ struct NotSimplificationVisitor<'a, 'tcx> {
499499
impl<'a, 'tcx> Visitor<'tcx> for NotSimplificationVisitor<'a, 'tcx> {
500500
fn visit_expr(&mut self, expr: &'tcx Expr<'_>) {
501501
if let ExprKind::Unary(UnOp::Not, inner) = &expr.kind
502+
&& !expr.span.from_expansion()
502503
&& !inner.span.from_expansion()
503504
&& let Some(suggestion) = simplify_not(self.cx, inner)
504505
&& self.cx.tcx.lint_level_at_node(NONMINIMAL_BOOL, expr.hir_id).0 != Level::Allow

Diff for: ‎tests/ui/nonminimal_bool.rs

+11
Original file line numberDiff line numberDiff line change
@@ -145,3 +145,14 @@ fn issue10836() {
145145
// Should not lint
146146
let _: bool = !!Foo(true);
147147
}
148+
149+
fn issue11932() {
150+
let x: i32 = unimplemented!();
151+
152+
#[allow(clippy::nonminimal_bool)]
153+
let _ = x % 2 == 0 || {
154+
// Should not lint
155+
assert!(x > 0);
156+
x % 3 == 0
157+
};
158+
}

0 commit comments

Comments
 (0)