@@ -310,7 +310,7 @@ impl<'tcx> SizeSkeleton<'tcx> {
310
310
ty : Ty < ' tcx > ,
311
311
tcx : TyCtxt < ' tcx > ,
312
312
param_env : ty:: ParamEnv < ' tcx > ,
313
- ) -> Result < SizeSkeleton < ' tcx > , LayoutError < ' tcx > > {
313
+ ) -> Result < SizeSkeleton < ' tcx > , & ' tcx LayoutError < ' tcx > > {
314
314
debug_assert ! ( !ty. has_non_region_infer( ) ) ;
315
315
316
316
// First try computing a static layout.
@@ -353,21 +353,21 @@ impl<'tcx> SizeSkeleton<'tcx> {
353
353
let size = s
354
354
. bytes ( )
355
355
. checked_mul ( c)
356
- . ok_or_else ( || LayoutError :: SizeOverflow ( ty) ) ?;
356
+ . ok_or_else ( || & * tcx . arena . alloc ( LayoutError :: SizeOverflow ( ty) ) ) ?;
357
357
return Ok ( SizeSkeleton :: Known ( Size :: from_bytes ( size) ) ) ;
358
358
}
359
359
let len = tcx. expand_abstract_consts ( len) ;
360
360
let prev = ty:: Const :: from_target_usize ( tcx, s. bytes ( ) ) ;
361
361
let Some ( gen_size) = mul_sorted_consts ( tcx, param_env, len, prev) else {
362
- return Err ( LayoutError :: SizeOverflow ( ty) ) ;
362
+ return Err ( tcx . arena . alloc ( LayoutError :: SizeOverflow ( ty) ) ) ;
363
363
} ;
364
364
Ok ( SizeSkeleton :: Generic ( gen_size) )
365
365
}
366
366
SizeSkeleton :: Pointer { .. } => Err ( err) ,
367
367
SizeSkeleton :: Generic ( g) => {
368
368
let len = tcx. expand_abstract_consts ( len) ;
369
369
let Some ( gen_size) = mul_sorted_consts ( tcx, param_env, len, g) else {
370
- return Err ( LayoutError :: SizeOverflow ( ty) ) ;
370
+ return Err ( tcx . arena . alloc ( LayoutError :: SizeOverflow ( ty) ) ) ;
371
371
} ;
372
372
Ok ( SizeSkeleton :: Generic ( gen_size) )
373
373
}
@@ -672,33 +672,43 @@ pub trait LayoutOf<'tcx>: LayoutOfHelpers<'tcx> {
672
672
673
673
MaybeResult :: from (
674
674
tcx. layout_of ( self . param_env ( ) . and ( ty) )
675
- . map_err ( |err| self . handle_layout_err ( err, span, ty) ) ,
675
+ . map_err ( |err| self . handle_layout_err ( * err, span, ty) ) ,
676
676
)
677
677
}
678
678
}
679
679
680
680
impl < ' tcx , C : LayoutOfHelpers < ' tcx > > LayoutOf < ' tcx > for C { }
681
681
682
682
impl < ' tcx > LayoutOfHelpers < ' tcx > for LayoutCx < ' tcx , TyCtxt < ' tcx > > {
683
- type LayoutOfResult = Result < TyAndLayout < ' tcx > , LayoutError < ' tcx > > ;
683
+ type LayoutOfResult = Result < TyAndLayout < ' tcx > , & ' tcx LayoutError < ' tcx > > ;
684
684
685
685
#[ inline]
686
- fn handle_layout_err ( & self , err : LayoutError < ' tcx > , _: Span , _: Ty < ' tcx > ) -> LayoutError < ' tcx > {
687
- err
686
+ fn handle_layout_err (
687
+ & self ,
688
+ err : LayoutError < ' tcx > ,
689
+ _: Span ,
690
+ _: Ty < ' tcx > ,
691
+ ) -> & ' tcx LayoutError < ' tcx > {
692
+ self . tcx . arena . alloc ( err)
688
693
}
689
694
}
690
695
691
696
impl < ' tcx > LayoutOfHelpers < ' tcx > for LayoutCx < ' tcx , TyCtxtAt < ' tcx > > {
692
- type LayoutOfResult = Result < TyAndLayout < ' tcx > , LayoutError < ' tcx > > ;
697
+ type LayoutOfResult = Result < TyAndLayout < ' tcx > , & ' tcx LayoutError < ' tcx > > ;
693
698
694
699
#[ inline]
695
700
fn layout_tcx_at_span ( & self ) -> Span {
696
701
self . tcx . span
697
702
}
698
703
699
704
#[ inline]
700
- fn handle_layout_err ( & self , err : LayoutError < ' tcx > , _: Span , _: Ty < ' tcx > ) -> LayoutError < ' tcx > {
701
- err
705
+ fn handle_layout_err (
706
+ & self ,
707
+ err : LayoutError < ' tcx > ,
708
+ _: Span ,
709
+ _: Ty < ' tcx > ,
710
+ ) -> & ' tcx LayoutError < ' tcx > {
711
+ self . tcx . arena . alloc ( err)
702
712
}
703
713
}
704
714
@@ -1250,18 +1260,6 @@ pub enum FnAbiError<'tcx> {
1250
1260
AdjustForForeignAbi ( call:: AdjustForForeignAbiError ) ,
1251
1261
}
1252
1262
1253
- impl < ' tcx > From < LayoutError < ' tcx > > for FnAbiError < ' tcx > {
1254
- fn from ( err : LayoutError < ' tcx > ) -> Self {
1255
- Self :: Layout ( err)
1256
- }
1257
- }
1258
-
1259
- impl From < call:: AdjustForForeignAbiError > for FnAbiError < ' _ > {
1260
- fn from ( err : call:: AdjustForForeignAbiError ) -> Self {
1261
- Self :: AdjustForForeignAbi ( err)
1262
- }
1263
- }
1264
-
1265
1263
impl < ' a , ' b > IntoDiagnostic < ' a , !> for FnAbiError < ' b > {
1266
1264
fn into_diagnostic ( self , handler : & ' a Handler ) -> DiagnosticBuilder < ' a , !> {
1267
1265
match self {
@@ -1321,7 +1319,7 @@ pub trait FnAbiOf<'tcx>: FnAbiOfHelpers<'tcx> {
1321
1319
let tcx = self . tcx ( ) . at ( span) ;
1322
1320
1323
1321
MaybeResult :: from ( tcx. fn_abi_of_fn_ptr ( self . param_env ( ) . and ( ( sig, extra_args) ) ) . map_err (
1324
- |err| self . handle_fn_abi_err ( err, span, FnAbiRequest :: OfFnPtr { sig, extra_args } ) ,
1322
+ |err| self . handle_fn_abi_err ( * err, span, FnAbiRequest :: OfFnPtr { sig, extra_args } ) ,
1325
1323
) )
1326
1324
}
1327
1325
@@ -1348,7 +1346,11 @@ pub trait FnAbiOf<'tcx>: FnAbiOfHelpers<'tcx> {
1348
1346
// However, we don't do this early in order to avoid calling
1349
1347
// `def_span` unconditionally (which may have a perf penalty).
1350
1348
let span = if !span. is_dummy ( ) { span } else { tcx. def_span ( instance. def_id ( ) ) } ;
1351
- self . handle_fn_abi_err ( err, span, FnAbiRequest :: OfInstance { instance, extra_args } )
1349
+ self . handle_fn_abi_err (
1350
+ * err,
1351
+ span,
1352
+ FnAbiRequest :: OfInstance { instance, extra_args } ,
1353
+ )
1352
1354
} ) ,
1353
1355
)
1354
1356
}
0 commit comments