]> git.lizzy.rs Git - rust.git/blob - src/test/ui/try-on-option.stderr
Auto merge of #75406 - mati865:mingw-aslr, r=Mark-Simulacrum
[rust.git] / src / test / ui / try-on-option.stderr
1 error[E0277]: `?` couldn't convert the error to `()`
2   --> $DIR/try-on-option.rs:7:6
3    |
4 LL | fn foo() -> Result<u32, ()> {
5    |             --------------- expected `()` because of this
6 LL |     let x: Option<u32> = None;
7 LL |     x?;
8    |      ^ the trait `From<NoneError>` is not implemented for `()`
9    |
10    = note: the question mark operation (`?`) implicitly performs a conversion on the error value using the `From` trait
11    = note: required by `from`
12 help: consider converting the `Option<T>` into a `Result<T, _>` using `Option::ok_or` or `Option::ok_or_else`
13    |
14 LL |     x.ok_or_else(|| /* error value */)?;
15    |      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16
17 error[E0277]: the `?` operator can only be used in a function that returns `Result` or `Option` (or another type that implements `Try`)
18   --> $DIR/try-on-option.rs:13:5
19    |
20 LL | / fn bar() -> u32 {
21 LL | |     let x: Option<u32> = None;
22 LL | |     x?;
23    | |     ^^ cannot use the `?` operator in a function that returns `u32`
24 LL | |     22
25 LL | | }
26    | |_- this function should return `Result` or `Option` to accept `?`
27    |
28    = help: the trait `Try` is not implemented for `u32`
29    = note: required by `from_error`
30
31 error: aborting due to 2 previous errors
32
33 For more information about this error, try `rustc --explain E0277`.