Properly deal with function pointer Fn
candidates with escaping bound vars
#104929
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.
Function pointers in where clauses can reference both bound regions from their own binder, and from the binder of the where clause predicate that they're the Self type of.
The UI test demonstrates that we need to be able to deal with both of these cases for
Fn
trait bounds, sometimes at the same time.This PR introduces a function called
flatten_binders
which takes aBinder<Binder<T>>
and flattens it into aBinder<T>
, concatenating the variables list and adjusting the de Bruijn indices accordingly. If we see a function pointer's signature that captures bound vars from the where-clause, flatten those bound variables so that we can subtype signatures properly inconfirm_poly_trait_refs
.cc @lcnr @jackh726 who know more about binders and higher-ranked subtyping than I do.
r? types
I'm pretty sure this approach is (at least mostly) correct, but maybe it's overkill. The
where
clauses in the UI test I added are certainly a bit contrived, but perhaps they could show up in the wild... I recall seeing an ICE that looked like this, but I can't find it anymore.We could alternatively deal with this in a forwards-compatible way by just erroring out if we see escaping bound vars in the fn ptr type... I mostly want to make sure that this code no longer ICEs: