diff options
| author | Jane Lusby <jlusby42@gmail.com> | 2018-09-21 00:26:38 -0700 |
|---|---|---|
| committer | Jane Lusby <jlusby42@gmail.com> | 2018-09-24 14:29:16 -0700 |
| commit | 14feb3670f4e1e5ff759253b9dc86cfbb29ff8a5 (patch) | |
| tree | eb3301c3073db80eb1b01a25cb72e4b9e97e3ebe /tests | |
| parent | 417cf206cace45cc656f9a605221017e4fe4ef94 (diff) | |
| download | rust-14feb3670f4e1e5ff759253b9dc86cfbb29ff8a5.tar.gz rust-14feb3670f4e1e5ff759253b9dc86cfbb29ff8a5.zip | |
Lint for chaining flatten after map
This change adds a lint to check for instances of `map(..).flatten()` that can be trivially shortened to `flat_map(..)` Closes #3196
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/ui/map_flatten.rs | 7 | ||||
| -rw-r--r-- | tests/ui/map_flatten.stderr | 10 |
2 files changed, 17 insertions, 0 deletions
diff --git a/tests/ui/map_flatten.rs b/tests/ui/map_flatten.rs new file mode 100644 index 00000000000..c5cf24d9bb0 --- /dev/null +++ b/tests/ui/map_flatten.rs @@ -0,0 +1,7 @@ +#![feature(tool_lints)] +#![warn(clippy::all, clippy::pedantic)] +#![allow(clippy::missing_docs_in_private_items)] + +fn main() { + let _: Vec<_> = vec![5_i8; 6].into_iter().map(|x| 0..x).flatten().collect(); +} diff --git a/tests/ui/map_flatten.stderr b/tests/ui/map_flatten.stderr new file mode 100644 index 00000000000..d4ce44490d1 --- /dev/null +++ b/tests/ui/map_flatten.stderr @@ -0,0 +1,10 @@ +error: called `map(..).flatten()` on an `Iterator`. This is more succinctly expressed by calling `.flat_map(..)` + --> $DIR/map_flatten.rs:6:21 + | +6 | let _: Vec<_> = vec![5_i8; 6].into_iter().map(|x| 0..x).flatten().collect(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using flat_map instead: `vec![5_i8; 6].into_iter().flat_map(|x| 0..x)` + | + = note: `-D clippy::map-flatten` implied by `-D warnings` + +error: aborting due to previous error + |
