diff options
| author | Nicholas Nethercote <n.nethercote@gmail.com> | 2022-11-24 16:00:57 +1100 | 
|---|---|---|
| committer | Nicholas Nethercote <n.nethercote@gmail.com> | 2022-11-29 12:08:57 +1100 | 
| commit | c9ae38c71e2838f1ac282803ddde47f21f4ca76e (patch) | |
| tree | b958e56a3adccd7d12f831c73691306ed4860904 /compiler/rustc_builtin_macros/src/util.rs | |
| parent | 2585bcea0bc2a9c42a4be2c1eba5c61137f2b167 (diff) | |
| download | rust-c9ae38c71e2838f1ac282803ddde47f21f4ca76e.tar.gz rust-c9ae38c71e2838f1ac282803ddde47f21f4ca76e.zip  | |
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.
Diffstat (limited to 'compiler/rustc_builtin_macros/src/util.rs')
| -rw-r--r-- | compiler/rustc_builtin_macros/src/util.rs | 11 | 
1 files changed, 8 insertions, 3 deletions
diff --git a/compiler/rustc_builtin_macros/src/util.rs b/compiler/rustc_builtin_macros/src/util.rs index 527fe50eff0..83812631c2f 100644 --- a/compiler/rustc_builtin_macros/src/util.rs +++ b/compiler/rustc_builtin_macros/src/util.rs @@ -1,4 +1,4 @@ -use rustc_ast::{Attribute, MetaItem}; +use rustc_ast::{AttrStyle, Attribute, MetaItem}; use rustc_expand::base::{Annotatable, ExtCtxt}; use rustc_feature::AttributeTemplate; use rustc_lint_defs::builtin::DUPLICATE_MACRO_ATTRIBUTES; @@ -8,8 +8,13 @@ use rustc_span::Symbol; pub fn check_builtin_macro_attribute(ecx: &ExtCtxt<'_>, meta_item: &MetaItem, name: Symbol) { // All the built-in macro attributes are "words" at the moment. let template = AttributeTemplate { word: true, ..Default::default() }; - let attr = ecx.attribute(meta_item.clone()); - validate_attr::check_builtin_attribute(&ecx.sess.parse_sess, &attr, name, template); + validate_attr::check_builtin_meta_item( + &ecx.sess.parse_sess, + &meta_item, + AttrStyle::Outer, + name, + template, + ); } /// Emit a warning if the item is annotated with the given attribute. This is used to diagnose when  | 
