generalize impl trait to permit multiple lifetime bounds#61775
Merged
bors merged 68 commits intorust-lang:masterfrom Jul 3, 2019
Merged
Conversation
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Generalizes the region solver to support "pick constraints". These have the form:
where
R1..Rnare called the "option regions". The idea is thatR0must be equal to some region in the setR1..Rn. These constraints are then used to handle cases like this:The problem here is that every region R in the hidden type must be equal to either
'aor'b(or'static) -- in the past, the only kinds of constraints we had were outlives constraints, and since'aand'bare unrelated, there was no outlives constraint we could issue that would enforce that (R: 'aandR: 'bare both too strict, for example). But now we can issue a pick constraint:pick R from ['a, 'b].In general, solving pick constraints is tricky. We integrate them into the solver as follows. In general, during the propagation phase, we are monotonically growing a set of inference regions. To handle a case like
pick R from [O...], whereO...represents the option regions, we do the following:R: LBmust hold.UB: Rmust hold.UB: OandO: LBfor each UB, LB bound.O: Mholds for every option region O.If there is such a minimal viable option, then we make
R: M. (This may in turn influence other bits of inference.) If there is no minimal viable option, either because all options were eliminated or because none of the remaining options are minimal, we do nothing. Ultimately, if the pick constraint is not satisfied, an error is reported.For this logic, we currently require that the option regions O are always lifetime parameters. To determine the bounds, we walk the various outlives edges that were otherwise introduced.
r? @matthewjasper
cc @cramertj
Fixes #56238
TODO:
existential typeand other impl Trait usage