@@ -370,8 +370,10 @@ impl<'a, 'tcx: 'a> CPlace<'tcx> {
370
370
}
371
371
372
372
pub fn write_cvalue ( self , fx : & mut FunctionCx < ' a , ' tcx , impl Backend > , from : CValue < ' tcx > ) {
373
- match ( & self . layout ( ) . ty . sty , & from. layout ( ) . ty . sty ) {
374
- ( ty:: Ref ( _, t, dest_mut) , ty:: Ref ( _, u, src_mut) )
373
+ let from_ty = from. layout ( ) . ty ;
374
+ let to_ty = self . layout ( ) . ty ;
375
+ match ( & from_ty. sty , & to_ty. sty ) {
376
+ ( ty:: Ref ( _, t, src_mut) , ty:: Ref ( _, u, dest_mut) )
375
377
if ( if * dest_mut != crate :: rustc:: hir:: Mutability :: MutImmutable
376
378
&& src_mut != dest_mut
377
379
{
@@ -385,13 +387,26 @@ impl<'a, 'tcx: 'a> CPlace<'tcx> {
385
387
// &mut T -> &T is allowed
386
388
// &'a T -> &'b T is allowed
387
389
}
390
+ ( ty:: FnPtr ( _) , ty:: FnPtr ( _) ) => {
391
+ let from_sig = fx. tcx . normalize_erasing_late_bound_regions ( ParamEnv :: reveal_all ( ) , & from_ty. fn_sig ( fx. tcx ) ) ;
392
+ let to_sig = fx. tcx . normalize_erasing_late_bound_regions ( ParamEnv :: reveal_all ( ) , & to_ty. fn_sig ( fx. tcx ) ) ;
393
+ assert_eq ! (
394
+ from_sig,
395
+ to_sig,
396
+ "Can't write fn ptr with incompatible sig {:?} to place with sig {:?}\n \n {:#?}" ,
397
+ from_sig,
398
+ to_sig,
399
+ fx,
400
+ ) ;
401
+ // fn(&T) -> for<'l> fn(&'l T) is allowed
402
+ }
388
403
_ => {
389
404
assert_eq ! (
390
- self . layout ( ) . ty ,
391
- from . layout ( ) . ty ,
392
- "Can't write value of incompatible type to place {:?} {:?}\n \n {:#?}" ,
393
- self . layout ( ) . ty . sty,
394
- from . layout ( ) . ty . sty,
405
+ from_ty ,
406
+ to_ty ,
407
+ "Can't write value with incompatible type {:?} to place with type {:?}\n \n {:#?}" ,
408
+ from_ty . sty,
409
+ to_ty . sty,
395
410
fx,
396
411
) ;
397
412
}
0 commit comments