Better error message when method name matches but not the where clause


The classic example is when people try to use unwrap() on Result and the error side doesn’t implement Debug. It’s in the docs but can be easily be missed.

Happened to me earlier this morning and I also saw this reddit post a few minutes ago.

Right now this is the error message you get

error: type `core::result::Result<T, <T as core::str::FromStr>::Err>` does not implement any method in scope named `unwrap`

If we could have something like this instead it’d be awesome

error: type `core::result::Result<T, <T as core::str::FromStr>::Err>` does not implement any `unwrap` variant in scope. Choices are:
    core::result::Result<T, E>.unwrap(self) -> T where E: std::fmt::Debug
// ok this sucks but you get the idea

We already have something similar when you use a trait method but the trait itself isn’t in the scope.

Thank you for reading.



I did stumble upon this error too and I was really confused by it. It should say something like

error: for `core::result::Result<T, MyErr>` , the type Err does not implement the Debug trait.

Try this:

pub enum MyErr

This would really help.


closed #3

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.