@@ -956,32 +956,23 @@ fn infer<'a, 'tcx>(i: ConstInt,
956
956
( & ty:: TyInt ( IntTy :: I32 ) , Infer ( i) ) => Ok ( I32 ( i as i64 as i32 ) ) ,
957
957
( & ty:: TyInt ( IntTy :: I64 ) , Infer ( i) ) => Ok ( I64 ( i as i64 ) ) ,
958
958
( & ty:: TyInt ( IntTy :: Is ) , Infer ( i) ) => {
959
- match ConstIsize :: new ( i as i64 , tcx. sess . target . int_type ) {
960
- Ok ( val) => Ok ( Isize ( val) ) ,
961
- Err ( _) => Ok ( Isize ( ConstIsize :: Is32 ( i as i64 as i32 ) ) ) ,
962
- }
959
+ Ok ( Isize ( ConstIsize :: new_truncating ( i as i64 , tcx. sess . target . int_type ) ) )
963
960
} ,
964
961
965
962
( & ty:: TyInt ( IntTy :: I8 ) , InferSigned ( i) ) => Ok ( I8 ( i as i8 ) ) ,
966
963
( & ty:: TyInt ( IntTy :: I16 ) , InferSigned ( i) ) => Ok ( I16 ( i as i16 ) ) ,
967
964
( & ty:: TyInt ( IntTy :: I32 ) , InferSigned ( i) ) => Ok ( I32 ( i as i32 ) ) ,
968
965
( & ty:: TyInt ( IntTy :: I64 ) , InferSigned ( i) ) => Ok ( I64 ( i) ) ,
969
966
( & ty:: TyInt ( IntTy :: Is ) , InferSigned ( i) ) => {
970
- match ConstIsize :: new ( i, tcx. sess . target . int_type ) {
971
- Ok ( val) => Ok ( Isize ( val) ) ,
972
- Err ( _) => Ok ( Isize ( ConstIsize :: Is32 ( i as i32 ) ) ) ,
973
- }
967
+ Ok ( Isize ( ConstIsize :: new_truncating ( i, tcx. sess . target . int_type ) ) )
974
968
} ,
975
969
976
970
( & ty:: TyUint ( UintTy :: U8 ) , Infer ( i) ) => Ok ( U8 ( i as u8 ) ) ,
977
971
( & ty:: TyUint ( UintTy :: U16 ) , Infer ( i) ) => Ok ( U16 ( i as u16 ) ) ,
978
972
( & ty:: TyUint ( UintTy :: U32 ) , Infer ( i) ) => Ok ( U32 ( i as u32 ) ) ,
979
973
( & ty:: TyUint ( UintTy :: U64 ) , Infer ( i) ) => Ok ( U64 ( i) ) ,
980
974
( & ty:: TyUint ( UintTy :: Us ) , Infer ( i) ) => {
981
- match ConstUsize :: new ( i, tcx. sess . target . uint_type ) {
982
- Ok ( val) => Ok ( Usize ( val) ) ,
983
- Err ( _) => Ok ( Usize ( ConstUsize :: Us32 ( i as u32 ) ) ) ,
984
- }
975
+ Ok ( Usize ( ConstUsize :: new_truncating ( i, tcx. sess . target . uint_type ) ) )
985
976
} ,
986
977
( & ty:: TyUint ( _) , InferSigned ( _) ) => Err ( IntermediateUnsignedNegative ) ,
987
978
@@ -1063,20 +1054,14 @@ fn cast_const_int<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, val: ConstInt, ty: ty::
1063
1054
ty:: TyInt ( ast:: IntTy :: I32 ) => Ok ( Integral ( I32 ( v as i64 as i32 ) ) ) ,
1064
1055
ty:: TyInt ( ast:: IntTy :: I64 ) => Ok ( Integral ( I64 ( v as i64 ) ) ) ,
1065
1056
ty:: TyInt ( ast:: IntTy :: Is ) => {
1066
- match ConstIsize :: new ( v as i64 , tcx. sess . target . int_type ) {
1067
- Ok ( val) => Ok ( Integral ( Isize ( val) ) ) ,
1068
- Err ( _) => Ok ( Integral ( Isize ( ConstIsize :: Is32 ( v as i64 as i32 ) ) ) ) ,
1069
- }
1057
+ Ok ( Integral ( Isize ( ConstIsize :: new_truncating ( v as i64 , tcx. sess . target . int_type ) ) ) )
1070
1058
} ,
1071
1059
ty:: TyUint ( ast:: UintTy :: U8 ) => Ok ( Integral ( U8 ( v as u8 ) ) ) ,
1072
1060
ty:: TyUint ( ast:: UintTy :: U16 ) => Ok ( Integral ( U16 ( v as u16 ) ) ) ,
1073
1061
ty:: TyUint ( ast:: UintTy :: U32 ) => Ok ( Integral ( U32 ( v as u32 ) ) ) ,
1074
1062
ty:: TyUint ( ast:: UintTy :: U64 ) => Ok ( Integral ( U64 ( v) ) ) ,
1075
1063
ty:: TyUint ( ast:: UintTy :: Us ) => {
1076
- match ConstUsize :: new ( v, tcx. sess . target . uint_type ) {
1077
- Ok ( val) => Ok ( Integral ( Usize ( val) ) ) ,
1078
- Err ( _) => Ok ( Integral ( Usize ( ConstUsize :: Us32 ( v as u32 ) ) ) ) ,
1079
- }
1064
+ Ok ( Integral ( Usize ( ConstUsize :: new_truncating ( v, tcx. sess . target . uint_type ) ) ) )
1080
1065
} ,
1081
1066
ty:: TyFloat ( ast:: FloatTy :: F64 ) => match val. erase_type ( ) {
1082
1067
Infer ( u) => Ok ( Float ( F64 ( u as f64 ) ) ) ,
0 commit comments