@@ -333,7 +333,7 @@ pub fn forget_unsized<T: ?Sized>(t: T) {
333333#[ rustc_const_stable( feature = "const_mem_size_of" , since = "1.24.0" ) ]
334334#[ rustc_diagnostic_item = "mem_size_of" ]
335335pub const fn size_of < T > ( ) -> usize {
336- intrinsics :: size_of :: < T > ( )
336+ < T as SizedTypeProperties > :: SIZE
337337}
338338
339339/// Returns the size of the pointed-to value in bytes.
@@ -441,7 +441,7 @@ pub const unsafe fn size_of_val_raw<T: ?Sized>(val: *const T) -> usize {
441441#[ stable( feature = "rust1" , since = "1.0.0" ) ]
442442#[ deprecated( note = "use `align_of` instead" , since = "1.2.0" , suggestion = "align_of" ) ]
443443pub fn min_align_of < T > ( ) -> usize {
444- intrinsics :: align_of :: < T > ( )
444+ < T as SizedTypeProperties > :: ALIGN
445445}
446446
447447/// Returns the [ABI]-required minimum alignment of the type of the value that `val` points to in
@@ -488,7 +488,7 @@ pub fn min_align_of_val<T: ?Sized>(val: &T) -> usize {
488488#[ rustc_const_stable( feature = "const_align_of" , since = "1.24.0" ) ]
489489#[ rustc_diagnostic_item = "mem_align_of" ]
490490pub const fn align_of < T > ( ) -> usize {
491- intrinsics :: align_of :: < T > ( )
491+ < T as SizedTypeProperties > :: ALIGN
492492}
493493
494494/// Returns the [ABI]-required minimum alignment of the type of the value that `val` points to in
@@ -1236,6 +1236,16 @@ pub const fn variant_count<T>() -> usize {
12361236#[ doc( hidden) ]
12371237#[ unstable( feature = "sized_type_properties" , issue = "none" ) ]
12381238pub trait SizedTypeProperties : Sized {
1239+ #[ doc( hidden) ]
1240+ #[ unstable( feature = "sized_type_properties" , issue = "none" ) ]
1241+ #[ lang = "mem_size_const" ]
1242+ const SIZE : usize = intrinsics:: size_of :: < Self > ( ) ;
1243+
1244+ #[ doc( hidden) ]
1245+ #[ unstable( feature = "sized_type_properties" , issue = "none" ) ]
1246+ #[ lang = "mem_align_const" ]
1247+ const ALIGN : usize = intrinsics:: align_of :: < Self > ( ) ;
1248+
12391249 /// `true` if this type requires no storage.
12401250 /// `false` if its [size](size_of) is greater than zero.
12411251 ///
@@ -1263,7 +1273,7 @@ pub trait SizedTypeProperties: Sized {
12631273 /// ```
12641274 #[ doc( hidden) ]
12651275 #[ unstable( feature = "sized_type_properties" , issue = "none" ) ]
1266- const IS_ZST : bool = size_of :: < Self > ( ) == 0 ;
1276+ const IS_ZST : bool = Self :: SIZE == 0 ;
12671277
12681278 #[ doc( hidden) ]
12691279 #[ unstable( feature = "sized_type_properties" , issue = "none" ) ]
@@ -1275,7 +1285,7 @@ pub trait SizedTypeProperties: Sized {
12751285 /// which is never allowed for a single object.
12761286 #[ doc( hidden) ]
12771287 #[ unstable( feature = "sized_type_properties" , issue = "none" ) ]
1278- const MAX_SLICE_LEN : usize = match size_of :: < Self > ( ) {
1288+ const MAX_SLICE_LEN : usize = match Self :: SIZE {
12791289 0 => usize:: MAX ,
12801290 n => ( isize:: MAX as usize ) / n,
12811291 } ;
0 commit comments