@@ -105,12 +105,8 @@ fn lit_to_mir_constant<'tcx>(tcx: TyCtxt<'tcx>, lit_input: LitToConstInput<'tcx>
105
105
return Const :: Ty ( Ty :: new_error ( tcx, guar) , ty:: Const :: new_error ( tcx, guar) ) ;
106
106
}
107
107
108
- let trunc = |n, width : ty:: UintTy | {
109
- let width = width
110
- . normalize ( tcx. data_layout . pointer_size . bits ( ) . try_into ( ) . unwrap ( ) )
111
- . bit_width ( )
112
- . unwrap ( ) ;
113
- let width = Size :: from_bits ( width) ;
108
+ let trunc = |n| {
109
+ let width = ty. primitive_size ( tcx) ;
114
110
trace ! ( "trunc {} with size {} and shift {}" , n, width. bits( ) , 128 - width. bits( ) ) ;
115
111
let result = width. truncate ( n) ;
116
112
trace ! ( "trunc result: {}" , result) ;
@@ -144,11 +140,10 @@ fn lit_to_mir_constant<'tcx>(tcx: TyCtxt<'tcx>, lit_input: LitToConstInput<'tcx>
144
140
( ast:: LitKind :: Byte ( n) , ty:: Uint ( ty:: UintTy :: U8 ) ) => {
145
141
ConstValue :: Scalar ( Scalar :: from_uint ( * n, Size :: from_bytes ( 1 ) ) )
146
142
}
147
- ( ast:: LitKind :: Int ( n, _) , ty:: Uint ( ui) ) if !neg => trunc ( n. get ( ) , * ui) ,
148
- ( ast:: LitKind :: Int ( n, _) , ty:: Int ( i) ) => trunc (
149
- if neg { ( n. get ( ) as i128 ) . overflowing_neg ( ) . 0 as u128 } else { n. get ( ) } ,
150
- i. to_unsigned ( ) ,
151
- ) ,
143
+ ( ast:: LitKind :: Int ( n, _) , ty:: Uint ( _) ) if !neg => trunc ( n. get ( ) ) ,
144
+ ( ast:: LitKind :: Int ( n, _) , ty:: Int ( _) ) => {
145
+ trunc ( if neg { ( n. get ( ) as i128 ) . overflowing_neg ( ) . 0 as u128 } else { n. get ( ) } )
146
+ }
152
147
( ast:: LitKind :: Float ( n, _) , ty:: Float ( fty) ) => {
153
148
parse_float_into_constval ( * n, * fty, neg) . unwrap ( )
154
149
}
0 commit comments