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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
|
error: this block may be rewritten with the `?` operator
--> tests/ui/question_mark.rs:9:5
|
LL | / if a.is_none() {
LL | |
LL | | return None;
LL | | }
| |_____^ help: replace it with: `a?;`
|
= note: `-D clippy::question-mark` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::question_mark)]`
error: this block may be rewritten with the `?` operator
--> tests/ui/question_mark.rs:55:9
|
LL | / if (self.opt).is_none() {
LL | |
LL | | return None;
LL | | }
| |_________^ help: replace it with: `(self.opt)?;`
error: this block may be rewritten with the `?` operator
--> tests/ui/question_mark.rs:60:9
|
LL | / if self.opt.is_none() {
LL | |
LL | | return None
LL | | }
| |_________^ help: replace it with: `self.opt?;`
error: this block may be rewritten with the `?` operator
--> tests/ui/question_mark.rs:65:17
|
LL | let _ = if self.opt.is_none() {
| _________________^
LL | |
LL | | return None;
LL | | } else {
LL | | self.opt
LL | | };
| |_________^ help: replace it with: `Some(self.opt?)`
error: this block may be rewritten with the `?` operator
--> tests/ui/question_mark.rs:72:17
|
LL | let _ = if let Some(x) = self.opt {
| _________________^
LL | |
LL | | x
LL | | } else {
LL | | return None;
LL | | };
| |_________^ help: replace it with: `self.opt?`
error: this block may be rewritten with the `?` operator
--> tests/ui/question_mark.rs:90:9
|
LL | / if self.opt.is_none() {
LL | |
LL | | return None;
LL | | }
| |_________^ help: replace it with: `self.opt.as_ref()?;`
error: this block may be rewritten with the `?` operator
--> tests/ui/question_mark.rs:99:9
|
LL | / if self.opt.is_none() {
LL | |
LL | | return None;
LL | | }
| |_________^ help: replace it with: `self.opt.as_ref()?;`
error: this block may be rewritten with the `?` operator
--> tests/ui/question_mark.rs:108:9
|
LL | / if self.opt.is_none() {
LL | |
LL | | return None;
LL | | }
| |_________^ help: replace it with: `self.opt.as_ref()?;`
error: this block may be rewritten with the `?` operator
--> tests/ui/question_mark.rs:116:26
|
LL | let v: &Vec<_> = if let Some(ref v) = self.opt {
| __________________________^
LL | |
LL | | v
LL | | } else {
LL | | return None;
LL | | };
| |_________^ help: replace it with: `self.opt.as_ref()?`
error: this block may be rewritten with the `?` operator
--> tests/ui/question_mark.rs:127:17
|
LL | let v = if let Some(v) = self.opt {
| _________________^
LL | |
LL | | v
LL | | } else {
LL | | return None;
LL | | };
| |_________^ help: replace it with: `self.opt?`
error: this block may be rewritten with the `?` operator
--> tests/ui/question_mark.rs:149:5
|
LL | / if f().is_none() {
LL | |
LL | | return None;
LL | | }
| |_____^ help: replace it with: `f()?;`
error: this `match` expression can be replaced with `?`
--> tests/ui/question_mark.rs:154:16
|
LL | let _val = match f() {
| ________________^
LL | |
LL | | Some(val) => val,
LL | | None => return None,
LL | | };
| |_____^ help: try instead: `f()?`
error: this `match` expression can be replaced with `?`
--> tests/ui/question_mark.rs:165:5
|
LL | / match f() {
LL | |
LL | | Some(val) => val,
LL | | None => return None,
LL | | };
| |_____^ help: try instead: `f()?`
error: this `match` expression can be replaced with `?`
--> tests/ui/question_mark.rs:171:5
|
LL | / match opt_none!() {
LL | |
LL | | Some(x) => x,
LL | | None => return None,
LL | | };
| |_____^ help: try instead: `opt_none!()?`
error: this block may be rewritten with the `?` operator
--> tests/ui/question_mark.rs:198:13
|
LL | let _ = if let Ok(x) = x { x } else { return x };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `x?`
error: this block may be rewritten with the `?` operator
--> tests/ui/question_mark.rs:201:5
|
LL | / if x.is_err() {
LL | |
LL | | return x;
LL | | }
| |_____^ help: replace it with: `x?;`
error: this `match` expression can be replaced with `?`
--> tests/ui/question_mark.rs:206:16
|
LL | let _val = match func_returning_result() {
| ________________^
LL | |
LL | | Ok(val) => val,
LL | | Err(err) => return Err(err),
LL | | };
| |_____^ help: try instead: `func_returning_result()?`
error: this `match` expression can be replaced with `?`
--> tests/ui/question_mark.rs:212:5
|
LL | / match func_returning_result() {
LL | |
LL | | Ok(val) => val,
LL | | Err(err) => return Err(err),
LL | | };
| |_____^ help: try instead: `func_returning_result()?`
error: this block may be rewritten with the `?` operator
--> tests/ui/question_mark.rs:304:5
|
LL | / if let Err(err) = func_returning_result() {
LL | |
LL | | return Err(err);
LL | | }
| |_____^ help: replace it with: `func_returning_result()?;`
error: this block may be rewritten with the `?` operator
--> tests/ui/question_mark.rs:312:5
|
LL | / if let Err(err) = func_returning_result() {
LL | |
LL | | return Err(err);
LL | | }
| |_____^ help: replace it with: `func_returning_result()?;`
error: this block may be rewritten with the `?` operator
--> tests/ui/question_mark.rs:395:13
|
LL | / if a.is_none() {
LL | |
LL | | return None;
... |
LL | | }
| |_____________^ help: replace it with: `a?;`
error: this `let...else` may be rewritten with the `?` operator
--> tests/ui/question_mark.rs:456:5
|
LL | / let Some(v) = bar.foo.owned.clone() else {
LL | | return None;
LL | | };
| |______^ help: replace it with: `let v = bar.foo.owned.clone()?;`
error: this `let...else` may be rewritten with the `?` operator
--> tests/ui/question_mark.rs:471:5
|
LL | / let Some(ref x) = foo.opt_x else {
LL | | return None;
LL | | };
| |______^ help: replace it with: `let x = foo.opt_x.as_ref()?;`
error: this `let...else` may be rewritten with the `?` operator
--> tests/ui/question_mark.rs:481:5
|
LL | / let Some(ref mut x) = foo.opt_x else {
LL | | return None;
LL | | };
| |______^ help: replace it with: `let x = foo.opt_x.as_mut()?;`
error: this `let...else` may be rewritten with the `?` operator
--> tests/ui/question_mark.rs:492:5
|
LL | / let Some(ref x @ ref y) = foo.opt_x else {
LL | | return None;
LL | | };
| |______^ help: replace it with: `let x @ y = foo.opt_x.as_ref()?;`
error: this `let...else` may be rewritten with the `?` operator
--> tests/ui/question_mark.rs:496:5
|
LL | / let Some(ref x @ WrapperStructWithString(_)) = bar else {
LL | | return None;
LL | | };
| |______^ help: replace it with: `let x @ &WrapperStructWithString(_) = bar.as_ref()?;`
error: this `let...else` may be rewritten with the `?` operator
--> tests/ui/question_mark.rs:500:5
|
LL | / let Some(ref mut x @ WrapperStructWithString(_)) = bar else {
LL | | return None;
LL | | };
| |______^ help: replace it with: `let x @ &mut WrapperStructWithString(_) = bar.as_mut()?;`
error: this block may be rewritten with the `?` operator
--> tests/ui/question_mark.rs:522:5
|
LL | / if arg.is_none() {
LL | |
LL | | return None;
LL | | }
| |_____^ help: replace it with: `arg?;`
error: this `match` expression can be replaced with `?`
--> tests/ui/question_mark.rs:526:15
|
LL | let val = match arg {
| _______________^
LL | |
LL | | Some(val) => val,
LL | | None => return None,
LL | | };
| |_____^ help: try instead: `arg?`
error: this `let...else` may be rewritten with the `?` operator
--> tests/ui/question_mark.rs:536:5
|
LL | / let Some(a) = *a else {
LL | | return None;
LL | | };
| |______^ help: replace it with: `let a = (*a)?;`
error: aborting due to 30 previous errors
|