about summary refs log tree commit diff
path: root/clippy_lints/src/utils
diff options
context:
space:
mode:
Diffstat (limited to 'clippy_lints/src/utils')
-rw-r--r--clippy_lints/src/utils/internal_lints.rs3
-rw-r--r--clippy_lints/src/utils/mod.rs12
2 files changed, 7 insertions, 8 deletions
diff --git a/clippy_lints/src/utils/internal_lints.rs b/clippy_lints/src/utils/internal_lints.rs
index 877f431e641..343098ceeee 100644
--- a/clippy_lints/src/utils/internal_lints.rs
+++ b/clippy_lints/src/utils/internal_lints.rs
@@ -164,8 +164,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LintWithoutLintPass {
                         output: &mut self.registered_lints,
                         cx,
                     };
-                    let node_id = cx.tcx.hir().hir_to_node_id(impl_item_refs[0].id.hir_id);
-                    let body_id = cx.tcx.hir().body_owned_by(node_id);
+                    let body_id = cx.tcx.hir().body_owned_by(impl_item_refs[0].id.hir_id);
                     collector.visit_expr(&cx.tcx.hir().body(body_id).value);
                 }
             }
diff --git a/clippy_lints/src/utils/mod.rs b/clippy_lints/src/utils/mod.rs
index 70ba0592caa..f6b9a77a573 100644
--- a/clippy_lints/src/utils/mod.rs
+++ b/clippy_lints/src/utils/mod.rs
@@ -829,15 +829,15 @@ pub fn iter_input_pats<'tcx>(decl: &FnDecl, body: &'tcx Body) -> impl Iterator<I
 
 /// Check if a given expression is a match expression
 /// expanded from `?` operator or `try` macro.
-pub fn is_try(expr: &Expr) -> Option<&Expr> {
-    fn is_ok(arm: &Arm) -> bool {
+pub fn is_try<'a>(cx: &'_ LateContext<'_, '_>, expr: &'a Expr) -> Option<&'a Expr> {
+    fn is_ok(cx: &'_ LateContext<'_, '_>, arm: &Arm) -> bool {
         if_chain! {
             if let PatKind::TupleStruct(ref path, ref pat, None) = arm.pats[0].node;
             if match_qpath(path, &paths::RESULT_OK[1..]);
-            if let PatKind::Binding(_, defid, _, _, None) = pat[0].node;
+            if let PatKind::Binding(_, hir_id, _, None) = pat[0].node;
             if let ExprKind::Path(QPath::Resolved(None, ref path)) = arm.body.node;
             if let Def::Local(lid) = path.def;
-            if lid == defid;
+            if cx.tcx.hir().node_to_hir_id(lid) == hir_id;
             then {
                 return true;
             }
@@ -863,8 +863,8 @@ pub fn is_try(expr: &Expr) -> Option<&Expr> {
             if arms.len() == 2;
             if arms[0].pats.len() == 1 && arms[0].guard.is_none();
             if arms[1].pats.len() == 1 && arms[1].guard.is_none();
-            if (is_ok(&arms[0]) && is_err(&arms[1])) ||
-                (is_ok(&arms[1]) && is_err(&arms[0]));
+            if (is_ok(cx, &arms[0]) && is_err(&arms[1])) ||
+                (is_ok(cx, &arms[1]) && is_err(&arms[0]));
             then {
                 return Some(expr);
             }