Add ui test for const Layout::from_size_align_unchecked
This commit is contained in:
parent
07e8d84479
commit
c0b6d3c975
2 changed files with 21 additions and 0 deletions
10
src/test/ui/consts/std/alloc.rs
Normal file
10
src/test/ui/consts/std/alloc.rs
Normal 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() {}
|
11
src/test/ui/consts/std/alloc.stderr
Normal file
11
src/test/ui/consts/std/alloc.stderr
Normal 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`.
|
Loading…
Add table
Add a link
Reference in a new issue