@@ -105,21 +105,27 @@ fn map_error<'tcx>(
105
105
// See `tests/ui/layout/trivial-bounds-sized.rs` for an example.
106
106
assert ! ( field. layout. is_unsized( ) , "invalid layout error {err:#?}" ) ;
107
107
if !field. ty . is_sized ( cx. tcx ( ) , cx. typing_env ) {
108
- cx. tcx ( ) . dcx ( ) . delayed_bug ( format ! (
108
+ let guar = cx. tcx ( ) . dcx ( ) . delayed_bug ( format ! (
109
109
"encountered unexpected unsized field in layout of {ty:?}: {field:#?}"
110
110
) ) ;
111
+ LayoutError :: ReferencesError ( guar)
112
+ } else {
113
+ LayoutError :: Unknown ( ty)
111
114
}
112
- LayoutError :: Unknown ( ty)
113
115
}
114
116
LayoutCalculatorError :: EmptyUnion => {
115
117
// This is always a compile error.
116
- cx. tcx ( ) . dcx ( ) . delayed_bug ( format ! ( "computed layout of empty union: {ty:?}" ) ) ;
117
- LayoutError :: Unknown ( ty)
118
+ let guar =
119
+ cx. tcx ( ) . dcx ( ) . delayed_bug ( format ! ( "computed layout of empty union: {ty:?}" ) ) ;
120
+ LayoutError :: ReferencesError ( guar)
118
121
}
119
122
LayoutCalculatorError :: ReprConflict => {
120
123
// packed enums are the only known trigger of this, but others might arise
121
- cx. tcx ( ) . dcx ( ) . delayed_bug ( format ! ( "computed impossible repr (packed enum?): {ty:?}" ) ) ;
122
- LayoutError :: Unknown ( ty)
124
+ let guar = cx
125
+ . tcx ( )
126
+ . dcx ( )
127
+ . delayed_bug ( format ! ( "computed impossible repr (packed enum?): {ty:?}" ) ) ;
128
+ LayoutError :: ReferencesError ( guar)
123
129
}
124
130
} ;
125
131
error ( cx, err)
@@ -432,8 +438,10 @@ fn layout_of_uncached<'tcx>(
432
438
ty:: Adt ( def, args) if def. repr ( ) . simd ( ) => {
433
439
if !def. is_struct ( ) {
434
440
// Should have yielded E0517 by now.
435
- tcx. dcx ( ) . delayed_bug ( "#[repr(simd)] was applied to an ADT that is not a struct" ) ;
436
- return Err ( error ( cx, LayoutError :: Unknown ( ty) ) ) ;
441
+ let guar = tcx
442
+ . dcx ( )
443
+ . delayed_bug ( "#[repr(simd)] was applied to an ADT that is not a struct" ) ;
444
+ return Err ( error ( cx, LayoutError :: ReferencesError ( guar) ) ) ;
437
445
}
438
446
439
447
let fields = & def. non_enum_variant ( ) . fields ;
@@ -459,10 +467,10 @@ fn layout_of_uncached<'tcx>(
459
467
// (should be caught by typeck)
460
468
for fi in fields {
461
469
if fi. ty ( tcx, args) != f0_ty {
462
- tcx. dcx ( ) . delayed_bug (
470
+ let guar = tcx. dcx ( ) . delayed_bug (
463
471
"#[repr(simd)] was applied to an ADT with heterogeneous field type" ,
464
472
) ;
465
- return Err ( error ( cx, LayoutError :: Unknown ( ty ) ) ) ;
473
+ return Err ( error ( cx, LayoutError :: ReferencesError ( guar ) ) ) ;
466
474
}
467
475
}
468
476
@@ -567,11 +575,11 @@ fn layout_of_uncached<'tcx>(
567
575
568
576
if def. is_union ( ) {
569
577
if def. repr ( ) . pack . is_some ( ) && def. repr ( ) . align . is_some ( ) {
570
- tcx. dcx ( ) . span_delayed_bug (
578
+ let guar = tcx. dcx ( ) . span_delayed_bug (
571
579
tcx. def_span ( def. did ( ) ) ,
572
580
"union cannot be packed and aligned" ,
573
581
) ;
574
- return Err ( error ( cx, LayoutError :: Unknown ( ty ) ) ) ;
582
+ return Err ( error ( cx, LayoutError :: ReferencesError ( guar ) ) ) ;
575
583
}
576
584
577
585
return Ok ( tcx. mk_layout (
0 commit comments