diff --git a/gcc/rust/hir/rust-ast-lower-base.cc b/gcc/rust/hir/rust-ast-lower-base.cc index eac2cba5c75..1197f855be4 100644 --- a/gcc/rust/hir/rust-ast-lower-base.cc +++ b/gcc/rust/hir/rust-ast-lower-base.cc @@ -993,12 +993,9 @@ ASTLoweringBase::lower_extern_block (AST::ExternBlock &extern_block) void ASTLoweringBase::lower_macro_definition (AST::MacroRulesDefinition &def) { - auto is_export = false; - for (const auto &attr : def.get_outer_attrs ()) - if (attr.get_path ().as_string () == Values::Attributes::MACRO_EXPORT) - is_export = true; - - if (is_export) + + + if (Analysis::Attributes::is_macro_export(def.get_outer_attrs())) { mappings.insert_exported_macro (def); mappings.insert_ast_item (&def); diff --git a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc index e51aef8e9d0..89b57a8bd9f 100644 --- a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc +++ b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc @@ -22,6 +22,7 @@ #include "rust-ast-full.h" #include "rust-hir-map.h" #include "rust-attribute-values.h" +#include "rust-attributes.h" namespace Rust { namespace Resolver2_0 { @@ -168,15 +169,15 @@ TopLevel::visit (AST::ExternCrate &crate) crate.get_referenced_crate ()); } -static bool -is_macro_export (AST::MacroRulesDefinition &def) -{ - for (const auto &attr : def.get_outer_attrs ()) - if (attr.get_path ().as_string () == Values::Attributes::MACRO_EXPORT) - return true; +// static bool +// is_macro_export (AST::MacroRulesDefinition &def) +// { +// for (const auto &attr : def.get_outer_attrs ()) +// if (attr.get_path ().as_string () == Values::Attributes::MACRO_EXPORT) +// return true; - return false; -} +// return false; +// } void TopLevel::visit (AST::MacroRulesDefinition ¯o) @@ -186,7 +187,7 @@ TopLevel::visit (AST::MacroRulesDefinition ¯o) // crate if they are marked with #[macro_export]. The execption to this is // macros 2.0, which get resolved and inserted like regular items. - if (is_macro_export (macro)) + if (Analysis::Attributes::is_macro_export (macro.get_outer_attrs())) { auto res = ctx.macros.insert_at_root (macro.get_rule_name (), macro.get_node_id ()); diff --git a/gcc/rust/util/rust-attributes.cc b/gcc/rust/util/rust-attributes.cc index 45ebf8c6546..bbe966bec77 100644 --- a/gcc/rust/util/rust-attributes.cc +++ b/gcc/rust/util/rust-attributes.cc @@ -37,6 +37,18 @@ Attributes::is_known (const std::string &attribute_path) return !lookup.is_error (); } +bool +Attributes::is_macro_export (AST::AttrVec outer_attrs) +{ + for (auto &attr : outer_attrs) + { + if (attr.get_path ().as_string() == Values::Attributes::MACRO_EXPORT) + { + return true; + } + } + return false; +} using Attrs = Values::Attributes; diff --git a/gcc/rust/util/rust-attributes.h b/gcc/rust/util/rust-attributes.h index c341b3e0a5d..9c8e1ab7884 100644 --- a/gcc/rust/util/rust-attributes.h +++ b/gcc/rust/util/rust-attributes.h @@ -29,6 +29,7 @@ class Attributes { public: static bool is_known (const std::string &attribute_path); + static bool is_macro_export (AST::AttrVec outer_attrs); }; enum CompilerPass