-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New lint: iter_next_slice #5597
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// run-rustfix | ||
#![warn(clippy::iter_next_slice)] | ||
|
||
fn main() { | ||
// test code goes here | ||
let s = [1, 2, 3]; | ||
let v = vec![1, 2, 3]; | ||
|
||
s.get(0); | ||
// Should be replaced by s.get(0) | ||
|
||
s.get(2); | ||
// Should be replaced by s.get(2) | ||
|
||
v.get(5); | ||
// Should be replaced by v.get(5) | ||
|
||
v.get(0); | ||
// Should be replaced by v.get(0) | ||
|
||
let o = Some(5); | ||
o.iter().next(); | ||
// Shouldn't be linted since this is not a Slice or an Array | ||
} |
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,24 @@ | ||||||||
// run-rustfix | ||||||||
#![warn(clippy::iter_next_slice)] | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
and a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay, I have added the However, the test failed at Clippy Test, cargo build stage. I'm not sure about the errors listed, is it about toolchain version incompatibility? Should I rebase this branch to the latest master? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You may have to rebase after #5665 is merged. In the meantime you could go ahead, remove the "WIP" prefixes from your commits and remove the "draft" status from this PR There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay, I have squashed all the commits into one, and have updated this PR status to Open. |
||||||||
|
||||||||
fn main() { | ||||||||
// test code goes here | ||||||||
let s = [1, 2, 3]; | ||||||||
let v = vec![1, 2, 3]; | ||||||||
|
||||||||
s.iter().next(); | ||||||||
// Should be replaced by s.get(0) | ||||||||
|
||||||||
s[2..].iter().next(); | ||||||||
// Should be replaced by s.get(2) | ||||||||
|
||||||||
v[5..].iter().next(); | ||||||||
// Should be replaced by v.get(5) | ||||||||
|
||||||||
v.iter().next(); | ||||||||
// Should be replaced by v.get(0) | ||||||||
|
||||||||
let o = Some(5); | ||||||||
o.iter().next(); | ||||||||
// Shouldn't be linted since this is not a Slice or an Array | ||||||||
} |
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:12: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:15:5 | ||
| | ||
LL | v[5..].iter().next(); | ||
| ^^^^^^^^^^^^^^^^^^^^ help: try calling: `v.get(5)` | ||
|
||
error: Using `.iter().next()` on an array | ||
--> $DIR/iter_next_slice.rs:18:5 | ||
| | ||
LL | v.iter().next(); | ||
| ^^^^^^^^^^^^^^^ help: try calling: `v.get(0)` | ||
|
||
error: aborting due to 4 previous errors | ||
|
Uh oh!
There was an error while loading. Please reload this page.