declare span variable before call
This commit is contained in:
parent
25fe4193ec
commit
134d0dee41
@ -1,5 +1,5 @@
|
|||||||
use super::{make_iterator_snippet, IncrementVisitor, InitializeVisitor, EXPLICIT_COUNTER_LOOP};
|
use super::{make_iterator_snippet, IncrementVisitor, InitializeVisitor, EXPLICIT_COUNTER_LOOP};
|
||||||
use clippy_utils::diagnostics::span_lint_and_then;
|
use clippy_utils::diagnostics::{span_lint_and_sugg, span_lint_and_then};
|
||||||
use clippy_utils::source::snippet_with_applicability;
|
use clippy_utils::source::snippet_with_applicability;
|
||||||
use clippy_utils::{get_enclosing_block, is_integer_const};
|
use clippy_utils::{get_enclosing_block, is_integer_const};
|
||||||
use if_chain::if_chain;
|
use if_chain::if_chain;
|
||||||
@ -35,28 +35,24 @@ pub(super) fn check<'tcx>(
|
|||||||
if is_integer_const(cx, initializer, 0);
|
if is_integer_const(cx, initializer, 0);
|
||||||
then {
|
then {
|
||||||
let mut applicability = Applicability::MaybeIncorrect;
|
let mut applicability = Applicability::MaybeIncorrect;
|
||||||
|
let span = expr.span.with_hi(arg.span.hi());
|
||||||
|
|
||||||
let int_name = match ty.map(Ty::kind) {
|
let int_name = match ty.map(Ty::kind) {
|
||||||
// usize or inferred
|
// usize or inferred
|
||||||
Some(ty::Uint(UintTy::Usize)) | None => {
|
Some(ty::Uint(UintTy::Usize)) | None => {
|
||||||
span_lint_and_then(
|
span_lint_and_sugg(
|
||||||
cx,
|
cx,
|
||||||
EXPLICIT_COUNTER_LOOP,
|
EXPLICIT_COUNTER_LOOP,
|
||||||
expr.span.with_hi(arg.span.hi()),
|
span,
|
||||||
&format!("the variable `{}` is used as a loop counter", name),
|
&format!("the variable `{}` is used as a loop counter", name),
|
||||||
|diag| {
|
"consider using",
|
||||||
diag.span_suggestion(
|
format!(
|
||||||
expr.span.with_hi(arg.span.hi()),
|
"for ({}, {}) in {}.enumerate()",
|
||||||
"consider using",
|
name,
|
||||||
format!(
|
snippet_with_applicability(cx, pat.span, "item", &mut applicability),
|
||||||
"for ({}, {}) in {}.enumerate()",
|
make_iterator_snippet(cx, arg, &mut applicability),
|
||||||
name,
|
),
|
||||||
snippet_with_applicability(cx, pat.span, "item", &mut applicability),
|
applicability,
|
||||||
make_iterator_snippet(cx, arg, &mut applicability),
|
|
||||||
),
|
|
||||||
applicability,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -68,11 +64,11 @@ pub(super) fn check<'tcx>(
|
|||||||
span_lint_and_then(
|
span_lint_and_then(
|
||||||
cx,
|
cx,
|
||||||
EXPLICIT_COUNTER_LOOP,
|
EXPLICIT_COUNTER_LOOP,
|
||||||
expr.span.with_hi(arg.span.hi()),
|
span,
|
||||||
&format!("the variable `{}` is used as a loop counter", name),
|
&format!("the variable `{}` is used as a loop counter", name),
|
||||||
|diag| {
|
|diag| {
|
||||||
diag.span_suggestion(
|
diag.span_suggestion(
|
||||||
expr.span.with_hi(arg.span.hi()),
|
span,
|
||||||
"consider using",
|
"consider using",
|
||||||
format!(
|
format!(
|
||||||
"for ({}, {}) in (0_{}..).zip({})",
|
"for ({}, {}) in (0_{}..).zip({})",
|
||||||
|
Loading…
Reference in New Issue
Block a user