@@ -105,21 +105,27 @@ fn map_error<'tcx>(
105105// See `tests/ui/layout/trivial-bounds-sized.rs` for an example.
106106assert ! ( field. layout. is_unsized( ) , "invalid layout error {err:#?}" ) ;
107107if !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}
114116LayoutCalculatorError :: EmptyUnion => {
115117// 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)
118121}
119122LayoutCalculatorError :: ReprConflict => {
120123// 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)
123129}
124130} ;
125131error ( cx, err)
@@ -432,8 +438,10 @@ fn layout_of_uncached<'tcx>(
432438 ty:: Adt ( def, args) if def. repr ( ) . simd ( ) => {
433439if !def. is_struct ( ) {
434440// 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) ) ) ;
437445}
438446
439447let fields = & def. non_enum_variant ( ) . fields ;
@@ -459,10 +467,10 @@ fn layout_of_uncached<'tcx>(
459467// (should be caught by typeck)
460468for fi in fields {
461469if fi. ty ( tcx, args) != f0_ty {
462- tcx. dcx ( ) . delayed_bug (
470+ let guar = tcx. dcx ( ) . delayed_bug (
463471"#[repr(simd)] was applied to an ADT with heterogeneous field type" ,
464472) ;
465- return Err ( error ( cx, LayoutError :: Unknown ( ty ) ) ) ;
473+ return Err ( error ( cx, LayoutError :: ReferencesError ( guar ) ) ) ;
466474}
467475}
468476
@@ -567,11 +575,11 @@ fn layout_of_uncached<'tcx>(
567575
568576if def. is_union ( ) {
569577if def. repr ( ) . pack . is_some ( ) && def. repr ( ) . align . is_some ( ) {
570- tcx. dcx ( ) . span_delayed_bug (
578+ let guar = tcx. dcx ( ) . span_delayed_bug (
571579 tcx. def_span ( def. did ( ) ) ,
572580"union cannot be packed and aligned" ,
573581) ;
574- return Err ( error ( cx, LayoutError :: Unknown ( ty ) ) ) ;
582+ return Err ( error ( cx, LayoutError :: ReferencesError ( guar ) ) ) ;
575583}
576584
577585return Ok ( tcx. mk_layout (
0 commit comments