forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#69794 - TimDiekmann:dangling, r=Amanieu
Add `Layout::dangling()` to return a well-aligned `NonNull<u8>` Adds a convenient function to `Layout` to create a `NonNull<u8>` out of a layout to be returned on ZST allocations. This is the first item on the roadmap to support ZSTs in `AllocRef`: rust-lang/wg-allocators#38 (comment) r? @Amanieu
- Loading branch information
Showing
3 changed files
with
16 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,13 @@ | ||
use core::alloc::Layout; | ||
use core::ptr::NonNull; | ||
|
||
#[test] | ||
fn const_unchecked_layout() { | ||
const SIZE: usize = 0x2000; | ||
const ALIGN: usize = 0x1000; | ||
const LAYOUT: Layout = unsafe { Layout::from_size_align_unchecked(SIZE, ALIGN) }; | ||
const DANGLING: NonNull<u8> = LAYOUT.dangling(); | ||
assert_eq!(LAYOUT.size(), SIZE); | ||
assert_eq!(LAYOUT.align(), ALIGN); | ||
assert_eq!(Some(DANGLING), NonNull::new(ALIGN as *mut u8)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
#![feature(alloc_layout_extra)] | ||
#![feature(bool_to_option)] | ||
#![feature(bound_cloned)] | ||
#![feature(box_syntax)] | ||
|