]> git.lizzy.rs Git - rust.git/blob - tests/ui/option_if_let_else.stderr
clippy_lint: Allow 'ref_option_ref' for 'option_if_let_else'
[rust.git] / tests / ui / option_if_let_else.stderr
1 error: use Option::map_or instead of an if let/else
2   --> $DIR/option_if_let_else.rs:7:5
3    |
4 LL | /     if let Some(x) = string {
5 LL | |         (true, x)
6 LL | |     } else {
7 LL | |         (false, "hello")
8 LL | |     }
9    | |_____^ help: try: `string.map_or((false, "hello"), |x| (true, x))`
10    |
11    = note: `-D clippy::option-if-let-else` implied by `-D warnings`
12
13 error: use Option::map_or instead of an if let/else
14   --> $DIR/option_if_let_else.rs:17:12
15    |
16 LL |       } else if let Some(x) = string {
17    |  ____________^
18 LL | |         Some((true, x))
19 LL | |     } else {
20 LL | |         Some((false, ""))
21 LL | |     }
22    | |_____^ help: try: `{ string.map_or(Some((false, "")), |x| Some((true, x))) }`
23
24 error: use Option::map_or instead of an if let/else
25   --> $DIR/option_if_let_else.rs:25:13
26    |
27 LL |     let _ = if let Some(s) = *string { s.len() } else { 0 };
28    |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `string.map_or(0, |s| s.len())`
29
30 error: use Option::map_or instead of an if let/else
31   --> $DIR/option_if_let_else.rs:26:13
32    |
33 LL |     let _ = if let Some(s) = &num { s } else { &0 };
34    |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `num.as_ref().map_or(&0, |s| s)`
35
36 error: use Option::map_or instead of an if let/else
37   --> $DIR/option_if_let_else.rs:27:13
38    |
39 LL |       let _ = if let Some(s) = &mut num {
40    |  _____________^
41 LL | |         *s += 1;
42 LL | |         s
43 LL | |     } else {
44 LL | |         &mut 0
45 LL | |     };
46    | |_____^
47    |
48 help: try
49    |
50 LL |     let _ = num.as_mut().map_or(&mut 0, |s| {
51 LL |         *s += 1;
52 LL |         s
53 LL |     });
54    |
55
56 error: use Option::map_or instead of an if let/else
57   --> $DIR/option_if_let_else.rs:33:13
58    |
59 LL |     let _ = if let Some(ref s) = num { s } else { &0 };
60    |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `num.as_ref().map_or(&0, |s| s)`
61
62 error: use Option::map_or instead of an if let/else
63   --> $DIR/option_if_let_else.rs:34:13
64    |
65 LL |       let _ = if let Some(mut s) = num {
66    |  _____________^
67 LL | |         s += 1;
68 LL | |         s
69 LL | |     } else {
70 LL | |         0
71 LL | |     };
72    | |_____^
73    |
74 help: try
75    |
76 LL |     let _ = num.map_or(0, |mut s| {
77 LL |         s += 1;
78 LL |         s
79 LL |     });
80    |
81
82 error: use Option::map_or instead of an if let/else
83   --> $DIR/option_if_let_else.rs:40:13
84    |
85 LL |       let _ = if let Some(ref mut s) = num {
86    |  _____________^
87 LL | |         *s += 1;
88 LL | |         s
89 LL | |     } else {
90 LL | |         &mut 0
91 LL | |     };
92    | |_____^
93    |
94 help: try
95    |
96 LL |     let _ = num.as_mut().map_or(&mut 0, |s| {
97 LL |         *s += 1;
98 LL |         s
99 LL |     });
100    |
101
102 error: use Option::map_or instead of an if let/else
103   --> $DIR/option_if_let_else.rs:49:5
104    |
105 LL | /     if let Some(x) = arg {
106 LL | |         let y = x * x;
107 LL | |         y * y
108 LL | |     } else {
109 LL | |         13
110 LL | |     }
111    | |_____^
112    |
113 help: try
114    |
115 LL |     arg.map_or(13, |x| {
116 LL |         let y = x * x;
117 LL |         y * y
118 LL |     })
119    |
120
121 error: use Option::map_or_else instead of an if let/else
122   --> $DIR/option_if_let_else.rs:62:13
123    |
124 LL |       let _ = if let Some(x) = arg {
125    |  _____________^
126 LL | |         x
127 LL | |     } else {
128 LL | |         // map_or_else must be suggested
129 LL | |         side_effect()
130 LL | |     };
131    | |_____^ help: try: `arg.map_or_else(|| side_effect(), |x| x)`
132
133 error: use Option::map_or_else instead of an if let/else
134   --> $DIR/option_if_let_else.rs:71:13
135    |
136 LL |       let _ = if let Some(x) = arg {
137    |  _____________^
138 LL | |         x * x * x * x
139 LL | |     } else {
140 LL | |         let mut y = 1;
141 ...  |
142 LL | |         y
143 LL | |     };
144    | |_____^
145    |
146 help: try
147    |
148 LL |     let _ = arg.map_or_else(|| {
149 LL |         let mut y = 1;
150 LL |         y = (y + 2 / y) / 2;
151 LL |         y = (y + 2 / y) / 2;
152 LL |         y
153 LL |     }, |x| x * x * x * x);
154    |
155
156 error: use Option::map_or instead of an if let/else
157   --> $DIR/option_if_let_else.rs:100:13
158    |
159 LL |     let _ = if let Some(x) = optional { x + 2 } else { 5 };
160    |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `optional.map_or(5, |x| x + 2)`
161
162 error: aborting due to 12 previous errors
163