Skip to content

Commit 373c362

Browse files
committed
Check that we don't access nonexisting union fields
1 parent 76fe6a4 commit 373c362

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/librustc_target/abi/mod.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -738,7 +738,11 @@ impl FieldPlacement {
738738

739739
pub fn offset(&self, i: usize) -> Size {
740740
match *self {
741-
FieldPlacement::Union(_) => Size::ZERO,
741+
FieldPlacement::Union(count) => {
742+
assert!(i < count,
743+
"Tried to access field {} of union with {} fields", i, count);
744+
Size::ZERO
745+
},
742746
FieldPlacement::Array { stride, count } => {
743747
let i = i as u64;
744748
assert!(i < count);

0 commit comments

Comments
 (0)