[committed,04/88] gccrs: rust: add bound parsing in parse_generic_arg.

Message ID 20230405140411.3016563-5-arthur.cohen@embecosm.com
State Accepted
Headers
Series [committed,01/88] gccrs: fatal_error_flag: Fix typo in error message |

Checks

Context Check Description
snail/gcc-patch-check success Github commit url

Commit Message

Arthur Cohen April 5, 2023, 2:02 p.m. UTC
  From: mxlol233 <mxlol233@outlook.com>

gcc/rust/ChangeLog:

	* parse/rust-parse-impl.h (Parser::parse_generic_arg): Add proper bound parsing.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Xiao Ma <mxlol233@outlook.com>
---
 gcc/rust/parse/rust-parse-impl.h     | 17 +++++++++++++++++
 gcc/testsuite/rust/compile/bounds.rs | 10 ++++++++++
 2 files changed, 27 insertions(+)
 create mode 100644 gcc/testsuite/rust/compile/bounds.rs
  

Patch

diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h
index cbd40efcc9b..959e0338a10 100644
--- a/gcc/rust/parse/rust-parse-impl.h
+++ b/gcc/rust/parse/rust-parse-impl.h
@@ -6198,6 +6198,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'" }
+}
+