Skip to content

Commit

Permalink
also accept fn-ptr-type-changing assignments
Browse files Browse the repository at this point in the history
  • Loading branch information
RalfJung committed Apr 2, 2020
1 parent f1ea273 commit 100c809
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/librustc_mir/interpret/place.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,10 +287,15 @@ impl<'tcx, Tag: ::std::fmt::Debug> PlaceTy<'tcx, Tag> {
fn mir_assign_valid_types<'tcx>(src: Ty<'tcx>, dest: Ty<'tcx>) -> bool {
src == dest
|| match (&src.kind, &dest.kind) {
// After MIR optimizations, there can be assignments that change reference mutability.
(ty::Ref(_, src_pointee, _), ty::Ref(_, dest_pointee, _)) => {
// After optimizations, there can be assignments that change reference mutability.
// This does not affect reference layout, so that is fine.
src_pointee == dest_pointee
}
(ty::FnPtr(_), ty::FnPtr(_)) => {
// All function pointers have equal layout, and thus can be assigned.
true
}
_ => false,
}
}
Expand Down Expand Up @@ -882,7 +887,7 @@ where
// actually "transmute" `&mut T` to `&T` in an assignment without a cast.
assert!(
mir_assign_valid_types(src.layout.ty, dest.layout.ty),
"type mismatch when copying!\nsrc: {:?}, dest: {:?}",
"type mismatch when copying!\nsrc: {:?},\ndest: {:?}",
src.layout.ty,
dest.layout.ty,
);
Expand Down

0 comments on commit 100c809

Please sign in to comment.