@@ -18,7 +18,7 @@ use rustc_errors::Diagnostic;
18
18
use rustc_hir as hir;
19
19
use rustc_hir:: def_id:: { DefId , LocalDefId } ;
20
20
use rustc_hir:: lang_items:: LangItem ;
21
- use rustc_hir:: { BodyOwnerKind , HirId } ;
21
+ use rustc_hir:: BodyOwnerKind ;
22
22
use rustc_index:: vec:: { Idx , IndexVec } ;
23
23
use rustc_infer:: infer:: NllRegionVariableOrigin ;
24
24
use rustc_middle:: ty:: fold:: TypeFoldable ;
@@ -231,9 +231,7 @@ impl<'tcx> UniversalRegions<'tcx> {
231
231
mir_def : ty:: WithOptConstParam < LocalDefId > ,
232
232
param_env : ty:: ParamEnv < ' tcx > ,
233
233
) -> Self {
234
- let tcx = infcx. tcx ;
235
- let mir_hir_id = tcx. hir ( ) . local_def_id_to_hir_id ( mir_def. did ) ;
236
- UniversalRegionsBuilder { infcx, mir_def, mir_hir_id, param_env } . build ( )
234
+ UniversalRegionsBuilder { infcx, mir_def, param_env } . build ( )
237
235
}
238
236
239
237
/// Given a reference to a closure type, extracts all the values
@@ -390,7 +388,6 @@ impl<'tcx> UniversalRegions<'tcx> {
390
388
struct UniversalRegionsBuilder < ' cx , ' tcx > {
391
389
infcx : & ' cx BorrowckInferCtxt < ' cx , ' tcx > ,
392
390
mir_def : ty:: WithOptConstParam < LocalDefId > ,
393
- mir_hir_id : HirId ,
394
391
param_env : ty:: ParamEnv < ' tcx > ,
395
392
}
396
393
@@ -560,12 +557,7 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
560
557
561
558
match tcx. hir ( ) . body_owner_kind ( self . mir_def . did ) {
562
559
BodyOwnerKind :: Closure | BodyOwnerKind :: Fn => {
563
- let defining_ty = if self . mir_def . did . to_def_id ( ) == typeck_root_def_id {
564
- tcx. type_of ( typeck_root_def_id) . subst_identity ( )
565
- } else {
566
- let tables = tcx. typeck ( self . mir_def . did ) ;
567
- tables. node_type ( self . mir_hir_id )
568
- } ;
560
+ let defining_ty = tcx. type_of ( self . mir_def . def_id_for_type_of ( ) ) . subst_identity ( ) ;
569
561
570
562
debug ! ( "defining_ty (pre-replacement): {:?}" , defining_ty) ;
571
563
@@ -594,7 +586,18 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
594
586
self . infcx . replace_free_regions_with_nll_infer_vars ( FR , identity_substs) ;
595
587
DefiningTy :: Const ( self . mir_def . did . to_def_id ( ) , substs)
596
588
} else {
597
- let ty = tcx. typeck ( self . mir_def . did ) . node_type ( self . mir_hir_id ) ;
589
+ // FIXME this line creates a dependency between borrowck and typeck.
590
+ //
591
+ // This is required for `AscribeUserType` canonical query, which will call
592
+ // `type_of(inline_const_def_id)`. That `type_of` would inject erased lifetimes
593
+ // into borrowck, which is ICE #78174.
594
+ //
595
+ // As a workaround, inline consts have an additional generic param (`ty`
596
+ // below), so that `type_of(inline_const_def_id).substs(substs)` uses the
597
+ // proper type with NLL infer vars.
598
+ let ty = tcx
599
+ . typeck ( self . mir_def . did )
600
+ . node_type ( tcx. local_def_id_to_hir_id ( self . mir_def . did ) ) ;
598
601
let substs = InlineConstSubsts :: new (
599
602
tcx,
600
603
InlineConstSubstsParts { parent_substs : identity_substs, ty } ,
0 commit comments