From: Pierre-Emmanuel Patry <[email protected]>

gcc/rust/ChangeLog:

        * expand/rust-extern-crate-loader.cc (ExternCrateLoaderVisitor::visit):
        Use explicit MacroUse enum instead of boolean.
        * resolve/rust-name-resolution-context.cc 
(NameResolutionContext::merge):
        Likewise.
        * resolve/rust-name-resolution-context.h: Likewise.
        * rust-session-manager.cc (Session::load_extern_crate): Likewise.
        * rust-session-manager.h: Likewise.
        * rust-load-crate.h: New file with MacroUse definition.

Signed-off-by: Pierre-Emmanuel Patry <[email protected]>
---
This change was merged into the gccrs repository and is posted here for
upstream visibility and potential drive-by review, as requested by GCC
release managers.
Each commit email contains a link to its details on github from where you can
find the Pull-Request and associated discussions.


Commit on github: 
https://github.com/Rust-GCC/gccrs/commit/6a45b39d3e54d1a8222c659759c34a39cd4f2dfc

The commit has NOT been mentioned in any issue.

The commit has been mentioned in the following pull-request(s):
 - https://github.com/Rust-GCC/gccrs/pull/5105

 gcc/rust/expand/rust-extern-crate-loader.cc   |  7 ++--
 .../resolve/rust-name-resolution-context.cc   |  4 +--
 .../resolve/rust-name-resolution-context.h    |  3 +-
 gcc/rust/rust-load-crate.h                    | 32 +++++++++++++++++++
 gcc/rust/rust-session-manager.cc              |  2 +-
 gcc/rust/rust-session-manager.h               |  7 ++--
 6 files changed, 46 insertions(+), 9 deletions(-)
 create mode 100644 gcc/rust/rust-load-crate.h

diff --git a/gcc/rust/expand/rust-extern-crate-loader.cc 
b/gcc/rust/expand/rust-extern-crate-loader.cc
index cc41f5561..2c6ec4213 100644
--- a/gcc/rust/expand/rust-extern-crate-loader.cc
+++ b/gcc/rust/expand/rust-extern-crate-loader.cc
@@ -19,6 +19,7 @@
 #include "rust-extern-crate-loader.h"
 #include "rust-session-manager.h"
 #include "rust-attribute-values.h"
+#include "rust-load-crate.h"
 
 namespace Rust {
 ExternCrateLoaderVisitor::ExternCrateLoaderVisitor (
@@ -49,8 +50,10 @@ ExternCrateLoaderVisitor::visit (AST::ExternCrate 
&extern_crate)
                                        == Values::Attributes::MACRO_USE;
                               });
     }
-  auto crate = session.load_extern_crate (extern_crate.get_referenced_crate (),
-                                         macro_use, extern_crate.get_locus ());
+  auto crate
+    = session.load_extern_crate (extern_crate.get_referenced_crate (),
+                                macro_use ? MacroUse::Present : MacroUse::None,
+                                extern_crate.get_locus ());
   if (crate)
     loaded_crates.push_back (std::move (crate.value ()));
 }
diff --git a/gcc/rust/resolve/rust-name-resolution-context.cc 
b/gcc/rust/resolve/rust-name-resolution-context.cc
index 3902db029..ead2a9b0b 100644
--- a/gcc/rust/resolve/rust-name-resolution-context.cc
+++ b/gcc/rust/resolve/rust-name-resolution-context.cc
@@ -413,7 +413,7 @@ NameResolutionContext::scoped (Rib::Kind rib_kind, 
Namespace ns,
 
 void
 NameResolutionContext::merge (NameResolutionContext &other, NodeId at,
-                             bool macro_use)
+                             MacroUse macro_use)
 {
   // TODO: merge once, for all namespaces at once
 
@@ -443,7 +443,7 @@ NameResolutionContext::merge (NameResolutionContext &other, 
NodeId at,
   merge_fstack (values, other.values, Namespace::Values);
   merge_fstack (types, other.types, Namespace::Types);
 
-  if (macro_use)
+  if (macro_use == MacroUse::Present)
     {
       for (auto kv : other.macros.root.rib_macros.get_values ())
        {
diff --git a/gcc/rust/resolve/rust-name-resolution-context.h 
b/gcc/rust/resolve/rust-name-resolution-context.h
index 997969431..6f97b414d 100644
--- a/gcc/rust/resolve/rust-name-resolution-context.h
+++ b/gcc/rust/resolve/rust-name-resolution-context.h
@@ -26,6 +26,7 @@
 #include "rust-stacked-contexts.h"
 #include "rust-item.h"
 #include "rust-name-resolution.h"
+#include "rust-load-crate.h"
 
 namespace Rust {
 namespace Resolver2_0 {
@@ -841,7 +842,7 @@ public:
    * @param at The node id of the container were the nr context should be
    * merged. Usually an extern crate node.
    */
-  void merge (NameResolutionContext &other, NodeId at, bool macro_use);
+  void merge (NameResolutionContext &other, NodeId at, MacroUse macro_use);
 
 // We disable this function for now as it causes regressions, but I think it
 // is important for a more proper final nameres context - need to investigate
diff --git a/gcc/rust/rust-load-crate.h b/gcc/rust/rust-load-crate.h
new file mode 100644
index 000000000..c88306c07
--- /dev/null
+++ b/gcc/rust/rust-load-crate.h
@@ -0,0 +1,32 @@
+// Copyright (C) 2026 Free Software Foundation, Inc.
+
+// This file is part of GCC.
+
+// GCC is free software; you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation; either version 3, or (at your option) any later
+// version.
+
+// GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+// WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+// for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with GCC; see the file COPYING3.  If not see
+// <http://www.gnu.org/licenses/>.
+
+#ifndef RUST_LOAD_CRATE_H
+#define RUST_LOAD_CRATE_H
+
+namespace Rust {
+
+enum class MacroUse
+{
+  Present,
+  None,
+};
+
+} // namespace Rust
+
+#endif
diff --git a/gcc/rust/rust-session-manager.cc b/gcc/rust/rust-session-manager.cc
index 75b855108..f7b663cae 100644
--- a/gcc/rust/rust-session-manager.cc
+++ b/gcc/rust/rust-session-manager.cc
@@ -1254,7 +1254,7 @@ Session::dump_hir_pretty (HIR::Crate &crate) const
 // imports
 
 tl::expected<Session::LoadedCrate, Session::LoadingError>
-Session::load_extern_crate (const std::string &crate_name, bool macro_use,
+Session::load_extern_crate (const std::string &crate_name, MacroUse macro_use,
                            location_t locus)
 {
   auto &crate_mapping = mappings.crate;
diff --git a/gcc/rust/rust-session-manager.h b/gcc/rust/rust-session-manager.h
index f80e13e33..6b753fa03 100644
--- a/gcc/rust/rust-session-manager.h
+++ b/gcc/rust/rust-session-manager.h
@@ -25,6 +25,7 @@
 #include "rust-hir-map.h"
 #include "safe-ctype.h"
 #include "rust-name-resolution-context.h"
+#include "rust-load-crate.h"
 
 #include "config.h"
 #include "rust-system.h"
@@ -448,7 +449,7 @@ public:
 
   struct LoadedCrate
   {
-    LoadedCrate (std::string name, bool macro_use, NodeId node_id,
+    LoadedCrate (std::string name, MacroUse macro_use, NodeId node_id,
                 Resolver2_0::NameResolutionContext ctx)
       : name (std::move (name)), node_id (node_id), macro_use (macro_use),
        ctx (std::move (ctx))
@@ -460,7 +461,7 @@ public:
 
     std::string name;
     NodeId node_id;
-    bool macro_use;
+    MacroUse macro_use;
     Resolver2_0::NameResolutionContext ctx;
   };
 
@@ -492,7 +493,7 @@ public:
   };
 
   tl::expected<LoadedCrate, LoadingError>
-  load_extern_crate (const std::string &crate_name, bool macro_use,
+  load_extern_crate (const std::string &crate_name, MacroUse macro_use,
                     location_t locus);
 
   int get_compat_version () const { return options.get_compat_version (); }
-- 
2.56.1

Reply via email to