fix(clippy): update loop lints to use arg.span
Adapts clippy for fe1a7f71fb
This commit is contained in:
parent
fe1a7f71fb
commit
543e601a9d
4 changed files with 9 additions and 10 deletions
|
@ -15,7 +15,6 @@ pub(super) fn check<'tcx>(
|
|||
pat: &'tcx Pat<'_>,
|
||||
arg: &'tcx Expr<'_>,
|
||||
body: &'tcx Expr<'_>,
|
||||
expr: &'tcx Expr<'_>,
|
||||
) {
|
||||
let pat_span = pat.span;
|
||||
|
||||
|
@ -43,7 +42,7 @@ pub(super) fn check<'tcx>(
|
|||
span_lint_and_then(
|
||||
cx,
|
||||
FOR_KV_MAP,
|
||||
expr.span,
|
||||
arg_span,
|
||||
&format!("you seem to want to iterate on a map's {}s", kind),
|
||||
|diag| {
|
||||
let map = sugg::Sugg::hir(cx, arg, "map");
|
||||
|
|
|
@ -5,12 +5,12 @@ use rustc_hir::Expr;
|
|||
use rustc_lint::LateContext;
|
||||
use rustc_span::sym;
|
||||
|
||||
pub(super) fn check(cx: &LateContext<'_>, arg: &Expr<'_>, expr: &Expr<'_>) -> bool {
|
||||
pub(super) fn check(cx: &LateContext<'_>, arg: &Expr<'_>) -> bool {
|
||||
if is_trait_method(cx, arg, sym::Iterator) {
|
||||
span_lint(
|
||||
cx,
|
||||
ITER_NEXT_LOOP,
|
||||
expr.span,
|
||||
arg.span,
|
||||
"you are iterating over `Iterator::next()` which is an Option; this will compile but is \
|
||||
probably not what you want",
|
||||
);
|
||||
|
|
|
@ -601,15 +601,15 @@ fn check_for_loop<'tcx>(
|
|||
needless_range_loop::check(cx, pat, arg, body, expr);
|
||||
explicit_counter_loop::check(cx, pat, arg, body, expr);
|
||||
}
|
||||
check_for_loop_arg(cx, pat, arg, expr);
|
||||
for_kv_map::check(cx, pat, arg, body, expr);
|
||||
check_for_loop_arg(cx, pat, arg);
|
||||
for_kv_map::check(cx, pat, arg, body);
|
||||
mut_range_bound::check(cx, arg, body);
|
||||
single_element_loop::check(cx, pat, arg, body, expr);
|
||||
same_item_push::check(cx, pat, arg, body, expr);
|
||||
manual_flatten::check(cx, pat, arg, body, span);
|
||||
}
|
||||
|
||||
fn check_for_loop_arg(cx: &LateContext<'_>, pat: &Pat<'_>, arg: &Expr<'_>, expr: &Expr<'_>) {
|
||||
fn check_for_loop_arg(cx: &LateContext<'_>, pat: &Pat<'_>, arg: &Expr<'_>) {
|
||||
let mut next_loop_linted = false; // whether or not ITER_NEXT_LOOP lint was used
|
||||
|
||||
if let ExprKind::MethodCall(method, _, [self_arg], _) = arg.kind {
|
||||
|
@ -622,7 +622,7 @@ fn check_for_loop_arg(cx: &LateContext<'_>, pat: &Pat<'_>, arg: &Expr<'_>, expr:
|
|||
explicit_into_iter_loop::check(cx, self_arg, arg);
|
||||
},
|
||||
"next" => {
|
||||
next_loop_linted = iter_next_loop::check(cx, arg, expr);
|
||||
next_loop_linted = iter_next_loop::check(cx, arg);
|
||||
},
|
||||
_ => {},
|
||||
}
|
||||
|
|
|
@ -146,7 +146,7 @@ pub(super) fn check<'tcx>(
|
|||
span_lint_and_then(
|
||||
cx,
|
||||
NEEDLESS_RANGE_LOOP,
|
||||
expr.span,
|
||||
arg.span,
|
||||
&format!("the loop variable `{}` is used to index `{}`", ident.name, indexed),
|
||||
|diag| {
|
||||
multispan_sugg(
|
||||
|
@ -172,7 +172,7 @@ pub(super) fn check<'tcx>(
|
|||
span_lint_and_then(
|
||||
cx,
|
||||
NEEDLESS_RANGE_LOOP,
|
||||
expr.span,
|
||||
arg.span,
|
||||
&format!("the loop variable `{}` is only used to index `{}`", ident.name, indexed),
|
||||
|diag| {
|
||||
multispan_sugg(
|
||||
|
|
Loading…
Reference in a new issue