@@ -945,32 +945,23 @@ fn infer<'a, 'tcx>(i: ConstInt,
945
945
( & ty:: TyInt ( IntTy :: I32 ) , Infer ( i) ) => Ok ( I32 ( i as i64 as i32 ) ) ,
946
946
( & ty:: TyInt ( IntTy :: I64 ) , Infer ( i) ) => Ok ( I64 ( i as i64 ) ) ,
947
947
( & ty:: TyInt ( IntTy :: Is ) , Infer ( i) ) => {
948
- match ConstIsize :: new ( i as i64 , tcx. sess . target . int_type ) {
949
- Ok ( val) => Ok ( Isize ( val) ) ,
950
- Err ( _) => Ok ( Isize ( ConstIsize :: Is32 ( i as i64 as i32 ) ) ) ,
951
- }
948
+ Ok ( Isize ( ConstIsize :: new_truncating ( i as i64 , tcx. sess . target . int_type ) ) )
952
949
} ,
953
950
954
951
( & ty:: TyInt ( IntTy :: I8 ) , InferSigned ( i) ) => Ok ( I8 ( i as i8 ) ) ,
955
952
( & ty:: TyInt ( IntTy :: I16 ) , InferSigned ( i) ) => Ok ( I16 ( i as i16 ) ) ,
956
953
( & ty:: TyInt ( IntTy :: I32 ) , InferSigned ( i) ) => Ok ( I32 ( i as i32 ) ) ,
957
954
( & ty:: TyInt ( IntTy :: I64 ) , InferSigned ( i) ) => Ok ( I64 ( i) ) ,
958
955
( & ty:: TyInt ( IntTy :: Is ) , InferSigned ( i) ) => {
959
- match ConstIsize :: new ( i, tcx. sess . target . int_type ) {
960
- Ok ( val) => Ok ( Isize ( val) ) ,
961
- Err ( _) => Ok ( Isize ( ConstIsize :: Is32 ( i as i32 ) ) ) ,
962
- }
956
+ Ok ( Isize ( ConstIsize :: new_truncating ( i, tcx. sess . target . int_type ) ) )
963
957
} ,
964
958
965
959
( & ty:: TyUint ( UintTy :: U8 ) , Infer ( i) ) => Ok ( U8 ( i as u8 ) ) ,
966
960
( & ty:: TyUint ( UintTy :: U16 ) , Infer ( i) ) => Ok ( U16 ( i as u16 ) ) ,
967
961
( & ty:: TyUint ( UintTy :: U32 ) , Infer ( i) ) => Ok ( U32 ( i as u32 ) ) ,
968
962
( & ty:: TyUint ( UintTy :: U64 ) , Infer ( i) ) => Ok ( U64 ( i) ) ,
969
963
( & ty:: TyUint ( UintTy :: Us ) , Infer ( i) ) => {
970
- match ConstUsize :: new ( i, tcx. sess . target . uint_type ) {
971
- Ok ( val) => Ok ( Usize ( val) ) ,
972
- Err ( _) => Ok ( Usize ( ConstUsize :: Us32 ( i as u32 ) ) ) ,
973
- }
964
+ Ok ( Usize ( ConstUsize :: new_truncating ( i, tcx. sess . target . uint_type ) ) )
974
965
} ,
975
966
( & ty:: TyUint ( _) , InferSigned ( _) ) => Err ( IntermediateUnsignedNegative ) ,
976
967
@@ -1052,20 +1043,14 @@ fn cast_const_int<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, val: ConstInt, ty: ty::
1052
1043
ty:: TyInt ( ast:: IntTy :: I32 ) => Ok ( Integral ( I32 ( v as i64 as i32 ) ) ) ,
1053
1044
ty:: TyInt ( ast:: IntTy :: I64 ) => Ok ( Integral ( I64 ( v as i64 ) ) ) ,
1054
1045
ty:: TyInt ( ast:: IntTy :: Is ) => {
1055
- match ConstIsize :: new ( v as i64 , tcx. sess . target . int_type ) {
1056
- Ok ( val) => Ok ( Integral ( Isize ( val) ) ) ,
1057
- Err ( _) => Ok ( Integral ( Isize ( ConstIsize :: Is32 ( v as i64 as i32 ) ) ) ) ,
1058
- }
1046
+ Ok ( Integral ( Isize ( ConstIsize :: new_truncating ( v as i64 , tcx. sess . target . int_type ) ) ) )
1059
1047
} ,
1060
1048
ty:: TyUint ( ast:: UintTy :: U8 ) => Ok ( Integral ( U8 ( v as u8 ) ) ) ,
1061
1049
ty:: TyUint ( ast:: UintTy :: U16 ) => Ok ( Integral ( U16 ( v as u16 ) ) ) ,
1062
1050
ty:: TyUint ( ast:: UintTy :: U32 ) => Ok ( Integral ( U32 ( v as u32 ) ) ) ,
1063
1051
ty:: TyUint ( ast:: UintTy :: U64 ) => Ok ( Integral ( U64 ( v) ) ) ,
1064
1052
ty:: TyUint ( ast:: UintTy :: Us ) => {
1065
- match ConstUsize :: new ( v, tcx. sess . target . uint_type ) {
1066
- Ok ( val) => Ok ( Integral ( Usize ( val) ) ) ,
1067
- Err ( _) => Ok ( Integral ( Usize ( ConstUsize :: Us32 ( v as u32 ) ) ) ) ,
1068
- }
1053
+ Ok ( Integral ( Usize ( ConstUsize :: new_truncating ( v, tcx. sess . target . uint_type ) ) ) )
1069
1054
} ,
1070
1055
ty:: TyFloat ( ast:: FloatTy :: F64 ) => match val. erase_type ( ) {
1071
1056
Infer ( u) => Ok ( Float ( F64 ( u as f64 ) ) ) ,
0 commit comments