mirror of
https://github.com/rust-lang/rust.git
synced 2025-10-31 21:16:44 +00:00
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`.
40 lines
1.9 KiB
Plaintext
40 lines
1.9 KiB
Plaintext
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-diagnostics.rs:7:6
|
|
|
|
|
LL | fn a_function() -> 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`
|
|
|
|
error[E0277]: the `?` operator can only be used in a closure that returns `Result` or `Option` (or another type that implements `FromResidual`)
|
|
--> $DIR/try-on-option-diagnostics.rs:14:10
|
|
|
|
|
LL | let a_closure = || {
|
|
| -- this function should return `Result` or `Option` to accept `?`
|
|
LL | let x: Option<u32> = None;
|
|
LL | x?;
|
|
| ^ cannot use the `?` operator in a closure that returns `{integer}`
|
|
|
|
error[E0277]: the `?` operator can only be used in a method that returns `Result` or `Option` (or another type that implements `FromResidual`)
|
|
--> $DIR/try-on-option-diagnostics.rs:26:14
|
|
|
|
|
LL | fn a_method() {
|
|
| ------------- this function should return `Result` or `Option` to accept `?`
|
|
LL | let x: Option<u32> = None;
|
|
LL | x?;
|
|
| ^ cannot use the `?` operator in a method that returns `()`
|
|
|
|
error[E0277]: the `?` operator can only be used in a trait method that returns `Result` or `Option` (or another type that implements `FromResidual`)
|
|
--> $DIR/try-on-option-diagnostics.rs:39:14
|
|
|
|
|
LL | fn a_trait_method() {
|
|
| ------------------- this function should return `Result` or `Option` to accept `?`
|
|
LL | let x: Option<u32> = None;
|
|
LL | x?;
|
|
| ^ cannot use the `?` operator in a trait method that returns `()`
|
|
|
|
error: aborting due to 4 previous errors
|
|
|
|
For more information about this error, try `rustc --explain E0277`.
|