gccrs now should be able to cast float types as numeric.
gcc/rust/ChangeLog:
* typecheck/rust-casts.cc (TypeCastRules::cast_rules): Add rule.
gcc/testsuite/ChangeLog:
* rust/compile/cast_float_as_integer.rs: New test.
Signed-off-by: Nobel Singh <nobel2073@gmail.com>
case TyTy::TypeKind::FLOAT:
switch (to.get_ty ()->get_kind ())
{
+ case TyTy::TypeKind::USIZE:
+ case TyTy::TypeKind::ISIZE:
+ case TyTy::TypeKind::UINT:
+ case TyTy::TypeKind::INT:
+ return TypeCoercionRules::CoercionResult{{}, to.get_ty ()->clone ()};
+
case TyTy::TypeKind::FLOAT:
return TypeCoercionRules::CoercionResult{{}, to.get_ty ()->clone ()};
--- /dev/null
+// { dg-options "-w" }
+fn main(){
+ let foo:f64 = 13.37;
+ let _ = foo as i64;
+ let _ = foo as u64;
+ let _ = foo as isize;
+ let _ = foo as usize;
+ let _ = foo as i8;
+ let _ = foo as u8;
+}