Skip to content

Commit 3faffa2

Browse files
committed
Rollup merge of rust-lang#55379 - RalfJung:no-empty-union, r=oli-obk
validity: assert that unions are non-empty
2 parents 477f6f7 + 6b98046 commit 3faffa2

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/librustc_mir/interpret/validity.rs

Lines changed: 5 additions & 1 deletion
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)