]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: Treat function pointers like pointers for cast
authorPierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Tue, 19 Aug 2025 13:18:27 +0000 (15:18 +0200)
committerArthur Cohen <arthur.cohen@embecosm.com>
Thu, 30 Oct 2025 19:58:42 +0000 (20:58 +0100)
Function pointers were not allowed to be cast to any integer like type
just like regular pointers were.

gcc/rust/ChangeLog:

* typecheck/rust-casts.cc (TypeCastRules::cast_rules): Authorize
cast from function pointer to integer like type.

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

index f06d9ed24e8e7d876bfee6c902894b944b3a31c0..7d086013e9f6fa08d7ca96480708e22b03ef3449 100644 (file)
@@ -277,6 +277,7 @@ TypeCastRules::cast_rules ()
       break;
 
     case TyTy::TypeKind::REF:
+    case TyTy::TypeKind::FNPTR:
     case TyTy::TypeKind::POINTER:
       switch (to.get_ty ()->get_kind ())
        {
@@ -286,8 +287,9 @@ TypeCastRules::cast_rules ()
        case TyTy::TypeKind::INT:
          {
            // refs should not cast to numeric type
-           bool from_ptr
-             = from.get_ty ()->get_kind () == TyTy::TypeKind::POINTER;
+           auto kind = from.get_ty ()->get_kind ();
+           bool from_ptr = kind == TyTy::TypeKind::POINTER
+                           || kind == TyTy::TypeKind::FNPTR;
            if (from_ptr)
              {
                return TypeCoercionRules::CoercionResult{