-
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
"Doesn't live long enough" error can be further improved #36537
Comments
I'm looking for test case, I've found some
just need to change text for line 21 and 22 and add note? |
These are slightly different examples, but I think you have the right idea. Your example would look like:
Notice also that the primary span (the ^^^ part) is on line 22 instead of 21. I don't think there's a note on this one since the note is shown if both the borrowed value and the borrower are dropped in the same scope. |
Is it example for first output?
|
@mikhail-m1 - that looks like it. Want to add it to the test suite, if it's not already there? |
@jonathandturner I did not find it in repo. I doubt about '^', I far as i know both '^' and '-' adds by by span_label, so need to change error place to change mark types, but error in line 4 not in 5 (in first output) |
Great, please add the test if you're creating a PR for this. The ^ and - are created by the labels. Labels that have the same span as the error message itself get ^, all other labels get - |
@jonathandturner Let me explain in another way:
for achieve target output it will be
so error will be in line 5, is it OK? |
Yup, you got it. |
@jonathandturner I've explored code borrow checker, and found several cases for "does not live long enough":
Should I change only second case or third too? and I've found some uncommon construction in closure case
Can I use it? |
Have you tried the closure case to do a before/after and see what it looks like? I don't remember using that functionality much. Does it let you set labels? |
@jonathandturner In closure case It works before but in other logical branch. It my case it allows minimize changes but not makes code harder to read. What about my first question? |
@jonathandturner error with different lifetime ranges like
remain unchanged
should I fix it too? |
Yes, please. I thought that's what this PR fixed? |
@jonathandturner it's different logic brunches of function, actually the function is used for output the error in next cases
the PR fixes just 2 and only for borrowed values |
If you want to tackle the other cases, definitely feel free. |
improve "Doesn't live long enough" error I've fixed only with same case issue #36537 part of #35233 r? @jonathandturner
Improve "Doesn't live long enough" error case with different lifetime scope issue rust-lang#36537 part of rust-lang#35233 r? @jonathandturner
Looks like this was improved by #37405 and others |
From @nikomatsakis (based on a chat with @wycats) - we can further improve the "doesn't live long enough" error by talking a bit more about how the values flow through the error. Something like:
The text was updated successfully, but these errors were encountered: