1
1
use rustc_index:: vec:: IndexVec ;
2
+ use rustc_middle:: ty:: layout:: LayoutError ;
2
3
use rustc_middle:: ty:: SymbolName ;
3
4
use rustc_target:: abi:: call:: FnAbi ;
4
5
use rustc_target:: abi:: { Integer , Primitive } ;
@@ -256,15 +257,6 @@ pub(crate) struct FunctionCx<'m, 'clif, 'tcx: 'm> {
256
257
pub ( crate ) inline_asm_index : u32 ,
257
258
}
258
259
259
- impl < ' tcx > LayoutOf < ' tcx > for FunctionCx < ' _ , ' _ , ' tcx > {
260
- type Ty = Ty < ' tcx > ;
261
- type TyAndLayout = TyAndLayout < ' tcx > ;
262
-
263
- fn layout_of ( & self , ty : Ty < ' tcx > ) -> TyAndLayout < ' tcx > {
264
- RevealAllLayoutCx ( self . tcx ) . layout_of ( ty)
265
- }
266
- }
267
-
268
260
impl < ' tcx > layout:: HasTyCtxt < ' tcx > for FunctionCx < ' _ , ' _ , ' tcx > {
269
261
fn tcx < ' b > ( & ' b self ) -> TyCtxt < ' tcx > {
270
262
self . tcx
@@ -289,6 +281,15 @@ impl<'tcx> HasTargetSpec for FunctionCx<'_, '_, 'tcx> {
289
281
}
290
282
}
291
283
284
+ impl < ' tcx > ty:: layout:: IsLayoutCx < ' tcx > for FunctionCx < ' _ , ' _ , ' tcx > {
285
+ type LayoutOfResult = TyAndLayout < ' tcx > ;
286
+
287
+ #[ inline]
288
+ fn map_err_for_layout_of ( err : LayoutError < ' tcx > , cx : & Self , span : Span , ty : Ty < ' tcx > ) -> ! {
289
+ RevealAllLayoutCx :: map_err_for_layout_of ( err, & RevealAllLayoutCx ( cx. tcx ) , span, ty)
290
+ }
291
+ }
292
+
292
293
impl < ' tcx > FunctionCx < ' _ , ' _ , ' tcx > {
293
294
pub ( crate ) fn monomorphize < T > ( & self , value : T ) -> T
294
295
where
@@ -364,22 +365,6 @@ impl<'tcx> FunctionCx<'_, '_, 'tcx> {
364
365
365
366
pub ( crate ) struct RevealAllLayoutCx < ' tcx > ( pub ( crate ) TyCtxt < ' tcx > ) ;
366
367
367
- impl < ' tcx > LayoutOf < ' tcx > for RevealAllLayoutCx < ' tcx > {
368
- type Ty = Ty < ' tcx > ;
369
- type TyAndLayout = TyAndLayout < ' tcx > ;
370
-
371
- fn layout_of ( & self , ty : Ty < ' tcx > ) -> TyAndLayout < ' tcx > {
372
- assert ! ( !ty. still_further_specializable( ) ) ;
373
- self . 0 . layout_of ( ParamEnv :: reveal_all ( ) . and ( & ty) ) . unwrap_or_else ( |e| {
374
- if let layout:: LayoutError :: SizeOverflow ( _) = e {
375
- self . 0 . sess . fatal ( & e. to_string ( ) )
376
- } else {
377
- bug ! ( "failed to get layout for `{}`: {}" , ty, e)
378
- }
379
- } )
380
- }
381
- }
382
-
383
368
impl < ' tcx > layout:: HasTyCtxt < ' tcx > for RevealAllLayoutCx < ' tcx > {
384
369
fn tcx < ' b > ( & ' b self ) -> TyCtxt < ' tcx > {
385
370
self . 0
@@ -403,3 +388,16 @@ impl<'tcx> HasTargetSpec for RevealAllLayoutCx<'tcx> {
403
388
& self . 0 . sess . target
404
389
}
405
390
}
391
+
392
+ impl < ' tcx > ty:: layout:: IsLayoutCx < ' tcx > for RevealAllLayoutCx < ' tcx > {
393
+ type LayoutOfResult = TyAndLayout < ' tcx > ;
394
+
395
+ #[ inline]
396
+ fn map_err_for_layout_of ( err : LayoutError < ' tcx > , cx : & Self , span : Span , ty : Ty < ' tcx > ) -> ! {
397
+ if let layout:: LayoutError :: SizeOverflow ( _) = err {
398
+ cx. 0 . sess . span_fatal ( span, & err. to_string ( ) )
399
+ } else {
400
+ span_bug ! ( span, "failed to get layout for `{}`: {}" , ty, err)
401
+ }
402
+ }
403
+ }
0 commit comments