aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArthur Cohen <arthur.cohen@embecosm.com>2023-02-01 12:41:47 +0100
committerArthur Cohen <arthur.cohen@embecosm.com>2023-02-03 11:49:11 +0100
commitd60022770403ee3799644fb3832cbdd0d721e0f7 (patch)
tree9b261f59b5bbc98b55c19dfa9d9415efa7f3a924
parent776c4247de465dd93438a738fff48d5b2076ec11 (diff)
downloadgcc-d60022770403ee3799644fb3832cbdd0d721e0f7.zip
gcc-d60022770403ee3799644fb3832cbdd0d721e0f7.tar.gz
gcc-d60022770403ee3799644fb3832cbdd0d721e0f7.tar.bz2
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.
-rw-r--r--gcc/rust/parse/rust-parse-impl.h4
-rw-r--r--gcc/testsuite/rust/compile/parse_complex_generic_application.rs17
-rw-r--r--gcc/testsuite/rust/compile/parse_complex_generic_application2.rs10
3 files changed, 30 insertions, 1 deletions
diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h
index f60d34f..b4c959e 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 0000000..d5c7bf4
--- /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 0000000..0361931
--- /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(())
+}