-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Provide more context on ?
where the error type can't be converted to the expected one
#137238
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Note: I believe that this change was inspired by me complaining on Mastodon about an error message I did not understand. In context on my machine, the true meaning of the error message was that my type had met the requirements for |
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`. rust-lang#137238.
@mcclure is there anything you'd want to add to the following?
|
Rollup merge of rust-lang#137245 - estebank:from-residual-note-2, r=oli-obk Tweak E0277 when predicate comes indirectly from ? 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:7: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` | | | this has type `Result<_, E>` | note: `E` needs to implement `std::error::Error` --> $DIR/bad-question-mark-on-trait-object.rs:1:1 | LL | struct 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`. Fix rust-lang#137238. ----- CC rust-lang#137232, which was a smaller step related to this.
@estebank , that seems fine to me |
Code
Current output
Desired output
Rationale and extra context
As far as the (stable) end user is concerned,
?
is a little more than a compiler intrinsic. We shouldn't mentionFromResidual
. We also should provide extra context on where the obligation comes from, and we should point at the return type of the enclosing function, and ideally also point at the type that couldn't be converted which is missing aFrom
orInto
impl.Other cases
Rust Version
Anything else?
No response
The text was updated successfully, but these errors were encountered: