]> git.lizzy.rs Git - rust.git/blobdiff - src/tools/clippy/clippy_lints/src/needless_bool.rs
Auto merge of #85690 - bstrie:m2_arena, r=jackh726,nagisa
[rust.git] / src / tools / clippy / clippy_lints / src / needless_bool.rs
index 36f2829a5b94ee4dcaca93701f4e2e0f137146ea..c9dd94400efb96163f0d01028cc92cb91eef4ecc 100644 (file)
@@ -3,6 +3,7 @@
 //! This lint is **warn** by default
 
 use clippy_utils::diagnostics::{span_lint, span_lint_and_sugg};
+use clippy_utils::higher;
 use clippy_utils::source::snippet_with_applicability;
 use clippy_utils::sugg::Sugg;
 use clippy_utils::{is_else_clause, is_expn_of};
@@ -77,10 +78,15 @@ fn check_expr(&mut self, cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) {
         if e.span.from_expansion() {
             return;
         }
-        if let ExprKind::If(pred, then_block, Some(else_expr)) = e.kind {
+        if let Some(higher::If {
+            cond,
+            then,
+            r#else: Some(r#else),
+        }) = higher::If::hir(e)
+        {
             let reduce = |ret, not| {
                 let mut applicability = Applicability::MachineApplicable;
-                let snip = Sugg::hir_with_applicability(cx, pred, "<predicate>", &mut applicability);
+                let snip = Sugg::hir_with_applicability(cx, cond, "<predicate>", &mut applicability);
                 let mut snip = if not { !snip } else { snip };
 
                 if ret {
@@ -101,8 +107,8 @@ fn check_expr(&mut self, cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) {
                     applicability,
                 );
             };
-            if let ExprKind::Block(then_block, _) = then_block.kind {
-                match (fetch_bool_block(then_block), fetch_bool_expr(else_expr)) {
+            if let ExprKind::Block(then, _) = then.kind {
+                match (fetch_bool_block(then), fetch_bool_expr(r#else)) {
                     (RetBool(true), RetBool(true)) | (Bool(true), Bool(true)) => {
                         span_lint(
                             cx,