-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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 description and test for E0311 #100747
Add long description and test for E0311 #100747
Conversation
Adds a long description and unit test for the E0311 compiler error.
Some changes occurred in diagnostic error codes |
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @fee1-dead (or someone else) soon. Please see the contribution instructions for more information. |
This comment has been minimized.
This comment has been minimized.
E0311 occurs when there is insufficient information for the rust compiler to | ||
prove that some time has a long enough lifetime. |
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.
Thank you for the contributions! This explanation could be a bit confusing, I don't know how it should be reworded into, cc @compiler-errors any ideas?
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.
Good point -- it would be great to have a better description here. I'm still pretty new to rust, so this was my initial attempt at reverse engineering why the fix worked.
Co-authored-by: Guillaume Gomez <[email protected]>
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.
Thanks for the quick review. I applied your suggestions and we can wait to see if we get an improved description of the error message from the compiler team.
E0311 occurs when there is insufficient information for the rust compiler to | ||
prove that some time has a long enough lifetime. |
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.
Good point -- it would be great to have a better description here. I'm still pretty new to rust, so this was my initial attempt at reverse engineering why the fix worked.
This comment has been minimized.
This comment has been minimized.
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.
I'm okay with the current description with the suggestions applied. A more accurate description could be a followup.
|
||
In this example we have a trait that borrows some inner data element of type `V` | ||
from an outer type `T`, through an intermediate type `U`. The compiler is unable | ||
to prove that the livetime of `U` is long enough to support the reference. To |
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.
to prove that the livetime of `U` is long enough to support the reference. To | |
to prove that the lifetime of `U` is long enough to support the reference. To |
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.
fixed.
@@ -0,0 +1,49 @@ | |||
This error occurs when there is insufficient information for the rust compiler | |||
to prove that some time has a long enough lifetime. |
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.
to prove that some time has a long enough lifetime. | |
to prove that a type has a long enough lifetime. |
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.
fixed.
I made an attempt at improving the description for the |
Let's do a rotation and find another reviewer who might have a better idea for the documentation :) r? rust-lang/compiler |
This error occurs when there is insufficient information for the rust compiler | ||
to prove that a type has a long enough lifetime. |
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.
This error occurs when there is insufficient information for the rust compiler | |
to prove that a type has a long enough lifetime. | |
This error occurs when there is an unsatisfied outlives bound on a generic type parameter or associated type. |
something like this maybe?
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.
Yeah - that's much better.
-- update summary based on review -- rewrite explanation to be more clear and correct
@@ -0,0 +1,70 @@ | |||
This error occurs when there is insufficient information for the rust compiler | |||
to prove that a type has a long enough lifetime. |
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.
I think that type
would be more correct as parameter
.
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.
Fixed.
trait for a type `T`, so the `&mut self` reference has the lifetime of `T`. | ||
We know that `T` implements the `BorrowMut` trait returning a reference to `U`, | ||
and that `U` implements the `BorrowMut` trait returning a reference to `V`. |
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.
This isn't quite right either: T
is a type and cannot have a lifetime. An object of type T
, such as self
can have a lifetime.
Really what we have is more like:
- suppose that
self
has a lifetime of'b
- the output object of type
V
has a lifetime of'c
If we split up the lines in the example we get:
let u_ref = self.borrow_mut(); // u_ref has lifetime `'b` matching `self`
u_ref.borrow_mut() // u_ref has lifetime of `'c` matching the output
The compiler problem then boils to do failing to prove that 'c
will be longer than 'b
.
Perhaps the right approach here is to copy the failing example above and then add the lifetime annotations that the compiler attempts to add implicitly, similar to how they are shown in the examples in https://doc.rust-lang.org/book/ch10-03-lifetime-syntax.html.
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.
I rewrote this to be more clear and correct.
This error occurs when there is insufficient information for the rust compiler | ||
to prove that a type has a long enough lifetime. |
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.
Yeah - that's much better.
@bors delegate+ |
✌️ @MatthewPeterKelly can now approve this pull request |
compiler would have added an implied bound [implied | ||
bound](https://rust-lang.github.io/rfcs/2089-implied-bounds.html), causing this |
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.
compiler would have added an implied bound [implied | |
bound](https://rust-lang.github.io/rfcs/2089-implied-bounds.html), causing this | |
compiler would have added an | |
[implied bound](https://rust-lang.github.io/rfcs/2089-implied-bounds.html), causing this |
oh wow, we really don't have a user facing doc for implied bounds xx that sucks
the rfc is about implied trait bounds. implied bounds already existed before that and are stable, unlike this rfc. We should really have a page in the reference for that
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.
opened rust-lang/reference#1261 so maybe we should wait for that to land so that you can point there
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.
Thanks for opening the PR to add the reference material. I added some comments on it and will hold this PR until that one lands.
This comment has been minimized.
This comment has been minimized.
marking as blocked on rust-lang/reference#1261 |
outlive `'anon` in `no_restriction()`. | ||
|
||
If `no_restriction()` were to use `&T` instead of `&()` as an argument, the | ||
compiler would have added an implied bound [implied |
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.
compiler would have added an implied bound [implied | |
compiler would have added an [implied |
(Remove the double "implied bound")
Alternatively, remove the link for now, and then send a new PR when the reference PR lands. I don't think it's worth blocking on the reference PR.
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.
I had figured that updating the docs would be quick, but it looks like it's going to be a more involved process. For now I removed the implied bounds link and will plan to merge this PR. Once rust-lang/reference#1261 has been merged I'll plan to open a smaller PR to add the reference link into the E0311.md
docs.
…message-for-E0311
also update .stderr outputs
df4dc2b
to
0d9c014
Compare
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.
2 nits, then r=me
@@ -0,0 +1,42 @@ | |||
This error occurs when there is an unsatisfied outlives bound involving an | |||
elided region on a generic type parameter or associated type. |
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.
elided region on a generic type parameter or associated type. | |
elided region and a generic type parameter or associated type. |
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.
fixed.
lifetime `'anon` in `no_restriction()`. The only information available to the | ||
compiler is that `'anon` is valid for the duration of the function. When | ||
calling `with_restriction()`, the compiler requires the completely unrelated | ||
type parameter `T` to outlive `'anon` because of the `T: 'a bound` in |
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.
still relevant
@bors delegate+ |
✌️ @MatthewPeterKelly can now approve this pull request |
@bors r+ rollup |
Rollup of 8 pull requests Successful merges: - rust-lang#100747 (Add long description and test for E0311) - rust-lang#102232 (Stabilize bench_black_box) - rust-lang#102288 (Suggest unwrapping `???<T>` if a method cannot be found on it but is present on `T`.) - rust-lang#102338 (Deny associated type bindings within associated type bindings) - rust-lang#102347 (Unescaping cleanups) - rust-lang#102348 (Tweak `FulfillProcessor`.) - rust-lang#102378 (Use already resolved `self_ty` in `confirm_fn_pointer_candidate`) - rust-lang#102380 (rustdoc: remove redundant mobile `.source > .sidebar` CSS) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
Merge commits kinda skipped review https://rustc-dev-guide.rust-lang.org/git.html#no-merge-policy |
You're totally right, and thanks for letting me know. This is my first PR for rust and I missed that policy when I was reading the docs. I'll be sure to do it correctly next time. Let me know if there is anything I should fix for this PR, but I suspect that we're locked-in at this point. |
Rollup of 8 pull requests Successful merges: - rust-lang#100747 (Add long description and test for E0311) - rust-lang#102232 (Stabilize bench_black_box) - rust-lang#102288 (Suggest unwrapping `???<T>` if a method cannot be found on it but is present on `T`.) - rust-lang#102338 (Deny associated type bindings within associated type bindings) - rust-lang#102347 (Unescaping cleanups) - rust-lang#102348 (Tweak `FulfillProcessor`.) - rust-lang#102378 (Use already resolved `self_ty` in `confirm_fn_pointer_candidate`) - rust-lang#102380 (rustdoc: remove redundant mobile `.source > .sidebar` CSS) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
Adds a long description and unit test for the E0311 compiler error.
Fixes one line-item in #61137.