From: Owen Avery <[email protected]>
gcc/rust/ChangeLog:
* expand/rust-macro-expand.cc (transcribe_expression): Parse any
outer attributes before parsing an expression.
* parse/rust-parse.h (Parser::parse_outer_attributes): Make
public.
gcc/testsuite/ChangeLog:
* rust/compile/attr-macro.rs: New test.
Signed-off-by: Owen Avery <[email protected]>
---
gcc/rust/expand/rust-macro-expand.cc | 3 ++-
gcc/rust/parse/rust-parse.h | 6 +++++-
gcc/testsuite/rust/compile/attr-macro.rs | 7 +++++++
3 files changed, 14 insertions(+), 2 deletions(-)
create mode 100644 gcc/testsuite/rust/compile/attr-macro.rs
diff --git a/gcc/rust/expand/rust-macro-expand.cc
b/gcc/rust/expand/rust-macro-expand.cc
index 5667a1a4f4f..dfead3acc1d 100644
--- a/gcc/rust/expand/rust-macro-expand.cc
+++ b/gcc/rust/expand/rust-macro-expand.cc
@@ -961,7 +961,8 @@ transcribe_expression (Parser<MacroInvocLexer> &parser)
auto &lexer = parser.get_token_source ();
auto start = lexer.get_offs ();
- auto expr = parser.parse_expr ();
+ auto attrs = parser.parse_outer_attributes ();
+ auto expr = parser.parse_expr (std::move (attrs));
if (expr == nullptr)
return AST::Fragment::create_error ();
diff --git a/gcc/rust/parse/rust-parse.h b/gcc/rust/parse/rust-parse.h
index fa518ac5544..fa9c909338b 100644
--- a/gcc/rust/parse/rust-parse.h
+++ b/gcc/rust/parse/rust-parse.h
@@ -212,6 +212,11 @@ public:
std::unique_ptr<AST::MacroInvocation>
parse_macro_invocation (AST::AttrVec outer_attrs);
+ /*
+ * This has to be public for parsing expressions with outer attributes
+ */
+ AST::AttrVec parse_outer_attributes ();
+
private:
void skip_after_semicolon ();
void skip_after_end ();
@@ -228,7 +233,6 @@ private:
// AST-related stuff - maybe move or something?
AST::Attribute parse_inner_attribute ();
- AST::AttrVec parse_outer_attributes ();
AST::Attribute parse_outer_attribute ();
std::unique_ptr<AST::AttrInput> parse_attr_input ();
std::tuple<AST::SimplePath, std::unique_ptr<AST::AttrInput>, location_t>
diff --git a/gcc/testsuite/rust/compile/attr-macro.rs
b/gcc/testsuite/rust/compile/attr-macro.rs
new file mode 100644
index 00000000000..de9fce12cb9
--- /dev/null
+++ b/gcc/testsuite/rust/compile/attr-macro.rs
@@ -0,0 +1,7 @@
+macro_rules! foo {
+ () => { #[cfg(all())] 12 }
+}
+
+fn main() -> i32 {
+ foo!()
+}
--
2.50.1