@@ -125,7 +125,7 @@ pub enum DefiningTy<'tcx> {
125
125
/// The MIR represents some form of constant. The signature then
126
126
/// is that it has no inputs and a single return value, which is
127
127
/// the value of the constant.
128
- Const ( Ty < ' tcx > ) ,
128
+ Const ( DefId , & ' tcx Substs < ' tcx > ) ,
129
129
}
130
130
131
131
#[ derive( Debug ) ]
@@ -534,34 +534,42 @@ impl<'cx, 'gcx, 'tcx> UniversalRegionsBuilder<'cx, 'gcx, 'tcx> {
534
534
/// see `DefiningTy` for details.
535
535
fn defining_ty ( & self ) -> DefiningTy < ' tcx > {
536
536
let tcx = self . infcx . tcx ;
537
-
538
537
let closure_base_def_id = tcx. closure_base_def_id ( self . mir_def_id ) ;
539
538
540
- let defining_ty = if self . mir_def_id == closure_base_def_id {
541
- tcx. type_of ( closure_base_def_id)
542
- } else {
543
- let tables = tcx. typeck_tables_of ( self . mir_def_id ) ;
544
- tables. node_id_to_type ( self . mir_hir_id )
545
- } ;
546
-
547
- let defining_ty = self . infcx
548
- . replace_free_regions_with_nll_infer_vars ( FR , & defining_ty) ;
549
-
550
539
match tcx. hir . body_owner_kind ( self . mir_node_id ) {
551
- BodyOwnerKind :: Fn => match defining_ty. sty {
552
- ty:: TyClosure ( def_id, substs) => DefiningTy :: Closure ( def_id, substs) ,
553
- ty:: TyGenerator ( def_id, substs, interior) => {
554
- DefiningTy :: Generator ( def_id, substs, interior)
540
+ BodyOwnerKind :: Fn => {
541
+ let defining_ty = if self . mir_def_id == closure_base_def_id {
542
+ tcx. type_of ( closure_base_def_id)
543
+ } else {
544
+ let tables = tcx. typeck_tables_of ( self . mir_def_id ) ;
545
+ tables. node_id_to_type ( self . mir_hir_id )
546
+ } ;
547
+
548
+ let defining_ty = self . infcx
549
+ . replace_free_regions_with_nll_infer_vars ( FR , & defining_ty) ;
550
+
551
+ match defining_ty. sty {
552
+ ty:: TyClosure ( def_id, substs) => DefiningTy :: Closure ( def_id, substs) ,
553
+ ty:: TyGenerator ( def_id, substs, interior) => {
554
+ DefiningTy :: Generator ( def_id, substs, interior)
555
+ }
556
+ ty:: TyFnDef ( def_id, substs) => DefiningTy :: FnDef ( def_id, substs) ,
557
+ _ => span_bug ! (
558
+ tcx. def_span( self . mir_def_id) ,
559
+ "expected defining type for `{:?}`: `{:?}`" ,
560
+ self . mir_def_id,
561
+ defining_ty
562
+ ) ,
555
563
}
556
- ty :: TyFnDef ( def_id , substs ) => DefiningTy :: FnDef ( def_id , substs ) ,
557
- _ => span_bug ! (
558
- tcx . def_span ( self . mir_def_id ) ,
559
- "expected defining type for `{:?}`: `{:?}`" ,
560
- self . mir_def_id ,
561
- defining_ty
562
- ) ,
563
- } ,
564
- BodyOwnerKind :: Const | BodyOwnerKind :: Static ( .. ) => DefiningTy :: Const ( defining_ty ) ,
564
+ }
565
+
566
+ BodyOwnerKind :: Const | BodyOwnerKind :: Static ( .. ) => {
567
+ assert_eq ! ( closure_base_def_id , self . mir_def_id ) ;
568
+ let identity_substs = Substs :: identity_for_item ( tcx , closure_base_def_id ) ;
569
+ let substs = self . infcx
570
+ . replace_free_regions_with_nll_infer_vars ( FR , & identity_substs ) ;
571
+ DefiningTy :: Const ( self . mir_def_id , substs )
572
+ }
565
573
}
566
574
}
567
575
@@ -592,13 +600,7 @@ impl<'cx, 'gcx, 'tcx> UniversalRegionsBuilder<'cx, 'gcx, 'tcx> {
592
600
substs. substs
593
601
}
594
602
595
- DefiningTy :: FnDef ( _, substs) => substs,
596
-
597
- // When we encounter a constant body, just return whatever
598
- // substitutions are in scope for that constant.
599
- DefiningTy :: Const ( _) => {
600
- identity_substs
601
- }
603
+ DefiningTy :: FnDef ( _, substs) | DefiningTy :: Const ( _, substs) => substs,
602
604
} ;
603
605
604
606
let global_mapping = iter:: once ( ( gcx. types . re_static , fr_static) ) ;
@@ -660,9 +662,14 @@ impl<'cx, 'gcx, 'tcx> UniversalRegionsBuilder<'cx, 'gcx, 'tcx> {
660
662
sig. inputs_and_output ( )
661
663
}
662
664
663
- // For a constant body, there are no inputs, and one
664
- // "output" (the type of the constant).
665
- DefiningTy :: Const ( ty) => ty:: Binder :: dummy ( tcx. mk_type_list ( iter:: once ( ty) ) ) ,
665
+ DefiningTy :: Const ( def_id, _) => {
666
+ // For a constant body, there are no inputs, and one
667
+ // "output" (the type of the constant).
668
+ assert_eq ! ( self . mir_def_id, def_id) ;
669
+ let ty = tcx. type_of ( def_id) ;
670
+ let ty = indices. fold_to_region_vids ( tcx, & ty) ;
671
+ ty:: Binder :: dummy ( tcx. mk_type_list ( iter:: once ( ty) ) )
672
+ }
666
673
}
667
674
}
668
675
0 commit comments