Skip to content

Commit

Permalink
test const size_of_val_raw on big value
Browse files Browse the repository at this point in the history
  • Loading branch information
RalfJung committed Mar 31, 2022
1 parent a417911 commit cb0d15b
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/test/ui/consts/const-size_of_val-align_of_val.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

#![feature(const_size_of_val, const_align_of_val)]
#![feature(const_size_of_val_raw, const_align_of_val_raw, layout_for_ptr)]
#![feature(const_slice_from_raw_parts)]

use std::mem;
use std::{mem, ptr};

struct Foo(u32);

Expand Down Expand Up @@ -34,6 +35,8 @@ const ALIGN_OF_UGH: usize = mem::align_of_val(&UGH);
const SIZE_OF_SLICE: usize = mem::size_of_val("foobar".as_bytes());

const SIZE_OF_DANGLING: usize = unsafe { mem::size_of_val_raw(0x100 as *const i32) };
const SIZE_OF_BIG: usize =
unsafe { mem::size_of_val_raw(ptr::slice_from_raw_parts(0 as *const u8, isize::MAX as usize)) };
const ALIGN_OF_DANGLING: usize = unsafe { mem::align_of_val_raw(0x100 as *const i16) };

fn main() {
Expand All @@ -46,6 +49,7 @@ fn main() {
assert_eq!(ALIGN_OF_UGH, mem::align_of::<Ugh>());

assert_eq!(SIZE_OF_DANGLING, mem::size_of::<i32>());
assert_eq!(SIZE_OF_BIG, isize::MAX as usize);
assert_eq!(ALIGN_OF_DANGLING, mem::align_of::<i16>());

assert_eq!(SIZE_OF_SLICE, "foobar".len());
Expand Down

0 comments on commit cb0d15b

Please sign in to comment.