Skip to content

Commit 4905f0c

Browse files
committed
temp
1 parent 9a20b54 commit 4905f0c

File tree

2 files changed

+64
-6
lines changed

2 files changed

+64
-6
lines changed

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

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

gcc/rust/expand/rust-cfg-strip.cc

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,23 +107,44 @@ expand_cfg_attrs (AST::AttrVec &attrs)
107107
for (std::size_t i = 0; i < attrs.size (); i++)
108108
{
109109
auto &attr = attrs[i];
110+
rust_debug ("expand_cfg_attrs: checking attr: %s",
111+
attr.get_path ().as_string ().c_str ());
110112
if (attr.get_path () == Values::Attributes::CFG_ATTR)
111113
{
114+
rust_debug ("expand_cfg_attrs: found cfg_attr: %s",
115+
attr.as_string ().c_str ());
112116
if (!attr.is_parsed_to_meta_item ())
113117
attr.parse_attr_to_meta_item ();
114118

115119
if (attr.check_cfg_predicate (session))
116120
{
121+
rust_debug ("expand_cfg_attrs: cfg_attr predicate is true, "
122+
"expanding");
117123
// split off cfg_attr
118124
AST::AttrVec new_attrs = attr.separate_cfg_attrs ();
119125

126+
rust_debug ("expand_cfg_attrs: got %lu new attrs",
127+
(unsigned long) new_attrs.size ());
128+
for (const auto &new_attr : new_attrs)
129+
rust_debug (" new attr: %s", new_attr.as_string ().c_str ());
130+
120131
// remove attr from vector
121132
attrs.erase (attrs.begin () + i);
122133

123134
// add new attrs to vector
124135
attrs.insert (attrs.begin () + i,
125136
std::make_move_iterator (new_attrs.begin ()),
126137
std::make_move_iterator (new_attrs.end ()));
138+
139+
// Decrement i so that the for loop's i++ will bring us back to
140+
// position i, allowing us to reprocess the newly inserted
141+
// attribute (in case it's also a cfg_attr that needs expansion)
142+
i--;
143+
}
144+
else
145+
{
146+
rust_debug ("expand_cfg_attrs: cfg_attr predicate is false, "
147+
"skipping");
127148
}
128149

129150
/* do something - if feature (first token in tree) is in fact enabled,
@@ -133,10 +154,6 @@ expand_cfg_attrs (AST::AttrVec &attrs)
133154
* recursive, so check for expanded attributes being recursive and
134155
* possibly recursively call the expand_attrs? */
135156
}
136-
else
137-
{
138-
i++;
139-
}
140157
}
141158
attrs.shrink_to_fit ();
142159
}

0 commit comments

Comments
 (0)