diff options
| author | Philipp Krones <hello@philkrones.com> | 2020-08-04 12:06:39 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-08-04 12:06:39 +0200 |
| commit | 378ba2e03e192cbf3a416c151c6fe98e69375e25 (patch) | |
| tree | aca648d6e6706cdfd713850b4cd01e05fab27467 /src/test/rustdoc-ui/coverage/json.rs | |
| parent | ca2a25d966de0007dea8676833da1c764c9d5e00 (diff) | |
| parent | d4ba561aafb501972f581c1f8e6d1885959f9306 (diff) | |
| download | rust-378ba2e03e192cbf3a416c151c6fe98e69375e25.tar.gz rust-378ba2e03e192cbf3a416c151c6fe98e69375e25.zip | |
Rollup merge of #5846 - dima74:map_flatten.map_to_option, r=flip1995
Handle mapping to Option in `map_flatten` lint
Fixes #4496
The existing [`map_flatten`](https://rust-lang.github.io/rust-clippy/master/index.html#map_flatten) lint suggests changing `expr.map(...).flatten()` to `expr.flat_map(...)` when `expr` is `Iterator`. This PR changes suggestion to `filter_map` instead of `flat_map` when mapping to `Option`, because it is more natural
Also here are some questions:
* If expression has type which implements `Iterator` trait (`match_trait_method(cx, expr, &paths::ITERATOR) == true`), how can I get type of iterator elements? Currently I use return type of closure inside `map`, but probably it is not good way
* I would like to change suggestion range to cover only `.map(...).flatten()`, that is from:
```
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
```
to
```
let _: Vec<_> = vec![5_i8; 6].into_iter().map(|x| 0..x).flatten().collect();
^^^^^^^^^^^^^^^^^^^^^^^^ help: try using `flat_map` instead: `.flat_map(|x| 0..x)`
```
Is it ok?
* Is `map_flatten` lint intentionally in `pedantic` category, or could it be moved to `complexity`?
changelog: Handle mapping to Option in [`map_flatten`](https://rust-lang.github.io/rust-clippy/master/index.html#map_flatten) lint
Diffstat (limited to 'src/test/rustdoc-ui/coverage/json.rs')
0 files changed, 0 insertions, 0 deletions
