]> git.lizzy.rs Git - rust.git/blob - src/test/ui/try-trait/try-on-option.stderr
Dedup logic and improve output for other types that impl trait
[rust.git] / src / test / 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 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, ()>`
13    = help: the trait `FromResidual<Result<Infallible, E>>` is implemented for `Result<T, F>`
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 LL | |     let x: Option<u32> = None;
20 LL | |     x?;
21    | |      ^ cannot use the `?` operator in a function that returns `u32`
22 LL | |     22
23 LL | | }
24    | |_- this function should return `Result` or `Option` to accept `?`
25    |
26    = help: the trait `FromResidual<Option<Infallible>>` is not implemented for `u32`
27
28 error: aborting due to 2 previous errors
29
30 For more information about this error, try `rustc --explain E0277`.