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#65174 - SimonSapin:zero-box, r=alexcrichton
Fix zero-size uninitialized boxes Requesting a zero-size allocation is not allowed, return a dangling pointer instead. CC rust-lang#63291 (comment)
- Loading branch information
Showing
3 changed files
with
34 additions
and
3 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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
use std::ptr::NonNull; | ||
use std::mem::MaybeUninit; | ||
|
||
#[test] | ||
fn unitialized_zero_size_box() { | ||
assert_eq!( | ||
&*Box::<()>::new_uninit() as *const _, | ||
NonNull::<MaybeUninit<()>>::dangling().as_ptr(), | ||
); | ||
assert_eq!( | ||
Box::<[()]>::new_uninit_slice(4).as_ptr(), | ||
NonNull::<MaybeUninit<()>>::dangling().as_ptr(), | ||
); | ||
assert_eq!( | ||
Box::<[String]>::new_uninit_slice(0).as_ptr(), | ||
NonNull::<MaybeUninit<String>>::dangling().as_ptr(), | ||
); | ||
} | ||
|
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