1
Fork 0

Add ui test for const Layout::from_size_align_unchecked

This commit is contained in:
Richard Wiedenhöft 2019-04-30 12:56:38 +02:00
parent 07e8d84479
commit c0b6d3c975
2 changed files with 21 additions and 0 deletions

View file

@ -0,0 +1,10 @@
use std::alloc::Layout;
// ok
const LAYOUT_VALID: Layout = unsafe { Layout::from_size_align_unchecked(0x1000, 0x08) };
// not ok, since alignment needs to be non-zero.
const LAYOUT_INVALID: Layout = unsafe { Layout::from_size_align_unchecked(0x1000, 0x00) };
//~^ ERROR it is undefined behavior to use this value
fn main() {}

View file

@ -0,0 +1,11 @@
error[E0080]: it is undefined behavior to use this value
--> $DIR/alloc.rs:7:1
|
LL | const LAYOUT_INVALID: Layout = unsafe { Layout::from_size_align_unchecked(0x1000, 0x00) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered 0 at .align_, but expected something greater or equal to 1
|
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rust compiler repository if you believe it should not be considered undefined behavior
error: aborting due to previous error
For more information about this error, try `rustc --explain E0080`.