Skip to content

Type inference for inline consts#89561

Merged
bors merged 8 commits intorust-lang:masterfrom
nbdd0121:const_typeck
Nov 9, 2021
Merged

Type inference for inline consts#89561
bors merged 8 commits intorust-lang:masterfrom
nbdd0121:const_typeck

Conversation

@nbdd0121
Copy link
Copy Markdown
Member

@nbdd0121 nbdd0121 commented Oct 5, 2021

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_id of the inline const to return the outer def, and since closure_base_def_id can be called on non-local crate (and thus have no HIR available), a new DefKind is 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, U to capture closure kind, input/output signature and upvars. I use a similar approach for inline consts, letting it have an extra type param R, and then typeof(InlineConst<[paremt generics], R>) would just be R. 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

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-inference Area: Type inference F-inline_const Inline constants (aka: const blocks, const expressions, anonymous constants) S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

9 participants