blob: 7d47ee09dc1acfdac5e5932713fff966412fab88 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
#![warn(clippy::map_flatten)]
#![feature(result_flattening)]
// issue #8506, multi-line
#[rustfmt::skip]
fn long_span() {
let _: Option<i32> = Some(1)
.map(|x| {
if x <= 5 {
Some(x)
} else {
None
}
})
.flatten();
let _: Result<i32, i32> = Ok(1)
.map(|x| {
if x == 1 {
Ok(x)
} else {
Err(0)
}
})
.flatten();
let result: Result<i32, i32> = Ok(2);
fn do_something() { }
let _: Result<i32, i32> = result
.map(|res| {
if res > 0 {
do_something();
Ok(res)
} else {
Err(0)
}
})
.flatten();
let _: Vec<_> = vec![5_i8; 6]
.into_iter()
.map(|some_value| {
if some_value > 3 {
Some(some_value)
} else {
None
}
})
.flatten()
.collect();
}
fn main() {
long_span();
}
|