From: Raiki Tamura <[email protected]>

gcc/rust/ChangeLog:

        * checks/errors/feature/rust-feature-gate.cc (FeatureGate::visit): Add 
check for lang_items.
        * checks/errors/feature/rust-feature-gate.h: Likewise.

Signed-off-by: Raiki Tamura <[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/f066e9f9972fdbd873b84c36ff931e31280d703b

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

 .../errors/feature/rust-feature-gate.cc       | 49 +++++++++++++++++++
 .../checks/errors/feature/rust-feature-gate.h |  6 +++
 2 files changed, 55 insertions(+)

diff --git a/gcc/rust/checks/errors/feature/rust-feature-gate.cc 
b/gcc/rust/checks/errors/feature/rust-feature-gate.cc
index b2a6b6c64..448fa18f2 100644
--- a/gcc/rust/checks/errors/feature/rust-feature-gate.cc
+++ b/gcc/rust/checks/errors/feature/rust-feature-gate.cc
@@ -146,6 +146,24 @@ FeatureGate::check_may_dangle_attribute (
     }
 }
 
+void
+FeatureGate::check_lang_item_attribute (
+  const std::vector<AST::Attribute> &attributes)
+{
+  for (const AST::Attribute &attr : attributes)
+    {
+      const auto &str_path = attr.get_path ().as_string ();
+      bool is_lang_item = str_path == Values::Attributes::LANG
+                         && attr.has_attr_input ()
+                         && attr.get_attr_input ().get_attr_input_type ()
+                              == AST::AttrInput::AttrInputType::LITERAL;
+
+      if (is_lang_item)
+       gate (Feature::Name::LANG_ITEMS, attr.get_locus (),
+             "lang items are subject to change");
+    }
+}
+
 void
 FeatureGate::visit (AST::MacroRulesDefinition &rules_def)
 {
@@ -158,6 +176,8 @@ FeatureGate::visit (AST::Function &function)
   if (!function.is_external ())
     check_rustc_attri (function.get_outer_attrs ());
 
+  check_lang_item_attribute (function.get_outer_attrs ());
+
   AST::DefaultASTVisitor::visit (function);
 }
 
@@ -186,6 +206,7 @@ FeatureGate::visit (AST::Trait &trait)
   if (trait.is_auto ())
     gate (Feature::Name::OPTIN_BUILTIN_TRAITS, trait.get_locus (),
          "auto traits are experimental and possibly buggy");
+  check_lang_item_attribute (trait.get_outer_attrs ());
   AST::DefaultASTVisitor::visit (trait);
 }
 
@@ -243,4 +264,32 @@ FeatureGate::visit (AST::UseTreeGlob &use)
   // #[feature(prelude_import)]
 }
 
+void
+FeatureGate::visit (AST::StructStruct &struct_item)
+{
+  check_lang_item_attribute (struct_item.get_outer_attrs ());
+  AST::DefaultASTVisitor::visit (struct_item);
+}
+
+void
+FeatureGate::visit (AST::TraitItemType &trait_item_type)
+{
+  check_lang_item_attribute (trait_item_type.get_outer_attrs ());
+  AST::DefaultASTVisitor::visit (trait_item_type);
+}
+
+void
+FeatureGate::visit (AST::Enum &enum_item)
+{
+  check_lang_item_attribute (enum_item.get_outer_attrs ());
+  AST::DefaultASTVisitor::visit (enum_item);
+}
+
+void
+FeatureGate::visit (AST::EnumItem &enum_variant)
+{
+  check_lang_item_attribute (enum_variant.get_outer_attrs ());
+  AST::DefaultASTVisitor::visit (enum_variant);
+}
+
 } // namespace Rust
diff --git a/gcc/rust/checks/errors/feature/rust-feature-gate.h 
b/gcc/rust/checks/errors/feature/rust-feature-gate.h
index f1011e532..c8ab66b75 100644
--- a/gcc/rust/checks/errors/feature/rust-feature-gate.h
+++ b/gcc/rust/checks/errors/feature/rust-feature-gate.h
@@ -47,12 +47,18 @@ public:
   void visit (AST::ExternBlock &block) override;
   void visit (AST::MacroRulesDefinition &rules_def) override;
   void visit (AST::RangePattern &pattern) override;
+  void visit (AST::StructStruct &struct_item) override;
+  void visit (AST::TraitItemType &trait_item_type) override;
+  void visit (AST::Enum &enum_item) override;
+  void visit (AST::EnumItem &enum_variant) override;
 
 private:
   void gate (Feature::Name name, location_t loc, const std::string &error_msg);
   void check_rustc_attri (const std::vector<AST::Attribute> &attributes);
   void
   check_may_dangle_attribute (const std::vector<AST::Attribute> &attributes);
+  void
+  check_lang_item_attribute (const std::vector<AST::Attribute> &attributes);
   std::set<Feature::Name> valid_features;
 };
 } // namespace Rust

base-commit: a9db302cbf593da5168d980da882a01843f01729
-- 
2.51.2

Reply via email to