rust/compiler/rustc_borrowck/src
Matthias Krüger fd74c93403
Rollup merge of #89561 - nbdd0121:const_typeck, r=nikomatsakis
Type inference for inline consts

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](https://rust-lang.zulipchat.com/#narrow/stream/260443-project-const-generics/topic/inline.20consts.20typeck).
cc `````@spastorino````` `````@lcnr`````
r? `````@nikomatsakis`````

`````@rustbot````` label A-inference F-inline_const T-compiler
2021-11-09 19:00:40 +01:00
..
constraints
diagnostics Rollup merge of #89561 - nbdd0121:const_typeck, r=nikomatsakis 2021-11-09 19:00:40 +01:00
region_infer Rename functions reflect that inline const is also "typeck_child" 2021-11-07 04:00:34 +00:00
type_check Rollup merge of #89561 - nbdd0121:const_typeck, r=nikomatsakis 2021-11-09 19:00:40 +01:00
borrow_set.rs Add BorrowSet to public api 2021-10-25 22:16:07 +02:00
borrowck_errors.rs
constraint_generation.rs
consumers.rs Add InferCtxt::with_opaque_type_inference to get_body_with_borrowck_facts 2021-10-06 19:07:56 -07:00
dataflow.rs clippy::complexity fixes 2021-10-08 20:07:44 +02:00
def_use.rs
facts.rs
invalidation.rs Introduce Rvalue::ShallowInitBox 2021-09-25 01:08:41 +01:00
lib.rs Auto merge of #90380 - Mark-Simulacrum:revert-89558-query-stable-lint, r=lcnr 2021-10-29 04:55:51 +00:00
location.rs
member_constraints.rs Replace Fn impls with RPIT impls in rustc_index 2021-10-03 17:50:53 +02:00
nll.rs Rename functions reflect that inline const is also "typeck_child" 2021-11-07 04:00:34 +00:00
path_utils.rs
place_ext.rs
places_conflict.rs
prefixes.rs
renumber.rs More tracing instrumentation 2021-09-28 12:28:22 +00:00
universal_regions.rs Rename functions reflect that inline const is also "typeck_child" 2021-11-07 04:00:34 +00:00
used_muts.rs