-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.D-papercutDiagnostics: An error or lint that needs small tweaks.Diagnostics: An error or lint that needs small tweaks.F-on_unimplementedError messages that can be tackled with `#[rustc_on_unimplemented]`Error messages that can be tackled with `#[rustc_on_unimplemented]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
It seems that rustc
should provide a better error message or hint when one tries to use the ?
operator on an Option
in a function returning a Result
or vice-versa.
Currently this is the error you get:
error[E0277]: `?` couldn't convert the error to `MyErrorType`
--> src/main.rs:10:19
|
10 | let a = foo(i)?;
| ^ the trait `std::convert::From<std::option::NoneError>` is not implemented for `MyErrorType`
|
= note: the question mark operation (`?`) implicitly performs a conversion on the error value using the `From` trait
= note: required by `std::convert::From::from`
However, it would be better to suggest the use of Option::ok_or
or Option::ok_or_else
, or Result::ok
, instead of referencing something dependent on the try_trait
feature (NoneError
).
This issue has been assigned to @Duddino via this comment.
jhpratt
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.D-papercutDiagnostics: An error or lint that needs small tweaks.Diagnostics: An error or lint that needs small tweaks.F-on_unimplementedError messages that can be tackled with `#[rustc_on_unimplemented]`Error messages that can be tackled with `#[rustc_on_unimplemented]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.