]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: allow unifications against non const types
authorPhilip Herron <herron.philip@googlemail.com>
Sun, 3 Aug 2025 18:53:23 +0000 (19:53 +0100)
committerArthur Cohen <arthur.cohen@embecosm.com>
Thu, 30 Oct 2025 19:59:04 +0000 (20:59 +0100)
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 <herron.philip@googlemail.com>
gcc/rust/typecheck/rust-unify.cc

index 841b42adca48013267846cf7d3b313b0c424d251..caecf2e1831eb2e3ed9520204c3cac6bdcfa3452 100644 (file)
@@ -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: