]> git.lizzy.rs Git - rust.git/blob - tests/ui/map_flatten.rs
Rollup merge of #92849 - flip1995:clippyup, r=Manishearth
[rust.git] / tests / ui / map_flatten.rs
1 // run-rustfix
2
3 #![warn(clippy::all, clippy::pedantic)]
4 #![allow(clippy::let_underscore_drop)]
5 #![allow(clippy::missing_docs_in_private_items)]
6 #![allow(clippy::map_identity)]
7 #![allow(clippy::redundant_closure)]
8 #![allow(clippy::unnecessary_wraps)]
9 #![feature(result_flattening)]
10
11 fn main() {
12     // mapping to Option on Iterator
13     fn option_id(x: i8) -> Option<i8> {
14         Some(x)
15     }
16     let option_id_ref: fn(i8) -> Option<i8> = option_id;
17     let option_id_closure = |x| Some(x);
18     let _: Vec<_> = vec![5_i8; 6].into_iter().map(option_id).flatten().collect();
19     let _: Vec<_> = vec![5_i8; 6].into_iter().map(option_id_ref).flatten().collect();
20     let _: Vec<_> = vec![5_i8; 6].into_iter().map(option_id_closure).flatten().collect();
21     let _: Vec<_> = vec![5_i8; 6].into_iter().map(|x| x.checked_add(1)).flatten().collect();
22
23     // mapping to Iterator on Iterator
24     let _: Vec<_> = vec![5_i8; 6].into_iter().map(|x| 0..x).flatten().collect();
25
26     // mapping to Option on Option
27     let _: Option<_> = (Some(Some(1))).map(|x| x).flatten();
28
29     // mapping to Result on Result
30     let _: Result<_, &str> = (Ok(Ok(1))).map(|x| x).flatten();
31 }