Make sure that outer opaques capture inner opaques's lifetimes even with precise capturing syntax #131789
+104
−70
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When lowering an opaque, we must capture and duplicate all of the lifetimes in the opaque's bounds to correctly lower the opaque's bounds. We do this even if the lifetime is not captured according to the
+ use<>
precise capturing bound; in that case, we will later reject that captured lifetime. For example, Given an opaque likeimpl Sized + 'a + use<>
, we will still duplicate'a
but later error that it is not mentioned in theuse<>
bound.The current heuristic was not properly handling cases like:
Which forces the outer
impl Trait
to capture'a
sinceimpl Trait2
implicitly captures'a
due to the new lifetime capture rules for edition 2024. We were only capturing lifetimes syntactically mentioned in the bounds. (Note that this still is an error; we just need to capture'a
so it is handled later in the compiler correctly -- hence the ICE in #131769 where a late-bound lifetime was being referenced outside of its binder).This PR reworks the way we collect lifetimes to capture and duplicate in AST lowering to fix this.
Fixes #131769