Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign upError messages are odd for delegating traits #22590
Comments
nagisa
changed the title
Error messages are odd for hand-over traits
Error messages are odd for delegating traits
Feb 20, 2015
kmcallister
added
the
A-traits
label
Feb 21, 2015
nagisa
referenced this issue
Mar 4, 2015
Closed
The error message isn't accurate when missing trait implement #23021
This comment has been minimized.
This comment has been minimized.
|
triage: I-nominated nominating for 1.0 polish as this is quite a confusing error message that leaks into many places. For example if you pass something to a function requiring a |
alexcrichton
assigned
nikomatsakis
and unassigned
nikomatsakis
Mar 4, 2015
alexcrichton
added
the
I-nominated
label
Mar 4, 2015
brson
added
the
E-easy
label
Mar 5, 2015
pnkfelix
added
A-diagnostics
and removed
E-easy
labels
Mar 5, 2015
This comment has been minimized.
This comment has been minimized.
|
we could provide more of a trace in the error message. anyway this is polish at best, not a 1.0 blocker. P-low. not on 1.0 milestone. |
pnkfelix
added
P-low
E-easy
and removed
I-nominated
labels
Mar 5, 2015
nikomatsakis
added
I-nominated
E-mentor
and removed
A-diagnostics
P-low
labels
Mar 5, 2015
This comment has been minimized.
This comment has been minimized.
|
I can help mentor this. |
pnkfelix
removed
the
I-nominated
label
Mar 5, 2015
This comment has been minimized.
This comment has been minimized.
az7arul
commented
Mar 15, 2015
|
@nikomatsakis I want to have a go at this if the mentor offer still stands. |
This comment has been minimized.
This comment has been minimized.
|
This problem still exists. @nikomatsakis I'm taking a look into this. Any pointers on where I should look? |
This comment has been minimized.
This comment has been minimized.
|
The new error message is
Maybe just improve the error explanation? |
This comment has been minimized.
This comment has been minimized.
|
Ah, I accidentally ran on stable and missed the up-to-date message. It might be good to show why that is required by |
This comment has been minimized.
This comment has been minimized.
|
@tsion sorry, I'm quite behind on notifications, but I agree that we could improve the message further. I'd still be happy to mentor -- easiest would be to ping me on IRC (nmatsakis). But the basic idea is that we track the cause of each trait obligation, and in this case we could probably use a more specific cause that would permit a more specific error message. Also, as @aturon noted on another issue recently, we might prefer to invert the print-out, so that we print out the root cause first, and the final error only later. That's a bit harder to do in the general case though I think, not without some greater reorganization of the code that @jroesch has been working on. |
This comment has been minimized.
This comment has been minimized.
chirag08
commented
Apr 11, 2016
|
@nikomatsakis I am really interested to work on this, needs your help |
brson
added
E-help-wanted
and removed
E-easy
labels
Jun 27, 2016
This comment has been minimized.
This comment has been minimized.
eugene-bulkin
commented
Jul 21, 2016
|
The current error message is this:
That looks like it covers most of the bases, right? |
This comment has been minimized.
This comment has been minimized.
|
@nagisa what do you think of @eugene-bulkin's output above? |
This comment has been minimized.
This comment has been minimized.
|
The output is better now, I’m still confused as to why compiler would even begin considering the
is preferable in this particular case. OTOH, reporting an error message the way as it is done currently automatically improves diagnostics involving marker traits like |
This comment has been minimized.
This comment has been minimized.
|
Perhaps something like
could be an option. |
This comment has been minimized.
This comment has been minimized.
|
I have been wanting for some time to switch to more of a "backtrace" style error. I think we should lead with the top-level thing which is unsatisfied (in this case, This seems relevant to the abstract model we define for errors, btw (cc @jonathandturner) in that it seems like a clear case where we want "attached notes" to define the backtrace. I would think that ideally those notes would be linked to the impl (like, citing the line/column of the impl when possible). But bah I'm not sure exactly how I think it should look. I'd like to avoid having to phrase trait errors in a new (i.e., "implementing |
This comment has been minimized.
This comment has been minimized.
|
Just sketching it out. Maybe something like this?
Though we might want to play with the spans. At least seems promising. |
This comment has been minimized.
This comment has been minimized.
|
A better one...
|
This comment has been minimized.
This comment has been minimized.
|
@jonathandturner remember that delegation chain could be inifinitely long¹, thus we should strive somewhat to ensure that multiple such suggestions can be presented in readable way. ¹: https://play.rust-lang.org/?gist=4a8db1abe419dab9a9fb4e52c4ebf4e3&version=stable&backtrace=0 is an example extended to have an extra trait in the chain. |
This comment has been minimized.
This comment has been minimized.
|
@nagisa Heuristics are fair game here. What we choose to add in addition to the main error is up to us, but we can opt to only show some of the available additional information. |
This comment has been minimized.
This comment has been minimized.
Interesting. I have no idea what the common depths of the stacktrace are. (Also, commonly the impls will be in other files, but that's ok). |
arielb1
added
I-nominated
T-compiler
labels
Jul 19, 2017
Mark-Simulacrum
added
the
C-enhancement
label
Jul 22, 2017
This comment has been minimized.
This comment has been minimized.
|
triage: P-medium Would be nice, but not P-high. We should write-up some mentoring instructions. |
rust-highfive
added
P-medium
and removed
I-nominated
labels
Aug 24, 2017
This comment has been minimized.
This comment has been minimized.
|
These error messages have always been confusing for me. The most common case is when something requires
I was playing around with some Anyway, I would like to try to fix this, if someone could give me some mentoring notes I'll get started on it this week |
This comment has been minimized.
This comment has been minimized.
|
First and foremost, I think the primary error message for the above case should be EDIT 2019-01-14: replaced |
This comment has been minimized.
This comment has been minimized.
|
Update: these error messages are still a problem and no progress has been made to make them better, except as a special case for trait Foo {}
fn requires_foo<T: Foo>() {}
trait Bar {}
impl<T: Bar> Foo for T {}
fn main() {
// try to call `requires_foo` with a type that doesn't implement it
requires_foo::<()>();
}The resulting error message:
Compare this to the error message if we comment out the blanket impl of
The error message when the blanket impl is present complains that This most recently came up on Reddit here |
nagisa commentedFeb 20, 2015
This is a more general version of #22478. (i.e. probably should be considered to supersede it)
Compiling this will result in
but
impl<T: B> A for T,T = CandCdoes not implementBand therefore the impl in question should not even be taken into consideration, even if it is the only implementation of a trait.