From 99c913ba859ab9c733e7804111cab553f90ccb87 Mon Sep 17 00:00:00 2001 From: Pierre-Emmanuel Patry Date: Mon, 9 Oct 2023 13:06:22 +0200 Subject: [PATCH 1/3] Change debug log call to as_string function This will ensure an accurate representation of the token. Also update the as_string function to represent accurately scope resolution tokens. gcc/rust/ChangeLog: * lex/rust-token.cc (Token::as_string): Update function to output scope resolution tokens correctly. * parse/rust-parse-impl.h (Parser::parse_generic_param): Change call to as_string. Signed-off-by: Pierre-Emmanuel Patry --- gcc/rust/lex/rust-token.cc | 2 ++ gcc/rust/parse/rust-parse-impl.h | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/gcc/rust/lex/rust-token.cc b/gcc/rust/lex/rust-token.cc index 9a1132f6a727..75967f239cbc 100644 --- a/gcc/rust/lex/rust-token.cc +++ b/gcc/rust/lex/rust-token.cc @@ -245,6 +245,8 @@ Token::as_string () const return "b'" + escape_special_chars (get_str (), Context::Char) + "'"; case LIFETIME: return "'" + get_str (); + case SCOPE_RESOLUTION: + return "::"; case INT_LITERAL: if (get_type_hint () == CORETYPE_UNKNOWN) return get_str (); diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h index fecff6153f39..91eb14be3cd3 100644 --- a/gcc/rust/parse/rust-parse-impl.h +++ b/gcc/rust/parse/rust-parse-impl.h @@ -3093,7 +3093,7 @@ Parser::parse_generic_param (EndTokenPred is_end_token) // FIXME: Can we clean this last call with a method call? rust_error_at (token->get_locus (), "unexpected token when parsing generic parameters: %qs", - token->get_str ().c_str ()); + token->as_string ().c_str ()); return nullptr; } From a8efbd87f01b4fd1c84572ca64f20c40b8bc8baa Mon Sep 17 00:00:00 2001 From: Pierre-Emmanuel Patry Date: Mon, 9 Oct 2023 14:46:55 +0200 Subject: [PATCH 2/3] Fix type param bound parsing with opening scope The function parsing type param bounds had a problem with scope resolution opening token. gcc/rust/ChangeLog: * parse/rust-parse-impl.h (Parser::parse_type_param_bound): Add missing case for lifetime switch. Signed-off-by: Pierre-Emmanuel Patry --- gcc/rust/parse/rust-parse-impl.h | 1 + 1 file changed, 1 insertion(+) diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h index 91eb14be3cd3..c2f35e210765 100644 --- a/gcc/rust/parse/rust-parse-impl.h +++ b/gcc/rust/parse/rust-parse-impl.h @@ -3886,6 +3886,7 @@ Parser::parse_type_param_bound () case SELF_ALIAS: case CRATE: case DOLLAR_SIGN: + case SCOPE_RESOLUTION: return parse_trait_bound (); default: // don't error - assume this is fine TODO From 1014b7a9f8d2057f068a843bcf078c76a86fe5de Mon Sep 17 00:00:00 2001 From: Pierre-Emmanuel Patry Date: Tue, 10 Oct 2023 10:37:18 +0200 Subject: [PATCH 3/3] Add a regression test for global path parsing Add a new test to highlight fix for #2649. gcc/testsuite/ChangeLog: * rust/compile/parse_global_path_generic.rs: New test. --- gcc/testsuite/rust/compile/parse_global_path_generic.rs | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 gcc/testsuite/rust/compile/parse_global_path_generic.rs diff --git a/gcc/testsuite/rust/compile/parse_global_path_generic.rs b/gcc/testsuite/rust/compile/parse_global_path_generic.rs new file mode 100644 index 000000000000..eb083a8bed2f --- /dev/null +++ b/gcc/testsuite/rust/compile/parse_global_path_generic.rs @@ -0,0 +1,4 @@ +// { dg-additional-options "-frust-compile-until=ast" } +pub fn foo(_d: D) -> u32 { + 0 +}