Skip to content

Commit

Permalink
Auto merge of #12700 - Luv-Ray:overly_complex_bool_expr, r=Jarcho
Browse files Browse the repository at this point in the history
[`overly_complex_bool_expr`]: Fix trigger wrongly on never type

fixes #12689

---

changelog: fix [`overly_complex_bool_expr`] triggers wrongly on never type
  • Loading branch information
bors committed Jun 5, 2024
2 parents bc00d7b + 334bab2 commit 1105e9d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
5 changes: 5 additions & 0 deletions clippy_lints/src/booleans.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,11 @@ impl<'a, 'tcx, 'v> Hir2Qmm<'a, 'tcx, 'v> {
_ => (),
}
}

if self.cx.typeck_results().expr_ty(e).is_never() {
return Err("contains never type".to_owned());
}

for (n, expr) in self.terminals.iter().enumerate() {
if eq_expr_value(self.cx, e, expr) {
#[expect(clippy::cast_possible_truncation)]
Expand Down
10 changes: 10 additions & 0 deletions tests/ui/overly_complex_bool_expr.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,13 @@ fn check_expect() {
#[expect(clippy::overly_complex_bool_expr)]
let _ = a < b && a >= b;
}

#[allow(clippy::never_loop)]
fn check_never_type() {
loop {
_ = (break) || true;
}
loop {
_ = (return) || true;
}
}
10 changes: 10 additions & 0 deletions tests/ui/overly_complex_bool_expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,13 @@ fn check_expect() {
#[expect(clippy::overly_complex_bool_expr)]
let _ = a < b && a >= b;
}

#[allow(clippy::never_loop)]
fn check_never_type() {
loop {
_ = (break) || true;
}
loop {
_ = (return) || true;
}
}

0 comments on commit 1105e9d

Please sign in to comment.