]> git.lizzy.rs Git - rust.git/blob - tests/ui/result_map_unit_fn.rs
Adapt the *.stderr files of the ui-tests to the tool_lints
[rust.git] / tests / ui / result_map_unit_fn.rs
1 #![feature(tool_lints)]
2
3 #![feature(never_type)]
4 #![warn(clippy::result_map_unit_fn)]
5 #![allow(unused)]
6
7 fn do_nothing<T>(_: T) {}
8
9 fn diverge<T>(_: T) -> ! {
10     panic!()
11 }
12
13 fn plus_one(value: usize) -> usize {
14     value + 1
15 }
16
17 struct HasResult {
18     field: Result<usize, usize>,
19 }
20
21 impl HasResult {
22     fn do_result_nothing(self: &Self, value: usize) {}
23
24     fn do_result_plus_one(self: &Self, value: usize) -> usize {
25         value + 1
26     }
27 }
28
29 fn 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     x.field.map(do_nothing);
36
37     x.field.map(do_nothing);
38
39     x.field.map(diverge);
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     x.field.map(|value| x.do_result_nothing(value + captured));
46
47     x.field.map(|value| { x.do_result_plus_one(value + captured); });
48
49
50     x.field.map(|value| do_nothing(value + captured));
51
52     x.field.map(|value| { do_nothing(value + captured) });
53
54     x.field.map(|value| { do_nothing(value + captured); });
55
56     x.field.map(|value| { { do_nothing(value + captured); } });
57
58
59     x.field.map(|value| diverge(value + captured));
60
61     x.field.map(|value| { diverge(value + captured) });
62
63     x.field.map(|value| { diverge(value + captured); });
64
65     x.field.map(|value| { { diverge(value + captured); } });
66
67
68     x.field.map(|value| plus_one(value + captured));
69     x.field.map(|value| { plus_one(value + captured) });
70     x.field.map(|value| { let y = plus_one(value + captured); });
71
72     x.field.map(|value| { plus_one(value + captured); });
73
74     x.field.map(|value| { { plus_one(value + captured); } });
75
76
77     x.field.map(|ref value| { do_nothing(value + captured) });
78
79
80     x.field.map(|value| { do_nothing(value); do_nothing(value) });
81
82     x.field.map(|value| if value > 0 { do_nothing(value); do_nothing(value) });
83
84     // Suggestion for the let block should be `{ ... }` as it's too difficult to build a
85     // proper suggestion for these cases
86     x.field.map(|value| {
87         do_nothing(value);
88         do_nothing(value)
89     });
90     x.field.map(|value| { do_nothing(value); do_nothing(value); });
91
92     // The following should suggest `if let Ok(_X) ...` as it's difficult to generate a proper let variable name for them
93     let res: Result<!, usize> = Ok(42).map(diverge);
94     "12".parse::<i32>().map(diverge);
95
96     let res: Result<(), usize> = Ok(plus_one(1)).map(do_nothing);
97
98     // Should suggest `if let Ok(_y) ...` to not override the existing foo variable
99     let y: Result<usize, usize> = Ok(42);
100     y.map(do_nothing);
101 }
102
103 fn main() {
104 }
105