Better handling of ref types equality in write_cvalue

This commit is contained in:
bjorn3 2018-06-29 18:57:59 +02:00
parent 4694fa4f3d
commit 42ea584b8e
1 changed files with 22 additions and 6 deletions

View File

@ -192,12 +192,28 @@ impl<'a, 'tcx: 'a> CPlace<'tcx> {
} }
pub fn write_cvalue(self, fx: &mut FunctionCx<'a, 'tcx>, from: CValue<'tcx>) { pub fn write_cvalue(self, fx: &mut FunctionCx<'a, 'tcx>, from: CValue<'tcx>) {
assert_eq!( match (&self.layout().ty.sty, &from.layout().ty.sty) {
self.layout().ty, from.layout().ty, (TypeVariants::TyRef(_, t, dest_mut), TypeVariants::TyRef(_, u, src_mut)) if (
"Can't write value of incompatible type to place {:?} {:?}\n\n{:#?}", if *dest_mut != ::rustc::hir::Mutability::MutImmutable && src_mut != dest_mut {
self.layout().ty.sty, from.layout().ty.sty, false
fx, } else if t != u {
); false
} else {
true
}
) => {
// &mut T -> &T is allowed
// &'a T -> &'b 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,
fx,
);
}
}
match self { match self {
CPlace::Var(var, _) => { CPlace::Var(var, _) => {