2021-02-21 17:12:17 +00:00
|
|
|
use super::EXPLICIT_INTO_ITER_LOOP;
|
2021-03-16 00:55:45 +00:00
|
|
|
use clippy_utils::diagnostics::span_lint_and_sugg;
|
2021-03-14 23:17:44 +00:00
|
|
|
use clippy_utils::source::snippet_with_applicability;
|
2021-02-21 17:12:17 +00:00
|
|
|
use rustc_errors::Applicability;
|
|
|
|
use rustc_hir::Expr;
|
|
|
|
use rustc_lint::LateContext;
|
2021-03-02 03:41:06 +00:00
|
|
|
use rustc_middle::ty::TyS;
|
|
|
|
|
|
|
|
pub(super) fn check(cx: &LateContext<'_>, args: &'hir [Expr<'hir>], arg: &Expr<'_>) {
|
|
|
|
let receiver_ty = cx.typeck_results().expr_ty(&args[0]);
|
|
|
|
let receiver_ty_adjusted = cx.typeck_results().expr_ty_adjusted(&args[0]);
|
|
|
|
if !TyS::same_type(receiver_ty, receiver_ty_adjusted) {
|
|
|
|
return;
|
|
|
|
}
|
2021-02-21 17:12:17 +00:00
|
|
|
|
|
|
|
let mut applicability = Applicability::MachineApplicable;
|
2021-03-02 03:41:06 +00:00
|
|
|
let object = snippet_with_applicability(cx, args[0].span, "_", &mut applicability);
|
2021-02-21 17:12:17 +00:00
|
|
|
span_lint_and_sugg(
|
|
|
|
cx,
|
|
|
|
EXPLICIT_INTO_ITER_LOOP,
|
|
|
|
arg.span,
|
|
|
|
"it is more concise to loop over containers instead of using explicit \
|
|
|
|
iteration methods",
|
|
|
|
"to write this more concisely, try",
|
|
|
|
object.to_string(),
|
|
|
|
applicability,
|
|
|
|
);
|
|
|
|
}
|