rust/compiler
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
..
rustc Migrate to 2021 2021-09-20 22:21:42 -04:00
rustc_apfloat Revert "Auto merge of #89709 - clemenswasser:apply_clippy_suggestions_2, r=petrochenkov" 2021-10-15 11:28:23 +02:00
rustc_arena Migrate to 2021 2021-09-20 22:21:42 -04:00
rustc_ast Rollup merge of #90657 - GuillaumeGomez:one-char-last-line-removed, r=jyn514 2021-11-08 15:15:24 +01:00
rustc_ast_lowering ast: Fix naming conventions in AST structures 2021-11-07 21:38:17 +08:00
rustc_ast_passes Auto merge of #90668 - matthiaskrgr:clippy_nov7, r=jyn514 2021-11-07 20:04:54 +00:00
rustc_ast_pretty Auto merge of #90668 - matthiaskrgr:clippy_nov7, r=jyn514 2021-11-07 20:04:54 +00:00
rustc_attr Correct typo 2021-10-16 13:36:05 -07:00
rustc_borrowck Rollup merge of #89561 - nbdd0121:const_typeck, r=nikomatsakis 2021-11-09 19:00:40 +01:00
rustc_builtin_macros Auto merge of #90485 - camsteffen:fmt-args-less-bind, r=m-ou-se 2021-11-09 05:33:16 +00:00
rustc_codegen_cranelift Make hash_result an Option. 2021-10-20 18:29:18 +02:00
rustc_codegen_gcc Auto merge of #89652 - rcvalle:rust-cfi, r=nagisa 2021-10-27 09:19:42 +00:00
rustc_codegen_llvm Rollup merge of #89561 - nbdd0121:const_typeck, r=nikomatsakis 2021-11-09 19:00:40 +01:00
rustc_codegen_ssa Rollup merge of #90688 - SparrowLii:dotprod, r=Amanieu 2021-11-09 22:02:24 +09:00
rustc_const_eval Rollup merge of #89561 - nbdd0121:const_typeck, r=nikomatsakis 2021-11-09 19:00:40 +01:00
rustc_data_structures more clippy fixes 2021-11-07 16:59:05 +01:00
rustc_driver Don't proceed to codegen if there are lint errors 2021-11-08 01:22:28 +00:00
rustc_error_codes Improve error when an .rlib can't be parsed 2021-11-07 15:03:40 +00:00
rustc_errors Don't abort compilation after giving a lint error 2021-11-08 01:22:28 +00:00
rustc_expand Don't abort compilation after giving a lint error 2021-11-08 01:22:28 +00:00
rustc_feature Add features gates for experimental asm features 2021-11-07 01:23:53 +00:00
rustc_fs_util Migrate to 2021 2021-09-20 22:21:42 -04:00
rustc_graphviz Revert "Auto merge of #89709 - clemenswasser:apply_clippy_suggestions_2, r=petrochenkov" 2021-10-15 11:28:23 +02:00
rustc_hir Give inline const separate DefKind 2021-11-07 03:59:06 +00:00
rustc_hir_pretty Auto merge of #89124 - cjgillot:owner-info, r=michaelwoerister 2021-10-18 19:53:05 +00:00
rustc_incremental Revert "Add rustc lint, warning when iterating over hashmaps" 2021-10-28 11:01:42 -04:00
rustc_index update cfg(bootstrap) 2021-10-23 21:55:57 -04:00
rustc_infer Rollup merge of #89561 - nbdd0121:const_typeck, r=nikomatsakis 2021-11-09 19:00:40 +01:00
rustc_interface Auto merge of #90668 - matthiaskrgr:clippy_nov7, r=jyn514 2021-11-07 20:04:54 +00:00
rustc_lexer use matches!() macro in more places 2021-11-06 16:13:14 +01:00
rustc_lint Auto merge of #90668 - matthiaskrgr:clippy_nov7, r=jyn514 2021-11-07 20:04:54 +00:00
rustc_lint_defs Properly register text_direction_codepoint_in_comment lint. 2021-11-05 20:12:40 +01:00
rustc_llvm Initialize LLVM time trace profiler on each code generation thread 2021-11-05 17:47:11 +01:00
rustc_macros more clippy fixes 2021-11-07 16:59:05 +01:00
rustc_metadata Rollup merge of #89561 - nbdd0121:const_typeck, r=nikomatsakis 2021-11-09 19:00:40 +01:00
rustc_middle Rollup merge of #89561 - nbdd0121:const_typeck, r=nikomatsakis 2021-11-09 19:00:40 +01:00
rustc_mir_build Implement type inference for inline consts 2021-11-07 04:00:32 +00:00
rustc_mir_dataflow Remove MaybeMutBorrowedLocals 2021-11-03 16:43:12 +01:00
rustc_mir_transform Rollup merge of #90649 - cjgillot:reveal-all-2, r=lcnr 2021-11-06 23:12:06 +01:00
rustc_monomorphize Rename functions reflect that inline const is also "typeck_child" 2021-11-07 04:00:34 +00:00
rustc_parse ast: Fix naming conventions in AST structures 2021-11-07 21:38:17 +08:00
rustc_parse_format Migrate to 2021 2021-09-20 22:21:42 -04:00
rustc_passes Rollup merge of #89561 - nbdd0121:const_typeck, r=nikomatsakis 2021-11-09 19:00:40 +01:00
rustc_plugin_impl Move rustc_middle::middle::cstore to rustc_session. 2021-10-03 16:08:51 +02:00
rustc_privacy Give inline const separate DefKind 2021-11-07 03:59:06 +00:00
rustc_query_impl Revert "Add rustc lint, warning when iterating over hashmaps" 2021-10-28 11:01:42 -04:00
rustc_query_system Auto merge of #90361 - Mark-Simulacrum:always-verify, r=michaelwoerister 2021-11-08 13:38:08 +00:00
rustc_resolve Rollup merge of #89561 - nbdd0121:const_typeck, r=nikomatsakis 2021-11-09 19:00:40 +01:00
rustc_save_analysis Give inline const separate DefKind 2021-11-07 03:59:06 +00:00
rustc_serialize Revert "Auto merge of #89709 - clemenswasser:apply_clippy_suggestions_2, r=petrochenkov" 2021-10-15 11:28:23 +02:00
rustc_session Auto merge of #87337 - jyn514:lint-error, r=oli-obk,flip1995 2021-11-09 08:21:10 +00:00
rustc_span Auto merge of #90485 - camsteffen:fmt-args-less-bind, r=m-ou-se 2021-11-09 05:33:16 +00:00
rustc_symbol_mangling Revert "Add rustc lint, warning when iterating over hashmaps" 2021-10-28 11:01:42 -04:00
rustc_target Rollup merge of #90494 - Meziu:armv6k-3ds-target, r=sanxiyn 2021-11-08 15:15:22 +01:00
rustc_trait_selection Rollup merge of #89561 - nbdd0121:const_typeck, r=nikomatsakis 2021-11-09 19:00:40 +01:00
rustc_traits Make select_* methods return Vec for TraitEngine 2021-11-08 23:35:23 +08:00
rustc_ty_utils Auto merge of #90218 - JakobDegen:adt_significant_drop_fix, r=nikomatsakis 2021-10-28 16:03:13 +00:00
rustc_type_ir Add two inline annotations for hot functions 2021-10-03 12:43:43 -04:00
rustc_typeck Rollup merge of #89561 - nbdd0121:const_typeck, r=nikomatsakis 2021-11-09 19:00:40 +01:00