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

Move the early feature gate store to it's own translation unit. This
will reduces the size of included headers within the parser.

gcc/rust/ChangeLog:

        * Make-lang.in: Add new specific feature store file.
        * checks/errors/feature/rust-feature-gate.cc 
(EarlyFeatureGateStore::get):
        Move from here to rust-feature-store.cc.
        (EarlyFeatureGateStore::add): Likewise.
        (EarlyFeatureGateStore::get_error): Likewise.
        (FeatureGate::check): Likewise.
        * checks/errors/feature/rust-feature-gate.h (class 
EarlyFeatureGateStore):
        Move class declaration to rust-feature-store.h header.
        * parse/rust-parse.h: Change included header.
        * checks/errors/feature/rust-feature-store.cc: New file.
        * checks/errors/feature/rust-feature-store.h: New file.

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/35afadb03b995aaaad47813e203ff5cb2edb33ab

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

 gcc/rust/Make-lang.in                         |  1 +
 .../errors/feature/rust-feature-gate.cc       | 24 +--------
 .../checks/errors/feature/rust-feature-gate.h | 19 -------
 .../errors/feature/rust-feature-store.cc      | 47 +++++++++++++++++
 .../errors/feature/rust-feature-store.h       | 51 +++++++++++++++++++
 gcc/rust/parse/rust-parse.h                   |  4 +-
 6 files changed, 103 insertions(+), 43 deletions(-)
 create mode 100644 gcc/rust/checks/errors/feature/rust-feature-store.cc
 create mode 100644 gcc/rust/checks/errors/feature/rust-feature-store.h

diff --git a/gcc/rust/Make-lang.in b/gcc/rust/Make-lang.in
index bd5eb8654..5a1551c09 100644
--- a/gcc/rust/Make-lang.in
+++ b/gcc/rust/Make-lang.in
@@ -230,6 +230,7 @@ GRS_OBJS = \
     rust/rust-builtins.o \
     rust/rust-feature.o \
     rust/rust-feature-gate.o \
+    rust/rust-feature-store.o \
     rust/rust-feature-collector.o \
     rust/rust-ast-validation.o \
     rust/rust-dir-owner.o \
diff --git a/gcc/rust/checks/errors/feature/rust-feature-gate.cc 
b/gcc/rust/checks/errors/feature/rust-feature-gate.cc
index 2164453ec..14471c4f7 100644
--- a/gcc/rust/checks/errors/feature/rust-feature-gate.cc
+++ b/gcc/rust/checks/errors/feature/rust-feature-gate.cc
@@ -23,34 +23,14 @@
 #include "rust-ast-visitor.h"
 #include "rust-feature.h"
 #include "rust-ast-full.h"
+#include "rust-feature-store.h"
 
 namespace Rust {
 
-EarlyFeatureGateStore &
-EarlyFeatureGateStore::get ()
-{
-  static EarlyFeatureGateStore instance{};
-  return instance;
-}
-
-void
-EarlyFeatureGateStore::add (Feature::Name name, Error error)
-{
-  potential_errors.emplace (name, error);
-}
-
-std::pair<Feature::Name, Error>
-EarlyFeatureGateStore::get_error ()
-{
-  auto ret = potential_errors.front ();
-  potential_errors.pop ();
-  return ret;
-}
-
 void
 FeatureGate::check (AST::Crate &crate)
 {
-  auto &store = EarlyFeatureGateStore::get ();
+  auto &store = Features::EarlyFeatureGateStore::get ();
   while (store.has_error ())
     {
       auto pair = store.get_error ();
diff --git a/gcc/rust/checks/errors/feature/rust-feature-gate.h 
b/gcc/rust/checks/errors/feature/rust-feature-gate.h
index 38a19d09e..21997bcae 100644
--- a/gcc/rust/checks/errors/feature/rust-feature-gate.h
+++ b/gcc/rust/checks/errors/feature/rust-feature-gate.h
@@ -20,29 +20,10 @@
 #define RUST_FEATURE_GATE_H
 
 #include "rust-ast-visitor.h"
-#include "rust-feature.h"
 #include "rust-feature-collector.h"
 
 namespace Rust {
 
-/**
- * We don't know the whole set of valid features until a crate has been parsed.
- * We're collecting in this store all the potential feature errors and check
- * them later.
- */
-class EarlyFeatureGateStore
-{
-  std::queue<std::pair<Feature::Name, Error>> potential_errors;
-
-public:
-  static EarlyFeatureGateStore &get ();
-  void add (Feature::Name name, Error error);
-
-  bool has_error () { return !potential_errors.empty (); }
-
-  std::pair<Feature::Name, Error> get_error ();
-};
-
 class FeatureGate : public AST::DefaultASTVisitor
 {
 public:
diff --git a/gcc/rust/checks/errors/feature/rust-feature-store.cc 
b/gcc/rust/checks/errors/feature/rust-feature-store.cc
new file mode 100644
index 000000000..da8a864cb
--- /dev/null
+++ b/gcc/rust/checks/errors/feature/rust-feature-store.cc
@@ -0,0 +1,47 @@
+
+// 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/>.
+
+#include "rust-feature-store.h"
+
+namespace Rust {
+namespace Features {
+
+EarlyFeatureGateStore &
+EarlyFeatureGateStore::get ()
+{
+  static EarlyFeatureGateStore instance{};
+  return instance;
+}
+
+void
+EarlyFeatureGateStore::add (Feature::Name name, Error error)
+{
+  potential_errors.emplace (name, error);
+}
+
+std::pair<Feature::Name, Error>
+EarlyFeatureGateStore::get_error ()
+{
+  auto ret = potential_errors.front ();
+  potential_errors.pop ();
+  return ret;
+}
+
+} // namespace Features
+} // namespace Rust
diff --git a/gcc/rust/checks/errors/feature/rust-feature-store.h 
b/gcc/rust/checks/errors/feature/rust-feature-store.h
new file mode 100644
index 000000000..0d119038c
--- /dev/null
+++ b/gcc/rust/checks/errors/feature/rust-feature-store.h
@@ -0,0 +1,51 @@
+// 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_FEATURE_STORE_H
+#define RUST_FEATURE_STORE_H
+
+#include "rust-system.h"
+#include "rust-diagnostics.h"
+#include "rust-feature.h"
+
+namespace Rust {
+
+namespace Features {
+
+/**
+ * We don't know the whole set of valid features until a crate has been parsed.
+ * We're collecting in this store all the potential feature errors and check
+ * them later.
+ */
+class EarlyFeatureGateStore
+{
+  std::queue<std::pair<Feature::Name, Error>> potential_errors;
+
+public:
+  static EarlyFeatureGateStore &get ();
+  void add (Feature::Name name, Error error);
+
+  bool has_error () { return !potential_errors.empty (); }
+
+  std::pair<Feature::Name, Error> get_error ();
+};
+} // namespace Features
+
+} // namespace Rust
+
+#endif // ! RUST_FEATURE_STORE_H
diff --git a/gcc/rust/parse/rust-parse.h b/gcc/rust/parse/rust-parse.h
index 70d3a18a8..289018e32 100644
--- a/gcc/rust/parse/rust-parse.h
+++ b/gcc/rust/parse/rust-parse.h
@@ -25,7 +25,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "rust-parse-error.h"
 #include "rust-parse-utils.h"
 #include "rust-feature.h"
-#include "rust-feature-gate.h"
+#include "rust-feature-store.h"
 
 #include "expected.h"
 
@@ -856,7 +856,7 @@ private:
 
   void collect_potential_gating_error (Feature::Name feature, Error error)
   {
-    EarlyFeatureGateStore::get ().add (feature, error);
+    Features::EarlyFeatureGateStore::get ().add (feature, error);
   }
 
 public:
-- 
2.53.0

Reply via email to