diff options
| author | Esteban Küber <esteban@kuber.com.ar> | 2016-12-27 17:02:52 -0800 |
|---|---|---|
| committer | Esteban Küber <esteban@kuber.com.ar> | 2016-12-27 17:02:52 -0800 |
| commit | e766c465d2e4c4e3c106bfa8343cbe6f9192d445 (patch) | |
| tree | 821a7cf1e0b04ac9c0cddede6eb760bbf2d0ce62 /src/libsyntax_ext | |
| parent | 96c52d4fd86aed6320732a511c04bcbfff7d117f (diff) | |
| parent | 314c28b729ae359b99586cc62c486c28e0d44424 (diff) | |
Merge branch 'master' into escape-reason-docs
Diffstat (limited to 'src/libsyntax_ext')
| -rw-r--r-- | src/libsyntax_ext/concat_idents.rs | 7 | ||||
| -rw-r--r-- | src/libsyntax_ext/deriving/generic/mod.rs | 11 | ||||
| -rw-r--r-- | src/libsyntax_ext/deriving/mod.rs | 4 | ||||
| -rw-r--r-- | src/libsyntax_ext/lib.rs | 5 | ||||
| -rw-r--r-- | src/libsyntax_ext/proc_macro_registrar.rs | 19 |
5 files changed, 19 insertions, 27 deletions
diff --git a/src/libsyntax_ext/concat_idents.rs b/src/libsyntax_ext/concat_idents.rs index b26e33eb384..1fc1bdff593 100644 --- a/src/libsyntax_ext/concat_idents.rs +++ b/src/libsyntax_ext/concat_idents.rs @@ -59,14 +59,9 @@ pub fn expand_syntax_ext<'cx>(cx: &'cx mut ExtCtxt, impl Result { fn path(&self) -> ast::Path { - let segment = ast::PathSegment { - identifier: self.ident, - parameters: ast::PathParameters::none(), - }; ast::Path { span: self.span, - global: false, - segments: vec![segment], + segments: vec![self.ident.into()], } } } diff --git a/src/libsyntax_ext/deriving/generic/mod.rs b/src/libsyntax_ext/deriving/generic/mod.rs index 51199819dfc..7f187d8d1c1 100644 --- a/src/libsyntax_ext/deriving/generic/mod.rs +++ b/src/libsyntax_ext/deriving/generic/mod.rs @@ -363,15 +363,12 @@ fn find_type_parameters(ty: &ast::Ty, impl<'a, 'b> visit::Visitor<'a> for Visitor<'a, 'b> { fn visit_ty(&mut self, ty: &'a ast::Ty) { - match ty.node { - ast::TyKind::Path(_, ref path) if !path.global => { - if let Some(segment) = path.segments.first() { - if self.ty_param_names.contains(&segment.identifier.name) { - self.types.push(P(ty.clone())); - } + if let ast::TyKind::Path(_, ref path) = ty.node { + if let Some(segment) = path.segments.first() { + if self.ty_param_names.contains(&segment.identifier.name) { + self.types.push(P(ty.clone())); } } - _ => {} } visit::walk_ty(self, ty) diff --git a/src/libsyntax_ext/deriving/mod.rs b/src/libsyntax_ext/deriving/mod.rs index 535d7de19e3..0511b0d252b 100644 --- a/src/libsyntax_ext/deriving/mod.rs +++ b/src/libsyntax_ext/deriving/mod.rs @@ -175,8 +175,10 @@ pub fn expand_derive(cx: &mut ExtCtxt, feature_gate::GateIssue::Language, feature_gate::EXPLAIN_CUSTOM_DERIVE); } else { - cx.span_warn(titem.span, feature_gate::EXPLAIN_DEPR_CUSTOM_DERIVE); let name = Symbol::intern(&format!("derive_{}", tname)); + if !cx.resolver.is_whitelisted_legacy_custom_derive(name) { + cx.span_warn(titem.span, feature_gate::EXPLAIN_DEPR_CUSTOM_DERIVE); + } let mitem = cx.meta_word(titem.span, name); new_attributes.push(cx.attribute(mitem.span, mitem)); } diff --git a/src/libsyntax_ext/lib.rs b/src/libsyntax_ext/lib.rs index 66d6c0570ac..e31b29d5cc1 100644 --- a/src/libsyntax_ext/lib.rs +++ b/src/libsyntax_ext/lib.rs @@ -50,8 +50,7 @@ pub mod deriving; use std::rc::Rc; use syntax::ast; -use syntax::ext::base::{MacroExpanderFn, NormalTT, IdentTT, MultiModifier, NamedSyntaxExtension}; -use syntax::ext::tt::macro_rules::MacroRulesExpander; +use syntax::ext::base::{MacroExpanderFn, NormalTT, MultiModifier, NamedSyntaxExtension}; use syntax::symbol::Symbol; pub fn register_builtins(resolver: &mut syntax::ext::base::Resolver, @@ -61,8 +60,6 @@ pub fn register_builtins(resolver: &mut syntax::ext::base::Resolver, resolver.add_ext(ast::Ident::with_empty_ctxt(name), Rc::new(ext)); }; - register(Symbol::intern("macro_rules"), IdentTT(Box::new(MacroRulesExpander), None, false)); - macro_rules! register { ($( $name:ident: $f:expr, )*) => { $( register(Symbol::intern(stringify!($name)), diff --git a/src/libsyntax_ext/proc_macro_registrar.rs b/src/libsyntax_ext/proc_macro_registrar.rs index 8fbd11a7a6e..5323ace79d8 100644 --- a/src/libsyntax_ext/proc_macro_registrar.rs +++ b/src/libsyntax_ext/proc_macro_registrar.rs @@ -108,6 +108,8 @@ impl<'a> CollectCustomDerives<'a> { impl<'a> Visitor<'a> for CollectCustomDerives<'a> { fn visit_item(&mut self, item: &'a ast::Item) { + let mut attrs = item.attrs.iter().filter(|a| a.check_name("proc_macro_derive")); + // First up, make sure we're checking a bare function. If we're not then // we're just not interested in this item. // @@ -117,10 +119,7 @@ impl<'a> Visitor<'a> for CollectCustomDerives<'a> { ast::ItemKind::Fn(..) => {} _ => { // Check for invalid use of proc_macro_derive - let attr = item.attrs.iter() - .filter(|a| a.check_name("proc_macro_derive")) - .next(); - if let Some(attr) = attr { + if let Some(attr) = attrs.next() { self.handler.span_err(attr.span(), "the `#[proc_macro_derive]` \ attribute may only be used \ @@ -132,8 +131,6 @@ impl<'a> Visitor<'a> for CollectCustomDerives<'a> { } } - let mut attrs = item.attrs.iter() - .filter(|a| a.check_name("proc_macro_derive")); let attr = match attrs.next() { Some(attr) => attr, None => { @@ -227,7 +224,7 @@ impl<'a> Visitor<'a> for CollectCustomDerives<'a> { Vec::new() }; - if self.in_root { + if self.in_root && item.vis == ast::Visibility::Public { self.derives.push(CustomDerive { span: item.span, trait_name: trait_name, @@ -235,8 +232,12 @@ impl<'a> Visitor<'a> for CollectCustomDerives<'a> { attrs: proc_attrs, }); } else { - let msg = "functions tagged with `#[proc_macro_derive]` must \ - currently reside in the root of the crate"; + let msg = if !self.in_root { + "functions tagged with `#[proc_macro_derive]` must \ + currently reside in the root of the crate" + } else { + "functions tagged with `#[proc_macro_derive]` must be `pub`" + }; self.handler.span_err(item.span, msg); } |
