]> git.proxmox.com Git - rustc.git/blob - src/tools/clippy/tests/ui/option_if_let_else.stderr
New upstream version 1.72.1+dfsg1
[rustc.git] / src / tools / clippy / 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:12: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:30:13
15 |
16 LL | let _ = if let Some(s) = *string { s.len() } else { 0 };
17 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `string.map_or(0, |s| s.len())`
18
19 error: use Option::map_or instead of an if let/else
20 --> $DIR/option_if_let_else.rs:31:13
21 |
22 LL | let _ = if let Some(s) = &num { s } else { &0 };
23 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `num.as_ref().map_or(&0, |s| s)`
24
25 error: use Option::map_or instead of an if let/else
26 --> $DIR/option_if_let_else.rs:32:13
27 |
28 LL | let _ = if let Some(s) = &mut num {
29 | _____________^
30 LL | | *s += 1;
31 LL | | s
32 LL | | } else {
33 LL | | &0
34 LL | | };
35 | |_____^
36 |
37 help: try
38 |
39 LL ~ let _ = num.as_mut().map_or(&0, |s| {
40 LL + *s += 1;
41 LL + s
42 LL ~ });
43 |
44
45 error: use Option::map_or instead of an if let/else
46 --> $DIR/option_if_let_else.rs:38:13
47 |
48 LL | let _ = if let Some(ref s) = num { s } else { &0 };
49 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `num.as_ref().map_or(&0, |s| s)`
50
51 error: use Option::map_or instead of an if let/else
52 --> $DIR/option_if_let_else.rs:39:13
53 |
54 LL | let _ = if let Some(mut s) = num {
55 | _____________^
56 LL | | s += 1;
57 LL | | s
58 LL | | } else {
59 LL | | 0
60 LL | | };
61 | |_____^
62 |
63 help: try
64 |
65 LL ~ let _ = num.map_or(0, |mut s| {
66 LL + s += 1;
67 LL + s
68 LL ~ });
69 |
70
71 error: use Option::map_or instead of an if let/else
72 --> $DIR/option_if_let_else.rs:45:13
73 |
74 LL | let _ = if let Some(ref mut s) = num {
75 | _____________^
76 LL | | *s += 1;
77 LL | | s
78 LL | | } else {
79 LL | | &0
80 LL | | };
81 | |_____^
82 |
83 help: try
84 |
85 LL ~ let _ = num.as_mut().map_or(&0, |s| {
86 LL + *s += 1;
87 LL + s
88 LL ~ });
89 |
90
91 error: use Option::map_or instead of an if let/else
92 --> $DIR/option_if_let_else.rs:54:5
93 |
94 LL | / if let Some(x) = arg {
95 LL | | let y = x * x;
96 LL | | y * y
97 LL | | } else {
98 LL | | 13
99 LL | | }
100 | |_____^
101 |
102 help: try
103 |
104 LL ~ arg.map_or(13, |x| {
105 LL + let y = x * x;
106 LL + y * y
107 LL + })
108 |
109
110 error: use Option::map_or_else instead of an if let/else
111 --> $DIR/option_if_let_else.rs:67:13
112 |
113 LL | let _ = if let Some(x) = arg {
114 | _____________^
115 LL | | x
116 LL | | } else {
117 LL | | // map_or_else must be suggested
118 LL | | side_effect()
119 LL | | };
120 | |_____^ help: try: `arg.map_or_else(|| side_effect(), |x| x)`
121
122 error: use Option::map_or_else instead of an if let/else
123 --> $DIR/option_if_let_else.rs:76:13
124 |
125 LL | let _ = if let Some(x) = arg {
126 | _____________^
127 LL | | x * x * x * x
128 LL | | } else {
129 LL | | let mut y = 1;
130 ... |
131 LL | | y
132 LL | | };
133 | |_____^
134 |
135 help: try
136 |
137 LL ~ let _ = arg.map_or_else(|| {
138 LL + let mut y = 1;
139 LL + y = (y + 2 / y) / 2;
140 LL + y = (y + 2 / y) / 2;
141 LL + y
142 LL ~ }, |x| x * x * x * x);
143 |
144
145 error: use Option::map_or_else instead of an if let/else
146 --> $DIR/option_if_let_else.rs:109:13
147 |
148 LL | / if let Some(idx) = s.find('.') {
149 LL | | vec![s[..idx].to_string(), s[idx..].to_string()]
150 LL | | } else {
151 LL | | vec![s.to_string()]
152 LL | | }
153 | |_____________^ help: try: `s.find('.').map_or_else(|| vec![s.to_string()], |idx| vec![s[..idx].to_string(), s[idx..].to_string()])`
154
155 error: use Option::map_or_else instead of an if let/else
156 --> $DIR/option_if_let_else.rs:120:5
157 |
158 LL | / if let Ok(binding) = variable {
159 LL | | println!("Ok {binding}");
160 LL | | } else {
161 LL | | println!("Err");
162 LL | | }
163 | |_____^
164 |
165 help: try
166 |
167 LL ~ variable.map_or_else(|_| {
168 LL + println!("Err");
169 LL + }, |binding| {
170 LL + println!("Ok {binding}");
171 LL + })
172 |
173
174 error: use Option::map_or instead of an if let/else
175 --> $DIR/option_if_let_else.rs:142:13
176 |
177 LL | let _ = if let Some(x) = optional { x + 2 } else { 5 };
178 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `optional.map_or(5, |x| x + 2)`
179
180 error: use Option::map_or instead of an if let/else
181 --> $DIR/option_if_let_else.rs:152:13
182 |
183 LL | let _ = if let Some(x) = Some(0) {
184 | _____________^
185 LL | | loop {
186 LL | | if x == 0 {
187 LL | | break x;
188 ... |
189 LL | | 0
190 LL | | };
191 | |_____^
192 |
193 help: try
194 |
195 LL ~ let _ = Some(0).map_or(0, |x| loop {
196 LL + if x == 0 {
197 LL + break x;
198 LL + }
199 LL ~ });
200 |
201
202 error: use Option::map_or instead of an if let/else
203 --> $DIR/option_if_let_else.rs:180:13
204 |
205 LL | let _ = if let Some(x) = Some(0) { s.len() + x } else { s.len() };
206 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Some(0).map_or(s.len(), |x| s.len() + x)`
207
208 error: use Option::map_or instead of an if let/else
209 --> $DIR/option_if_let_else.rs:184:13
210 |
211 LL | let _ = if let Some(x) = Some(0) {
212 | _____________^
213 LL | | let s = s;
214 LL | | s.len() + x
215 LL | | } else {
216 LL | | 1
217 LL | | };
218 | |_____^
219 |
220 help: try
221 |
222 LL ~ let _ = Some(0).map_or(1, |x| {
223 LL + let s = s;
224 LL + s.len() + x
225 LL ~ });
226 |
227
228 error: use Option::map_or instead of an if let/else
229 --> $DIR/option_if_let_else.rs:223:13
230 |
231 LL | let _ = match s {
232 | _____________^
233 LL | | Some(string) => string.len(),
234 LL | | None => 1,
235 LL | | };
236 | |_____^ help: try: `s.map_or(1, |string| string.len())`
237
238 error: use Option::map_or instead of an if let/else
239 --> $DIR/option_if_let_else.rs:227:13
240 |
241 LL | let _ = match Some(10) {
242 | _____________^
243 LL | | Some(a) => a + 1,
244 LL | | None => 5,
245 LL | | };
246 | |_____^ help: try: `Some(10).map_or(5, |a| a + 1)`
247
248 error: use Option::map_or instead of an if let/else
249 --> $DIR/option_if_let_else.rs:233:13
250 |
251 LL | let _ = match res {
252 | _____________^
253 LL | | Ok(a) => a + 1,
254 LL | | _ => 1,
255 LL | | };
256 | |_____^ help: try: `res.map_or(1, |a| a + 1)`
257
258 error: use Option::map_or instead of an if let/else
259 --> $DIR/option_if_let_else.rs:237:13
260 |
261 LL | let _ = match res {
262 | _____________^
263 LL | | Err(_) => 1,
264 LL | | Ok(a) => a + 1,
265 LL | | };
266 | |_____^ help: try: `res.map_or(1, |a| a + 1)`
267
268 error: use Option::map_or instead of an if let/else
269 --> $DIR/option_if_let_else.rs:241:13
270 |
271 LL | let _ = if let Ok(a) = res { a + 1 } else { 5 };
272 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `res.map_or(5, |a| a + 1)`
273
274 error: use Option::map_or instead of an if let/else
275 --> $DIR/option_if_let_else.rs:258:9
276 |
277 LL | / match initial {
278 LL | | Some(value) => do_something(value),
279 LL | | None => {},
280 LL | | }
281 | |_________^ help: try: `initial.as_ref().map_or({}, |value| do_something(value))`
282
283 error: use Option::map_or instead of an if let/else
284 --> $DIR/option_if_let_else.rs:265:9
285 |
286 LL | / match initial {
287 LL | | Some(value) => do_something2(value),
288 LL | | None => {},
289 LL | | }
290 | |_________^ help: try: `initial.as_mut().map_or({}, |value| do_something2(value))`
291
292 error: aborting due to 23 previous errors
293