Skip to content

Commit e858695

Browse files
committed
Auto merge of #10845 - disco07:master, r=giraffate
nonminimal_bool fix double not fix issue #10836 changelog: Fix [`nonminimal_bool`] false positive when `!!x`, `x` isn't boolean and implements `Not`
2 parents 8793c2a + e4927f9 commit e858695

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

clippy_lints/src/booleans.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ impl<'tcx> LateLintPass<'tcx> for NonminimalBool {
8888
NonminimalBoolVisitor { cx }.visit_body(body);
8989
}
9090
}
91-
9291
struct NonminimalBoolVisitor<'a, 'tcx> {
9392
cx: &'a LateContext<'tcx>,
9493
}
@@ -473,6 +472,10 @@ impl<'a, 'tcx> Visitor<'tcx> for NonminimalBoolVisitor<'a, 'tcx> {
473472
self.bool_expr(e);
474473
},
475474
ExprKind::Unary(UnOp::Not, inner) => {
475+
if let ExprKind::Unary(UnOp::Not, ex) = inner.kind &&
476+
!self.cx.typeck_results().node_types()[ex.hir_id].is_bool() {
477+
return;
478+
}
476479
if self.cx.typeck_results().node_types()[inner.hir_id].is_bool() {
477480
self.bool_expr(e);
478481
}

tests/ui/nonminimal_bool.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,3 +110,17 @@ fn issue_10435() {
110110
println!("{}", line!());
111111
}
112112
}
113+
114+
fn issue10836() {
115+
struct Foo(bool);
116+
impl std::ops::Not for Foo {
117+
type Output = bool;
118+
119+
fn not(self) -> Self::Output {
120+
!self.0
121+
}
122+
}
123+
124+
// Should not lint
125+
let _: bool = !!Foo(true);
126+
}

0 commit comments

Comments
 (0)