From 47bf742e41b099c5147a8258b5401e48b352de83 Mon Sep 17 00:00:00 2001 From: Pierre-Emmanuel Patry Date: Tue, 10 Oct 2023 10:04:57 +0200 Subject: [PATCH 1/2] Fix path expr segment parsing with generic path When a token was identified as bit left shift it slipped through the parser and resulted in an error. gcc/rust/ChangeLog: * parse/rust-parse-impl.h (Parser::parse_path_expr_segment): Accept left shift tokens in order to let generic parsing function split the token. Signed-off-by: Pierre-Emmanuel Patry --- gcc/rust/parse/rust-parse-impl.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h index fecff6153f39..d0e44ce83ebf 100644 --- a/gcc/rust/parse/rust-parse-impl.h +++ b/gcc/rust/parse/rust-parse-impl.h @@ -6804,11 +6804,13 @@ Parser::parse_path_expr_segment () /* use lookahead to determine if they actually exist (don't want to * accidently parse over next ident segment) */ if (lexer.peek_token ()->get_id () == SCOPE_RESOLUTION - && lexer.peek_token (1)->get_id () == LEFT_ANGLE) + && (lexer.peek_token (1)->get_id () == LEFT_ANGLE + || lexer.peek_token (1)->get_id () == LEFT_SHIFT)) { // skip scope resolution lexer.skip_token (); + // Let parse_path_generic_args split "<<" tokens AST::GenericArgs generic_args = parse_path_generic_args (); return AST::PathExprSegment (std::move (ident), locus, From 1077751396ea5924e8eceb6e23116fd8de5fe2e5 Mon Sep 17 00:00:00 2001 From: Pierre-Emmanuel Patry Date: Tue, 10 Oct 2023 10:21:16 +0200 Subject: [PATCH 2/2] Add a new regression test New regression test to highlight behavior of #2652. gcc/testsuite/ChangeLog: * rust/compile/parse_generic_path_expr.rs: New test. Signed-off-by: Pierre-Emmanuel Patry --- gcc/testsuite/rust/compile/parse_generic_path_expr.rs | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 gcc/testsuite/rust/compile/parse_generic_path_expr.rs diff --git a/gcc/testsuite/rust/compile/parse_generic_path_expr.rs b/gcc/testsuite/rust/compile/parse_generic_path_expr.rs new file mode 100644 index 000000000000..a340067e9ea5 --- /dev/null +++ b/gcc/testsuite/rust/compile/parse_generic_path_expr.rs @@ -0,0 +1,4 @@ +// { dg-additional-options "-frust-compile-until=ast" } +fn main() { + only_foo::<::Item>(); +}