diff options
| author | Christian Poveda <christian.poveda@ferrous-systems.com> | 2025-09-11 15:11:25 -0500 |
|---|---|---|
| committer | Christian Poveda <christian.poveda@ferrous-systems.com> | 2025-09-12 10:49:52 -0500 |
| commit | 18059a0053d186ab47cde823dff64fe490bfbed0 (patch) | |
| tree | 1a7ea795903ca83de7bf023e68de19eec59dceaa /library/coretests | |
| parent | 76c5ed2847cdb26ef2822a3a165d710f6b772217 (diff) | |
| download | rust-18059a0053d186ab47cde823dff64fe490bfbed0.tar.gz rust-18059a0053d186ab47cde823dff64fe490bfbed0.zip | |
Improve `core::alloc` coverage
Diffstat (limited to 'library/coretests')
| -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(); |
