]> git.lizzy.rs Git - rust.git/blob - tests/ui/try-trait/try-on-option.stderr
Rollup merge of #106321 - compiler-errors:delayed-bug-backtrace, r=Nilstrieb
[rust.git] / tests / ui / try-trait / try-on-option.stderr
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:5:6
3    |
4 LL | fn foo() -> Result<u32, ()> {
5    | --------------------------- this function returns a `Result`
6 LL |     let x: Option<u32> = None;
7 LL |     x?;
8    |      ^ use `.ok_or(...)?` to provide an error compatible with `Result<u32, ()>`
9    |
10    = help: the trait `FromResidual<Option<Infallible>>` is not implemented for `Result<u32, ()>`
11    = help: the following other types implement trait `FromResidual<R>`:
12              <Result<T, F> as FromResidual<Result<Infallible, E>>>
13              <Result<T, F> as FromResidual<Yeet<E>>>
14
15 error[E0277]: the `?` operator can only be used in a function that returns `Result` or `Option` (or another type that implements `FromResidual`)
16   --> $DIR/try-on-option.rs:11:6
17    |
18 LL | fn bar() -> u32 {
19    | --------------- this function should return `Result` or `Option` to accept `?`
20 LL |     let x: Option<u32> = None;
21 LL |     x?;
22    |      ^ cannot use the `?` operator in a function that returns `u32`
23    |
24    = help: the trait `FromResidual<Option<Infallible>>` is not implemented for `u32`
25
26 error: aborting due to 2 previous errors
27
28 For more information about this error, try `rustc --explain E0277`.