-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Add long error explanation for E0271 #24728
Conversation
r? @nrc (rust_highfive has picked a reviewer for you, use r? to override) |
r? @pnkfelix |
@@ -329,6 +329,49 @@ loop. Without a loop to break out of or continue in, no sensible action can be | |||
taken. | |||
"##, | |||
|
|||
E0271: r##" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't you also need to remove the other entry for E0271
from the register_diagnostics!
call below?
(I imagine this is why the Travis build failed.)
You can check this sort of thing quickly + locally by running make tidy
on your end.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Erf, it's because I wasn't on the good branch and copy/paste my code. I just forgot to remove the entry in the register_diagnostics
. I fix it.
@pnkfelix: I removed the entry. If you want me to squash, I'll do it this evening. Beside, have you see something that I'd need to fix ? |
@GuillaumeGomez so, looking at this again, it seems like you have a very specific help message attached to E0271, which is signaled from So, how did you decide on this help text? In particular, I would have guessed that while this message does arise when one writes code like the example you gave (transcribed here): fn main() {
let vs = vec![1, 2, 3, 4];
for v in &vs {
match v {
1 => {}
_ => {}
}
}
} it can also arise in scenarios that have nothing to do with Here is another example where this same error code (E0271) can arise, and your help would be very confusing: fn main() {
trait Trait { type AssociatedType; }
impl Trait for i8 { type AssociatedType = char; }
fn foo<T>(t: T) where T: Trait<AssociatedType=u32> {
println!("in foo");
}
foo(3i8);
} |
In case it is not clear: In your example, this error message bubbles up from constraints that arise from the mix of the way that a constraint on the type for But in general, this error message has nothing to do with In your example, the constraint is that In my follow-up example, the constraint is that |
Oh okay ! My example was the only case I succeed to have the E0271 error. Thanks to your explanations, I'll be able to add a lot more precise error description. So thank you ! |
9735fc2
to
da9019d
Compare
@pnkfelix: I changed it. I used you example and some of your explanations to do so. What do you think of it ? |
I don't know, something about this error and this message just does not sit quite right with me. Sorry I do not have more constructive feedback at the moment |
I have this feeling too but it's hard to have a good sight of our own work. Then let's wait for others' opinion. |
This looks like a tricky error to explain, I'll help you dig into it more tomorrow 😄 |
Yes, kind of. Thanks a lot ! |
Okay, after reflecting a long time on this, I think I know what has been bothering me and how I would fix it. The problem with your descriptionIn your description of the error, you say "a type mismatch that happens to involve a constraint that forces the associated type of some particular trait to be equivalent to some other type" -- I find this somewhat vague. That is, it is technically correct, but as a novice reader (and perhaps even as an expert), I would not be confident in my understanding of what features of the language are involved that are causing this error to arise. That sort of vagueness would be okay, if the first example I saw was as simple as possible and very clearly indicated how the terms above map to the example. But in your text, the very first example is of how the problem can arise with a combination of a How I would fix it
Suggested revised text
|
(okay its taken me nearly an hour but I think I'm done updating the above example in place. Maybe I should have just taken over this PR... oh well, anyway, feel free to incorporate as much of the above as you'd like...) |
Wo... That's very impressive. Your revised version is perfect. I'd feel bad to just take your work and commit it. So as you prefer : do you want to open a new PR and I close this one or do you want me to commit your code ? |
@GuillaumeGomez do whatever you like; I don't need authorship credit. I was more looking at this as an exercise, in terms of identifying why I didn't like the original message (which was hard) and then how to fix it (which was easier, once the first task was done) |
If you do incorporate it yourself, please do try to fix the typos. (There are at least two I can see offhand, like |
Then I'll do as you say, but it'll be said in the commit that is it your work. I'm really not comfortable to not mention you and your work. |
@pnkfelix: I updated your code, I only found two typos (just like you said actually) and it made me discover a dead link in documentations. :-) |
@GuillaumeGomez great; please do fix |
(And squash as well...) |
b687921
to
d628a00
Compare
d628a00
to
30f88c8
Compare
Squash done. @pnkfelix: Thanks a lot for your "help" (since you did all the job, I don't think help is the good word ^^). |
Part of #24407.