Skip to content

Commit 7ec38a9

Browse files
committed
attr: remove dep on ExtCtxt
1 parent 55f3c2d commit 7ec38a9

File tree

5 files changed

+22
-11
lines changed

5 files changed

+22
-11
lines changed

src/libsyntax/attr/builtin.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
33
use crate::ast::{self, Attribute, MetaItem, NestedMetaItem};
44
use crate::early_buffered_lints::BufferedEarlyLintId;
5-
use crate::ext::base::ExtCtxt;
65
use crate::feature_gate::{Features, GatedCfg};
76
use crate::print::pprust;
87
use crate::sess::ParseSess;
@@ -32,6 +31,10 @@ pub struct AttributeTemplate {
3231
}
3332

3433
impl AttributeTemplate {
34+
pub fn only_word() -> Self {
35+
Self { word: true, list: None, name_value_str: None }
36+
}
37+
3538
/// Checks that the given meta-item is compatible with this template.
3639
fn compatible(&self, meta_item_kind: &ast::MetaItemKind) -> bool {
3740
match meta_item_kind {
@@ -937,14 +940,7 @@ pub fn find_transparency(
937940
(transparency.map_or(fallback, |t| t.0), error)
938941
}
939942

940-
pub fn check_builtin_macro_attribute(ecx: &ExtCtxt<'_>, meta_item: &MetaItem, name: Symbol) {
941-
// All the built-in macro attributes are "words" at the moment.
942-
let template = AttributeTemplate { word: true, list: None, name_value_str: None };
943-
let attr = ecx.attribute(meta_item.clone());
944-
check_builtin_attribute(ecx.parse_sess, &attr, name, template);
945-
}
946-
947-
crate fn check_builtin_attribute(
943+
pub fn check_builtin_attribute(
948944
sess: &ParseSess, attr: &ast::Attribute, name: Symbol, template: AttributeTemplate
949945
) {
950946
// Some special attributes like `cfg` must be checked

src/libsyntax_ext/global_allocator.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
use crate::util::check_builtin_macro_attribute;
2+
13
use syntax::ast::{ItemKind, Mutability, Stmt, Ty, TyKind, Unsafety};
24
use syntax::ast::{self, Param, Attribute, Expr, FnHeader, Generics, Ident};
3-
use syntax::attr::check_builtin_macro_attribute;
45
use syntax::ext::allocator::{AllocatorKind, AllocatorMethod, AllocatorTy, ALLOCATOR_METHODS};
56
use syntax::ext::base::{Annotatable, ExtCtxt};
67
use syntax::ptr::P;

src/libsyntax_ext/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ mod log_syntax;
3737
mod source_util;
3838
mod test;
3939
mod trace_macros;
40+
mod util;
4041

4142
pub mod cmdline_attrs;
4243
pub mod plugin_macro_defs;

src/libsyntax_ext/test.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
/// The expansion from a test function to the appropriate test struct for libtest
22
/// Ideally, this code would be in libtest but for efficiency and error messages it lives here.
33
4+
use crate::util::check_builtin_macro_attribute;
5+
46
use syntax::ast;
5-
use syntax::attr::{self, check_builtin_macro_attribute};
7+
use syntax::attr;
68
use syntax::ext::base::*;
79
use syntax::print::pprust;
810
use syntax::source_map::respan;

src/libsyntax_ext/util.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
use syntax_pos::Symbol;
2+
use syntax::ast::MetaItem;
3+
use syntax::attr::{check_builtin_attribute, AttributeTemplate};
4+
use syntax::ext::base::ExtCtxt;
5+
6+
pub fn check_builtin_macro_attribute(ecx: &ExtCtxt<'_>, meta_item: &MetaItem, name: Symbol) {
7+
// All the built-in macro attributes are "words" at the moment.
8+
let template = AttributeTemplate::only_word();
9+
let attr = ecx.attribute(meta_item.clone());
10+
check_builtin_attribute(ecx.parse_sess, &attr, name, template);
11+
}

0 commit comments

Comments
 (0)