lint_iter_method(cx, args, arg, method_name);
}
} else if method_name == "into_iter" && match_trait_method(cx, arg, &paths::INTO_ITERATOR) {
- let def_id = cx.tables.type_dependent_defs()[arg.hir_id].def_id();
+ let def_id = cx.tables.type_dependent_def_id(arg.hir_id).unwrap();
let substs = cx.tables.node_substs(arg.hir_id);
let method_type = cx.tcx.type_of(def_id).subst(cx.tcx, substs);
if visitor2.state == VarState::Warn {
if let Some(name) = visitor2.name {
- span_lint(
+ let mut applicability = Applicability::MachineApplicable;
+ span_lint_and_sugg(
cx,
EXPLICIT_COUNTER_LOOP,
expr.span,
- &format!(
- "the variable `{0}` is used as a loop counter. Consider using `for ({0}, \
- {1}) in {2}.enumerate()` or similar iterators",
+ &format!("the variable `{}` is used as a loop counter.", name),
+ "consider using",
+ format!(
+ "for ({}, {}) in {}.enumerate()",
name,
- snippet(cx, pat.span, "_"),
+ snippet_with_applicability(cx, pat.span, "item", &mut applicability),
if higher::range(cx, arg).is_some() {
- format!("({})", snippet(cx, arg.span, "_"))
+ format!(
+ "({})",
+ snippet_with_applicability(cx, arg.span, "_", &mut applicability)
+ )
} else {
- format!("{}", sugg::Sugg::hir(cx, arg, "_").maybe_par())
+ format!(
+ "{}",
+ sugg::Sugg::hir_with_applicability(cx, arg, "_", &mut applicability)
+ .maybe_par()
+ )
}
),
+ applicability,
);
}
}
}
},
ExprKind::MethodCall(_, _, ref args) => {
- let def_id = self.cx.tables.type_dependent_defs()[expr.hir_id].def_id();
+ let def_id = self.cx.tables.type_dependent_def_id(expr.hir_id).unwrap();
for (ty, expr) in self.cx.tcx.fn_sig(def_id).inputs().skip_binder().iter().zip(args) {
self.prefer_mutable = false;
if let ty::Ref(_, _, mutbl) = ty.sty {