@@ -8,15 +8,6 @@ use rustc_middle::ty::layout::{HasTyCtxt, LayoutCx, TyAndLayout};
8
8
pub ( super ) fn layout_sanity_check < ' tcx > ( cx : & LayoutCx < ' tcx > , layout : & TyAndLayout < ' tcx > ) {
9
9
let tcx = cx. tcx ( ) ;
10
10
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
-
20
11
if layout. size . bytes ( ) % layout. align . abi . bytes ( ) != 0 {
21
12
bug ! ( "size is not a multiple of align, in the following layout:\n {layout:#?}" ) ;
22
13
}
@@ -29,6 +20,19 @@ pub(super) fn layout_sanity_check<'tcx>(cx: &LayoutCx<'tcx>, layout: &TyAndLayou
29
20
return ;
30
21
}
31
22
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
+
32
36
/// Yields non-ZST fields of the type
33
37
fn non_zst_fields < ' tcx , ' a > (
34
38
cx : & ' a LayoutCx < ' tcx > ,
0 commit comments