aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoremanuele-em <micheletti.emanuele@hotmail.com>2023-03-29 03:45:01 +0200
committerPhilip Herron <philip.herron@embecosm.com>2023-03-29 21:11:43 +0000
commitc5427467abbd672aa39b43f1648d93ff7b11c2dc (patch)
tree0c6a7f4e55d6553a4cf46a83f64e6d384ecf2c86
parent3eb5dcb67c40a2d26fe05442d1d64dcb3b9d1d09 (diff)
downloadgcc-c5427467abbd672aa39b43f1648d93ff7b11c2dc.zip
gcc-c5427467abbd672aa39b43f1648d93ff7b11c2dc.tar.gz
gcc-c5427467abbd672aa39b43f1648d93ff7b11c2dc.tar.bz2
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>
-rw-r--r--gcc/rust/typecheck/rust-casts.cc1
-rw-r--r--gcc/testsuite/rust/compile/cast4.rs5
2 files changed, 5 insertions, 1 deletions
diff --git a/gcc/rust/typecheck/rust-casts.cc b/gcc/rust/typecheck/rust-casts.cc
index f41c713..31449a6 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 0000000..ab00010
--- /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 }
+}