@@ -45,18 +45,6 @@ impl<'tcx> fmt::Display for Discr<'tcx> {
4545 }
4646}
4747
48- fn signed_min ( size : Size ) -> i128 {
49- size. sign_extend ( 1_u128 << ( size. bits ( ) - 1 ) ) as i128
50- }
51-
52- fn signed_max ( size : Size ) -> i128 {
53- i128:: MAX >> ( 128 - size. bits ( ) )
54- }
55-
56- fn unsigned_max ( size : Size ) -> u128 {
57- u128:: MAX >> ( 128 - size. bits ( ) )
58- }
59-
6048fn int_size_and_signed < ' tcx > ( tcx : TyCtxt < ' tcx > , ty : Ty < ' tcx > ) -> ( Size , bool ) {
6149 let ( int, signed) = match * ty. kind ( ) {
6250 Int ( ity) => ( Integer :: from_int_ty ( & tcx, ity) , true ) ,
@@ -74,8 +62,8 @@ impl<'tcx> Discr<'tcx> {
7462 pub fn checked_add ( self , tcx : TyCtxt < ' tcx > , n : u128 ) -> ( Self , bool ) {
7563 let ( size, signed) = int_size_and_signed ( tcx, self . ty ) ;
7664 let ( val, oflo) = if signed {
77- let min = signed_min ( size ) ;
78- let max = signed_max ( size ) ;
65+ let min = size . signed_min ( ) ;
66+ let max = size . signed_max ( ) ;
7967 let val = size. sign_extend ( self . val ) as i128 ;
8068 assert ! ( n < ( i128 :: MAX as u128 ) ) ;
8169 let n = n as i128 ;
@@ -86,7 +74,7 @@ impl<'tcx> Discr<'tcx> {
8674 let val = size. truncate ( val) ;
8775 ( val, oflo)
8876 } else {
89- let max = unsigned_max ( size ) ;
77+ let max = size . unsigned_max ( ) ;
9078 let val = self . val ;
9179 let oflo = val > max - n;
9280 let val = if oflo { n - ( max - val) - 1 } else { val + n } ;
@@ -621,7 +609,7 @@ impl<'tcx> ty::TyS<'tcx> {
621609 let val = match self . kind ( ) {
622610 ty:: Int ( _) | ty:: Uint ( _) => {
623611 let ( size, signed) = int_size_and_signed ( tcx, self ) ;
624- let val = if signed { signed_max ( size ) as u128 } else { unsigned_max ( size ) } ;
612+ let val = if signed { size . signed_max ( ) as u128 } else { size . unsigned_max ( ) } ;
625613 Some ( val)
626614 }
627615 ty:: Char => Some ( std:: char:: MAX as u128 ) ,
@@ -640,7 +628,7 @@ impl<'tcx> ty::TyS<'tcx> {
640628 let val = match self . kind ( ) {
641629 ty:: Int ( _) | ty:: Uint ( _) => {
642630 let ( size, signed) = int_size_and_signed ( tcx, self ) ;
643- let val = if signed { size. truncate ( signed_min ( size ) as u128 ) } else { 0 } ;
631+ let val = if signed { size. truncate ( size . signed_min ( ) as u128 ) } else { 0 } ;
644632 Some ( val)
645633 }
646634 ty:: Char => Some ( 0 ) ,
0 commit comments