From: Raiki Tamura Date: Sun, 23 Nov 2025 16:02:31 +0000 (+0900) Subject: gccrs: rust: add feature gate for lang_items. X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e4a853fd7d659778084a2f24189102f30aa4d544;p=thirdparty%2Fgcc.git gccrs: rust: add feature gate for lang_items. 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 --- diff --git a/gcc/rust/checks/errors/feature/rust-feature-gate.cc b/gcc/rust/checks/errors/feature/rust-feature-gate.cc index b2a6b6c6481..448fa18f21d 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 &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 f1011e53224..c8ab66b753d 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 &attributes); void check_may_dangle_attribute (const std::vector &attributes); + void + check_lang_item_attribute (const std::vector &attributes); std::set valid_features; }; } // namespace Rust