@@ -254,6 +254,18 @@ pub trait Try: FromResidual {
254
254
label = "this `?` produces `{R}`, which is incompatible with `{Self}`" ,
255
255
enclosing_scope = "this function returns a `Result`"
256
256
) ,
257
+ on(
258
+ all(
259
+ from_method = "from_residual" ,
260
+ from_desugaring = "QuestionMark" ,
261
+ _Self = "std::option::Option<T>" ,
262
+ R = "std::result::Result<T, E>" ,
263
+ ) ,
264
+ message = "the `?` operator can only be used on `Option`s, not `Result`s, \
265
+ in {ItemContext} that returns `Option`",
266
+ label = "use `.ok()?` if you want to discard the `{R}` error information" ,
267
+ enclosing_scope = "this function returns an `Option`"
268
+ ) ,
257
269
on(
258
270
all(
259
271
from_method = "from_residual" ,
@@ -272,13 +284,26 @@ pub trait Try: FromResidual {
272
284
from_method = "from_residual" ,
273
285
from_desugaring = "QuestionMark" ,
274
286
_Self = "std::ops::ControlFlow<B, C>" ,
287
+ R = "std::ops::ControlFlow<B, C>" ,
275
288
) ,
276
- message = "the `?` operator can only be used on `ControlFlow<B, _>`s \
277
- in {ItemContext} that returns `ControlFlow<B, _>`",
289
+ message = "the `?` operator in {ItemContext} that returns `ControlFlow<B, _>` \
290
+ can only be used on other `ControlFlow<B, _>`s (with the same Break type) ",
278
291
label = "this `?` produces `{R}`, which is incompatible with `{Self}`" ,
279
292
enclosing_scope = "this function returns a `ControlFlow`" ,
280
293
note = "unlike `Result`, there's no `From`-conversion performed for `ControlFlow`"
281
294
) ,
295
+ on(
296
+ all(
297
+ from_method = "from_residual" ,
298
+ from_desugaring = "QuestionMark" ,
299
+ _Self = "std::ops::ControlFlow<B, C>" ,
300
+ // `R` is not a `ControlFlow`, as that case was matched previously
301
+ ) ,
302
+ message = "the `?` operator can only be used on `ControlFlow`s \
303
+ in {ItemContext} that returns `ControlFlow`",
304
+ label = "this `?` produces `{R}`, which is incompatible with `{Self}`" ,
305
+ enclosing_scope = "this function returns a `ControlFlow`" ,
306
+ ) ,
282
307
on(
283
308
all(
284
309
from_method = "from_residual" ,
0 commit comments