CTFE: test size/align_of_val_raw on dangling pointers
This commit is contained in:
@@ -374,7 +374,8 @@ pub const fn size_of_val<T: ?Sized>(val: &T) -> usize {
|
|||||||
/// ```
|
/// ```
|
||||||
#[inline]
|
#[inline]
|
||||||
#[unstable(feature = "layout_for_ptr", issue = "69835")]
|
#[unstable(feature = "layout_for_ptr", issue = "69835")]
|
||||||
pub unsafe fn size_of_val_raw<T: ?Sized>(val: *const T) -> usize {
|
#[rustc_const_unstable(feature = "const_size_of_val_raw", issue = "46571")]
|
||||||
|
pub const unsafe fn size_of_val_raw<T: ?Sized>(val: *const T) -> usize {
|
||||||
intrinsics::size_of_val(val)
|
intrinsics::size_of_val(val)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -505,7 +506,8 @@ pub const fn align_of_val<T: ?Sized>(val: &T) -> usize {
|
|||||||
/// ```
|
/// ```
|
||||||
#[inline]
|
#[inline]
|
||||||
#[unstable(feature = "layout_for_ptr", issue = "69835")]
|
#[unstable(feature = "layout_for_ptr", issue = "69835")]
|
||||||
pub unsafe fn align_of_val_raw<T: ?Sized>(val: *const T) -> usize {
|
#[rustc_const_unstable(feature = "const_align_of_val_raw", issue = "46571")]
|
||||||
|
pub const unsafe fn align_of_val_raw<T: ?Sized>(val: *const T) -> usize {
|
||||||
intrinsics::min_align_of_val(val)
|
intrinsics::min_align_of_val(val)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
// run-pass
|
// run-pass
|
||||||
|
|
||||||
#![feature(const_size_of_val, const_align_of_val)]
|
#![feature(const_size_of_val, const_align_of_val)]
|
||||||
|
#![feature(const_size_of_val_raw, const_align_of_val_raw, layout_for_ptr)]
|
||||||
|
|
||||||
use std::mem;
|
use std::mem;
|
||||||
|
|
||||||
@@ -32,6 +33,9 @@ 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_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 ALIGN_OF_DANGLING: usize = unsafe { mem::align_of_val_raw(0x100 as *const i16) };
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
assert_eq!(SIZE_OF_FOO, mem::size_of::<Foo>());
|
assert_eq!(SIZE_OF_FOO, mem::size_of::<Foo>());
|
||||||
assert_eq!(SIZE_OF_BAR, mem::size_of::<Bar>());
|
assert_eq!(SIZE_OF_BAR, mem::size_of::<Bar>());
|
||||||
@@ -41,5 +45,8 @@ fn main() {
|
|||||||
assert_eq!(ALIGN_OF_BAR, mem::align_of::<Bar>());
|
assert_eq!(ALIGN_OF_BAR, mem::align_of::<Bar>());
|
||||||
assert_eq!(ALIGN_OF_UGH, mem::align_of::<Ugh>());
|
assert_eq!(ALIGN_OF_UGH, mem::align_of::<Ugh>());
|
||||||
|
|
||||||
|
assert_eq!(SIZE_OF_DANGLING, mem::size_of::<i32>());
|
||||||
|
assert_eq!(ALIGN_OF_DANGLING, mem::align_of::<i16>());
|
||||||
|
|
||||||
assert_eq!(SIZE_OF_SLICE, "foobar".len());
|
assert_eq!(SIZE_OF_SLICE, "foobar".len());
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user