]>
Commit | Line | Data |
---|---|---|
17df50a5 XL |
1 | error[E0277]: the `?` operator can only be used on `Result`s, not `Option`s, in a function that returns `Result` |
2 | --> $DIR/try-on-option.rs:7:6 | |
3 | | | |
4 | LL | / fn foo() -> Result<u32, ()> { | |
5 | LL | | let x: Option<u32> = None; | |
6 | LL | | x?; | |
7 | | | ^ use `.ok_or(...)?` to provide an error compatible with `Result<u32, ()>` | |
8 | LL | | Ok(22) | |
9 | LL | | } | |
10 | | |_- this function returns a `Result` | |
11 | | | |
12 | = help: the trait `FromResidual<Option<Infallible>>` is not implemented for `Result<u32, ()>` | |
136023e0 XL |
13 | note: required by `from_residual` |
14 | --> $SRC_DIR/core/src/ops/try_trait.rs:LL:COL | |
15 | | | |
16 | LL | fn from_residual(residual: R) -> Self; | |
17 | | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | |
17df50a5 XL |
18 | |
19 | error[E0277]: the `?` operator can only be used in a function that returns `Result` or `Option` (or another type that implements `FromResidual`) | |
20 | --> $DIR/try-on-option.rs:13:6 | |
21 | | | |
22 | LL | / fn bar() -> u32 { | |
23 | LL | | let x: Option<u32> = None; | |
24 | LL | | x?; | |
25 | | | ^ cannot use the `?` operator in a function that returns `u32` | |
26 | LL | | 22 | |
27 | LL | | } | |
28 | | |_- this function should return `Result` or `Option` to accept `?` | |
29 | | | |
30 | = help: the trait `FromResidual<Option<Infallible>>` is not implemented for `u32` | |
136023e0 XL |
31 | note: required by `from_residual` |
32 | --> $SRC_DIR/core/src/ops/try_trait.rs:LL:COL | |
33 | | | |
34 | LL | fn from_residual(residual: R) -> Self; | |
35 | | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | |
17df50a5 XL |
36 | |
37 | error: aborting due to 2 previous errors | |
38 | ||
39 | For more information about this error, try `rustc --explain E0277`. |