|  | 
| 6 | 6 |     extern_types, | 
| 7 | 7 |     decl_macro, | 
| 8 | 8 |     rustc_attrs, | 
|  | 9 | +    rustc_private, | 
| 9 | 10 |     transparent_unions, | 
| 10 | 11 |     auto_traits, | 
| 11 | 12 |     freeze_impls, | 
| @@ -594,7 +595,7 @@ impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<Box<U>> for Box<T> {} | 
| 594 | 595 | impl<T> Box<T> { | 
| 595 | 596 |     pub fn new(val: T) -> Box<T> { | 
| 596 | 597 |         unsafe { | 
| 597 |  | -            let size = intrinsics::size_of::<T>(); | 
|  | 598 | +            let size = size_of::<T>(); | 
| 598 | 599 |             let ptr = libc::malloc(size); | 
| 599 | 600 |             intrinsics::copy(&val as *const T as *const u8, ptr, size); | 
| 600 | 601 |             Box(Unique { pointer: NonNull(ptr as *const T), _marker: PhantomData }, Global) | 
| @@ -646,11 +647,11 @@ pub mod intrinsics { | 
| 646 | 647 |     #[rustc_intrinsic] | 
| 647 | 648 |     pub fn abort() -> !; | 
| 648 | 649 |     #[rustc_intrinsic] | 
| 649 |  | -    pub fn size_of<T>() -> usize; | 
|  | 650 | +    pub const fn size_of<T>() -> usize; | 
| 650 | 651 |     #[rustc_intrinsic] | 
| 651 | 652 |     pub unsafe fn size_of_val<T: ?::Sized>(val: *const T) -> usize; | 
| 652 | 653 |     #[rustc_intrinsic] | 
| 653 |  | -    pub fn align_of<T>() -> usize; | 
|  | 654 | +    pub const fn align_of<T>() -> usize; | 
| 654 | 655 |     #[rustc_intrinsic] | 
| 655 | 656 |     pub unsafe fn align_of_val<T: ?::Sized>(val: *const T) -> usize; | 
| 656 | 657 |     #[rustc_intrinsic] | 
| @@ -715,6 +716,23 @@ impl<T> Index<usize> for [T] { | 
| 715 | 716 |     } | 
| 716 | 717 | } | 
| 717 | 718 | 
 | 
|  | 719 | +pub const fn size_of<T>() -> usize { | 
|  | 720 | +    const { intrinsics::size_of::<T>() } | 
|  | 721 | +} | 
|  | 722 | + | 
|  | 723 | +pub const fn align_of<T>() -> usize { | 
|  | 724 | +    const { intrinsics::align_of::<T>() } | 
|  | 725 | +} | 
|  | 726 | + | 
|  | 727 | +trait SizedTypeProperties: Sized { | 
|  | 728 | +    #[lang = "mem_size_const"] | 
|  | 729 | +    const SIZE: usize = intrinsics::size_of::<Self>(); | 
|  | 730 | + | 
|  | 731 | +    #[lang = "mem_align_const"] | 
|  | 732 | +    const ALIGN: usize = intrinsics::align_of::<Self>(); | 
|  | 733 | +} | 
|  | 734 | +impl<T> SizedTypeProperties for T {} | 
|  | 735 | + | 
| 718 | 736 | extern "C" { | 
| 719 | 737 |     type VaListImpl; | 
| 720 | 738 | } | 
|  | 
0 commit comments