-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Lifetime error messages could be improved. #9716
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
Comments
cc #12238 |
I totally agree. The current error messages are too vague. If one is not familiar with the language, it takes ages to figure out what is wrong. To give a concrete example:
Gives the error message
I named the relevant lifetime 'a, 'b and 'c to make my point. In my original code, they were of course all called 'a, such that I had no clue what was going on. The first error message only gives a hint when you rename the lifetimes, but even then it is hard to figure out why he wants 'a and not 'b. It should be written where the lifetime 'a in question is defined. On top of that one should give a hint that the trait itself might be annotated with a lifetime as well. On top of that it is totally possible to shadow the lifetime of the trait with the definition in the function signature:
In that case a warning should be given that it is shadowed. The second message is partially wrong because there is no &'c defined at 10:54. There is only a 'c introduced at 8:6. |
rust newbie here. I just got this one trying to upgrade rgtk to work with rust-nightly:
The types it is saying are mismatched are identical, and the suggested code change is identical to the original code. |
So, this issue is pretty vague. It's true that we have room to improve errors, but since the OP didn't give any code, I can't see if it's gotten better. @nwin's has, though. With the different names:
and with all of them being
whoo, shadowing! As such, I'm going to give this issue a close. If any of you still have specific code with bad errors, please make new issues for them, thank you! |
Here's an example I just got:
Now, I'm developing some experience with lifetimes so I have some intuition about what I did wrong. And I appreciate the effort that went into this error message! But still, saying "the lifetime can't outlive the expression X in location Y because it must be valid at the function call at exactly the same expression X in the same location Y" - that's not exactly explaining things in a way that is understandable to a newcomer (which I still am).
Perhaps there's a better way to phrase the problem, and possibly eliminate the duplications?
The text was updated successfully, but these errors were encountered: