@@ -39,10 +39,16 @@ FeatureGate::visit (AST::Crate &crate)
3939
4040 // avoid clearing defined features (?)
4141
42+ rust_debug (" FeatureGate: checking %lu crate inner attributes" ,
43+ (unsigned long ) crate.inner_attrs .size ());
4244 for (const auto &attr : crate.inner_attrs )
4345 {
46+ rust_debug (" FeatureGate: checking attr: %s" ,
47+ attr.get_path ().as_string ().c_str ());
4448 if (attr.get_path ().as_string () == " feature" )
4549 {
50+ rust_debug (" FeatureGate: found feature attr: %s" ,
51+ attr.as_string ().c_str ());
4652 // check for empty feature, such as `#![feature], this is an error
4753 if (attr.empty_input ())
4854 {
@@ -52,6 +58,9 @@ FeatureGate::visit (AST::Crate &crate)
5258 }
5359 const auto &attr_input = attr.get_attr_input ();
5460 auto type = attr_input.get_attr_input_type ();
61+ rust_debug (" FeatureGate: attr input type: %d (TOKEN_TREE=%d)" ,
62+ (int ) type,
63+ (int ) AST::AttrInput::AttrInputType::TOKEN_TREE);
5564 if (type == AST::AttrInput::AttrInputType::TOKEN_TREE)
5665 {
5766 const auto &option = static_cast <const AST::DelimTokenTree &> (
@@ -64,9 +73,41 @@ FeatureGate::visit (AST::Crate &crate)
6473
6574 // TODO: detect duplicates
6675 if (auto tname = Feature::as_name (name_str))
67- valid_lang_features.insert (tname.value ());
76+ {
77+ rust_debug (" FeatureGate: adding lang feature: %s" ,
78+ name_str.c_str ());
79+ valid_lang_features.insert (tname.value ());
80+ }
6881 else
69- valid_lib_features.emplace (name_str, item->get_locus ());
82+ {
83+ rust_debug (" FeatureGate: adding lib feature: %s" ,
84+ name_str.c_str ());
85+ valid_lib_features.emplace (name_str, item->get_locus ());
86+ }
87+ }
88+ }
89+ else if (type == AST::AttrInput::AttrInputType::META_ITEM)
90+ {
91+ const auto &meta_item
92+ = static_cast <const AST::AttrInputMetaItemContainer &> (
93+ attr_input);
94+ for (const auto &item : meta_item.get_items ())
95+ {
96+ const auto &name_str = item->as_string ();
97+
98+ // TODO: detect duplicates
99+ if (auto tname = Feature::as_name (name_str))
100+ {
101+ rust_debug (" FeatureGate: adding lang feature: %s" ,
102+ name_str.c_str ());
103+ valid_lang_features.insert (tname.value ());
104+ }
105+ else
106+ {
107+ rust_debug (" FeatureGate: adding lib feature: %s" ,
108+ name_str.c_str ());
109+ valid_lib_features.emplace (name_str, item->get_locus ());
110+ }
70111 }
71112 }
72113 }
0 commit comments