Skip to content
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

Better Error Messages for Partially Implemented Traits #22337

Closed
eyolfson opened this issue Feb 14, 2015 · 7 comments
Closed

Better Error Messages for Partially Implemented Traits #22337

eyolfson opened this issue Feb 14, 2015 · 7 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints

Comments

@eyolfson
Copy link

Specifically, for types that have a trait implemented, but require the types they use to have the trait implemented as well. For instance, Result. Consider the following example:

#[derive(Debug)]
struct X;

struct Y;

fn main() {
    let x: Result<X, Y> = Ok(X);
    println!("{:?}", x);
}

Produces the following error message:

issue.rs:8:22: 8:23 error: the trait `core::fmt::Debug` is not implemented for the type `core::result::Result<X, Y>` [E0277]

This error message is confusing to someone beginning Rust, because according to the documentation, Result does implement Debug. In this case a clearer error message would be something like:

issue.rs:8:22: 8:23 error: the trait `core::fmt::Debug` is not implemented for the type `core::result::Result<X, Y>` because type `Y` does not implement `core::fmt::Debug`

Perhaps the error message could be tweaked, but in this case it should clearly point to Y as being the problem. Of course, if X and Y don't implement core::fmt::Debug the error message should reflect that was well.

@nagisa
Copy link
Member

nagisa commented Feb 14, 2015

according to the documentation, Result does implement Debug.

Documentation clearly states there’s only impl<T, E> Debug for Result<T, E> where T: Debug, E: Debug, which does not apply to Result<A, B>A, B, which your sentence implies is the case.

@eyolfson
Copy link
Author

I stated, for a beginner. So someone that just scans that it exists, at all. The main point is to just improve the error message to state which specific type T or E is missing an implementation of the Debug trait that's causing Results implementation of Debug not to exist.

@steveklabnik steveklabnik added the A-diagnostics Area: Messages for errors, warnings, and lints label Feb 15, 2015
@gsingh93
Copy link
Contributor

gsingh93 commented Apr 4, 2015

Related: #20941

@apasel422
Copy link
Contributor

This is essentially fixed:

> rustc --version
rustc 1.3.0-nightly (e4e93196e 2015-07-14)
> rustc foo.rs 
foo.rs:8:22: 8:23 error: the trait `core::fmt::Debug` is not implemented for the type `Y` [E0277]
foo.rs:8     println!("{:?}", x);

@Gankra
Copy link
Contributor

Gankra commented Jul 19, 2015

... which is just #21793

@birkenfeld
Copy link
Contributor

New error, but seems still fixed:

<anon>:8:22: 8:23 error: the trait bound `Y: std::fmt::Debug` is not satisfied [E0277]
<anon>:8     println!("{:?}", x);
                              ^
<anon>:8:22: 8:23 help: see the detailed explanation for E0277
<anon>:8:22: 8:23 note: `Y` cannot be formatted using `:?`; if it is defined in your crate, add `#[derive(Debug)]` or manually implement it

@arielb1
Copy link
Contributor

arielb1 commented May 2, 2016

Yeah. Fixed.

@arielb1 arielb1 closed this as completed May 2, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints
Projects
None yet
Development

No branches or pull requests

8 participants