[gcc r14-7400] gccrs: Fix bad cast error to bool
Arthur Cohen
cohenarthur@gcc.gnu.org
Tue Jan 16 17:31:27 GMT 2024
https://gcc.gnu.org/g:41a104fadeae4776f7d8efd4157776910a3edfe7
commit r14-7400-g41a104fadeae4776f7d8efd4157776910a3edfe7
Author: emanuele-em <micheletti.emanuele@hotmail.com>
Date: Wed Mar 29 03:45:01 2023 +0200
gccrs: Fix bad cast error to bool
In rust is not allowed to cast from int to bool. This patch handles the case when we cast a integer to bool with 'as bool'
Fixes #2026
gcc/rust/ChangeLog:
* typecheck/rust-casts.cc (TypeCastRules::cast_rules): BOOL removed from switch cases
gcc/testsuite/ChangeLog:
* rust/compile/cast4.rs: New test.
Signed-off-by: Emanuele Micheletti <micheletti.emanuele@hotmail.com>
Diff:
---
gcc/rust/typecheck/rust-casts.cc | 1 -
gcc/testsuite/rust/compile/cast4.rs | 5 +++++
2 files changed, 5 insertions(+), 1 deletion(-)
diff --git a/gcc/rust/typecheck/rust-casts.cc b/gcc/rust/typecheck/rust-casts.cc
index bbcd8460a94..08bdcbb4a5a 100644
--- a/gcc/rust/typecheck/rust-casts.cc
+++ b/gcc/rust/typecheck/rust-casts.cc
@@ -80,7 +80,6 @@ TypeCastRules::cast_rules ()
switch (to.get_ty ()->get_kind ())
{
case TyTy::TypeKind::CHAR:
- case TyTy::TypeKind::BOOL:
case TyTy::TypeKind::USIZE:
case TyTy::TypeKind::ISIZE:
case TyTy::TypeKind::UINT:
diff --git a/gcc/testsuite/rust/compile/cast4.rs b/gcc/testsuite/rust/compile/cast4.rs
new file mode 100644
index 00000000000..ab00010e35b
--- /dev/null
+++ b/gcc/testsuite/rust/compile/cast4.rs
@@ -0,0 +1,5 @@
+fn main() {
+ let a: i32 = 123;
+ let u = a as bool;
+ // { dg-error "invalid cast .i32. to .bool." "" { target *-*-* } .-1 }
+}
More information about the Gcc-cvs
mailing list