@@ -340,29 +340,27 @@ fn trans_stmt<'tcx>(
340
340
} ;
341
341
lval. write_cvalue ( fx, res) ;
342
342
}
343
- Rvalue :: Cast ( CastKind :: Pointer ( PointerCast :: ReifyFnPointer ) , operand, ty) => {
344
- let layout = fx. layout_of ( ty) ;
345
- match fx
346
- . monomorphize ( & operand. ty ( & fx. mir . local_decls , fx. tcx ) )
347
- . kind
348
- {
343
+ Rvalue :: Cast ( CastKind :: Pointer ( PointerCast :: ReifyFnPointer ) , operand, to_ty) => {
344
+ let from_ty = fx. monomorphize ( & operand. ty ( & fx. mir . local_decls , fx. tcx ) ) ;
345
+ let to_layout = fx. layout_of ( fx. monomorphize ( to_ty) ) ;
346
+ match from_ty. kind {
349
347
ty:: FnDef ( def_id, substs) => {
350
348
let func_ref = fx. get_function_ref (
351
349
Instance :: resolve ( fx. tcx , ParamEnv :: reveal_all ( ) , def_id, substs)
352
350
. unwrap ( ) ,
353
351
) ;
354
352
let func_addr = fx. bcx . ins ( ) . func_addr ( fx. pointer_type , func_ref) ;
355
- lval. write_cvalue ( fx, CValue :: by_val ( func_addr, layout ) ) ;
353
+ lval. write_cvalue ( fx, CValue :: by_val ( func_addr, to_layout ) ) ;
356
354
}
357
- _ => bug ! ( "Trying to ReifyFnPointer on non FnDef {:?}" , ty ) ,
355
+ _ => bug ! ( "Trying to ReifyFnPointer on non FnDef {:?}" , from_ty ) ,
358
356
}
359
357
}
360
- Rvalue :: Cast ( CastKind :: Pointer ( PointerCast :: UnsafeFnPointer ) , operand, ty)
361
- | Rvalue :: Cast ( CastKind :: Pointer ( PointerCast :: MutToConstPointer ) , operand, ty)
362
- | Rvalue :: Cast ( CastKind :: Pointer ( PointerCast :: ArrayToPointer ) , operand, ty) => {
358
+ Rvalue :: Cast ( CastKind :: Pointer ( PointerCast :: UnsafeFnPointer ) , operand, to_ty)
359
+ | Rvalue :: Cast ( CastKind :: Pointer ( PointerCast :: MutToConstPointer ) , operand, to_ty)
360
+ | Rvalue :: Cast ( CastKind :: Pointer ( PointerCast :: ArrayToPointer ) , operand, to_ty) => {
361
+ let to_layout = fx. layout_of ( fx. monomorphize ( to_ty) ) ;
363
362
let operand = trans_operand ( fx, operand) ;
364
- let layout = fx. layout_of ( ty) ;
365
- lval. write_cvalue ( fx, operand. unchecked_cast_to ( layout) ) ;
363
+ lval. write_cvalue ( fx, operand. unchecked_cast_to ( to_layout) ) ;
366
364
}
367
365
Rvalue :: Cast ( CastKind :: Misc , operand, to_ty) => {
368
366
let operand = trans_operand ( fx, operand) ;
@@ -420,7 +418,7 @@ fn trans_stmt<'tcx>(
420
418
lval. write_cvalue ( fx, CValue :: by_val ( res, dest_layout) ) ;
421
419
}
422
420
}
423
- Rvalue :: Cast ( CastKind :: Pointer ( PointerCast :: ClosureFnPointer ( _) ) , operand, _ty ) => {
421
+ Rvalue :: Cast ( CastKind :: Pointer ( PointerCast :: ClosureFnPointer ( _) ) , operand, _to_ty ) => {
424
422
let operand = trans_operand ( fx, operand) ;
425
423
match operand. layout ( ) . ty . kind {
426
424
ty:: Closure ( def_id, substs) => {
@@ -437,7 +435,7 @@ fn trans_stmt<'tcx>(
437
435
_ => bug ! ( "{} cannot be cast to a fn ptr" , operand. layout( ) . ty) ,
438
436
}
439
437
}
440
- Rvalue :: Cast ( CastKind :: Pointer ( PointerCast :: Unsize ) , operand, _ty ) => {
438
+ Rvalue :: Cast ( CastKind :: Pointer ( PointerCast :: Unsize ) , operand, _to_ty ) => {
441
439
let operand = trans_operand ( fx, operand) ;
442
440
operand. unsize_value ( fx, lval) ;
443
441
}
@@ -466,6 +464,7 @@ fn trans_stmt<'tcx>(
466
464
use rustc:: middle:: lang_items:: ExchangeMallocFnLangItem ;
467
465
468
466
let usize_type = fx. clif_type ( fx. tcx . types . usize ) . unwrap ( ) ;
467
+ let content_ty = fx. monomorphize ( content_ty) ;
469
468
let layout = fx. layout_of ( content_ty) ;
470
469
let llsize = fx. bcx . ins ( ) . iconst ( usize_type, layout. size . bytes ( ) as i64 ) ;
471
470
let llalign = fx
@@ -494,7 +493,7 @@ fn trans_stmt<'tcx>(
494
493
. layout( )
495
494
. ty
496
495
. is_sized( fx. tcx. at( DUMMY_SP ) , ParamEnv :: reveal_all( ) ) ) ;
497
- let ty_size = fx. layout_of ( ty ) . size . bytes ( ) ;
496
+ let ty_size = fx. layout_of ( fx . monomorphize ( ty ) ) . size . bytes ( ) ;
498
497
let val = CValue :: const_val ( fx, fx. tcx . types . usize , ty_size. into ( ) ) ;
499
498
lval. write_cvalue ( fx, val) ;
500
499
}
0 commit comments