rust-lang / rust-lang/rust-clippy
map_flatten: suggest just `flatten` where `map(|a| a.into_iter()).flatten()`
Open
Nobody has claimed this yet.
C-enhancement
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
Description
map_flatten could suggest flatten() on map(|a| a.into_iter()).flatten() instead of flat_map(|b| b.into_iter()).
Example:
use bytes::Bytes;
pub fn flatten_bytes_seq(bytes_collection: Vec<Bytes>) -> Bytes {
bytes_collection.into_iter().map(|b| b.into_iter()).flatten().collect()
}
can be
use bytes::Bytes;
pub fn flatten_bytes_seq(bytes_collection: Vec<Bytes>) -> Bytes {
bytes_collection.into_iter().flatten().collect()
}
version: 1.75.0 on playground
Version
No response
Additional Labels
@rustbot label +C-enhancement
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating the map_flatten lint and its existing tests in rust-clippy. Add coverage for the map(|a| a.into_iter()).flatten() pattern and verify that the lint suggests flatten() while preserving the intended behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100