diff options
| author | bjorn3 <bjorn3@users.noreply.github.com> | 2018-11-17 11:41:20 +0100 |
|---|---|---|
| committer | bjorn3 <bjorn3@users.noreply.github.com> | 2018-11-17 11:55:49 +0100 |
| commit | b2f7386f7ed34f24f293c201779a89cbc08f8243 (patch) | |
| tree | 6d1c34a2b0f0a269d90f182c80fd7b1878085f42 | |
| parent | 158294de5ca26e80de243da5f3aa3fcf82eb0ca3 (diff) | |
| download | rust-b2f7386f7ed34f24f293c201779a89cbc08f8243.tar.gz rust-b2f7386f7ed34f24f293c201779a89cbc08f8243.zip | |
Fix fn(&T) -> for<'l> fn(&'l T) write
| -rw-r--r-- | src/common.rs | 29 |
1 files changed, 22 insertions, 7 deletions
diff --git a/src/common.rs b/src/common.rs index 77376182756..e3f13260e8b 100644 --- a/src/common.rs +++ b/src/common.rs @@ -370,8 +370,10 @@ impl<'a, 'tcx: 'a> CPlace<'tcx> { } pub fn write_cvalue(self, fx: &mut FunctionCx<'a, 'tcx, impl Backend>, from: CValue<'tcx>) { - match (&self.layout().ty.sty, &from.layout().ty.sty) { - (ty::Ref(_, t, dest_mut), ty::Ref(_, u, src_mut)) + let from_ty = from.layout().ty; + let to_ty = self.layout().ty; + match (&from_ty.sty, &to_ty.sty) { + (ty::Ref(_, t, src_mut), ty::Ref(_, u, dest_mut)) if (if *dest_mut != crate::rustc::hir::Mutability::MutImmutable && src_mut != dest_mut { @@ -385,13 +387,26 @@ impl<'a, 'tcx: 'a> CPlace<'tcx> { // &mut T -> &T is allowed // &'a T -> &'b T is allowed } + (ty::FnPtr(_), ty::FnPtr(_)) => { + let from_sig = fx.tcx.normalize_erasing_late_bound_regions(ParamEnv::reveal_all(), &from_ty.fn_sig(fx.tcx)); + let to_sig = fx.tcx.normalize_erasing_late_bound_regions(ParamEnv::reveal_all(), &to_ty.fn_sig(fx.tcx)); + assert_eq!( + from_sig, + to_sig, + "Can't write fn ptr with incompatible sig {:?} to place with sig {:?}\n\n{:#?}", + from_sig, + to_sig, + fx, + ); + // fn(&T) -> for<'l> fn(&'l T) is allowed + } _ => { assert_eq!( - self.layout().ty, - from.layout().ty, - "Can't write value of incompatible type to place {:?} {:?}\n\n{:#?}", - self.layout().ty.sty, - from.layout().ty.sty, + from_ty, + to_ty, + "Can't write value with incompatible type {:?} to place with type {:?}\n\n{:#?}", + from_ty.sty, + to_ty.sty, fx, ); } |
