[COMMITTED 81/83] gccrs: feature-gate: Return a value to indicate the result of gating

arthur.cohen@opensrcsec.com arthur.cohen@opensrcsec.com
Wed Sep 16 12:30:40 GMT 2026


From: Arthur Cohen <arthur.cohen@opensrcsec.com>

Create a new enum class to indicate whether a feature was gated or not
to the FeatureGate checker.

As well as moving `gate` into a public function since the aim is to make
it available to other passes.

gcc/rust/ChangeLog:

	* checks/errors/feature/rust-feature-gate.cc (FeatureGate::gate): Move into public
	methods, use GateResult enum.
	* checks/errors/feature/rust-feature-gate.h: Add new GateResult enum.
---
 gcc/rust/checks/errors/feature/rust-feature-gate.cc |  6 +++++-
 gcc/rust/checks/errors/feature/rust-feature-gate.h  | 10 +++++++++-
 2 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/gcc/rust/checks/errors/feature/rust-feature-gate.cc b/gcc/rust/checks/errors/feature/rust-feature-gate.cc
index 775df43791a..3d43d736ece 100644
--- a/gcc/rust/checks/errors/feature/rust-feature-gate.cc
+++ b/gcc/rust/checks/errors/feature/rust-feature-gate.cc
@@ -76,7 +76,7 @@ FeatureGate::visit (AST::Crate &crate)
     }
 }
 
-void
+FeatureGate::GateResult
 FeatureGate::gate (Feature::Name name, location_t loc,
 		   const std::string &error_msg)
 {
@@ -102,7 +102,11 @@ FeatureGate::gate (Feature::Name name, location_t loc,
 	  rust_error_at (loc, ErrorCode::E0658, fmt_str, error_msg.c_str (),
 			 feature.as_string ().c_str ());
 	}
+
+      return GateResult::Gated;
     }
+
+  return GateResult::Allowed;
 }
 
 void
diff --git a/gcc/rust/checks/errors/feature/rust-feature-gate.h b/gcc/rust/checks/errors/feature/rust-feature-gate.h
index e8bb61b1f61..74d81a5e1ae 100644
--- a/gcc/rust/checks/errors/feature/rust-feature-gate.h
+++ b/gcc/rust/checks/errors/feature/rust-feature-gate.h
@@ -52,8 +52,16 @@ public:
   void visit (AST::Enum &enum_item) override;
   void visit (AST::EnumItem &enum_variant) override;
 
+  enum class GateResult
+  {
+    Gated,
+    Allowed,
+  };
+
+  GateResult gate (Feature::Name name, location_t loc,
+		   const std::string &error_msg);
+
 private:
-  void gate (Feature::Name name, location_t loc, const std::string &error_msg);
   void check_no_core_attribute (const AST::Attribute &attribute);
   void check_rustc_attri (const std::vector<AST::Attribute> &attributes);
   void
-- 
2.50.1



More information about the Gcc-rust mailing list