diff --git a/gcc/rust/typecheck/rust-casts.cc b/gcc/rust/typecheck/rust-casts.cc index fb7951032491..c6c1a890e74d 100644 --- a/gcc/rust/typecheck/rust-casts.cc +++ b/gcc/rust/typecheck/rust-casts.cc @@ -225,6 +225,12 @@ TypeCastRules::cast_rules () 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 ()}; diff --git a/gcc/testsuite/rust/compile/cast_float_as_integer.rs b/gcc/testsuite/rust/compile/cast_float_as_integer.rs new file mode 100644 index 000000000000..e6b86db8a664 --- /dev/null +++ b/gcc/testsuite/rust/compile/cast_float_as_integer.rs @@ -0,0 +1,10 @@ +// { 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; +}