aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust
diff options
context:
space:
mode:
authorPhilip Herron <herron.philip@googlemail.com>2024-11-26 15:33:35 +0000
committerArthur Cohen <arthur.cohen@embecosm.com>2025-03-21 12:33:04 +0100
commit80bc600efeb6d2e4342da3e558cd2b5562e78477 (patch)
tree8a65bf7d33ac31e32dbfd279fc41dc2cf60c40a5 /gcc/rust
parentb10f33764e690158cbec10765f9209470c271cd6 (diff)
downloadgcc-80bc600efeb6d2e4342da3e558cd2b5562e78477.zip
gcc-80bc600efeb6d2e4342da3e558cd2b5562e78477.tar.gz
gcc-80bc600efeb6d2e4342da3e558cd2b5562e78477.tar.bz2
gccrs: allow casts from numeric types to floats
Fixes Rust-GCC#3261 gcc/rust/ChangeLog: * typecheck/rust-casts.cc (TypeCastRules::cast_rules): allow casts to float gcc/testsuite/ChangeLog: * rust/compile/issue-3261.rs: New test. Signed-off-by: Philip Herron <herron.philip@googlemail.com>
Diffstat (limited to 'gcc/rust')
-rw-r--r--gcc/rust/typecheck/rust-casts.cc10
1 files changed, 10 insertions, 0 deletions
diff --git a/gcc/rust/typecheck/rust-casts.cc b/gcc/rust/typecheck/rust-casts.cc
index 5235069f..cf4de4b 100644
--- a/gcc/rust/typecheck/rust-casts.cc
+++ b/gcc/rust/typecheck/rust-casts.cc
@@ -200,6 +200,16 @@ TypeCastRules::cast_rules ()
}
break;
+ case TyTy::TypeKind::FLOAT: {
+ // can only do this for number types not char
+ bool from_char
+ = from.get_ty ()->get_kind () == TyTy::TypeKind::CHAR;
+ if (!from_char)
+ return TypeCoercionRules::CoercionResult{{},
+ to.get_ty ()->clone ()};
+ }
+ break;
+
case TyTy::TypeKind::INFER:
case TyTy::TypeKind::USIZE:
case TyTy::TypeKind::ISIZE: