feat: 7125 shorten lint text

This commit is contained in:
Christoph Beberweil 2023-11-24 10:38:45 +01:00
parent c58d692e1f
commit 2512341fe4
2 changed files with 7 additions and 5 deletions

View File

@ -88,12 +88,14 @@ pub(super) fn check<'tcx>(
} }
if clippy_utils::higher::Range::hir(arg_expression).is_some() { if clippy_utils::higher::Range::hir(arg_expression).is_some() {
let range_expr = snippet(cx, arg_expression.span, "?").to_string();
let sugg = snippet(cx, arg_expression.span, ".."); let sugg = snippet(cx, arg_expression.span, "..");
span_lint_and_sugg( span_lint_and_sugg(
cx, cx,
SINGLE_ELEMENT_LOOP, SINGLE_ELEMENT_LOOP,
arg.span, arg.span,
"for loop over a single range inside an array, rather than iterating over the elements in the range directly", format!("This loops only once with {pat_snip} being {range_expr}").as_str(),
"did you mean to iterate over the range instead?", "did you mean to iterate over the range instead?",
sugg.to_string(), sugg.to_string(),
Applicability::Unspecified, Applicability::Unspecified,

View File

@ -32,25 +32,25 @@ LL + dbg!(item);
LL + } LL + }
| |
error: for loop over a single range inside an array, rather than iterating over the elements in the range directly error: This loops only once with item being 0..5
--> $DIR/single_element_loop.rs:16:17 --> $DIR/single_element_loop.rs:16:17
| |
LL | for item in &[0..5] { LL | for item in &[0..5] {
| ^^^^^^^ help: did you mean to iterate over the range instead?: `0..5` | ^^^^^^^ help: did you mean to iterate over the range instead?: `0..5`
error: for loop over a single range inside an array, rather than iterating over the elements in the range directly error: This loops only once with item being 0..5
--> $DIR/single_element_loop.rs:20:17 --> $DIR/single_element_loop.rs:20:17
| |
LL | for item in [0..5].iter_mut() { LL | for item in [0..5].iter_mut() {
| ^^^^^^^^^^^^^^^^^ help: did you mean to iterate over the range instead?: `0..5` | ^^^^^^^^^^^^^^^^^ help: did you mean to iterate over the range instead?: `0..5`
error: for loop over a single range inside an array, rather than iterating over the elements in the range directly error: This loops only once with item being 0..5
--> $DIR/single_element_loop.rs:24:17 --> $DIR/single_element_loop.rs:24:17
| |
LL | for item in [0..5] { LL | for item in [0..5] {
| ^^^^^^ help: did you mean to iterate over the range instead?: `0..5` | ^^^^^^ help: did you mean to iterate over the range instead?: `0..5`
error: for loop over a single range inside an array, rather than iterating over the elements in the range directly error: This loops only once with item being 0..5
--> $DIR/single_element_loop.rs:28:17 --> $DIR/single_element_loop.rs:28:17
| |
LL | for item in [0..5].into_iter() { LL | for item in [0..5].into_iter() {