From 6c61f7106f2de290df22047cdb15de30a140543e Mon Sep 17 00:00:00 2001 From: Alex Macleod Date: Thu, 30 Jun 2022 10:13:54 +0000 Subject: [PATCH] Uncomment test for #8734 --- tests/ui/map_flatten_fixable.fixed | 29 +++++++++++++-------------- tests/ui/map_flatten_fixable.rs | 30 ++++++++++++++-------------- tests/ui/map_flatten_fixable.stderr | 31 ++++++++++++++++++++++++++++- 3 files changed, 59 insertions(+), 31 deletions(-) diff --git a/tests/ui/map_flatten_fixable.fixed b/tests/ui/map_flatten_fixable.fixed index e9b41354c58f..9097a6b99673 100644 --- a/tests/ui/map_flatten_fixable.fixed +++ b/tests/ui/map_flatten_fixable.fixed @@ -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 diff --git a/tests/ui/map_flatten_fixable.rs b/tests/ui/map_flatten_fixable.rs index 4345c6eee746..3916263404ac 100644 --- a/tests/ui/map_flatten_fixable.rs +++ b/tests/ui/map_flatten_fixable.rs @@ -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 diff --git a/tests/ui/map_flatten_fixable.stderr b/tests/ui/map_flatten_fixable.stderr index f3b82ad08d0f..afaf6af66b22 100644 --- a/tests/ui/map_flatten_fixable.stderr +++ b/tests/ui/map_flatten_fixable.stderr @@ -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 | @@ -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