@@ -603,7 +603,7 @@ impl<T: ?Sized + Unsize<U>, U: ?Sized, A: Allocator> CoerceUnsized<Box<U, A>> fo
603603impl < T > Box < T > {
604604 pub fn new ( val : T ) -> Box < T > {
605605 unsafe {
606- let size = intrinsics :: size_of :: < T > ( ) ;
606+ let size = size_of :: < T > ( ) ;
607607 let ptr = libc:: malloc ( size) ;
608608 intrinsics:: copy ( & val as * const T as * const u8 , ptr, size) ;
609609 Box ( Unique { pointer : NonNull ( ptr as * const T ) , _marker : PhantomData } , Global )
@@ -657,11 +657,11 @@ pub mod intrinsics {
657657 #[ rustc_intrinsic]
658658 pub fn abort ( ) -> !;
659659 #[ rustc_intrinsic]
660- pub fn size_of < T > ( ) -> usize ;
660+ pub const fn size_of < T > ( ) -> usize ;
661661 #[ rustc_intrinsic]
662662 pub unsafe fn size_of_val < T : ?:: Sized > ( val : * const T ) -> usize ;
663663 #[ rustc_intrinsic]
664- pub fn align_of < T > ( ) -> usize ;
664+ pub const fn align_of < T > ( ) -> usize ;
665665 #[ rustc_intrinsic]
666666 pub unsafe fn align_of_val < T : ?:: Sized > ( val : * const T ) -> usize ;
667667 #[ rustc_intrinsic]
@@ -699,6 +699,24 @@ pub mod libc {
699699 }
700700}
701701
702+ pub const fn size_of < T > ( ) -> usize {
703+ <T as SizedTypeProperties >:: SIZE
704+ }
705+
706+ pub const fn align_of < T > ( ) -> usize {
707+ <T as SizedTypeProperties >:: ALIGN
708+ }
709+
710+ trait SizedTypeProperties : Sized {
711+ #[ lang = "mem_size_const" ]
712+ const SIZE : usize = intrinsics:: size_of :: < Self > ( ) ;
713+
714+ #[ lang = "mem_align_const" ]
715+ const ALIGN : usize = intrinsics:: align_of :: < Self > ( ) ;
716+ }
717+
718+ impl < T > SizedTypeProperties for T { }
719+
702720#[ lang = "index" ]
703721pub trait Index < Idx : ?Sized > {
704722 type Output : ?Sized ;
0 commit comments