Skip to content

Commit b2f7386

Browse files
committed
Fix fn(&T) -> for<'l> fn(&'l T) write
1 parent 158294d commit b2f7386

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

src/common.rs

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -370,8 +370,10 @@ impl<'a, 'tcx: 'a> CPlace<'tcx> {
370370
}
371371

372372
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))
375377
if (if *dest_mut != crate::rustc::hir::Mutability::MutImmutable
376378
&& src_mut != dest_mut
377379
{
@@ -385,13 +387,26 @@ impl<'a, 'tcx: 'a> CPlace<'tcx> {
385387
// &mut T -> &T is allowed
386388
// &'a T -> &'b T is allowed
387389
}
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+
}
388403
_ => {
389404
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,
395410
fx,
396411
);
397412
}

0 commit comments

Comments
 (0)