-
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.
Auto merge of #5067 - JohnTitor:lint-skip-while-next, r=flip1995
Add `skip_while_next` lint Fixes #4036 changelog: Add `skip_while_next` lint
- Loading branch information
Showing
9 changed files
with
117 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// aux-build:option_helpers.rs | ||
|
||
#![warn(clippy::skip_while_next)] | ||
#![allow(clippy::blacklisted_name)] | ||
|
||
extern crate option_helpers; | ||
use option_helpers::IteratorFalsePositives; | ||
|
||
#[rustfmt::skip] | ||
fn skip_while_next() { | ||
let v = vec![3, 2, 1, 0, -1, -2, -3]; | ||
|
||
// Single-line case. | ||
let _ = v.iter().skip_while(|&x| *x < 0).next(); | ||
|
||
// Multi-line case. | ||
let _ = v.iter().skip_while(|&x| { | ||
*x < 0 | ||
} | ||
).next(); | ||
|
||
// Check that hat we don't lint if the caller is not an `Iterator`. | ||
let foo = IteratorFalsePositives { foo: 0 }; | ||
let _ = foo.skip_while().next(); | ||
} | ||
|
||
fn main() { | ||
skip_while_next(); | ||
} |
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,23 @@ | ||
error: called `skip_while(p).next()` on an `Iterator` | ||
--> $DIR/skip_while_next.rs:14:13 | ||
| | ||
LL | let _ = v.iter().skip_while(|&x| *x < 0).next(); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= note: `-D clippy::skip-while-next` implied by `-D warnings` | ||
= help: this is more succinctly expressed by calling `.find(!p)` instead | ||
|
||
error: called `skip_while(p).next()` on an `Iterator` | ||
--> $DIR/skip_while_next.rs:17:13 | ||
| | ||
LL | let _ = v.iter().skip_while(|&x| { | ||
| _____________^ | ||
LL | | *x < 0 | ||
LL | | } | ||
LL | | ).next(); | ||
| |___________________________^ | ||
| | ||
= help: this is more succinctly expressed by calling `.find(!p)` instead | ||
|
||
error: aborting due to 2 previous errors | ||
|