From b9840366b6e4f2bba8f3c67a4ee805d9f4f3c1c5 Mon Sep 17 00:00:00 2001 From: Philip Herron Date: Mon, 8 Aug 2022 17:07:42 +0100 Subject: [PATCH] Unify generic substitutions on unit-structs When we have generic unit-structs there are no fields to unify the generic. This adds a case to ensure we iterate and check these. We might end up making it always do this for all structs always. Addresses #1447 --- gcc/rust/typecheck/rust-tyty-coercion.h | 22 ++++++++++++++++++++++ gcc/rust/typecheck/rust-tyty-rules.h | 22 ++++++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/gcc/rust/typecheck/rust-tyty-coercion.h b/gcc/rust/typecheck/rust-tyty-coercion.h index 34267b30838..ed1636593c5 100644 --- a/gcc/rust/typecheck/rust-tyty-coercion.h +++ b/gcc/rust/typecheck/rust-tyty-coercion.h @@ -1130,6 +1130,28 @@ public: } } + // generic args for the unit-struct case + if (type.is_unit () && base->is_unit ()) + { + rust_assert (type.get_num_substitutions () + == base->get_num_substitutions ()); + + for (size_t i = 0; i < type.get_num_substitutions (); i++) + { + auto &a = base->get_substs ().at (i); + auto &b = type.get_substs ().at (i); + + auto pa = a.get_param_ty (); + auto pb = b.get_param_ty (); + + auto res = pa->unify (pb); + if (res->get_kind () == TyTy::TypeKind::ERROR) + { + return; + } + } + } + resolved = type.clone (); } diff --git a/gcc/rust/typecheck/rust-tyty-rules.h b/gcc/rust/typecheck/rust-tyty-rules.h index ad2d4b79b00..77d912a5921 100644 --- a/gcc/rust/typecheck/rust-tyty-rules.h +++ b/gcc/rust/typecheck/rust-tyty-rules.h @@ -1128,6 +1128,28 @@ public: } } + // generic args for the unit-struct case + if (type.is_unit () && base->is_unit ()) + { + rust_assert (type.get_num_substitutions () + == base->get_num_substitutions ()); + + for (size_t i = 0; i < type.get_num_substitutions (); i++) + { + auto &a = base->get_substs ().at (i); + auto &b = type.get_substs ().at (i); + + auto pa = a.get_param_ty (); + auto pb = b.get_param_ty (); + + auto res = pa->unify (pb); + if (res->get_kind () == TyTy::TypeKind::ERROR) + { + return; + } + } + } + resolved = type.clone (); }