diff options
author | Nobel <nobel2073@gmail.com> | 2024-12-21 23:56:39 +0545 |
---|---|---|
committer | Philip Herron <philip.herron@embecosm.com> | 2025-01-10 09:08:00 +0000 |
commit | c960e034f3d66f88127818cabfd486e68d717872 (patch) | |
tree | 412ff61eb19f882dad0524404ac86618aabdd024 /gcc | |
parent | 806166db9db83bee816d169a13ab9992de9d66a0 (diff) | |
download | gcc-c960e034f3d66f88127818cabfd486e68d717872.zip gcc-c960e034f3d66f88127818cabfd486e68d717872.tar.gz gcc-c960e034f3d66f88127818cabfd486e68d717872.tar.bz2 |
Allow float type to be casted as integer type
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>
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/rust/typecheck/rust-casts.cc | 6 | ||||
-rw-r--r-- | gcc/testsuite/rust/compile/cast_float_as_integer.rs | 10 |
2 files changed, 16 insertions, 0 deletions
diff --git a/gcc/rust/typecheck/rust-casts.cc b/gcc/rust/typecheck/rust-casts.cc index c1996ca..99f84f3 100644 --- a/gcc/rust/typecheck/rust-casts.cc +++ b/gcc/rust/typecheck/rust-casts.cc @@ -235,6 +235,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 0000000..e6b86db --- /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; +} |