From d60022770403ee3799644fb3832cbdd0d721e0f7 Mon Sep 17 00:00:00 2001 From: Arthur Cohen Date: Wed, 1 Feb 2023 12:41:47 +0100 Subject: 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. --- gcc/rust/parse/rust-parse-impl.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'gcc/rust/parse') 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::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) -- cgit v1.1 From 38bad2bf21ef0649b3e89bcccfe7e8f7c366de68 Mon Sep 17 00:00:00 2001 From: Arthur Cohen Date: Thu, 2 Feb 2023 15:32:17 +0100 Subject: parser: Fix parsing of closure param list gcc/rust/ChangeLog: * parse/rust-parse-impl.h (Parser::parse_closure_expr): Advance tokens properly when parsing closure param list. gcc/testsuite/ChangeLog: * rust/compile/closure_move_expr.rs: New test. --- gcc/rust/parse/rust-parse-impl.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'gcc/rust/parse') diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h index f60d34f..a3fc9f3 100644 --- a/gcc/rust/parse/rust-parse-impl.h +++ b/gcc/rust/parse/rust-parse-impl.h @@ -7590,6 +7590,7 @@ Parser::parse_closure_expr (AST::AttrVec outer_attrs) case PIPE: // actually may have parameters lexer.skip_token (); + t = lexer.peek_token (); while (t->get_id () != PIPE) { @@ -7606,6 +7607,7 @@ Parser::parse_closure_expr (AST::AttrVec outer_attrs) if (lexer.peek_token ()->get_id () != COMMA) { + lexer.skip_token (); // not an error but means param list is done break; } -- cgit v1.1