https://gcc.gnu.org/g:f8aaded3180c2f8ae413763169aa20dfa635993c

commit r16-4841-gf8aaded3180c2f8ae413763169aa20dfa635993c
Author: Philip Herron <[email protected]>
Date:   Sun Aug 3 19:53:23 2025 +0100

    gccrs: allow unifications against non const types
    
    When type resolving a function which returns a const generic for example
    this means its unifying the ConstType vs the the specified type so this
    mean unwrapping the type of the const.
    
    gcc/rust/ChangeLog:
    
            * typecheck/rust-unify.cc (UnifyRules::go): unwrap the const type
    
    Signed-off-by: Philip Herron <[email protected]>

Diff:
---
 gcc/rust/typecheck/rust-unify.cc | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/gcc/rust/typecheck/rust-unify.cc b/gcc/rust/typecheck/rust-unify.cc
index 841b42adca48..caecf2e1831e 100644
--- a/gcc/rust/typecheck/rust-unify.cc
+++ b/gcc/rust/typecheck/rust-unify.cc
@@ -266,6 +266,21 @@ UnifyRules::go ()
        }
     }
 
+  if ((ltype->is<TyTy::ConstType> () || rtype->is<TyTy::ConstType> ())
+      && !(ltype->is<TyTy::ConstType> () && rtype->is<TyTy::ConstType> ()))
+    {
+      if (ltype->is<TyTy::ConstType> ())
+       {
+         auto const_type = static_cast<TyTy::ConstType *> (ltype);
+         ltype = const_type->get_ty ();
+       }
+      else if (rtype->is<TyTy::ConstType> ())
+       {
+         auto const_type = static_cast<TyTy::ConstType *> (rtype);
+         rtype = const_type->get_ty ();
+       }
+    }
+
   switch (ltype->get_kind ())
     {
     case TyTy::INFER:

Reply via email to