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)]
12 // mapping to Option on Iterator
13 fn option_id(x: i8) -> Option<i8> {
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().filter_map(option_id).collect();
19 let _: Vec<_> = vec![5_i8; 6].into_iter().filter_map(option_id_ref).collect();
20 let _: Vec<_> = vec![5_i8; 6].into_iter().filter_map(option_id_closure).collect();
21 let _: Vec<_> = vec![5_i8; 6].into_iter().filter_map(|x| x.checked_add(1)).collect();
23 // mapping to Iterator on Iterator
24 let _: Vec<_> = vec![5_i8; 6].into_iter().flat_map(|x| 0..x).collect();
26 // mapping to Option on Option
27 let _: Option<_> = (Some(Some(1))).and_then(|x| x);
29 // mapping to Result on Result
30 let _: Result<_, &str> = (Ok(Ok(1))).and_then(|x| x);
37 let _ = [0u8, 1, 2, 3]
39 .flat_map(|n| match n {
53 #[allow(clippy::bind_instead_of_map)] // map + flatten will be suggested to `and_then`, but afterwards `map` is suggested again
54 #[rustfmt::skip] // whitespace is important for this one
56 std::collections::HashMap::<u32, u32>::new()
59 // we need some newlines
60 // so that the span is big enough
61 // for a split output of the diagnostic
63 // whitespace beforehand is important as well