@@ -105,11 +105,13 @@ fn map_error<'tcx>(
105105 // See `tests/ui/layout/trivial-bounds-sized.rs` for an example.
106106 assert ! ( field. layout. is_unsized( ) , "invalid layout error {err:#?}" ) ;
107107 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 ! (
109109 "encountered unexpected unsized field in layout of {ty:?}: {field:#?}"
110110 ) ) ;
111+ LayoutError :: ReferencesError ( guar)
112+ } else {
113+ LayoutError :: Unknown ( ty)
111114 }
112- LayoutError :: Unknown ( ty)
113115 }
114116 LayoutCalculatorError :: EmptyUnion => {
115117 // This is always a compile error.
@@ -427,8 +429,10 @@ fn layout_of_uncached<'tcx>(
427429 ty:: Adt ( def, args) if def. repr ( ) . simd ( ) => {
428430 if !def. is_struct ( ) {
429431 // Should have yielded E0517 by now.
430- tcx. dcx ( ) . delayed_bug ( "#[repr(simd)] was applied to an ADT that is not a struct" ) ;
431- return Err ( error ( cx, LayoutError :: Unknown ( ty) ) ) ;
432+ let guar = tcx
433+ . dcx ( )
434+ . delayed_bug ( "#[repr(simd)] was applied to an ADT that is not a struct" ) ;
435+ return Err ( error ( cx, LayoutError :: ReferencesError ( guar) ) ) ;
432436 }
433437
434438 let fields = & def. non_enum_variant ( ) . fields ;
@@ -454,10 +458,10 @@ fn layout_of_uncached<'tcx>(
454458 // (should be caught by typeck)
455459 for fi in fields {
456460 if fi. ty ( tcx, args) != f0_ty {
457- tcx. dcx ( ) . delayed_bug (
461+ let guar = tcx. dcx ( ) . delayed_bug (
458462 "#[repr(simd)] was applied to an ADT with heterogeneous field type" ,
459463 ) ;
460- return Err ( error ( cx, LayoutError :: Unknown ( ty ) ) ) ;
464+ return Err ( error ( cx, LayoutError :: ReferencesError ( guar ) ) ) ;
461465 }
462466 }
463467
@@ -561,11 +565,11 @@ fn layout_of_uncached<'tcx>(
561565
562566 if def. is_union ( ) {
563567 if def. repr ( ) . pack . is_some ( ) && def. repr ( ) . align . is_some ( ) {
564- tcx. dcx ( ) . span_delayed_bug (
568+ let guar = tcx. dcx ( ) . span_delayed_bug (
565569 tcx. def_span ( def. did ( ) ) ,
566570 "union cannot be packed and aligned" ,
567571 ) ;
568- return Err ( error ( cx, LayoutError :: Unknown ( ty ) ) ) ;
572+ return Err ( error ( cx, LayoutError :: ReferencesError ( guar ) ) ) ;
569573 }
570574
571575 return Ok ( tcx. mk_layout (
0 commit comments