-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Fixes manual_flatten
removes the useless if let
#14861
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
Open
donkomura
wants to merge
5
commits into
rust-lang:master
Choose a base branch
from
donkomura:manual_flatten_snippet
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
ac06a73
flatten and remove the if let pat
donkomura f25207a
replace for pat to if_let pat
donkomura 029bde5
remove no-rustfix
donkomura f4242ee
do not trigger macro expansions
donkomura d4b1e62
applicability: MachineApplicable if the suggestion is complete, other…
donkomura File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
---|---|---|
@@ -1,18 +1,15 @@ | ||
error: unnecessary `if let` since only the `Some` variant of the iterator element is used | ||
--> tests/ui/manual_flatten.rs:7:5 | ||
| | ||
LL | for n in x { | ||
| ^ - help: try: `x.into_iter().flatten()` | ||
| _____| | ||
| | | ||
LL | / for n in x { | ||
LL | | | ||
LL | | | ||
LL | | if let Some(y) = n { | ||
... | | ||
LL | | } | ||
| |_____^ | ||
| | ||
help: ...and remove the `if let` statement in the for loop | ||
help: try `.flatten()` and remove the `if let` statement in the for loop | ||
--> tests/ui/manual_flatten.rs:10:9 | ||
| | ||
LL | / if let Some(y) = n { | ||
|
@@ -21,14 +18,17 @@ LL | | } | |
| |_________^ | ||
= note: `-D clippy::manual-flatten` implied by `-D warnings` | ||
= help: to override `-D warnings` add `#[allow(clippy::manual_flatten)]` | ||
help: try | ||
| | ||
LL ~ for y in x.into_iter().flatten() { | ||
LL + println!("{}", y); | ||
LL + } | ||
| | ||
|
||
error: unnecessary `if let` since only the `Ok` variant of the iterator element is used | ||
--> tests/ui/manual_flatten.rs:17:5 | ||
| | ||
LL | for n in y.clone() { | ||
| ^ --------- help: try: `y.clone().into_iter().flatten()` | ||
| _____| | ||
| | | ||
LL | / for n in y.clone() { | ||
LL | | | ||
LL | | | ||
LL | | if let Ok(n) = n { | ||
|
@@ -37,145 +37,169 @@ LL | | }; | |
LL | | } | ||
| |_____^ | ||
| | ||
help: ...and remove the `if let` statement in the for loop | ||
help: try `.flatten()` and remove the `if let` statement in the for loop | ||
--> tests/ui/manual_flatten.rs:20:9 | ||
| | ||
LL | / if let Ok(n) = n { | ||
LL | | println!("{}", n); | ||
LL | | }; | ||
| |_________^ | ||
help: try | ||
| | ||
LL ~ for n in y.clone().into_iter().flatten() { | ||
LL + println!("{}", n); | ||
LL + } | ||
| | ||
|
||
error: unnecessary `if let` since only the `Ok` variant of the iterator element is used | ||
--> tests/ui/manual_flatten.rs:26:5 | ||
| | ||
LL | for n in &y { | ||
| ^ -- help: try: `y.iter().flatten()` | ||
| _____| | ||
| | | ||
LL | / for n in &y { | ||
LL | | | ||
LL | | | ||
LL | | if let Ok(n) = n { | ||
... | | ||
LL | | } | ||
| |_____^ | ||
| | ||
help: ...and remove the `if let` statement in the for loop | ||
help: try `.flatten()` and remove the `if let` statement in the for loop | ||
--> tests/ui/manual_flatten.rs:29:9 | ||
| | ||
LL | / if let Ok(n) = n { | ||
LL | | println!("{}", n); | ||
LL | | } | ||
| |_________^ | ||
help: try | ||
| | ||
LL ~ for n in y.iter().flatten() { | ||
LL + println!("{}", n); | ||
LL + } | ||
| | ||
|
||
error: unnecessary `if let` since only the `Ok` variant of the iterator element is used | ||
--> tests/ui/manual_flatten.rs:36:5 | ||
| | ||
LL | for n in z { | ||
| ^ - help: try: `z.iter().flatten()` | ||
| _____| | ||
| | | ||
LL | / for n in z { | ||
LL | | | ||
LL | | | ||
LL | | if let Ok(n) = n { | ||
... | | ||
LL | | } | ||
| |_____^ | ||
| | ||
help: ...and remove the `if let` statement in the for loop | ||
help: try `.flatten()` and remove the `if let` statement in the for loop | ||
--> tests/ui/manual_flatten.rs:39:9 | ||
| | ||
LL | / if let Ok(n) = n { | ||
LL | | println!("{}", n); | ||
LL | | } | ||
| |_________^ | ||
help: try | ||
| | ||
LL ~ for n in z.iter().flatten() { | ||
LL + println!("{}", n); | ||
LL + } | ||
| | ||
|
||
error: unnecessary `if let` since only the `Some` variant of the iterator element is used | ||
--> tests/ui/manual_flatten.rs:47:5 | ||
| | ||
LL | for n in z { | ||
| ^ - help: try: `z.flatten()` | ||
| _____| | ||
| | | ||
LL | / for n in z { | ||
LL | | | ||
LL | | | ||
LL | | if let Some(m) = n { | ||
... | | ||
LL | | } | ||
| |_____^ | ||
| | ||
help: ...and remove the `if let` statement in the for loop | ||
help: try `.flatten()` and remove the `if let` statement in the for loop | ||
--> tests/ui/manual_flatten.rs:50:9 | ||
| | ||
LL | / if let Some(m) = n { | ||
LL | | println!("{}", m); | ||
LL | | } | ||
| |_________^ | ||
help: try | ||
| | ||
LL ~ for m in z.flatten() { | ||
LL + println!("{}", m); | ||
LL + } | ||
Comment on lines
+124
to
+126
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. I'd fixed it to out valid code. |
||
| | ||
|
||
error: unnecessary `if let` since only the `Some` variant of the iterator element is used | ||
--> tests/ui/manual_flatten.rs:82:5 | ||
| | ||
LL | for n in &vec_of_ref { | ||
| ^ ----------- help: try: `vec_of_ref.iter().copied().flatten()` | ||
| _____| | ||
| | | ||
LL | / for n in &vec_of_ref { | ||
LL | | | ||
LL | | | ||
LL | | if let Some(n) = n { | ||
... | | ||
LL | | } | ||
| |_____^ | ||
| | ||
help: ...and remove the `if let` statement in the for loop | ||
help: try `.flatten()` and remove the `if let` statement in the for loop | ||
--> tests/ui/manual_flatten.rs:85:9 | ||
| | ||
LL | / if let Some(n) = n { | ||
LL | | println!("{:?}", n); | ||
LL | | } | ||
| |_________^ | ||
help: try | ||
| | ||
LL ~ for n in vec_of_ref.iter().copied().flatten() { | ||
LL + println!("{:?}", n); | ||
LL + } | ||
| | ||
|
||
error: unnecessary `if let` since only the `Some` variant of the iterator element is used | ||
--> tests/ui/manual_flatten.rs:91:5 | ||
| | ||
LL | for n in vec_of_ref { | ||
| ^ ---------- help: try: `vec_of_ref.iter().copied().flatten()` | ||
| _____| | ||
| | | ||
LL | / for n in vec_of_ref { | ||
LL | | | ||
LL | | | ||
LL | | if let Some(n) = n { | ||
... | | ||
LL | | } | ||
| |_____^ | ||
| | ||
help: ...and remove the `if let` statement in the for loop | ||
help: try `.flatten()` and remove the `if let` statement in the for loop | ||
--> tests/ui/manual_flatten.rs:94:9 | ||
| | ||
LL | / if let Some(n) = n { | ||
LL | | println!("{:?}", n); | ||
LL | | } | ||
| |_________^ | ||
help: try | ||
| | ||
LL ~ for n in vec_of_ref.iter().copied().flatten() { | ||
LL + println!("{:?}", n); | ||
LL + } | ||
| | ||
|
||
error: unnecessary `if let` since only the `Some` variant of the iterator element is used | ||
--> tests/ui/manual_flatten.rs:100:5 | ||
| | ||
LL | for n in slice_of_ref { | ||
| ^ ------------ help: try: `slice_of_ref.iter().copied().flatten()` | ||
| _____| | ||
| | | ||
LL | / for n in slice_of_ref { | ||
LL | | | ||
LL | | | ||
LL | | if let Some(n) = n { | ||
... | | ||
LL | | } | ||
| |_____^ | ||
| | ||
help: ...and remove the `if let` statement in the for loop | ||
help: try `.flatten()` and remove the `if let` statement in the for loop | ||
--> tests/ui/manual_flatten.rs:103:9 | ||
| | ||
LL | / if let Some(n) = n { | ||
LL | | println!("{:?}", n); | ||
LL | | } | ||
| |_________^ | ||
help: try | ||
| | ||
LL ~ for n in slice_of_ref.iter().copied().flatten() { | ||
LL + println!("{:?}", n); | ||
LL + } | ||
| | ||
|
||
error: unnecessary `if let` since only the `Some` variant of the iterator element is used | ||
--> tests/ui/manual_flatten.rs:132:5 | ||
|
@@ -188,7 +212,7 @@ LL | | Some(1), | |
LL | | } | ||
| |_____^ | ||
| | ||
help: remove the `if let` statement in the for loop and then... | ||
help: try `.flatten()` and remove the `if let` statement in the for loop | ||
--> tests/ui/manual_flatten.rs:139:9 | ||
| | ||
LL | / if let Some(n) = n { | ||
|
@@ -201,6 +225,8 @@ LL | for n in vec![ | |
... | ||
LL | Some(3) | ||
LL ~ ].iter().flatten() { | ||
LL + println!("{:?}", n); | ||
LL + } | ||
| | ||
|
||
error: aborting due to 9 previous errors | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't you initialize
applicability
withMachineApplicable
if the suggestion is complete?