From 7ec38a9ae3c5e7b8eef0ec4696d058cd9e85583d Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Tue, 8 Oct 2019 14:15:26 +0200 Subject: attr: remove dep on ExtCtxt --- src/libsyntax/attr/builtin.rs | 14 +++++--------- src/libsyntax_ext/global_allocator.rs | 3 ++- src/libsyntax_ext/lib.rs | 1 + src/libsyntax_ext/test.rs | 4 +++- src/libsyntax_ext/util.rs | 11 +++++++++++ 5 files changed, 22 insertions(+), 11 deletions(-) create mode 100644 src/libsyntax_ext/util.rs diff --git a/src/libsyntax/attr/builtin.rs b/src/libsyntax/attr/builtin.rs index 1fe698c2572..28b61c5aa77 100644 --- a/src/libsyntax/attr/builtin.rs +++ b/src/libsyntax/attr/builtin.rs @@ -2,7 +2,6 @@ use crate::ast::{self, Attribute, MetaItem, NestedMetaItem}; use crate::early_buffered_lints::BufferedEarlyLintId; -use crate::ext::base::ExtCtxt; use crate::feature_gate::{Features, GatedCfg}; use crate::print::pprust; use crate::sess::ParseSess; @@ -32,6 +31,10 @@ pub struct AttributeTemplate { } impl AttributeTemplate { + pub fn only_word() -> Self { + Self { word: true, list: None, name_value_str: None } + } + /// Checks that the given meta-item is compatible with this template. fn compatible(&self, meta_item_kind: &ast::MetaItemKind) -> bool { match meta_item_kind { @@ -937,14 +940,7 @@ pub fn find_transparency( (transparency.map_or(fallback, |t| t.0), error) } -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, list: None, name_value_str: None }; - let attr = ecx.attribute(meta_item.clone()); - check_builtin_attribute(ecx.parse_sess, &attr, name, template); -} - -crate fn check_builtin_attribute( +pub fn check_builtin_attribute( sess: &ParseSess, attr: &ast::Attribute, name: Symbol, template: AttributeTemplate ) { // Some special attributes like `cfg` must be checked diff --git a/src/libsyntax_ext/global_allocator.rs b/src/libsyntax_ext/global_allocator.rs index cd2a9b61a76..f014b4f4f9f 100644 --- a/src/libsyntax_ext/global_allocator.rs +++ b/src/libsyntax_ext/global_allocator.rs @@ -1,6 +1,7 @@ +use crate::util::check_builtin_macro_attribute; + use syntax::ast::{ItemKind, Mutability, Stmt, Ty, TyKind, Unsafety}; use syntax::ast::{self, Param, Attribute, Expr, FnHeader, Generics, Ident}; -use syntax::attr::check_builtin_macro_attribute; use syntax::ext::allocator::{AllocatorKind, AllocatorMethod, AllocatorTy, ALLOCATOR_METHODS}; use syntax::ext::base::{Annotatable, ExtCtxt}; use syntax::ptr::P; diff --git a/src/libsyntax_ext/lib.rs b/src/libsyntax_ext/lib.rs index 64d46a84cba..5ba76a52350 100644 --- a/src/libsyntax_ext/lib.rs +++ b/src/libsyntax_ext/lib.rs @@ -37,6 +37,7 @@ mod log_syntax; mod source_util; mod test; mod trace_macros; +mod util; pub mod cmdline_attrs; pub mod plugin_macro_defs; diff --git a/src/libsyntax_ext/test.rs b/src/libsyntax_ext/test.rs index d4638c45473..4d7441ca0b6 100644 --- a/src/libsyntax_ext/test.rs +++ b/src/libsyntax_ext/test.rs @@ -1,8 +1,10 @@ /// The expansion from a test function to the appropriate test struct for libtest /// Ideally, this code would be in libtest but for efficiency and error messages it lives here. +use crate::util::check_builtin_macro_attribute; + use syntax::ast; -use syntax::attr::{self, check_builtin_macro_attribute}; +use syntax::attr; use syntax::ext::base::*; use syntax::print::pprust; use syntax::source_map::respan; diff --git a/src/libsyntax_ext/util.rs b/src/libsyntax_ext/util.rs new file mode 100644 index 00000000000..fbae68057c5 --- /dev/null +++ b/src/libsyntax_ext/util.rs @@ -0,0 +1,11 @@ +use syntax_pos::Symbol; +use syntax::ast::MetaItem; +use syntax::attr::{check_builtin_attribute, AttributeTemplate}; +use syntax::ext::base::ExtCtxt; + +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::only_word(); + let attr = ecx.attribute(meta_item.clone()); + check_builtin_attribute(ecx.parse_sess, &attr, name, template); +} -- cgit 1.4.1-3-g733a5