]> git.proxmox.com Git - rustc.git/blame - src/tools/clippy/tests/ui/result_map_unit_fn_fixable.fixed
Update upstream source from tag 'upstream/1.52.1+dfsg1'
[rustc.git] / src / tools / clippy / tests / ui / result_map_unit_fn_fixable.fixed
CommitLineData
f20569fa
XL
1// run-rustfix
2
3#![warn(clippy::result_map_unit_fn)]
4#![allow(unused)]
5
6fn do_nothing<T>(_: T) {}
7
8fn diverge<T>(_: T) -> ! {
9 panic!()
10}
11
12fn plus_one(value: usize) -> usize {
13 value + 1
14}
15
16struct HasResult {
17 field: Result<usize, usize>,
18}
19
20impl HasResult {
21 fn do_result_nothing(&self, value: usize) {}
22
23 fn do_result_plus_one(&self, value: usize) -> usize {
24 value + 1
25 }
26}
27
28#[rustfmt::skip]
29fn result_map_unit_fn() {
30 let x = HasResult { field: Ok(10) };
31
32 x.field.map(plus_one);
33 let _: Result<(), usize> = x.field.map(do_nothing);
34
35 if let Ok(x_field) = x.field { do_nothing(x_field) }
36
37 if let Ok(x_field) = x.field { do_nothing(x_field) }
38
39 if let Ok(x_field) = x.field { diverge(x_field) }
40
41 let captured = 10;
42 if let Ok(value) = x.field { do_nothing(value + captured) };
43 let _: Result<(), usize> = x.field.map(|value| do_nothing(value + captured));
44
45 if let Ok(value) = x.field { x.do_result_nothing(value + captured) }
46
47 if let Ok(value) = x.field { x.do_result_plus_one(value + captured); }
48
49
50 if let Ok(value) = x.field { do_nothing(value + captured) }
51
52 if let Ok(value) = x.field { do_nothing(value + captured) }
53
54 if let Ok(value) = x.field { do_nothing(value + captured); }
55
56 if let Ok(value) = x.field { do_nothing(value + captured); }
57
58
59 if let Ok(value) = x.field { diverge(value + captured) }
60
61 if let Ok(value) = x.field { diverge(value + captured) }
62
63 if let Ok(value) = x.field { diverge(value + captured); }
64
65 if let Ok(value) = x.field { diverge(value + captured); }
66
67
68 x.field.map(|value| plus_one(value + captured));
69 x.field.map(|value| { plus_one(value + captured) });
70 if let Ok(value) = x.field { let y = plus_one(value + captured); }
71
72 if let Ok(value) = x.field { plus_one(value + captured); }
73
74 if let Ok(value) = x.field { plus_one(value + captured); }
75
76
77 if let Ok(ref value) = x.field { do_nothing(value + captured) }
78}
79
80fn main() {}