From: Lucas Ly Ba <[email protected]>

A type alias with generic parameters never resolved those parameters
into the type context, so the reachability pass asserted when looking
up their types. Resolve the generic parameters, as the other items do.

gcc/rust/ChangeLog:

        * typecheck/rust-hir-type-check-item.cc (TypeCheckItem::visit): Resolve
        the generic parameters of a type alias.

gcc/testsuite/ChangeLog:

        * rust/compile/type-alias-generic-params.rs: New test.

Signed-off-by: Lucas Ly Ba <[email protected]>
---
This change was merged into the gccrs repository and is posted here for
upstream visibility and potential drive-by review, as requested by GCC
release managers.
Each commit email contains a link to its details on github from where you can
find the Pull-Request and associated discussions.


Commit on github: 
https://github.com/Rust-GCC/gccrs/commit/daaf19e1a57923725e4acb94f82fad41b0747440

The commit has NOT been mentioned in any issue.

The commit has been mentioned in the following pull-request(s):
 - https://github.com/Rust-GCC/gccrs/pull/4637

 gcc/rust/typecheck/rust-hir-type-check-item.cc          | 7 +++++++
 gcc/testsuite/rust/compile/type-alias-generic-params.rs | 9 +++++++++
 2 files changed, 16 insertions(+)
 create mode 100644 gcc/testsuite/rust/compile/type-alias-generic-params.rs

diff --git a/gcc/rust/typecheck/rust-hir-type-check-item.cc 
b/gcc/rust/typecheck/rust-hir-type-check-item.cc
index d8f2b8754..8c8d7e416 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-item.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-item.cc
@@ -228,6 +228,13 @@ TypeCheckItem::validate_trait_impl_block (
 void
 TypeCheckItem::visit (HIR::TypeAlias &alias)
 {
+  auto lifetime_pin = context->push_clean_lifetime_resolver ();
+
+  std::vector<TyTy::SubstitutionParamMapping> substitutions;
+  if (alias.has_generics ())
+    resolve_generic_params (HIR::Item::ItemKind::TypeAlias, alias.get_locus (),
+                           alias.get_generic_params (), substitutions);
+
   TyTy::BaseType *actual_type
     = TypeCheckType::Resolve (alias.get_type_aliased ());
 
diff --git a/gcc/testsuite/rust/compile/type-alias-generic-params.rs 
b/gcc/testsuite/rust/compile/type-alias-generic-params.rs
new file mode 100644
index 000000000..8e0883fea
--- /dev/null
+++ b/gcc/testsuite/rust/compile/type-alias-generic-params.rs
@@ -0,0 +1,9 @@
+// Generic type aliases used to ICE in the reachability pass because their
+// generic parameters were never resolved into the type context.
+#![feature(no_core, lang_items)]
+#![no_core]
+
+#[lang = "sized"]
+pub trait Sized {}
+
+pub type Alias<T> = T;

base-commit: 5f7a4e198e8ab0fc9dd633931889d41e8ba1f5d6
-- 
2.54.0

Reply via email to