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>
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:
--- /dev/null
+fn main() {
+ let a: i32 = 123;
+ let u = a as bool;
+ // { dg-error "invalid cast .i32. to .bool." "" { target *-*-* } .-1 }
+}