@@ -8,15 +8,6 @@ use rustc_middle::ty::layout::{HasTyCtxt, LayoutCx, TyAndLayout};
88pub ( super ) fn layout_sanity_check < ' tcx > ( cx : & LayoutCx < ' tcx > , layout : & TyAndLayout < ' tcx > ) {
99 let tcx = cx. tcx ( ) ;
1010
11- // Type-level uninhabitedness should always imply ABI uninhabitedness.
12- if layout. ty . is_privately_uninhabited ( tcx, cx. typing_env ) {
13- assert ! (
14- layout. is_uninhabited( ) ,
15- "{:?} is type-level uninhabited but not ABI-uninhabited?" ,
16- layout. ty
17- ) ;
18- }
19-
2011 if layout. size . bytes ( ) % layout. align . abi . bytes ( ) != 0 {
2112 bug ! ( "size is not a multiple of align, in the following layout:\n {layout:#?}" ) ;
2213 }
@@ -29,6 +20,19 @@ pub(super) fn layout_sanity_check<'tcx>(cx: &LayoutCx<'tcx>, layout: &TyAndLayou
2920 return ;
3021 }
3122
23+ // Type-level uninhabitedness should always imply ABI uninhabitedness. This can be expensive on
24+ // big non-exhaustive types, and is [hard to
25+ // fix](https://github.com/rust-lang/rust/issues/141006#issuecomment-2883415000) in general.
26+ // Only doing this sanity check when debug assertions are turned on avoids the issue for the
27+ // very specific case of #140944.
28+ if layout. ty . is_privately_uninhabited ( tcx, cx. typing_env ) {
29+ assert ! (
30+ layout. is_uninhabited( ) ,
31+ "{:?} is type-level uninhabited but not ABI-uninhabited?" ,
32+ layout. ty
33+ ) ;
34+ }
35+
3236 /// Yields non-ZST fields of the type
3337 fn non_zst_fields < ' tcx , ' a > (
3438 cx : & ' a LayoutCx < ' tcx > ,
0 commit comments