Skip to content

Commit bdb2a17

Browse files
committed
declare needs_ref later
1 parent 3122e3d commit bdb2a17

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

clippy_lints/src/methods/get_unwrap.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ pub(super) fn check<'tcx>(
2222
let mut applicability = Applicability::MachineApplicable;
2323
let expr_ty = cx.typeck_results().expr_ty(recv);
2424
let get_args_str = snippet_with_applicability(cx, get_arg.span, "..", &mut applicability);
25-
let mut needs_ref = true;
2625
let caller_type = if derefs_to_slice(cx, recv, expr_ty).is_some() {
2726
"slice"
2827
} else if is_type_diagnostic_item(cx, expr_ty, sym::Vec) {
@@ -42,8 +41,7 @@ pub(super) fn check<'tcx>(
4241
// Handle the case where the result is immediately dereferenced,
4342
// either directly be the user, or as a result of a method call or the like
4443
// by not requiring an explicit reference
45-
if needs_ref
46-
&& let Some(parent) = get_parent_expr(cx, expr)
44+
let needs_ref = if let Some(parent) = get_parent_expr(cx, expr)
4745
&& let hir::ExprKind::Unary(hir::UnOp::Deref, _)
4846
| hir::ExprKind::MethodCall(..)
4947
| hir::ExprKind::Field(..)
@@ -54,8 +52,10 @@ pub(super) fn check<'tcx>(
5452
// the span to also include the deref part
5553
span = parent.span;
5654
}
57-
needs_ref = false;
58-
}
55+
false
56+
} else {
57+
true
58+
};
5959

6060
let mut_str = if is_mut { "_mut" } else { "" };
6161
let borrow_str = if !needs_ref {

0 commit comments

Comments
 (0)