From 4ae5d60e45208f868697370455bdc92a8789a9ce Mon Sep 17 00:00:00 2001 From: Om Swaroop Nayak <96killerat96@gmail.com> Date: Sat, 4 Jan 2025 06:11:02 -0800 Subject: [PATCH] gcc/rust/ChangeLog: * resolve/rust-early-name-resolver.cc (EarlyNameResolver::visit): "modified impl" * util/rust-attributes.cc (Attributes::is_rustc_builtin_macro): "helper function" * util/rust-attributes.h: "added" * util/rust-hir-map.cc (Mappings::insert_macro_def): "modified impl" Signed-off-by: Om Swaroop Nayak <96killerat96@gmail.com> --- gcc/rust/resolve/rust-early-name-resolver.cc | 11 +++-------- gcc/rust/util/rust-attributes.cc | 12 ++++++++++++ gcc/rust/util/rust-attributes.h | 1 + gcc/rust/util/rust-hir-map.cc | 10 +++------- 4 files changed, 19 insertions(+), 15 deletions(-) diff --git a/gcc/rust/resolve/rust-early-name-resolver.cc b/gcc/rust/resolve/rust-early-name-resolver.cc index 634523181139..fab52edb0ed0 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 45ebf8c65461..f050b0960a6e 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 c341b3e0a5db..46f6f681de74 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 2edf0996276b..e0d83b1b4041 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 ());