Skip to content

Commit 6b98046

Browse files
committed
validity: assert that unions are non-empty
1 parent 82239b0 commit 6b98046

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/librustc_mir/interpret/validity.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,11 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M>
463463
// Validate all fields of compound data structures
464464
let path_len = path.len(); // Remember the length, in case we need to truncate
465465
match dest.layout.fields {
466-
layout::FieldPlacement::Union(..) => {
466+
layout::FieldPlacement::Union(fields) => {
467+
// Empty unions are not accepted by rustc. That's great, it means we can
468+
// use that as an unambiguous signal for detecting primitives. Make sure
469+
// we did not miss any primitive.
470+
debug_assert!(fields > 0);
467471
// We can't check unions, their bits are allowed to be anything.
468472
// The fields don't need to correspond to any bit pattern of the union's fields.
469473
// See https://github.com/rust-lang/rust/issues/32836#issuecomment-406875389

0 commit comments

Comments
 (0)