mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-29 18:23:49 +00:00
00da9fc961
This commit starts using `#[diagnostic::do_not_recommend]` in the standard library to improve some error messages. In this case we just hide a certain nightly only impl as suggested in #121521
27 lines
1.2 KiB
Plaintext
27 lines
1.2 KiB
Plaintext
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:5:6
|
|
|
|
|
LL | fn foo() -> Result<u32, ()> {
|
|
| --------------------------- this function returns a `Result`
|
|
LL | let x: Option<u32> = None;
|
|
LL | x?;
|
|
| ^ use `.ok_or(...)?` to provide an error compatible with `Result<u32, ()>`
|
|
|
|
|
= help: the trait `FromResidual<Option<Infallible>>` is not implemented for `Result<u32, ()>`
|
|
= help: the trait `FromResidual<Result<Infallible, E>>` is implemented for `Result<T, F>`
|
|
|
|
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:11:6
|
|
|
|
|
LL | fn bar() -> u32 {
|
|
| --------------- this function should return `Result` or `Option` to accept `?`
|
|
LL | let x: Option<u32> = None;
|
|
LL | x?;
|
|
| ^ cannot use the `?` operator in a function that returns `u32`
|
|
|
|
|
= help: the trait `FromResidual<Option<Infallible>>` is not implemented for `u32`
|
|
|
|
error: aborting due to 2 previous errors
|
|
|
|
For more information about this error, try `rustc --explain E0277`.
|