public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/rust/master] rust: add bound parsing in parse_generic_arg.
@ 2023-01-12  7:44 Thomas Schwinge
  0 siblings, 0 replies; only message in thread
From: Thomas Schwinge @ 2023-01-12  7:44 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:2f36f38054279e66b1af55995e41dd14e56beb25

commit 2f36f38054279e66b1af55995e41dd14e56beb25
Author: mxlol233 <mxlol233@outlook.com>
Date:   Wed Jan 4 21:21:59 2023 +0800

    rust: add bound parsing in parse_generic_arg.
    
    Signed-off-by: Xiao Ma <mxlol233@outlook.com>

Diff:
---
 gcc/rust/parse/rust-parse-impl.h     | 17 +++++++++++++++++
 gcc/testsuite/rust/compile/bounds.rs | 10 ++++++++++
 2 files changed, 27 insertions(+)

diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h
index 864fb86ce06..86124ee658e 100644
--- a/gcc/rust/parse/rust-parse-impl.h
+++ b/gcc/rust/parse/rust-parse-impl.h
@@ -6189,6 +6189,23 @@ Parser<ManagedTokenSource>::parse_generic_arg ()
 	    else
 	      return AST::GenericArg::create_error ();
 	  }
+	else if (next_tok->get_id () == COLON)
+	  {
+	    lexer.skip_token (); // skip ident
+	    lexer.skip_token (); // skip colon
+
+	    auto tok = lexer.peek_token ();
+	    std::vector<std::unique_ptr<AST::TypeParamBound>> bounds
+	      = parse_type_param_bounds ();
+
+	    auto type = std::unique_ptr<AST::TraitObjectType> (
+	      new AST::TraitObjectType (std::move (bounds), tok->get_locus (),
+					false));
+	    if (type)
+	      return AST::GenericArg::create_type (std::move (type));
+	    else
+	      return AST::GenericArg::create_error ();
+	  }
 	lexer.skip_token ();
 	return AST::GenericArg::create_ambiguous (tok->get_str (),
 						  tok->get_locus ());
diff --git a/gcc/testsuite/rust/compile/bounds.rs b/gcc/testsuite/rust/compile/bounds.rs
new file mode 100644
index 00000000000..ecb10d81f65
--- /dev/null
+++ b/gcc/testsuite/rust/compile/bounds.rs
@@ -0,0 +1,10 @@
+trait Foo {
+    type Bar;
+}
+
+trait Copy {}
+
+
+fn c<F: Foo<Bar: Foo>>() where F::Bar: Copy { // { dg-warning "function is never used: 'c'" }
+}
+

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-01-12  7:44 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-12  7:44 [gcc/devel/rust/master] rust: add bound parsing in parse_generic_arg Thomas Schwinge

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).