Skip to content

Commit 6d91419

Browse files
committed
Add tests.
1 parent 5fb1e6b commit 6d91419

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/test/run-pass/enum-null-pointer-opt.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,21 @@ fn main() {
3434
// Pointers - Box<T>
3535
assert_eq!(size_of::<Box<int>>(), size_of::<Option<Box<int>>>());
3636

37-
3837
// The optimization can't apply to raw pointers
3938
assert!(size_of::<Option<*const int>>() != size_of::<*const int>());
4039
assert!(Some(0 as *const int).is_some()); // Can't collapse None to null
4140

41+
struct Foo {
42+
_a: Box<int>
43+
}
44+
struct Bar(Box<int>);
45+
46+
// Should apply through structs
47+
assert_eq!(size_of::<Foo>(), size_of::<Option<Foo>>());
48+
assert_eq!(size_of::<Bar>(), size_of::<Option<Bar>>());
49+
// and tuples
50+
assert_eq!(size_of::<(u8, Box<int>)>(), size_of::<Option<(u8, Box<int>)>>());
51+
// and fixed-size arrays
52+
assert_eq!(size_of::<[Box<int>, ..1]>(), size_of::<Option<[Box<int>, ..1]>>());
53+
4254
}

0 commit comments

Comments
 (0)