From: "lenny.chiadmi-delage" <[email protected]>
Fix parsing of outer attributes in expressions.
Fixes Rust-GCC/gccrs#3904
gcc/rust/ChangeLog:
* parse/rust-parse-impl-expr.hxx(Parser::null_denotation): Add
HASH case to handle outer attributes in expressions.
Signed-off-by: lenny.chiadmi-delage <[email protected]>
---
This change was merged into the gccrs repository and is posted here for
upstream visibility and potential drive-by review, as requested by GCC
release managers.
Each commit email contains a link to its details on github from where you can
find the Pull-Request and associated discussions.
Commit on github:
https://github.com/Rust-GCC/gccrs/commit/a0897c4dfe5229a4a0d59153f108cf2299bb1168
The commit is not linked to any pull-request
gcc/rust/parse/rust-parse-impl-expr.hxx | 26 +++++++++++++++++++++++++
1 file changed, 26 insertions(+)
diff --git a/gcc/rust/parse/rust-parse-impl-expr.hxx
b/gcc/rust/parse/rust-parse-impl-expr.hxx
index 96a2686df..b870273e2 100644
--- a/gcc/rust/parse/rust-parse-impl-expr.hxx
+++ b/gcc/rust/parse/rust-parse-impl-expr.hxx
@@ -1901,6 +1901,32 @@ Parser<ManagedTokenSource>::null_denotation
(AST::AttrVec outer_attrs,
return null_denotation_path (std::move (path), std::move (outer_attrs),
restrictions);
}
+ case HASH:
+ {
+ // Parse outer attributes and then the expression that follows
+ AST::AttrVec attrs = parse_outer_attributes ();
+
+ // Merge with any existing outer attributes
+ if (!outer_attrs.empty ())
+ attrs.insert (attrs.begin (), outer_attrs.begin (),
+ outer_attrs.end ());
+
+ // Try to parse the expression that should follow the attributes
+ auto expr = parse_expr (std::move (attrs), restrictions);
+ if (!expr)
+ {
+ /* If parsing failed and we're at a semicolon, provide a better
+ * error
+ */
+ const_TokenPtr next_tok = lexer.peek_token ();
+ if (next_tok->get_id () == SEMICOLON)
+ add_error (Error (next_tok->get_locus (),
+ "expected expression, found %<;%>"));
+ return tl::unexpected<Parse::Error::Expr> (
+ Parse::Error::Expr::CHILD_ERROR);
+ }
+ return expr;
+ }
default:
if (tok->get_id () == LEFT_SHIFT)
{
base-commit: 8e0858dfb29db614cc865a503a53a1846f08b5f2
--
2.52.0