From: Philip Herron Date: Tue, 19 Aug 2025 18:34:38 +0000 (+0100) Subject: gccrs: Add implicit infer support for unify on const types X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=f96905887701cce16f80e701f3944e1476ae53ef;p=thirdparty%2Fgcc.git gccrs: Add implicit infer support for unify on const types gcc/rust/ChangeLog: * typecheck/rust-unify.cc (UnifyRules::commit): commit hook update (UnifyRules::go): insert implicit infer const types Signed-off-by: Philip Herron --- diff --git a/gcc/rust/typecheck/rust-unify.cc b/gcc/rust/typecheck/rust-unify.cc index caecf2e1831..10e4b6b3806 100644 --- a/gcc/rust/typecheck/rust-unify.cc +++ b/gcc/rust/typecheck/rust-unify.cc @@ -137,6 +137,16 @@ UnifyRules::commit (TyTy::BaseType *base, TyTy::BaseType *other, // if any of the types are inference variables lets fix them if (ref_tyty->is ()) context.insert_implicit_type (ref, resolved); + else if (resolved->is () + && ref_tyty->is ()) + { + auto &const_expr = *static_cast (resolved); + if (const_expr.get_const_kind () + == TyTy::ConstType::ConstKind::Value) + { + context.insert_implicit_type (ref, resolved); + } + } } } } @@ -264,6 +274,35 @@ UnifyRules::go () // set the rtype now to the new inference var ltype = i; } + else if (ltype->is () && rtype->is ()) + { + const auto &lhs = *static_cast (ltype); + const auto &rhs = *static_cast (rtype); + + bool both_are_decls + = lhs.get_const_kind () == TyTy::ConstType::ConstKind::Decl + && rhs.get_const_kind () == TyTy::ConstType::ConstKind::Decl; + bool have_decls + = lhs.get_const_kind () == TyTy::ConstType::ConstKind::Decl + || rhs.get_const_kind () == TyTy::ConstType::ConstKind::Decl; + + if (have_decls && !both_are_decls) + { + if (lhs.get_const_kind () == TyTy::ConstType::ConstKind::Decl) + { + TyTy::TyVar iv = TyTy::TyVar::get_implicit_const_infer_var ( + lhs, lhs.get_locus ()); + ltype = iv.get_tyty (); + } + else if (rhs.get_const_kind () + == TyTy::ConstType::ConstKind::Decl) + { + TyTy::TyVar iv = TyTy::TyVar::get_implicit_const_infer_var ( + rhs, rhs.get_locus ()); + rtype = iv.get_tyty (); + } + } + } } if ((ltype->is () || rtype->is ())