Skip to content

Commit 00d20c9

Browse files
committed
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 <pierre-emmanuel.patry@embecosm.com>
1 parent 0746a27 commit 00d20c9

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

gcc/rust/typecheck/rust-casts.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,7 @@ TypeCastRules::cast_rules ()
277277
break;
278278

279279
case TyTy::TypeKind::REF:
280+
case TyTy::TypeKind::FNPTR:
280281
case TyTy::TypeKind::POINTER:
281282
switch (to.get_ty ()->get_kind ())
282283
{
@@ -286,8 +287,9 @@ TypeCastRules::cast_rules ()
286287
case TyTy::TypeKind::INT:
287288
{
288289
// refs should not cast to numeric type
289-
bool from_ptr
290-
= from.get_ty ()->get_kind () == TyTy::TypeKind::POINTER;
290+
auto kind = from.get_ty ()->get_kind ();
291+
bool from_ptr = kind == TyTy::TypeKind::POINTER
292+
|| kind == TyTy::TypeKind::FNPTR;
291293
if (from_ptr)
292294
{
293295
return TypeCoercionRules::CoercionResult{

0 commit comments

Comments
 (0)