
When a `?` operation requires an `Into` conversion with additional bounds (like having a concrete error but wanting to convert to a trait object), we handle it speficically and provide the same kind of information we give other `?` related errors. ``` error[E0277]: `?` couldn't convert the error: `E: std::error::Error` is not satisfied --> $DIR/bad-question-mark-on-trait-object.rs:5:13 | LL | fn foo() -> Result<(), Box<dyn std::error::Error>> { | -------------------------------------- required `E: std::error::Error` because of this LL | Ok(bar()?) | ^ the trait `std::error::Error` is not implemented for `E` | = note: the question mark operation (`?`) implicitly performs a conversion on the error value using the `From` trait = note: required for `Box<dyn std::error::Error>` to implement `From<E>` ``` Avoid talking about `FromResidual` when other more relevant information is being given, particularly from `rust_on_unimplemented`.
36 lines
1.6 KiB
Text
36 lines
1.6 KiB
Text
error[E0277]: the `?` operator can only be used in an async block that returns `Result` or `Option` (or another type that implements `FromResidual`)
|
|
--> $DIR/try-on-option-in-async.rs:7:10
|
|
|
|
|
LL | async {
|
|
| ----- this function should return `Result` or `Option` to accept `?`
|
|
LL | let x: Option<u32> = None;
|
|
LL | x?;
|
|
| ^ cannot use the `?` operator in an async block that returns `{integer}`
|
|
|
|
error[E0277]: the `?` operator can only be used in an async closure that returns `Result` or `Option` (or another type that implements `FromResidual`)
|
|
--> $DIR/try-on-option-in-async.rs:16:10
|
|
|
|
|
LL | let async_closure = async || {
|
|
| __________________________________-
|
|
LL | | let x: Option<u32> = None;
|
|
LL | | x?;
|
|
| | ^ cannot use the `?` operator in an async closure that returns `u32`
|
|
LL | | 22_u32
|
|
LL | | };
|
|
| |_____- this function should return `Result` or `Option` to accept `?`
|
|
|
|
error[E0277]: the `?` operator can only be used in an async function that returns `Result` or `Option` (or another type that implements `FromResidual`)
|
|
--> $DIR/try-on-option-in-async.rs:25:6
|
|
|
|
|
LL | async fn an_async_function() -> u32 {
|
|
| _____________________________________-
|
|
LL | | let x: Option<u32> = None;
|
|
LL | | x?;
|
|
| | ^ cannot use the `?` operator in an async function that returns `u32`
|
|
LL | | 22
|
|
LL | | }
|
|
| |_- this function should return `Result` or `Option` to accept `?`
|
|
|
|
error: aborting due to 3 previous errors
|
|
|
|
For more information about this error, try `rustc --explain E0277`.
|