diff --git a/gcc/rust/expand/rust-macro-expand.cc b/gcc/rust/expand/rust-macro-expand.cc index 62273448677..2620fea1bb5 100644 --- a/gcc/rust/expand/rust-macro-expand.cc +++ b/gcc/rust/expand/rust-macro-expand.cc @@ -490,11 +490,7 @@ MacroExpander::match_fragment (Parser &parser, // is meta attributes? case AST::MacroFragSpec::META: - // parser.parse_inner_attribute ? - // parser.parse_outer_attribute ? - // parser.parse_attribute_body ? - // parser.parse_doc_comment ? - gcc_unreachable (); + parser.parse_attribute_body (); break; case AST::MacroFragSpec::TT: diff --git a/gcc/rust/parse/rust-parse.h b/gcc/rust/parse/rust-parse.h index 88bd311935b..1362c56c5ad 100644 --- a/gcc/rust/parse/rust-parse.h +++ b/gcc/rust/parse/rust-parse.h @@ -143,6 +143,7 @@ public: AST::Visibility parse_visibility (); std::unique_ptr parse_identifier_pattern (); std::unique_ptr parse_token_tree (); + AST::Attribute parse_attribute_body (); private: void skip_after_semicolon (); @@ -162,7 +163,6 @@ private: AST::Attribute parse_inner_attribute (); AST::AttrVec parse_outer_attributes (); AST::Attribute parse_outer_attribute (); - AST::Attribute parse_attribute_body (); std::unique_ptr parse_attr_input (); AST::Attribute parse_doc_comment (); diff --git a/gcc/testsuite/rust/execute/torture/macros27.rs b/gcc/testsuite/rust/execute/torture/macros27.rs new file mode 100644 index 00000000000..d515bb278a0 --- /dev/null +++ b/gcc/testsuite/rust/execute/torture/macros27.rs @@ -0,0 +1,24 @@ +// { dg-additional-options "-frust-cfg=A" } + +macro_rules! attr { + (#[$attr:meta] $s:stmt) => { + #[$attr] + $s; + }; +} + +fn main() -> i32 { + let mut a = 0; + + attr! { + #[cfg(A)] + a = 3 + }; + + attr! { + #[cfg(B)] + a = 40 + }; + + a - 3 +}