diff --git a/gcc/rust/resolve/rust-early-name-resolver.cc b/gcc/rust/resolve/rust-early-name-resolver.cc index 63452318113..fab52edb0ed 100644 --- a/gcc/rust/resolve/rust-early-name-resolver.cc +++ b/gcc/rust/resolve/rust-early-name-resolver.cc @@ -21,6 +21,7 @@ #include "rust-name-resolver.h" #include "rust-macro-builtins.h" #include "rust-attribute-values.h" +#include "rust-attributes.h" namespace Rust { namespace Resolver { @@ -485,14 +486,8 @@ EarlyNameResolver::visit (AST::MacroInvocation &invoc) auto rules_def = mappings.lookup_macro_def (resolved_node); auto &outer_attrs = rules_def.value ()->get_outer_attrs (); - bool is_builtin - = std::any_of (outer_attrs.begin (), outer_attrs.end (), - [] (AST::Attribute attr) { - return attr.get_path () - == Values::Attributes::RUSTC_BUILTIN_MACRO; - }); - - if (is_builtin) + + if (Analysis::Attributes::is_rustc_builtin_macro (outer_attrs)) { auto builtin_kind = builtin_macro_from_string ( rules_def.value ()->get_rule_name ().as_string ()); diff --git a/gcc/rust/util/rust-attributes.cc b/gcc/rust/util/rust-attributes.cc index 45ebf8c6546..f050b0960a6 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_rustc_builtin_macro (AST::AttrVec outer_attrs) +{ + for (auto attr : outer_attrs) + { + if (attr.get_path () == Values::Attributes::RUSTC_BUILTIN_MACRO) + { + 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..46f6f681de7 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_rustc_builtin_macro (AST::AttrVec outer_attrs); }; enum CompilerPass diff --git a/gcc/rust/util/rust-hir-map.cc b/gcc/rust/util/rust-hir-map.cc index 2edf0996276..e0d83b1b404 100644 --- a/gcc/rust/util/rust-hir-map.cc +++ b/gcc/rust/util/rust-hir-map.cc @@ -25,6 +25,7 @@ #include "rust-macro-builtins.h" #include "rust-mapping-common.h" #include "rust-attribute-values.h" +#include "rust-attributes.h" namespace Rust { namespace Analysis { @@ -848,13 +849,8 @@ void Mappings::insert_macro_def (AST::MacroRulesDefinition *macro) { auto outer_attrs = macro->get_outer_attrs (); - bool should_be_builtin - = std::any_of (outer_attrs.begin (), outer_attrs.end (), - [] (AST::Attribute attr) { - return attr.get_path () - == Values::Attributes::RUSTC_BUILTIN_MACRO; - }); - if (should_be_builtin) + + if (Analysis::Attributes::is_rustc_builtin_macro (outer_attrs)) { auto builtin = MacroBuiltin::builtins.lookup (macro->get_rule_name ().as_string ());