]> git.lizzy.rs Git - rust.git/blobdiff - clippy_lints/src/implicit_return.rs
ast/hir: Rename field-related structures
[rust.git] / clippy_lints / src / implicit_return.rs
index 22c4fef32a32b00c5cac0b25a44a066eba1d0b53..b4f814e1dcccfb1894c73f14abf0ad2d268d0dcd 100644 (file)
@@ -1,8 +1,4 @@
-use crate::utils::{
-    fn_has_unsatisfiable_preds, match_def_path,
-    paths::{BEGIN_PANIC, BEGIN_PANIC_FMT},
-    snippet_opt, span_lint_and_then,
-};
+use crate::utils::{match_panic_def_id, snippet_opt, span_lint_and_then};
 use if_chain::if_chain;
 use rustc_errors::Applicability;
 use rustc_hir::intravisit::FnKind;
@@ -72,8 +68,7 @@ fn expr_match(cx: &LateContext<'_>, expr: &Expr<'_>) {
                 if_chain! {
                     if let StmtKind::Semi(expr, ..) = &stmt.kind;
                     // make sure it's a break, otherwise we want to skip
-                    if let ExprKind::Break(.., break_expr) = &expr.kind;
-                    if let Some(break_expr) = break_expr;
+                    if let ExprKind::Break(.., Some(break_expr)) = &expr.kind;
                     then {
                             lint(cx, expr.span, break_expr.span, LINT_BREAK);
                     }
@@ -86,6 +81,13 @@ fn expr_match(cx: &LateContext<'_>, expr: &Expr<'_>) {
                 lint(cx, expr.span, break_expr.span, LINT_BREAK);
             }
         },
+        ExprKind::If(.., if_expr, else_expr) => {
+            expr_match(cx, if_expr);
+
+            if let Some(else_expr) = else_expr {
+                expr_match(cx, else_expr);
+            }
+        },
         ExprKind::Match(.., arms, source) => {
             let check_all_arms = match source {
                 MatchSource::IfLetDesugar {
@@ -109,8 +111,7 @@ fn expr_match(cx: &LateContext<'_>, expr: &Expr<'_>) {
             if_chain! {
                 if let ExprKind::Path(qpath) = &expr.kind;
                 if let Some(path_def_id) = cx.qpath_res(qpath, expr.hir_id).opt_def_id();
-                if match_def_path(cx, path_def_id, &BEGIN_PANIC) ||
-                    match_def_path(cx, path_def_id, &BEGIN_PANIC_FMT);
+                if match_panic_def_id(cx, path_def_id);
                 then { }
                 else {
                     lint(cx, expr.span, expr.span, LINT_RETURN)
@@ -132,19 +133,13 @@ fn check_fn(
         span: Span,
         _: HirId,
     ) {
-        let def_id = cx.tcx.hir().body_owner_def_id(body.id());
-
-        // Building MIR for `fn`s with unsatisfiable preds results in ICE.
-        if fn_has_unsatisfiable_preds(cx, def_id.to_def_id()) {
+        if span.from_expansion() {
             return;
         }
-
-        let mir = cx.tcx.optimized_mir(def_id.to_def_id());
-
-        // checking return type through MIR, HIR is not able to determine inferred closure return types
-        // make sure it's not a macro
-        if !mir.return_ty().is_unit() && !span.from_expansion() {
-            expr_match(cx, &body.value);
+        let body = cx.tcx.hir().body(body.id());
+        if cx.typeck_results().expr_ty(&body.value).is_unit() {
+            return;
         }
+        expr_match(cx, &body.value);
     }
 }