Fix cfg_attr expansion and feature gate attribute handling
Fixes Rust-GCC#4245
gcc/rust/ChangeLog:
* checks/errors/feature/rust-feature-gate.cc (FeatureGate::visit): Added
handling for META_ITEM type attributes to properly process feature gates.
* expand/rust-cfg-strip.cc (expand_cfg_attrs): Fixed a bug where
newly inserted cfg_attr attributes wheren't being reprocessed,
and cleaned up the loop increment logic.
Signed-off-by: lenny.chiadmi-delage <lenny.chiadmi-delage@epita.fr>
valid_lib_features.emplace (name_str, item->get_locus ());
}
}
+ else if (type == AST::AttrInput::AttrInputType::META_ITEM)
+ {
+ const auto &meta_item
+ = static_cast<const AST::AttrInputMetaItemContainer &> (
+ attr_input);
+ for (const auto &item : meta_item.get_items ())
+ {
+ const auto &name_str = item->as_string ();
+
+ // TODO: detect duplicates
+ if (auto tname = Feature::as_name (name_str))
+ valid_lang_features.insert (tname.value ());
+ else
+ valid_lib_features.emplace (name_str, item->get_locus ());
+ }
+ }
}
}
attrs.insert (attrs.begin () + i,
std::make_move_iterator (new_attrs.begin ()),
std::make_move_iterator (new_attrs.end ()));
+
+ /* Decrement i so that the for loop's i++ will bring us back to
+ * position i, allowing us to reprocess the newly inserted
+ * attribute (in case it's also a cfg_attr that needs expansion)
+ */
+ i--;
}
/* do something - if feature (first token in tree) is in fact enabled,
* recursive, so check for expanded attributes being recursive and
* possibly recursively call the expand_attrs? */
}
- else
- {
- i++;
- }
}
attrs.shrink_to_fit ();
}