Skip to content

Commit 100c809

Browse files
committed
also accept fn-ptr-type-changing assignments
1 parent f1ea273 commit 100c809

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/librustc_mir/interpret/place.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -287,10 +287,15 @@ impl<'tcx, Tag: ::std::fmt::Debug> PlaceTy<'tcx, Tag> {
287287
fn mir_assign_valid_types<'tcx>(src: Ty<'tcx>, dest: Ty<'tcx>) -> bool {
288288
src == dest
289289
|| match (&src.kind, &dest.kind) {
290-
// After MIR optimizations, there can be assignments that change reference mutability.
291290
(ty::Ref(_, src_pointee, _), ty::Ref(_, dest_pointee, _)) => {
291+
// After optimizations, there can be assignments that change reference mutability.
292+
// This does not affect reference layout, so that is fine.
292293
src_pointee == dest_pointee
293294
}
295+
(ty::FnPtr(_), ty::FnPtr(_)) => {
296+
// All function pointers have equal layout, and thus can be assigned.
297+
true
298+
}
294299
_ => false,
295300
}
296301
}
@@ -882,7 +887,7 @@ where
882887
// actually "transmute" `&mut T` to `&T` in an assignment without a cast.
883888
assert!(
884889
mir_assign_valid_types(src.layout.ty, dest.layout.ty),
885-
"type mismatch when copying!\nsrc: {:?}, dest: {:?}",
890+
"type mismatch when copying!\nsrc: {:?},\ndest: {:?}",
886891
src.layout.ty,
887892
dest.layout.ty,
888893
);

0 commit comments

Comments
 (0)