Skip to content

Commit

Permalink
Auto merge of #9071 - Alexendoo:8734, r=dswij
Browse files Browse the repository at this point in the history
Uncomment test for #8734

I believe the issue was an interaction between rustfix and `span_lint_and_sugg_for_edges`, so this would've been fixed by rust-lang/rust#98261 (Thanks, `@WaffleLapkin!)`

Closes #8734

changelog: none
  • Loading branch information
bors committed Jun 30, 2022
2 parents 6206d2a + 6c61f71 commit 4198013
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 31 deletions.
29 changes: 14 additions & 15 deletions tests/ui/map_flatten_fixable.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,20 @@ fn main() {
}

fn issue8734() {
// let _ = [0u8, 1, 2, 3]
// .into_iter()
// .map(|n| match n {
// 1 => [n
// .saturating_add(1)
// .saturating_add(1)
// .saturating_add(1)
// .saturating_add(1)
// .saturating_add(1)
// .saturating_add(1)
// .saturating_add(1)
// .saturating_add(1)],
// n => [n],
// })
// .flatten();
let _ = [0u8, 1, 2, 3]
.into_iter()
.flat_map(|n| match n {
1 => [n
.saturating_add(1)
.saturating_add(1)
.saturating_add(1)
.saturating_add(1)
.saturating_add(1)
.saturating_add(1)
.saturating_add(1)
.saturating_add(1)],
n => [n],
});
}

#[allow(clippy::bind_instead_of_map)] // map + flatten will be suggested to `and_then`, but afterwards `map` is suggested again
Expand Down
30 changes: 15 additions & 15 deletions tests/ui/map_flatten_fixable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,21 @@ fn main() {
}

fn issue8734() {
// let _ = [0u8, 1, 2, 3]
// .into_iter()
// .map(|n| match n {
// 1 => [n
// .saturating_add(1)
// .saturating_add(1)
// .saturating_add(1)
// .saturating_add(1)
// .saturating_add(1)
// .saturating_add(1)
// .saturating_add(1)
// .saturating_add(1)],
// n => [n],
// })
// .flatten();
let _ = [0u8, 1, 2, 3]
.into_iter()
.map(|n| match n {
1 => [n
.saturating_add(1)
.saturating_add(1)
.saturating_add(1)
.saturating_add(1)
.saturating_add(1)
.saturating_add(1)
.saturating_add(1)
.saturating_add(1)],
n => [n],
})
.flatten();
}

#[allow(clippy::bind_instead_of_map)] // map + flatten will be suggested to `and_then`, but afterwards `map` is suggested again
Expand Down
31 changes: 30 additions & 1 deletion tests/ui/map_flatten_fixable.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,35 @@ error: called `map(..).flatten()` on `Result`
LL | let _: Result<_, &str> = (Ok(Ok(1))).map(|x| x).flatten();
| ^^^^^^^^^^^^^^^^^^^^ help: try replacing `map` with `and_then` and remove the `.flatten()`: `and_then(|x| x)`

error: called `map(..).flatten()` on `Iterator`
--> $DIR/map_flatten_fixable.rs:39:10
|
LL | .map(|n| match n {
| __________^
LL | | 1 => [n
LL | | .saturating_add(1)
LL | | .saturating_add(1)
... |
LL | | })
LL | | .flatten();
| |__________________^
|
help: try replacing `map` with `flat_map` and remove the `.flatten()`
|
LL ~ .flat_map(|n| match n {
LL + 1 => [n
LL + .saturating_add(1)
LL + .saturating_add(1)
LL + .saturating_add(1)
LL + .saturating_add(1)
LL + .saturating_add(1)
LL + .saturating_add(1)
LL + .saturating_add(1)
LL + .saturating_add(1)],
LL + n => [n],
LL ~ });
|

error: called `map(..).flatten()` on `Option`
--> $DIR/map_flatten_fixable.rs:59:10
|
Expand All @@ -66,5 +95,5 @@ LL + // whitespace beforehand is important as well
LL ~ });
|

error: aborting due to 8 previous errors
error: aborting due to 9 previous errors

0 comments on commit 4198013

Please sign in to comment.