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 61e9ea4a928..29cc05ebe3d 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 { diff --git a/gcc/rust/util/rust-attributes.cc b/gcc/rust/util/rust-attributes.cc index 45ebf8c6546..e8fe2c13482 100644 --- a/gcc/rust/util/rust-attributes.cc +++ b/gcc/rust/util/rust-attributes.cc @@ -37,7 +37,17 @@ Attributes::is_known (const std::string &attribute_path) return !lookup.is_error (); } +bool +Attributes::is_macro_export (const AST::AttrVec outer_attrs) +{ + for (const auto &attr : outer_attrs) + + if (attr.get_path ().as_string () == Values::Attributes::MACRO_EXPORT) + return true; + + return false; +} using Attrs = Values::Attributes; // https://doc.rust-lang.org/stable/nightly-rustc/src/rustc_feature/builtin_attrs.rs.html#248 diff --git a/gcc/rust/util/rust-attributes.h b/gcc/rust/util/rust-attributes.h index c341b3e0a5d..7a029b8c29e 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 (const AST::AttrVec outer_attrs); }; enum CompilerPass