From 0a4f9a26962d85d57a0b603ad324bd86fdd474cf Mon Sep 17 00:00:00 2001 From: Nick Cameron Date: Sat, 25 Apr 2015 15:31:11 +1200 Subject: [PATCH] Rebasing and making MulitDecorators work --- src/librustc/plugin/registry.rs | 9 ++------- src/libsyntax/ext/base.rs | 18 +++--------------- src/libsyntax/ext/deriving/mod.rs | 15 +++------------ src/libsyntax/ext/expand.rs | 7 +++++-- 4 files changed, 13 insertions(+), 36 deletions(-) diff --git a/src/librustc/plugin/registry.rs b/src/librustc/plugin/registry.rs index fccde9a2f178..04df46412954 100644 --- a/src/librustc/plugin/registry.rs +++ b/src/librustc/plugin/registry.rs @@ -14,13 +14,8 @@ use lint::{LintPassObject, LintId, Lint}; use session::Session; use syntax::ext::base::{SyntaxExtension, NamedSyntaxExtension, NormalTT}; -<<<<<<< HEAD -use syntax::ext::base::{IdentTT, Decorator, Modifier, MultiModifier, MacroRulesTT}; -use syntax::ext::base::MacroExpanderFn; -======= -use syntax::ext::base::{IdentTT, Decorator, MultiDecorator, Modifier, MultiModifier, MacroRulesTT}; -use syntax::ext::base::{MacroExpanderFn}; ->>>>>>> 143f2db3174103e459218958f567985b1f47944b +use syntax::ext::base::{IdentTT, Decorator, Modifier, MultiModifier, MultiDecorator}; +use syntax::ext::base::{MacroExpanderFn, MacroRulesTT}; use syntax::codemap::Span; use syntax::parse::token; use syntax::ptr::P; diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs index f84d3ed98c76..3e54e43c0296 100644 --- a/src/libsyntax/ext/base.rs +++ b/src/libsyntax/ext/base.rs @@ -145,18 +145,18 @@ pub trait MultiItemDecorator { sp: Span, meta_item: &ast::MetaItem, item: &Annotatable, - push: Box); + push: &mut FnMut(Annotatable)); } impl MultiItemDecorator for F - where F : Fn(&mut ExtCtxt, Span, &ast::MetaItem, &Annotatable, Box) + where F : Fn(&mut ExtCtxt, Span, &ast::MetaItem, &Annotatable, &mut FnMut(Annotatable)) { fn expand(&self, ecx: &mut ExtCtxt, sp: Span, meta_item: &ast::MetaItem, item: &Annotatable, - push: Box) { + push: &mut FnMut(Annotatable)) { (*self)(ecx, sp, meta_item, item, push) } } @@ -515,13 +515,6 @@ fn initial_syntax_expander_table<'feat>(ecfg: &expand::ExpansionConfig<'feat>) syntax_expanders.insert(intern("log_syntax"), builtin_normal_expander( ext::log_syntax::expand_syntax_ext)); -<<<<<<< HEAD -======= - syntax_expanders.insert(intern("derive"), - MultiDecorator(box ext::deriving::expand_meta_derive)); - syntax_expanders.insert(intern("deriving"), - MultiDecorator(box ext::deriving::expand_deprecated_deriving)); ->>>>>>> 143f2db3174103e459218958f567985b1f47944b ext::deriving::register_all(&mut syntax_expanders); @@ -586,11 +579,6 @@ fn initial_syntax_expander_table<'feat>(ecfg: &expand::ExpansionConfig<'feat>) syntax_expanders.insert(intern("cfg"), builtin_normal_expander( ext::cfg::expand_cfg)); -<<<<<<< HEAD -======= - syntax_expanders.insert(intern("cfg_attr"), - MultiModifier(box ext::cfg_attr::expand)); ->>>>>>> 143f2db3174103e459218958f567985b1f47944b syntax_expanders.insert(intern("trace_macros"), builtin_normal_expander( ext::trace_macros::expand_trace_macros)); diff --git a/src/libsyntax/ext/deriving/mod.rs b/src/libsyntax/ext/deriving/mod.rs index 586e73ad6455..bc4a7f90911d 100644 --- a/src/libsyntax/ext/deriving/mod.rs +++ b/src/libsyntax/ext/deriving/mod.rs @@ -80,17 +80,8 @@ pub mod generic; fn expand_derive(cx: &mut ExtCtxt, span: Span, mitem: &MetaItem, - annotatable: &Annotatable) - -> P { - // Derive can only be applied to items - let item = match annotatable { - &Annotatable::Item(ref it) => it.clone(), - _ => { - cx.span_err(span, "`derive` can only be applied to items"); - return; - } - }; - + item: P) + -> P { item.map(|mut item| { if mitem.value_str().is_some() { cx.span_err(mitem.span, "unexpected value in `derive`"); @@ -123,7 +114,7 @@ fn expand_derive(cx: &mut ExtCtxt, intern_and_get_ident(&format!("derive_{}", tname))))); } - Annotatable::Item(item) + item }) } diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index 76a4ef2f4ed7..106d862042a9 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -1134,9 +1134,12 @@ fn expand_annotatable(a: Annotatable, fld.cx.bt_push(ExpnInfo { call_site: attr.span, callee: NameAndSpan { - name: mname.get().to_string(), + name: mname.to_string(), format: MacroAttribute, - span: None + span: Some(attr.span), + // attributes can do whatever they like, + // for now. + allow_internal_unstable: true, } });