diff options
| author | Jana Dönszelmann <jonathan@donsz.nl> | 2025-09-13 02:40:45 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-09-13 02:40:45 +0200 |
| commit | e4dbbbd322d8f03e49fd510a5636227388802125 (patch) | |
| tree | 534d0994156970c71ff48c8b545f646cedf695cb | |
| parent | 5dd5264d14c833e889202f61a044aade7ae92ab8 (diff) | |
| parent | 18059a0053d186ab47cde823dff64fe490bfbed0 (diff) | |
| download | rust-e4dbbbd322d8f03e49fd510a5636227388802125.tar.gz rust-e4dbbbd322d8f03e49fd510a5636227388802125.zip | |
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: https://github.com/rust-lang/rust/issues/55724
| -rw-r--r-- | library/coretests/tests/alloc.rs | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/library/coretests/tests/alloc.rs b/library/coretests/tests/alloc.rs index 72fdf82c1f8..a4af6fd32a1 100644 --- a/library/coretests/tests/alloc.rs +++ b/library/coretests/tests/alloc.rs @@ -56,6 +56,30 @@ fn layout_array_edge_cases() { } #[test] +fn layout_errors() { + let layout = Layout::new::<[u8; 2]>(); + // Should error if the alignment is not a power of two. + assert!(layout.align_to(3).is_err()); + + // The remaining assertions ensure that the methods error on arithmetic overflow as the + // alignment cannot overflow `isize`. + let size = layout.size(); + let size_max = isize::MAX as usize; + let align_max = size_max / size; + + assert!(layout.align_to(size_max + 1).is_err()); + + assert!(layout.repeat(align_max).is_ok()); + assert!(layout.repeat(align_max + 1).is_err()); + + assert!(layout.repeat_packed(align_max).is_ok()); + assert!(layout.repeat_packed(align_max + 1).is_err()); + + let next = Layout::from_size_align(size_max, 1).unwrap(); + assert!(layout.extend(next).is_err()); +} + +#[test] fn layout_debug_shows_log2_of_alignment() { // `Debug` is not stable, but here's what it does right now let layout = Layout::from_size_align(24576, 8192).unwrap(); |
