https://gcc.gnu.org/g:94b82f54e81f1202136e02619663a2b815cede27

commit r16-4802-g94b82f54e81f1202136e02619663a2b815cede27
Author: Pierre-Emmanuel Patry <[email protected]>
Date:   Tue Aug 19 15:18:27 2025 +0200

    gccrs: Treat function pointers like pointers for cast
    
    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 <[email protected]>

Diff:
---
 gcc/rust/typecheck/rust-casts.cc | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/gcc/rust/typecheck/rust-casts.cc b/gcc/rust/typecheck/rust-casts.cc
index f06d9ed24e8e..7d086013e9f6 100644
--- a/gcc/rust/typecheck/rust-casts.cc
+++ b/gcc/rust/typecheck/rust-casts.cc
@@ -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{

Reply via email to