diff options
author | Philip Herron <philip.herron@embecosm.com> | 2022-08-08 17:07:42 +0100 |
---|---|---|
committer | Philip Herron <philip.herron@embecosm.com> | 2022-08-08 17:23:27 +0100 |
commit | b9840366b6e4f2bba8f3c67a4ee805d9f4f3c1c5 (patch) | |
tree | 73013bb20f735e00f271da63e57a908e7f1148be | |
parent | e0a14f483979aea48f7588656b4269e1b9dbee34 (diff) | |
download | gcc-b9840366b6e4f2bba8f3c67a4ee805d9f4f3c1c5.zip gcc-b9840366b6e4f2bba8f3c67a4ee805d9f4f3c1c5.tar.gz gcc-b9840366b6e4f2bba8f3c67a4ee805d9f4f3c1c5.tar.bz2 |
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
-rw-r--r-- | gcc/rust/typecheck/rust-tyty-coercion.h | 22 | ||||
-rw-r--r-- | gcc/rust/typecheck/rust-tyty-rules.h | 22 |
2 files changed, 44 insertions, 0 deletions
diff --git a/gcc/rust/typecheck/rust-tyty-coercion.h b/gcc/rust/typecheck/rust-tyty-coercion.h index 34267b3..ed16365 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 ad2d4b7..77d912a 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 (); } |