Skip to content

Commit 0e1cbc5

Browse files
committed
fix code
1 parent 7bb69c0 commit 0e1cbc5

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

clippy_lints/src/loops/utils.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use rustc_hir::intravisit::{walk_expr, walk_local, walk_pat, walk_stmt, Visitor}
77
use rustc_hir::{BinOpKind, BorrowKind, Expr, ExprKind, HirId, HirIdMap, Local, Mutability, Pat, PatKind, Stmt};
88
use rustc_lint::LateContext;
99
use rustc_middle::hir::nested_filter;
10-
use rustc_middle::ty::Ty;
10+
use rustc_middle::ty::{self, Ty};
1111
use rustc_span::source_map::Spanned;
1212
use rustc_span::symbol::{sym, Symbol};
1313
use rustc_typeck::hir_ty_to_ty;
@@ -332,17 +332,20 @@ pub(super) fn make_iterator_snippet(cx: &LateContext<'_>, arg: &Expr<'_>, applic
332332
} else {
333333
// (&x).into_iter() ==> x.iter()
334334
// (&mut x).into_iter() ==> x.iter_mut()
335-
match &arg.kind {
336-
ExprKind::AddrOf(BorrowKind::Ref, mutability, arg_inner)
337-
if has_iter_method(cx, cx.typeck_results().expr_ty(arg_inner)).is_some() =>
338-
{
339-
let meth_name = match mutability {
335+
let arg_ty = cx.typeck_results().expr_ty_adjusted(arg);
336+
match &arg_ty.kind() {
337+
ty::Ref(_, inner_ty, mutbl) if has_iter_method(cx, inner_ty).is_some() => {
338+
let meth_name = match mutbl {
340339
Mutability::Mut => "iter_mut",
341340
Mutability::Not => "iter",
342341
};
342+
let caller = match &arg.kind {
343+
ExprKind::AddrOf(BorrowKind::Ref, _, arg_inner) => arg_inner,
344+
_ => arg,
345+
};
343346
format!(
344347
"{}.{}()",
345-
sugg::Sugg::hir_with_applicability(cx, arg_inner, "_", applic_ref).maybe_par(),
348+
sugg::Sugg::hir_with_applicability(cx, caller, "_", applic_ref).maybe_par(),
346349
meth_name,
347350
)
348351
},

0 commit comments

Comments
 (0)