mirror of
https://github.com/rust-lang/rust.git
synced 2025-04-15 05:26:47 +00:00
improve advice in iter_nth_zero
The "use .next()" replacement advice is on the last line of the code snippet, where it is vulnerable to truncation. Display that advice at the beginning instead. closes #5783
This commit is contained in:
parent
4b8700879c
commit
201999ccfd
@ -2348,8 +2348,8 @@ fn lint_iter_nth_zero<'tcx>(cx: &LateContext<'tcx>, expr: &hir::Expr<'_>, nth_ar
|
||||
cx,
|
||||
ITER_NTH_ZERO,
|
||||
expr.span,
|
||||
"called `.nth(0)` on a `std::iter::Iterator`",
|
||||
"try calling",
|
||||
"called `.nth(0)` on a `std::iter::Iterator`, when `.next()` is equivalent",
|
||||
"try calling .next() instead of .nth(0)",
|
||||
format!("{}.next()", snippet_with_applicability(cx, nth_args[0].span, "..", &mut applicability)),
|
||||
applicability,
|
||||
);
|
||||
|
@ -1,22 +1,22 @@
|
||||
error: called `.nth(0)` on a `std::iter::Iterator`
|
||||
error: called `.nth(0)` on a `std::iter::Iterator`, when `.next()` is equivalent
|
||||
--> $DIR/iter_nth_zero.rs:20:14
|
||||
|
|
||||
LL | let _x = s.iter().nth(0);
|
||||
| ^^^^^^^^^^^^^^^ help: try calling: `s.iter().next()`
|
||||
| ^^^^^^^^^^^^^^^ help: try calling .next() instead of .nth(0): `s.iter().next()`
|
||||
|
|
||||
= note: `-D clippy::iter-nth-zero` implied by `-D warnings`
|
||||
|
||||
error: called `.nth(0)` on a `std::iter::Iterator`
|
||||
error: called `.nth(0)` on a `std::iter::Iterator`, when `.next()` is equivalent
|
||||
--> $DIR/iter_nth_zero.rs:25:14
|
||||
|
|
||||
LL | let _y = iter.nth(0);
|
||||
| ^^^^^^^^^^^ help: try calling: `iter.next()`
|
||||
| ^^^^^^^^^^^ help: try calling .next() instead of .nth(0): `iter.next()`
|
||||
|
||||
error: called `.nth(0)` on a `std::iter::Iterator`
|
||||
error: called `.nth(0)` on a `std::iter::Iterator`, when `.next()` is equivalent
|
||||
--> $DIR/iter_nth_zero.rs:30:22
|
||||
|
|
||||
LL | let _unwrapped = iter2.nth(0).unwrap();
|
||||
| ^^^^^^^^^^^^ help: try calling: `iter2.next()`
|
||||
| ^^^^^^^^^^^^ help: try calling .next() instead of .nth(0): `iter2.next()`
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user