From: emanuele-em Date: Wed, 29 Mar 2023 01:45:01 +0000 (+0200) Subject: gccrs: Fix bad cast error to bool X-Git-Tag: basepoints/gcc-15~2739 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=41a104fadeae4776f7d8efd4157776910a3edfe7;p=thirdparty%2Fgcc.git 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 --- diff --git a/gcc/rust/typecheck/rust-casts.cc b/gcc/rust/typecheck/rust-casts.cc index bbcd8460a943..08bdcbb4a5aa 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 000000000000..ab00010e35b1 --- /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 } +}