Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve advice in iter_nth_zero #5793

Merged
merged 2 commits into from
Jul 14, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions clippy_lints/src/methods/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT:

Suggested change
"try calling .next() instead of .nth(0)",
"try calling `.next()` instead of `.nth(0)`",

(remember to also update the stderr files after this change)

format!("{}.next()", snippet_with_applicability(cx, nth_args[0].span, "..", &mut applicability)),
applicability,
);
Expand Down
12 changes: 6 additions & 6 deletions tests/ui/iter_nth_zero.stderr
Original file line number Diff line number Diff line change
@@ -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