[COMMITTED 17/77] gccrs: Fix type param forward declare check

[email protected]
Newsgroups gmane.comp.gcc.rust,gmane.comp.gcc.patches
Message-ID <[email protected]>
From: Owen Avery <[email protected]>

Type param bounds are allowed to use forward declared generic
parameters.

gcc/rust/ChangeLog:

	* resolve/rust-default-resolver.cc
	(DefaultResolver::visit (TypeParam)): Visit bounds outside of
	ForwardTypeParamBan rib.

gcc/testsuite/ChangeLog:

	* rust/compile/generics15.rs: New test.

Signed-off-by: Owen Avery <[email protected]>
---
 gcc/rust/resolve/rust-default-resolver.cc | 12 ++++++++++--
 gcc/testsuite/rust/compile/generics15.rs  |  9 +++++++++
 2 files changed, 19 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/rust/compile/generics15.rs

diff --git a/gcc/rust/resolve/rust-default-resolver.cc b/gcc/rust/resolve/rust-default-resolver.cc
index 10f506bb236..ba65308688f 100644
--- a/gcc/rust/resolve/rust-default-resolver.cc
+++ b/gcc/rust/resolve/rust-default-resolver.cc
@@ -433,9 +433,17 @@ DefaultResolver::visit (AST::StaticItem &item)
 void
 DefaultResolver::visit (AST::TypeParam &param)
 {
-  auto expr_vis = [this, &param] () { AST::DefaultASTVisitor::visit (param); };
+  auto param_ban_vis = [this, &param] () {
+    visit_outer_attrs (param);
+    if (param.has_type ())
+      visit (param.get_type ());
+  };
+
+  ctx.scoped (Rib::Kind::ForwardTypeParamBan, param.get_node_id (),
+	      param_ban_vis);
 
-  ctx.scoped (Rib::Kind::ForwardTypeParamBan, param.get_node_id (), expr_vis);
+  for (auto &bound : param.get_type_param_bounds ())
+    visit (bound);
 }
 
 void
diff --git a/gcc/testsuite/rust/compile/generics15.rs b/gcc/testsuite/rust/compile/generics15.rs
new file mode 100644
index 00000000000..bb50be4e88f
--- /dev/null
+++ b/gcc/testsuite/rust/compile/generics15.rs
@@ -0,0 +1,9 @@
+#![feature(no_core, lang_items)]
+#![no_core]
+
+#[lang = "sized"]
+pub trait Sized {}
+
+pub trait A<T> {}
+
+pub struct B<T: A<T>> (T);
-- 
2.50.1
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.