@@ -45,18 +45,6 @@ impl<'tcx> fmt::Display for Discr<'tcx> {
45
45
}
46
46
}
47
47
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
-
60
48
fn int_size_and_signed < ' tcx > ( tcx : TyCtxt < ' tcx > , ty : Ty < ' tcx > ) -> ( Size , bool ) {
61
49
let ( int, signed) = match * ty. kind ( ) {
62
50
Int ( ity) => ( Integer :: from_int_ty ( & tcx, ity) , true ) ,
@@ -74,8 +62,8 @@ impl<'tcx> Discr<'tcx> {
74
62
pub fn checked_add ( self , tcx : TyCtxt < ' tcx > , n : u128 ) -> ( Self , bool ) {
75
63
let ( size, signed) = int_size_and_signed ( tcx, self . ty ) ;
76
64
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 ( ) ;
79
67
let val = size. sign_extend ( self . val ) as i128 ;
80
68
assert ! ( n < ( i128 :: MAX as u128 ) ) ;
81
69
let n = n as i128 ;
@@ -86,7 +74,7 @@ impl<'tcx> Discr<'tcx> {
86
74
let val = size. truncate ( val) ;
87
75
( val, oflo)
88
76
} else {
89
- let max = unsigned_max ( size ) ;
77
+ let max = size . unsigned_max ( ) ;
90
78
let val = self . val ;
91
79
let oflo = val > max - n;
92
80
let val = if oflo { n - ( max - val) - 1 } else { val + n } ;
@@ -621,7 +609,7 @@ impl<'tcx> ty::TyS<'tcx> {
621
609
let val = match self . kind ( ) {
622
610
ty:: Int ( _) | ty:: Uint ( _) => {
623
611
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 ( ) } ;
625
613
Some ( val)
626
614
}
627
615
ty:: Char => Some ( std:: char:: MAX as u128 ) ,
@@ -640,7 +628,7 @@ impl<'tcx> ty::TyS<'tcx> {
640
628
let val = match self . kind ( ) {
641
629
ty:: Int ( _) | ty:: Uint ( _) => {
642
630
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 } ;
644
632
Some ( val)
645
633
}
646
634
ty:: Char => Some ( 0 ) ,
0 commit comments