@@ -105,23 +105,19 @@ fn lit_to_mir_constant<'tcx>(tcx: TyCtxt<'tcx>, lit_input: LitToConstInput<'tcx>
105105 return Const :: Ty ( Ty :: new_error ( tcx, guar) , ty:: Const :: new_error ( tcx, guar) ) ;
106106 }
107107
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 lit_ty = match * ty. kind ( ) {
109+ ty:: Pat ( base, _) => base,
110+ _ => ty,
111+ } ;
112+
113+ let trunc = |n| {
114+ let width = lit_ty. primitive_size ( tcx) ;
114115 trace ! ( "trunc {} with size {} and shift {}" , n, width. bits( ) , 128 - width. bits( ) ) ;
115116 let result = width. truncate ( n) ;
116117 trace ! ( "trunc result: {}" , result) ;
117118 ConstValue :: Scalar ( Scalar :: from_uint ( result, width) )
118119 } ;
119120
120- let lit_ty = match * ty. kind ( ) {
121- ty:: Pat ( base, _) => base,
122- _ => ty,
123- } ;
124-
125121 let value = match ( lit, lit_ty. kind ( ) ) {
126122 ( ast:: LitKind :: Str ( s, _) , ty:: Ref ( _, inner_ty, _) ) if inner_ty. is_str ( ) => {
127123 let s = s. as_str ( ) ;
@@ -149,11 +145,10 @@ fn lit_to_mir_constant<'tcx>(tcx: TyCtxt<'tcx>, lit_input: LitToConstInput<'tcx>
149145 ( ast:: LitKind :: Byte ( n) , ty:: Uint ( ty:: UintTy :: U8 ) ) => {
150146 ConstValue :: Scalar ( Scalar :: from_uint ( * n, Size :: from_bytes ( 1 ) ) )
151147 }
152- ( ast:: LitKind :: Int ( n, _) , ty:: Uint ( ui) ) if !neg => trunc ( n. get ( ) , * ui) ,
153- ( ast:: LitKind :: Int ( n, _) , ty:: Int ( i) ) => trunc (
154- if neg { ( n. get ( ) as i128 ) . overflowing_neg ( ) . 0 as u128 } else { n. get ( ) } ,
155- i. to_unsigned ( ) ,
156- ) ,
148+ ( ast:: LitKind :: Int ( n, _) , ty:: Uint ( _) ) if !neg => trunc ( n. get ( ) ) ,
149+ ( ast:: LitKind :: Int ( n, _) , ty:: Int ( _) ) => {
150+ trunc ( if neg { ( n. get ( ) as i128 ) . overflowing_neg ( ) . 0 as u128 } else { n. get ( ) } )
151+ }
157152 ( ast:: LitKind :: Float ( n, _) , ty:: Float ( fty) ) => {
158153 parse_float_into_constval ( * n, * fty, neg) . unwrap ( )
159154 }
0 commit comments