From f8aaded3180c2f8ae413763169aa20dfa635993c Mon Sep 17 00:00:00 2001 From: Philip Herron Date: Sun, 3 Aug 2025 19:53:23 +0100 Subject: [PATCH] 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 --- 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 () || rtype->is ()) + && !(ltype->is () && rtype->is ())) + { + if (ltype->is ()) + { + auto const_type = static_cast (ltype); + ltype = const_type->get_ty (); + } + else if (rtype->is ()) + { + auto const_type = static_cast (rtype); + rtype = const_type->get_ty (); + } + } + switch (ltype->get_kind ()) { case TyTy::INFER: -- 2.47.3