]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: Use as member function instead of static cast
authorPierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Fri, 22 Aug 2025 10:28:08 +0000 (12:28 +0200)
committerArthur Cohen <arthur.cohen@embecosm.com>
Thu, 30 Oct 2025 19:58:43 +0000 (20:58 +0100)
gcc/rust/ChangeLog:

* typecheck/rust-coercion.cc (TypeCoercionRules::do_coercion): Use as
member function.
(TypeCoercionRules::coerce_borrowed_pointer): Likewise.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
gcc/rust/typecheck/rust-coercion.cc

index cf285956d16d5ee5b65db2bb72b8ea9df16207ed..2b023ed0edd2645f8e34141409d99df39eb2145d 100644 (file)
@@ -88,15 +88,14 @@ TypeCoercionRules::do_coercion (TyTy::BaseType *receiver)
     {
     case TyTy::TypeKind::POINTER:
       {
-       TyTy::PointerType *ptr = static_cast<TyTy::PointerType *> (expected);
+       auto *ptr = expected->as<TyTy::PointerType> ();
        try_result = coerce_unsafe_ptr (receiver, ptr, ptr->mutability ());
        return !try_result.is_error ();
       }
 
     case TyTy::TypeKind::REF:
       {
-       TyTy::ReferenceType *ptr
-         = static_cast<TyTy::ReferenceType *> (expected);
+       auto *ptr = expected->as<TyTy::ReferenceType> ();
        try_result
          = coerce_borrowed_pointer (receiver, ptr, ptr->mutability ());
        return !try_result.is_error ();
@@ -272,12 +271,9 @@ TypeCoercionRules::coerce_borrowed_pointer (TyTy::BaseType *receiver,
     {
     case TyTy::TypeKind::REF:
       {
-       TyTy::ReferenceType *from
-         = static_cast<TyTy::ReferenceType *> (receiver);
-       from_mutbl = from->mutability ();
+       from_mutbl = receiver->as<TyTy::ReferenceType> ()->mutability ();
       }
       break;
-
     default:
       {
        rust_debug ("coerce_borrowed_pointer -- unify");