Skip to content

Commit cb82cdc

Browse files
committed
union padding computation: add fast-path for ZST
Also avoid even tracking empty ranges, and add fast-path for arrays of scalars
1 parent 4c77f86 commit cb82cdc

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

tests/pass/arrays.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,20 @@ fn debug() {
6161
println!("{:?}", array);
6262
}
6363

64+
fn huge_zst() {
65+
fn id<T>(x: T) -> T { x }
66+
67+
// A "huge" zero-sized array. Make sure we don't loop over it in any part of Miri.
68+
let val = [(); usize::MAX];
69+
id(val); // make a copy
70+
71+
let val = [val; 2];
72+
id(val);
73+
74+
// Also wrap it in a union (which, in particular, hits the logic for computing union padding).
75+
let _copy = std::mem::MaybeUninit::new(val);
76+
}
77+
6478
fn main() {
6579
assert_eq!(empty_array(), []);
6680
assert_eq!(index_unsafe(), 20);
@@ -73,4 +87,5 @@ fn main() {
7387
from();
7488
eq();
7589
debug();
90+
huge_zst();
7691
}

0 commit comments

Comments
 (0)