Type inference for inline consts#89561
Merged
bors merged 8 commits intorust-lang:masterfrom Nov 9, 2021
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.
Fixes #78132
Fixes #78174
Fixes #81857
Fixes #89964
Perform type checking/inference of inline consts in the same context as the outer def, similar to what is currently done to closure.
Doing so would require
closure_base_def_idof the inline const to return the outer def, and sinceclosure_base_def_idcan be called on non-local crate (and thus have no HIR available), a newDefKindis created for inline consts.The type of the generated anon const can capture lifetime of outer def, so we couldn't just use the typeck result as the type of the inline const's def. Closure has a similar issue, and it uses extra type params
CK, CS, Uto capture closure kind, input/output signature and upvars. I use a similar approach for inline consts, letting it have an extra type paramR, and thentypeof(InlineConst<[paremt generics], R>)would just beR. In borrowck region requirements are also propagated to the outer MIR body just like it's currently done for closure.With this PR, inline consts in expression position are quitely usable now; however the usage in pattern position is still incomplete -- since those does not remain in the MIR borrowck couldn't verify the lifetime there. I have left an ignored test as a FIXME.
Some disucssions can be found on this Zulip thread.
cc @spastorino @lcnr
r? @nikomatsakis
@rustbot label A-inference F-inline_const T-compiler