Skip to content

Commit 35911ee

Browse files
committed
reduce sanity check in debug mode
1 parent a593728 commit 35911ee

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/librustc_mir/interpret/eval_context.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -230,8 +230,14 @@ pub(super) fn mir_assign_valid_types<'tcx>(
230230
// late-bound lifetimes are still around and can lead to type
231231
// differences. So we compare ignoring lifetimes.
232232
if equal_up_to_regions(tcx, param_env, src.ty, dest.ty) {
233-
// Make sure the layout is equal, too -- just to be safe. Miri really needs layout equality.
234-
assert_eq!(src.layout, dest.layout);
233+
// Make sure the layout is equal, too -- just to be safe. Miri really
234+
// needs layout equality. For performance reason we skip this check when
235+
// the types are equal. Equal types *can* have different layouts when
236+
// enum downcast is involved (as enum variants carry the type of the
237+
// enum), but those should never occur in assignments.
238+
if cfg!(debug_assertions) || src.ty != dest.ty {
239+
assert_eq!(src.layout, dest.layout);
240+
}
235241
true
236242
} else {
237243
false

0 commit comments

Comments
 (0)