about summary refs log tree commit diff
diff options
context:
space:
mode:
authory21 <30553356+y21@users.noreply.github.com>2023-06-21 09:16:25 +0200
committery21 <30553356+y21@users.noreply.github.com>2023-06-21 09:16:25 +0200
commitbdb2a1710774e0d77058c81fa3c7182f27565ddd (patch)
treeebdcf2d8fe182e890547f3a1cdd69731f0c9d011
parent3122e3d78f91bc28becf205193fc4ce67955520a (diff)
downloadrust-bdb2a1710774e0d77058c81fa3c7182f27565ddd.tar.gz
rust-bdb2a1710774e0d77058c81fa3c7182f27565ddd.zip
declare needs_ref later
-rw-r--r--clippy_lints/src/methods/get_unwrap.rs10
1 files changed, 5 insertions, 5 deletions
diff --git a/clippy_lints/src/methods/get_unwrap.rs b/clippy_lints/src/methods/get_unwrap.rs
index ba5aae28bd6..e35fb12ed79 100644
--- a/clippy_lints/src/methods/get_unwrap.rs
+++ b/clippy_lints/src/methods/get_unwrap.rs
@@ -22,7 +22,6 @@ pub(super) fn check<'tcx>(
     let mut applicability = Applicability::MachineApplicable;
     let expr_ty = cx.typeck_results().expr_ty(recv);
     let get_args_str = snippet_with_applicability(cx, get_arg.span, "..", &mut applicability);
-    let mut needs_ref = true;
     let caller_type = if derefs_to_slice(cx, recv, expr_ty).is_some() {
         "slice"
     } else if is_type_diagnostic_item(cx, expr_ty, sym::Vec) {
@@ -42,8 +41,7 @@ pub(super) fn check<'tcx>(
     // Handle the case where the result is immediately dereferenced,
     // either directly be the user, or as a result of a method call or the like
     // by not requiring an explicit reference
-    if needs_ref
-        && let Some(parent) = get_parent_expr(cx, expr)
+    let needs_ref = if let Some(parent) = get_parent_expr(cx, expr)
         && let hir::ExprKind::Unary(hir::UnOp::Deref, _)
             | hir::ExprKind::MethodCall(..)
             | hir::ExprKind::Field(..)
@@ -54,8 +52,10 @@ pub(super) fn check<'tcx>(
             // the span to also include the deref part
             span = parent.span;
         }
-        needs_ref = false;
-    }
+        false
+    } else {
+        true
+    };
 
     let mut_str = if is_mut { "_mut" } else { "" };
     let borrow_str = if !needs_ref {