@@ -191,7 +191,14 @@ fn layout_raw<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
191191
192192 ty:: tls:: enter_context ( & icx, |_| {
193193 let cx = LayoutCx { tcx, param_env } ;
194- cx. layout_raw_uncached ( ty)
194+ let layout = cx. layout_raw_uncached ( ty) ;
195+ // Type-level uninhabitedness should always imply ABI uninhabitedness.
196+ if let Ok ( layout) = layout {
197+ if ty. conservative_is_privately_uninhabited ( tcx) {
198+ assert ! ( layout. abi. is_uninhabited( ) ) ;
199+ }
200+ }
201+ layout
195202 } )
196203 } )
197204}
@@ -205,12 +212,11 @@ pub fn provide(providers: &mut ty::query::Providers<'_>) {
205212
206213pub struct LayoutCx < ' tcx , C > {
207214 pub tcx : C ,
208- pub param_env : ty:: ParamEnv < ' tcx >
215+ pub param_env : ty:: ParamEnv < ' tcx > ,
209216}
210217
211218impl < ' a , ' tcx > LayoutCx < ' tcx , TyCtxt < ' a , ' tcx , ' tcx > > {
212- fn layout_raw_uncached ( & self , ty : Ty < ' tcx > )
213- -> Result < & ' tcx LayoutDetails , LayoutError < ' tcx > > {
219+ fn layout_raw_uncached ( & self , ty : Ty < ' tcx > ) -> Result < & ' tcx LayoutDetails , LayoutError < ' tcx > > {
214220 let tcx = self . tcx ;
215221 let param_env = self . param_env ;
216222 let dl = self . data_layout ( ) ;
@@ -551,13 +557,19 @@ impl<'a, 'tcx> LayoutCx<'tcx, TyCtxt<'a, 'tcx, 'tcx>> {
551557 let size = element. size . checked_mul ( count, dl)
552558 . ok_or ( LayoutError :: SizeOverflow ( ty) ) ?;
553559
560+ let abi = if count != 0 && ty. conservative_is_privately_uninhabited ( tcx) {
561+ Abi :: Uninhabited
562+ } else {
563+ Abi :: Aggregate { sized : true }
564+ } ;
565+
554566 tcx. intern_layout ( LayoutDetails {
555567 variants : Variants :: Single { index : VariantIdx :: new ( 0 ) } ,
556568 fields : FieldPlacement :: Array {
557569 stride : element. size ,
558570 count
559571 } ,
560- abi : Abi :: Aggregate { sized : true } ,
572+ abi,
561573 align : element. align ,
562574 size
563575 } )
0 commit comments