-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
177 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#![warn(clippy::iter_next_slice)] | ||
|
||
fn main() { | ||
// test code goes here | ||
let s = [1, 2, 3]; | ||
let v = vec![1, 2, 3]; | ||
let o = Some(5); | ||
|
||
s.iter().next(); | ||
// Should be replaced by s.get(0) | ||
|
||
// s.into_iter().next(); | ||
// Probaby can rely on the default `array_into_iter`/`clippy::into_iter_on_ref` lint | ||
|
||
s[2..].iter().next(); | ||
// Should be replaced by s.get(2) | ||
|
||
// s[1..].into_iter().next(); | ||
// Probaby can rely on the default `clippy::into_iter_on_ref` lint | ||
|
||
v[5..].iter().next(); | ||
// Should be replaced by v.get(5) | ||
|
||
// v[1..].into_iter().next(); | ||
// Probaby can rely on the default `clippy::into_iter_on_ref` lint | ||
|
||
v.iter().next(); | ||
// Should be replaced by v.get(0) | ||
|
||
// v.into_iter().next(); | ||
// Tricky one—I don't think there's any other (short) way to say this (take ownership of first value) | ||
// So this should probably not get any warnings | ||
|
||
o.iter().next(); | ||
// Replace with o.as_ref() | ||
|
||
// o.into_iter().next(); | ||
// Replace with o | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
error: Using `.iter().next()` on an array | ||
--> $DIR/iter_next_slice.rs:9:5 | ||
| | ||
LL | s.iter().next(); | ||
| ^^^^^^^^^^^^^^^ help: try calling: `s.get(0)` | ||
| | ||
= note: `-D clippy::iter-next-slice` implied by `-D warnings` | ||
|
||
error: Using `.iter().next()` on a Slice without end index. | ||
--> $DIR/iter_next_slice.rs:15:5 | ||
| | ||
LL | s[2..].iter().next(); | ||
| ^^^^^^^^^^^^^^^^^^^^ help: try calling: `s.get(2)` | ||
|
||
error: Using `.iter().next()` on a Slice without end index. | ||
--> $DIR/iter_next_slice.rs:21:5 | ||
| | ||
LL | v[5..].iter().next(); | ||
| ^^^^^^^^^^^^^^^^^^^^ help: try calling: `v.get(5)` | ||
|
||
error: Using `.iter().next()` on an array | ||
--> $DIR/iter_next_slice.rs:27:5 | ||
| | ||
LL | v.iter().next(); | ||
| ^^^^^^^^^^^^^^^ help: try calling: `v.get(0)` | ||
|
||
error: aborting due to 4 previous errors | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters