Skip to content

Commit 93dd7b6

Browse files
committed
Improve core::alloc coverage
1 parent 76c5ed2 commit 93dd7b6

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

library/coretests/tests/alloc.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,23 @@ fn layout_array_edge_cases() {
5555
}
5656
}
5757

58+
#[test]
59+
fn layout_errors() {
60+
let layout = Layout::new::<[u8; 2]>();
61+
// Should error if the alignment is not a power of two.
62+
assert!(layout.align_to(3).is_err());
63+
64+
// The remaining assertions ensure that the methods error on arithmetic overflow as the
65+
// alignment cannot overflow `isize`.
66+
assert!(layout.align_to(isize::MAX as usize + 1).is_err());
67+
assert!(layout.repeat(usize::MAX).is_err());
68+
69+
assert!(layout.repeat_packed(usize::MAX).is_err());
70+
71+
let next = Layout::from_size_align(isize::MAX as usize, 1).unwrap();
72+
assert!(layout.extend(next).is_err());
73+
}
74+
5875
#[test]
5976
fn layout_debug_shows_log2_of_alignment() {
6077
// `Debug` is not stable, but here's what it does right now

0 commit comments

Comments
 (0)