From: Pierre-Emmanuel Patry <[email protected]>

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]>
---
 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 f06d9ed24e8..7d086013e9f 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{
-- 
2.50.1

Reply via email to