public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Thomas Schwinge <tschwinge@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc/devel/rust/master] parser: Improve parsing of complex generic arguments
Date: Sat, 11 Feb 2023 15:30:12 +0000 (GMT)	[thread overview]
Message-ID: <20230211153012.060DD3858D32@sourceware.org> (raw)

https://gcc.gnu.org/g:d60022770403ee3799644fb3832cbdd0d721e0f7

commit d60022770403ee3799644fb3832cbdd0d721e0f7
Author: Arthur Cohen <arthur.cohen@embecosm.com>
Date:   Wed Feb 1 12:41:47 2023 +0100

    parser: Improve parsing of complex generic arguments
    
    The parser was missing code for handling complex type arguments such
    as type paths or nested generics.
    
    gcc/rust/ChangeLog:
    
            * parse/rust-parse-impl.h (Parser::parse_generic_arg): Handle type
            paths and nested generics properly.
    
    gcc/testsuite/ChangeLog:
    
            * rust/compile/parse_complex_generic_application.rs: New test.
            * rust/compile/parse_complex_generic_application2.rs: New test.

Diff:
---
 gcc/rust/parse/rust-parse-impl.h                        |  4 +++-
 .../rust/compile/parse_complex_generic_application.rs   | 17 +++++++++++++++++
 .../rust/compile/parse_complex_generic_application2.rs  | 10 ++++++++++
 3 files changed, 30 insertions(+), 1 deletion(-)

diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h
index f60d34fdb94..b4c959e6684 100644
--- a/gcc/rust/parse/rust-parse-impl.h
+++ b/gcc/rust/parse/rust-parse-impl.h
@@ -6309,7 +6309,9 @@ Parser<ManagedTokenSource>::parse_generic_arg ()
 	// could either have a valid type or a macro (FIXME: anything else?). So
 	// we need one bit of lookahead to differentiate if this is really
 	auto next_tok = lexer.peek_token (1);
-	if (next_tok->get_id () == EXCLAM)
+	if (next_tok->get_id () == LEFT_ANGLE
+	    || next_tok->get_id () == SCOPE_RESOLUTION
+	    || next_tok->get_id () == EXCLAM)
 	  {
 	    auto type = parse_type ();
 	    if (type)
diff --git a/gcc/testsuite/rust/compile/parse_complex_generic_application.rs b/gcc/testsuite/rust/compile/parse_complex_generic_application.rs
new file mode 100644
index 00000000000..d5c7bf488b7
--- /dev/null
+++ b/gcc/testsuite/rust/compile/parse_complex_generic_application.rs
@@ -0,0 +1,17 @@
+pub enum Either<T, E> {
+    Left(T),
+    Right(E),
+}
+
+pub mod err {
+    pub struct Error;
+    pub struct ErrorWrap<T>(T);
+}
+
+pub fn foo_err() -> Either<(), err::Error> {
+    Either::Left(())
+}
+
+pub fn foo_err_wrap() -> Either<(), err::ErrorWrap<u8>> {
+    Either::Left(())
+}
diff --git a/gcc/testsuite/rust/compile/parse_complex_generic_application2.rs b/gcc/testsuite/rust/compile/parse_complex_generic_application2.rs
new file mode 100644
index 00000000000..0361931c50c
--- /dev/null
+++ b/gcc/testsuite/rust/compile/parse_complex_generic_application2.rs
@@ -0,0 +1,10 @@
+pub enum Either<L, R> {
+    Left(L),
+    Right(R),
+}
+
+pub struct Wrap<T>(T);
+
+pub fn foo_wrap() -> Either<(), Wrap<u8>> {
+    Either::Left(())
+}

                 reply	other threads:[~2023-02-11 15:30 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230211153012.060DD3858D32@sourceware.org \
    --to=tschwinge@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).