From: Philip Herron <[email protected]>

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]>
---
 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 841b42adca4..caecf2e1831 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:
-- 
2.50.1

Reply via email to