summary refs log tree commit diff
path: root/src/test/ui/try-trait/try-on-option.stderr
blob: b522dd5709b2946601927dc00480e362887fd5c2 (plain)
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
error[E0277]: the `?` operator can only be used on `Result`s, not `Option`s, in a function that returns `Result`
  --> $DIR/try-on-option.rs:7:6
   |
LL | / fn foo() -> Result<u32, ()> {
LL | |     let x: Option<u32> = None;
LL | |     x?;
   | |      ^ use `.ok_or(...)?` to provide an error compatible with `Result<u32, ()>`
LL | |     Ok(22)
LL | | }
   | |_- this function returns a `Result`
   |
   = help: the trait `FromResidual<Option<Infallible>>` is not implemented for `Result<u32, ()>`
note: required by `from_residual`
  --> $SRC_DIR/core/src/ops/try_trait.rs:LL:COL
   |
LL |     fn from_residual(residual: R) -> Self;
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error[E0277]: the `?` operator can only be used in a function that returns `Result` or `Option` (or another type that implements `FromResidual`)
  --> $DIR/try-on-option.rs:13:6
   |
LL | / fn bar() -> u32 {
LL | |     let x: Option<u32> = None;
LL | |     x?;
   | |      ^ cannot use the `?` operator in a function that returns `u32`
LL | |     22
LL | | }
   | |_- this function should return `Result` or `Option` to accept `?`
   |
   = help: the trait `FromResidual<Option<Infallible>>` is not implemented for `u32`
note: required by `from_residual`
  --> $SRC_DIR/core/src/ops/try_trait.rs:LL:COL
   |
LL |     fn from_residual(residual: R) -> Self;
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0277`.