Skip to content

Commit f066e9f

Browse files
tamaroningP-E-P
authored andcommitted
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 <tamaron1203@gmail.com>
1 parent a9db302 commit f066e9f

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

gcc/rust/checks/errors/feature/rust-feature-gate.cc

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,24 @@ FeatureGate::check_may_dangle_attribute (
146146
}
147147
}
148148

149+
void
150+
FeatureGate::check_lang_item_attribute (
151+
const std::vector<AST::Attribute> &attributes)
152+
{
153+
for (const AST::Attribute &attr : attributes)
154+
{
155+
const auto &str_path = attr.get_path ().as_string ();
156+
bool is_lang_item = str_path == Values::Attributes::LANG
157+
&& attr.has_attr_input ()
158+
&& attr.get_attr_input ().get_attr_input_type ()
159+
== AST::AttrInput::AttrInputType::LITERAL;
160+
161+
if (is_lang_item)
162+
gate (Feature::Name::LANG_ITEMS, attr.get_locus (),
163+
"lang items are subject to change");
164+
}
165+
}
166+
149167
void
150168
FeatureGate::visit (AST::MacroRulesDefinition &rules_def)
151169
{
@@ -158,6 +176,8 @@ FeatureGate::visit (AST::Function &function)
158176
if (!function.is_external ())
159177
check_rustc_attri (function.get_outer_attrs ());
160178

179+
check_lang_item_attribute (function.get_outer_attrs ());
180+
161181
AST::DefaultASTVisitor::visit (function);
162182
}
163183

@@ -186,6 +206,7 @@ FeatureGate::visit (AST::Trait &trait)
186206
if (trait.is_auto ())
187207
gate (Feature::Name::OPTIN_BUILTIN_TRAITS, trait.get_locus (),
188208
"auto traits are experimental and possibly buggy");
209+
check_lang_item_attribute (trait.get_outer_attrs ());
189210
AST::DefaultASTVisitor::visit (trait);
190211
}
191212

@@ -243,4 +264,32 @@ FeatureGate::visit (AST::UseTreeGlob &use)
243264
// #[feature(prelude_import)]
244265
}
245266

267+
void
268+
FeatureGate::visit (AST::StructStruct &struct_item)
269+
{
270+
check_lang_item_attribute (struct_item.get_outer_attrs ());
271+
AST::DefaultASTVisitor::visit (struct_item);
272+
}
273+
274+
void
275+
FeatureGate::visit (AST::TraitItemType &trait_item_type)
276+
{
277+
check_lang_item_attribute (trait_item_type.get_outer_attrs ());
278+
AST::DefaultASTVisitor::visit (trait_item_type);
279+
}
280+
281+
void
282+
FeatureGate::visit (AST::Enum &enum_item)
283+
{
284+
check_lang_item_attribute (enum_item.get_outer_attrs ());
285+
AST::DefaultASTVisitor::visit (enum_item);
286+
}
287+
288+
void
289+
FeatureGate::visit (AST::EnumItem &enum_variant)
290+
{
291+
check_lang_item_attribute (enum_variant.get_outer_attrs ());
292+
AST::DefaultASTVisitor::visit (enum_variant);
293+
}
294+
246295
} // namespace Rust

gcc/rust/checks/errors/feature/rust-feature-gate.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,18 @@ class FeatureGate : public AST::DefaultASTVisitor
4747
void visit (AST::ExternBlock &block) override;
4848
void visit (AST::MacroRulesDefinition &rules_def) override;
4949
void visit (AST::RangePattern &pattern) override;
50+
void visit (AST::StructStruct &struct_item) override;
51+
void visit (AST::TraitItemType &trait_item_type) override;
52+
void visit (AST::Enum &enum_item) override;
53+
void visit (AST::EnumItem &enum_variant) override;
5054

5155
private:
5256
void gate (Feature::Name name, location_t loc, const std::string &error_msg);
5357
void check_rustc_attri (const std::vector<AST::Attribute> &attributes);
5458
void
5559
check_may_dangle_attribute (const std::vector<AST::Attribute> &attributes);
60+
void
61+
check_lang_item_attribute (const std::vector<AST::Attribute> &attributes);
5662
std::set<Feature::Name> valid_features;
5763
};
5864
} // namespace Rust

0 commit comments

Comments
 (0)