Skip to content

Commit 55da88b

Browse files
authored
Unrolled build for #146452
Rollup merge of #146452 - ferrocene:pvdrz/improve-alloc-coverage, r=tgross35 Improve `alloc::Layout` coverage This PR improves the `core::alloc` coverage by adding a new test to `coretests` that cover the `Layout` methods when they error. Tracking issue: #55724
2 parents 4ba1cf9 + 18059a0 commit 55da88b

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

library/coretests/tests/alloc.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,30 @@ 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+
let size = layout.size();
67+
let size_max = isize::MAX as usize;
68+
let align_max = size_max / size;
69+
70+
assert!(layout.align_to(size_max + 1).is_err());
71+
72+
assert!(layout.repeat(align_max).is_ok());
73+
assert!(layout.repeat(align_max + 1).is_err());
74+
75+
assert!(layout.repeat_packed(align_max).is_ok());
76+
assert!(layout.repeat_packed(align_max + 1).is_err());
77+
78+
let next = Layout::from_size_align(size_max, 1).unwrap();
79+
assert!(layout.extend(next).is_err());
80+
}
81+
5882
#[test]
5983
fn layout_debug_shows_log2_of_alignment() {
6084
// `Debug` is not stable, but here's what it does right now

0 commit comments

Comments
 (0)