From c5427467abbd672aa39b43f1648d93ff7b11c2dc Mon Sep 17 00:00:00 2001 From: emanuele-em Date: Wed, 29 Mar 2023 03:45:01 +0200 Subject: 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 --- gcc/rust/typecheck/rust-casts.cc | 1 - gcc/testsuite/rust/compile/cast4.rs | 5 +++++ 2 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/rust/compile/cast4.rs (limited to 'gcc') 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 } +} -- cgit v1.1