Skip to content

Commit eaeb425

Browse files
committed
Add tests.
1 parent 39be76e commit eaeb425

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
@@ -35,9 +35,21 @@ fn main() {
3535
// Pointers - Box<T>
3636
assert_eq!(size_of::<Box<int>>(), size_of::<Option<Box<int>>>());
3737

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

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

0 commit comments

Comments
 (0)