blob: 5dcc6464ff5f37f1bfb5e4bd4c2592b01bc500ea (
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
#![warn(clippy::option_map_unit_fn)]
#![allow(unused)]
#![allow(clippy::uninlined_format_args, clippy::unnecessary_wraps)]
fn do_nothing<T>(_: T) {}
fn diverge<T>(_: T) -> ! {
panic!()
}
fn plus_one(value: usize) -> usize {
value + 1
}
fn option() -> Option<usize> {
Some(10)
}
struct HasOption {
field: Option<usize>,
}
impl HasOption {
fn do_option_nothing(&self, value: usize) {}
fn do_option_plus_one(&self, value: usize) -> usize {
value + 1
}
}
#[rustfmt::skip]
fn option_map_unit_fn() {
let x = HasOption { field: Some(10) };
x.field.map(plus_one);
let _ : Option<()> = x.field.map(do_nothing);
if let Some(x_field) = x.field { do_nothing(x_field) }
if let Some(x_field) = x.field { do_nothing(x_field) }
if let Some(x_field) = x.field { diverge(x_field) }
let captured = 10;
if let Some(value) = x.field { do_nothing(value + captured) };
let _ : Option<()> = x.field.map(|value| do_nothing(value + captured));
if let Some(value) = x.field { x.do_option_nothing(value + captured) }
if let Some(value) = x.field { x.do_option_plus_one(value + captured); }
if let Some(value) = x.field { do_nothing(value + captured) }
if let Some(value) = x.field { do_nothing(value + captured) }
if let Some(value) = x.field { do_nothing(value + captured); }
if let Some(value) = x.field { do_nothing(value + captured); }
if let Some(value) = x.field { diverge(value + captured) }
if let Some(value) = x.field { diverge(value + captured) }
if let Some(value) = x.field { diverge(value + captured); }
if let Some(value) = x.field { diverge(value + captured); }
x.field.map(|value| plus_one(value + captured));
x.field.map(|value| { plus_one(value + captured) });
if let Some(value) = x.field { let y = plus_one(value + captured); }
if let Some(value) = x.field { plus_one(value + captured); }
if let Some(value) = x.field { plus_one(value + captured); }
if let Some(ref value) = x.field { do_nothing(value + captured) }
if let Some(a) = option() { do_nothing(a) }
if let Some(value) = option() { println!("{:?}", value) }
}
fn main() {}
|