Avoid unnecessary MetaItem/Attribute conversions.

`check_builtin_attribute` calls `parse_meta` to convert an `Attribute`
to a `MetaItem`, which it then checks. However, many callers of
`check_builtin_attribute` start with a `MetaItem`, and then convert it
to an `Attribute` by calling `cx.attribute(meta_item)`. This `MetaItem`
to `Attribute` to `MetaItem` conversion is silly.

This commit adds a new function `check_builtin_meta_item`, which can be
called instead from these call sites. `check_builtin_attribute` also now
calls it. The commit also renames `check_meta` as `check_attr` to better
match its arguments.
This commit is contained in:
Nicholas Nethercote
2022-11-24 16:00:57 +11:00
parent 2585bcea0b
commit c9ae38c71e
6 changed files with 44 additions and 29 deletions

View File

@@ -37,10 +37,10 @@ impl MultiItemModifier for Expander {
_is_derive_const: bool,
) -> ExpandResult<Vec<Annotatable>, Annotatable> {
let template = AttributeTemplate { list: Some("path"), ..Default::default() };
let attr = &ecx.attribute(meta_item.clone());
validate_attr::check_builtin_attribute(
validate_attr::check_builtin_meta_item(
&ecx.sess.parse_sess,
attr,
&meta_item,
ast::AttrStyle::Outer,
sym::cfg_accessible,
template,
);