@@ -23,7 +23,7 @@ use rustc_index::vec::{Idx, IndexVec};
2323use rustc_infer:: infer:: { InferCtxt , NllRegionVariableOrigin } ;
2424use rustc_middle:: ty:: fold:: TypeFoldable ;
2525use rustc_middle:: ty:: subst:: { InternalSubsts , Subst , SubstsRef } ;
26- use rustc_middle:: ty:: { self , RegionVid , Ty , TyCtxt } ;
26+ use rustc_middle:: ty:: { self , InlineConstSubsts , InlineConstSubstsParts , RegionVid , Ty , TyCtxt } ;
2727use std:: iter;
2828
2929use crate :: nll:: ToRegionVid ;
@@ -108,6 +108,10 @@ pub enum DefiningTy<'tcx> {
108108 /// is that it has no inputs and a single return value, which is
109109 /// the value of the constant.
110110 Const ( DefId , SubstsRef < ' tcx > ) ,
111+
112+ /// The MIR represents an inline const. The signature has no inputs and a
113+ /// single return value found via `InlineConstSubsts::ty`.
114+ InlineConst ( DefId , SubstsRef < ' tcx > ) ,
111115}
112116
113117impl < ' tcx > DefiningTy < ' tcx > {
@@ -121,7 +125,7 @@ impl<'tcx> DefiningTy<'tcx> {
121125 DefiningTy :: Generator ( _, substs, _) => {
122126 Either :: Right ( Either :: Left ( substs. as_generator ( ) . upvar_tys ( ) ) )
123127 }
124- DefiningTy :: FnDef ( ..) | DefiningTy :: Const ( ..) => {
128+ DefiningTy :: FnDef ( ..) | DefiningTy :: Const ( ..) | DefiningTy :: InlineConst ( .. ) => {
125129 Either :: Right ( Either :: Right ( iter:: empty ( ) ) )
126130 }
127131 }
@@ -133,7 +137,7 @@ impl<'tcx> DefiningTy<'tcx> {
133137 pub fn implicit_inputs ( self ) -> usize {
134138 match self {
135139 DefiningTy :: Closure ( ..) | DefiningTy :: Generator ( ..) => 1 ,
136- DefiningTy :: FnDef ( ..) | DefiningTy :: Const ( ..) => 0 ,
140+ DefiningTy :: FnDef ( ..) | DefiningTy :: Const ( ..) | DefiningTy :: InlineConst ( .. ) => 0 ,
137141 }
138142 }
139143
@@ -142,15 +146,16 @@ impl<'tcx> DefiningTy<'tcx> {
142146 }
143147
144148 pub fn is_const ( & self ) -> bool {
145- matches ! ( * self , DefiningTy :: Const ( ..) )
149+ matches ! ( * self , DefiningTy :: Const ( ..) | DefiningTy :: InlineConst ( .. ) )
146150 }
147151
148152 pub fn def_id ( & self ) -> DefId {
149153 match * self {
150154 DefiningTy :: Closure ( def_id, ..)
151155 | DefiningTy :: Generator ( def_id, ..)
152156 | DefiningTy :: FnDef ( def_id, ..)
153- | DefiningTy :: Const ( def_id, ..) => def_id,
157+ | DefiningTy :: Const ( def_id, ..)
158+ | DefiningTy :: InlineConst ( def_id, ..) => def_id,
154159 }
155160 }
156161}
@@ -376,6 +381,12 @@ impl<'tcx> UniversalRegions<'tcx> {
376381 tcx. def_path_str_with_substs( def_id, substs) ,
377382 ) ) ;
378383 }
384+ DefiningTy :: InlineConst ( def_id, substs) => {
385+ err. note ( & format ! (
386+ "defining inline constant type: {}" ,
387+ tcx. def_path_str_with_substs( def_id, substs) ,
388+ ) ) ;
389+ }
379390 }
380391 }
381392}
@@ -534,11 +545,21 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
534545 }
535546
536547 BodyOwnerKind :: Const | BodyOwnerKind :: Static ( ..) => {
537- assert_eq ! ( self . mir_def. did. to_def_id( ) , closure_base_def_id) ;
538548 let identity_substs = InternalSubsts :: identity_for_item ( tcx, closure_base_def_id) ;
539- let substs =
540- self . infcx . replace_free_regions_with_nll_infer_vars ( FR , identity_substs) ;
541- DefiningTy :: Const ( self . mir_def . did . to_def_id ( ) , substs)
549+ if self . mir_def . did . to_def_id ( ) == closure_base_def_id {
550+ let substs =
551+ self . infcx . replace_free_regions_with_nll_infer_vars ( FR , identity_substs) ;
552+ DefiningTy :: Const ( self . mir_def . did . to_def_id ( ) , substs)
553+ } else {
554+ let ty = tcx. typeck ( self . mir_def . did ) . node_type ( self . mir_hir_id ) ;
555+ let substs = InlineConstSubsts :: new (
556+ tcx,
557+ InlineConstSubstsParts { parent_substs : identity_substs, ty } ,
558+ )
559+ . substs ;
560+ let substs = self . infcx . replace_free_regions_with_nll_infer_vars ( FR , substs) ;
561+ DefiningTy :: InlineConst ( self . mir_def . did . to_def_id ( ) , substs)
562+ }
542563 }
543564 }
544565 }
@@ -556,7 +577,9 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
556577 let closure_base_def_id = tcx. closure_base_def_id ( self . mir_def . did . to_def_id ( ) ) ;
557578 let identity_substs = InternalSubsts :: identity_for_item ( tcx, closure_base_def_id) ;
558579 let fr_substs = match defining_ty {
559- DefiningTy :: Closure ( _, ref substs) | DefiningTy :: Generator ( _, ref substs, _) => {
580+ DefiningTy :: Closure ( _, ref substs)
581+ | DefiningTy :: Generator ( _, ref substs, _)
582+ | DefiningTy :: InlineConst ( _, ref substs) => {
560583 // In the case of closures, we rely on the fact that
561584 // the first N elements in the ClosureSubsts are
562585 // inherited from the `closure_base_def_id`.
@@ -648,6 +671,12 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
648671 let ty = indices. fold_to_region_vids ( tcx, ty) ;
649672 ty:: Binder :: dummy ( tcx. intern_type_list ( & [ ty] ) )
650673 }
674+
675+ DefiningTy :: InlineConst ( def_id, substs) => {
676+ assert_eq ! ( self . mir_def. did. to_def_id( ) , def_id) ;
677+ let ty = substs. as_inline_const ( ) . ty ( ) ;
678+ ty:: Binder :: dummy ( tcx. intern_type_list ( & [ ty] ) )
679+ }
651680 }
652681 }
653682}
0 commit comments