@@ -412,6 +412,47 @@ impl GenericArgs {
412412 }
413413}
414414
415+ impl IntTy {
416+ /// Important: this returns the target byte count for the types.
417+ /// Must not be used for host types from rustc.
418+ pub fn target_size ( & self , ptr_size : ByteCount ) -> usize {
419+ match self {
420+ IntTy :: Isize => ptr_size as usize ,
421+ IntTy :: I8 => size_of :: < i8 > ( ) ,
422+ IntTy :: I16 => size_of :: < i16 > ( ) ,
423+ IntTy :: I32 => size_of :: < i32 > ( ) ,
424+ IntTy :: I64 => size_of :: < i64 > ( ) ,
425+ IntTy :: I128 => size_of :: < i128 > ( ) ,
426+ }
427+ }
428+ }
429+ impl UIntTy {
430+ /// Important: this returns the target byte count for the types.
431+ /// Must not be used for host types from rustc.
432+ pub fn target_size ( & self , ptr_size : ByteCount ) -> usize {
433+ match self {
434+ UIntTy :: Usize => ptr_size as usize ,
435+ UIntTy :: U8 => size_of :: < u8 > ( ) ,
436+ UIntTy :: U16 => size_of :: < u16 > ( ) ,
437+ UIntTy :: U32 => size_of :: < u32 > ( ) ,
438+ UIntTy :: U64 => size_of :: < u64 > ( ) ,
439+ UIntTy :: U128 => size_of :: < u128 > ( ) ,
440+ }
441+ }
442+ }
443+ impl FloatTy {
444+ /// Important: this returns the target byte count for the types.
445+ /// Must not be used for host types from rustc.
446+ pub fn target_size ( & self ) -> usize {
447+ match self {
448+ FloatTy :: F16 => size_of :: < u16 > ( ) ,
449+ FloatTy :: F32 => size_of :: < u32 > ( ) ,
450+ FloatTy :: F64 => size_of :: < u64 > ( ) ,
451+ FloatTy :: F128 => size_of :: < u128 > ( ) ,
452+ }
453+ }
454+ }
455+
415456impl IntegerTy {
416457 pub fn to_unsigned ( & self ) -> Self {
417458 match self {
@@ -429,18 +470,8 @@ impl IntegerTy {
429470 /// Must not be used for host types from rustc.
430471 pub fn target_size ( & self , ptr_size : ByteCount ) -> usize {
431472 match self {
432- IntegerTy :: Signed ( IntTy :: Isize ) => ptr_size as usize ,
433- IntegerTy :: Signed ( IntTy :: I8 ) => size_of :: < i8 > ( ) ,
434- IntegerTy :: Signed ( IntTy :: I16 ) => size_of :: < i16 > ( ) ,
435- IntegerTy :: Signed ( IntTy :: I32 ) => size_of :: < i32 > ( ) ,
436- IntegerTy :: Signed ( IntTy :: I64 ) => size_of :: < i64 > ( ) ,
437- IntegerTy :: Signed ( IntTy :: I128 ) => size_of :: < i128 > ( ) ,
438- IntegerTy :: Unsigned ( UIntTy :: Usize ) => ptr_size as usize ,
439- IntegerTy :: Unsigned ( UIntTy :: U8 ) => size_of :: < u8 > ( ) ,
440- IntegerTy :: Unsigned ( UIntTy :: U16 ) => size_of :: < u16 > ( ) ,
441- IntegerTy :: Unsigned ( UIntTy :: U32 ) => size_of :: < u32 > ( ) ,
442- IntegerTy :: Unsigned ( UIntTy :: U64 ) => size_of :: < u64 > ( ) ,
443- IntegerTy :: Unsigned ( UIntTy :: U128 ) => size_of :: < u128 > ( ) ,
473+ IntegerTy :: Signed ( ty) => ty. target_size ( ptr_size) ,
474+ IntegerTy :: Unsigned ( ty) => ty. target_size ( ptr_size) ,
444475 }
445476 }
446477}
@@ -453,6 +484,18 @@ impl LiteralTy {
453484 _ => None ,
454485 }
455486 }
487+
488+ /// Important: this returns the target byte count for the types.
489+ /// Must not be used for host types from rustc.
490+ pub fn target_size ( & self , ptr_size : ByteCount ) -> usize {
491+ match self {
492+ LiteralTy :: Int ( int_ty) => int_ty. target_size ( ptr_size) ,
493+ LiteralTy :: UInt ( uint_ty) => uint_ty. target_size ( ptr_size) ,
494+ LiteralTy :: Float ( float_ty) => float_ty. target_size ( ) ,
495+ LiteralTy :: Char => 4 ,
496+ LiteralTy :: Bool => 1 ,
497+ }
498+ }
456499}
457500
458501/// A value of type `T` bound by the generic parameters of item
0 commit comments