Suggest missing Debug Impl when unwrapping #85851
Labels
A-diagnostics
Area: Messages for errors, warnings, and lints
C-enhancement
Category: An issue proposing an enhancement or a PR with one.
D-newcomer-roadblock
Diagnostics: Confusing error or lint; hard to understand for new users.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
Uh oh!
There was an error while loading. Please reload this page.
Hey all, here's another common pitfall our new Rust learners stumble into during our training. The diagnostics you get on
unwrap
when theE: Debug
bound isn't met do tell you that it isn't possible, BUT it doesn't tell you how to fix this. I think in most cases, suggesting#[derive(Debug)]
is a better option, though this might give false positives if the user doesn't control the Error type (I don't know if diagnostics can "see" whether a type is local or not, but maybe you can!)Given the following code: Playground Link
The current output is:
I would hope for something that tells users more directly "When you use
unwrap()
, theErr
variant must implement theDebug
trait in case the unwrap fails and we need to display a panic message".Applies to Rust 1.51.1, and likely all other older versions of Rust.
The text was updated successfully, but these errors were encountered: