]> git.lizzy.rs Git - rust.git/blob - tests/ui/map_flatten.rs
Merge commit '09bd400243ed6f7059fedc0c1623aae3792521d6' into clippyup
[rust.git] / tests / ui / map_flatten.rs
1 // run-rustfix
2
3 #![warn(clippy::all, clippy::pedantic)]
4 #![allow(clippy::missing_docs_in_private_items)]
5 #![allow(clippy::map_identity)]
6
7 fn main() {
8     // mapping to Option on Iterator
9     fn option_id(x: i8) -> Option<i8> {
10         Some(x)
11     }
12     let option_id_ref: fn(i8) -> Option<i8> = option_id;
13     let option_id_closure = |x| Some(x);
14     let _: Vec<_> = vec![5_i8; 6].into_iter().map(option_id).flatten().collect();
15     let _: Vec<_> = vec![5_i8; 6].into_iter().map(option_id_ref).flatten().collect();
16     let _: Vec<_> = vec![5_i8; 6].into_iter().map(option_id_closure).flatten().collect();
17     let _: Vec<_> = vec![5_i8; 6].into_iter().map(|x| x.checked_add(1)).flatten().collect();
18
19     // mapping to Iterator on Iterator
20     let _: Vec<_> = vec![5_i8; 6].into_iter().map(|x| 0..x).flatten().collect();
21
22     // mapping to Option on Option
23     let _: Option<_> = (Some(Some(1))).map(|x| x).flatten();
24 }