Skip to content

Commit

Permalink
attr: remove dep on ExtCtxt
Browse files Browse the repository at this point in the history
  • Loading branch information
Centril committed Oct 16, 2019
1 parent 55f3c2d commit 7ec38a9
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 11 deletions.
14 changes: 5 additions & 9 deletions src/libsyntax/attr/builtin.rs
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion 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;
Expand Down
1 change: 1 addition & 0 deletions src/libsyntax_ext/lib.rs
Expand Up @@ -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;
Expand Down
4 changes: 3 additions & 1 deletion 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;
Expand Down
11 changes: 11 additions & 0 deletions 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);
}

0 comments on commit 7ec38a9

Please sign in to comment.