]> git.lizzy.rs Git - rust.git/blobdiff - clippy_lints/src/suspicious_trait_impl.rs
Auto merge of #83213 - rylev:update-lints-to-errors, r=nikomatsakis
[rust.git] / clippy_lints / src / suspicious_trait_impl.rs
index 99e3d818b798b53ed3253fa1762f15c14f4ebdff..512abde11a63433a827f797f95002b6489ac6a20 100644 (file)
@@ -68,14 +68,13 @@ fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>) {
 
             // Check for more than one binary operation in the implemented function
             // Linting when multiple operations are involved can result in false positives
+            let parent_fn = cx.tcx.hir().get_parent_item(expr.hir_id);
             if_chain! {
-                let parent_fn = cx.tcx.hir().get_parent_item(expr.hir_id);
                 if let hir::Node::ImplItem(impl_item) = cx.tcx.hir().get(parent_fn);
                 if let hir::ImplItemKind::Fn(_, body_id) = impl_item.kind;
-                let body = cx.tcx.hir().body(body_id);
-                let mut visitor = BinaryExprVisitor { nb_binops: 0 };
-
                 then {
+                    let body = cx.tcx.hir().body(body_id);
+                    let mut visitor = BinaryExprVisitor { nb_binops: 0 };
                     walk_expr(&mut visitor, &body.value);
                     if visitor.nb_binops > 1 {
                         return;