Skip to content

Commit 128c5de

Browse files
committed
Auto merge of rust-lang#5793 - warner:5783-nth-zero-next, r=flip1995
improve advice in iter_nth_zero fixes rust-lang#5783 *Please keep the line below* changelog: For 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.
2 parents 97d7a8b + e83b3eb commit 128c5de

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

clippy_lints/src/methods/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2348,8 +2348,8 @@ fn lint_iter_nth_zero<'tcx>(cx: &LateContext<'tcx>, expr: &hir::Expr<'_>, nth_ar
23482348
cx,
23492349
ITER_NTH_ZERO,
23502350
expr.span,
2351-
"called `.nth(0)` on a `std::iter::Iterator`",
2352-
"try calling",
2351+
"called `.nth(0)` on a `std::iter::Iterator`, when `.next()` is equivalent",
2352+
"try calling `.next()` instead of `.nth(0)`",
23532353
format!("{}.next()", snippet_with_applicability(cx, nth_args[0].span, "..", &mut applicability)),
23542354
applicability,
23552355
);

tests/ui/iter_nth_zero.stderr

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
error: called `.nth(0)` on a `std::iter::Iterator`
1+
error: called `.nth(0)` on a `std::iter::Iterator`, when `.next()` is equivalent
22
--> $DIR/iter_nth_zero.rs:20:14
33
|
44
LL | let _x = s.iter().nth(0);
5-
| ^^^^^^^^^^^^^^^ help: try calling: `s.iter().next()`
5+
| ^^^^^^^^^^^^^^^ help: try calling `.next()` instead of `.nth(0)`: `s.iter().next()`
66
|
77
= note: `-D clippy::iter-nth-zero` implied by `-D warnings`
88

9-
error: called `.nth(0)` on a `std::iter::Iterator`
9+
error: called `.nth(0)` on a `std::iter::Iterator`, when `.next()` is equivalent
1010
--> $DIR/iter_nth_zero.rs:25:14
1111
|
1212
LL | let _y = iter.nth(0);
13-
| ^^^^^^^^^^^ help: try calling: `iter.next()`
13+
| ^^^^^^^^^^^ help: try calling `.next()` instead of `.nth(0)`: `iter.next()`
1414

15-
error: called `.nth(0)` on a `std::iter::Iterator`
15+
error: called `.nth(0)` on a `std::iter::Iterator`, when `.next()` is equivalent
1616
--> $DIR/iter_nth_zero.rs:30:22
1717
|
1818
LL | let _unwrapped = iter2.nth(0).unwrap();
19-
| ^^^^^^^^^^^^ help: try calling: `iter2.next()`
19+
| ^^^^^^^^^^^^ help: try calling `.next()` instead of `.nth(0)`: `iter2.next()`
2020

2121
error: aborting due to 3 previous errors
2222

0 commit comments

Comments
 (0)