rust_debug ("cast_rules from={%s} to={%s}", from_type->debug_str ().c_str (),
to.get_ty ()->debug_str ().c_str ());
-
switch (from_type->get_kind ())
{
case TyTy::TypeKind::INFER: {
case TyTy::InferType::InferTypeKind::INTEGRAL:
switch (to.get_ty ()->get_kind ())
{
- case TyTy::TypeKind::CHAR:
+ case TyTy::TypeKind::CHAR: {
+ // only u8 and char
+ bool was_uint
+ = from.get_ty ()->get_kind () == TyTy::TypeKind::UINT;
+ bool was_u8
+ = was_uint
+ && (static_cast<TyTy::UintType *> (from.get_ty ())
+ ->get_uint_kind ()
+ == TyTy::UintType::UintKind::U8);
+ if (was_u8)
+ return TypeCoercionRules::CoercionResult{
+ {}, to.get_ty ()->clone ()};
+ }
+ break;
+
case TyTy::TypeKind::USIZE:
case TyTy::TypeKind::ISIZE:
case TyTy::TypeKind::UINT:
--- /dev/null
+fn main() {
+ const A: char = 0x1F888 as char;
+ // { dg-error "invalid cast .<integer>. to .char." "" { target *-*-* } .-1 }
+ const B: char = 129160 as char;
+ // { dg-error "invalid cast .<integer>. to .char." "" { target *-*-* } .-1 }
+ const C: i32 = 42;
+ const D: char = C as char;
+ // { dg-error "invalid cast .i32. to .char." "" { target *-*-* } .-1 }
+ const E: char = '\u{01F888}';
+ const F: u8 = 42;
+ const G: char= F as char;
+}