about summary refs log tree commit diff
diff options
context:
space:
mode:
authorkennytm <kennytm@gmail.com>2018-10-26 20:48:08 +0800
committerkennytm <kennytm@gmail.com>2018-10-26 23:07:02 +0800
commit3faffa2e94045c5543d7fb107f39518375b0aa4f (patch)
treec727c44881a082f0df2b175b48d80e7bb2c5cc5a
parent477f6f7577b701895083357d8d8dda9c7ee3e670 (diff)
parent6b980462c6f5273b5b38d0e83c6da09c41d865e3 (diff)
downloadrust-3faffa2e94045c5543d7fb107f39518375b0aa4f.tar.gz
rust-3faffa2e94045c5543d7fb107f39518375b0aa4f.zip
Rollup merge of #55379 - RalfJung:no-empty-union, r=oli-obk
validity: assert that unions are non-empty
-rw-r--r--src/librustc_mir/interpret/validity.rs6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/librustc_mir/interpret/validity.rs b/src/librustc_mir/interpret/validity.rs
index ac1ba0edc3b..25e2ff6edb7 100644
--- a/src/librustc_mir/interpret/validity.rs
+++ b/src/librustc_mir/interpret/validity.rs
@@ -463,7 +463,11 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M>
         // Validate all fields of compound data structures
         let path_len = path.len(); // Remember the length, in case we need to truncate
         match dest.layout.fields {
-            layout::FieldPlacement::Union(..) => {
+            layout::FieldPlacement::Union(fields) => {
+                // Empty unions are not accepted by rustc. That's great, it means we can
+                // use that as an unambiguous signal for detecting primitives.  Make sure
+                // we did not miss any primitive.
+                debug_assert!(fields > 0);
                 // We can't check unions, their bits are allowed to be anything.
                 // The fields don't need to correspond to any bit pattern of the union's fields.
                 // See https://github.com/rust-lang/rust/issues/32836#issuecomment-406875389