1
Fork 0

Rename CustomDerive to ProcMacroDerive for macros 1.1

This commit is contained in:
Josh Driver 2017-01-24 08:55:08 +10:30
parent 0477daf9f0
commit 0a7380d7fc
12 changed files with 31 additions and 27 deletions

View file

@ -577,7 +577,7 @@ impl<'a> CrateLoader<'a> {
use proc_macro::TokenStream;
use proc_macro::__internal::Registry;
use rustc_back::dynamic_lib::DynamicLibrary;
use syntax_ext::deriving::custom::CustomDerive;
use syntax_ext::deriving::custom::ProcMacroDerive;
use syntax_ext::proc_macro_impl::AttrProcMacro;
let path = match dylib {
@ -609,8 +609,8 @@ impl<'a> CrateLoader<'a> {
expand: fn(TokenStream) -> TokenStream,
attributes: &[&'static str]) {
let attrs = attributes.iter().cloned().map(Symbol::intern).collect();
let derive = SyntaxExtension::CustomDerive(
Box::new(CustomDerive::new(expand, attrs))
let derive = SyntaxExtension::ProcMacroDerive(
Box::new(ProcMacroDerive::new(expand, attrs))
);
self.0.push((Symbol::intern(trait_name), Rc::new(derive)));
}

View file

@ -559,7 +559,7 @@ impl<'a> Resolver<'a> {
"an `extern crate` loading macros must be at the crate root");
} else if !self.use_extern_macros && !used &&
self.session.cstore.dep_kind(module.def_id().unwrap().krate).macros_only() {
let msg = "custom derive crates and `#[no_link]` crates have no effect without \
let msg = "proc macro crates and `#[no_link]` crates have no effect without \
`#[macro_use]`";
self.session.span_warn(item.span, msg);
used = true; // Avoid the normal unused extern crate warning

View file

@ -510,7 +510,11 @@ pub enum SyntaxExtension {
///
IdentTT(Box<IdentMacroExpander>, Option<Span>, bool),
CustomDerive(Box<MultiItemModifier>),
/// An attribute-like procedural macro. TokenStream -> TokenStream.
/// The input is the annotated item.
/// Allows generating code to implement a Trait for a given struct
/// or enum item.
ProcMacroDerive(Box<MultiItemModifier>),
/// An attribute-like procedural macro that derives a builtin trait.
BuiltinDerive(BuiltinDeriveFn),

View file

@ -370,7 +370,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
let tok_result = mac.expand(self.cx, attr.span, attr_toks, item_toks);
self.parse_expansion(tok_result, kind, name, attr.span)
}
SyntaxExtension::CustomDerive(..) | SyntaxExtension::BuiltinDerive(..) => {
SyntaxExtension::ProcMacroDerive(..) | SyntaxExtension::BuiltinDerive(..) => {
self.cx.span_err(attr.span, &format!("`{}` is a derive mode", name));
kind.dummy(attr.span)
}
@ -440,7 +440,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
return kind.dummy(span);
}
SyntaxExtension::CustomDerive(..) | SyntaxExtension::BuiltinDerive(..) => {
SyntaxExtension::ProcMacroDerive(..) | SyntaxExtension::BuiltinDerive(..) => {
self.cx.span_err(path.span, &format!("`{}` is a derive mode", extname));
return kind.dummy(span);
}

View file

@ -32,18 +32,18 @@ impl<'a> Visitor<'a> for MarkAttrs<'a> {
fn visit_mac(&mut self, _mac: &Mac) {}
}
pub struct CustomDerive {
pub struct ProcMacroDerive {
inner: fn(TokenStream) -> TokenStream,
attrs: Vec<ast::Name>,
}
impl CustomDerive {
pub fn new(inner: fn(TokenStream) -> TokenStream, attrs: Vec<ast::Name>) -> CustomDerive {
CustomDerive { inner: inner, attrs: attrs }
impl ProcMacroDerive {
pub fn new(inner: fn(TokenStream) -> TokenStream, attrs: Vec<ast::Name>) -> ProcMacroDerive {
ProcMacroDerive { inner: inner, attrs: attrs }
}
}
impl MultiItemModifier for CustomDerive {
impl MultiItemModifier for ProcMacroDerive {
fn expand(&self,
ecx: &mut ExtCtxt,
span: Span,
@ -54,7 +54,7 @@ impl MultiItemModifier for CustomDerive {
Annotatable::Item(item) => item,
Annotatable::ImplItem(_) |
Annotatable::TraitItem(_) => {
ecx.span_err(span, "custom derive attributes may only be \
ecx.span_err(span, "proc_macro_derive attributes may only be \
applied to struct/enum items");
return Vec::new()
}
@ -63,7 +63,7 @@ impl MultiItemModifier for CustomDerive {
ItemKind::Struct(..) |
ItemKind::Enum(..) => {},
_ => {
ecx.span_err(span, "custom derive attributes may only be \
ecx.span_err(span, "proc_macro_derive attributes may only be \
applied to struct/enum items");
return Vec::new()
}
@ -81,7 +81,7 @@ impl MultiItemModifier for CustomDerive {
let stream = match res {
Ok(stream) => stream,
Err(e) => {
let msg = "custom derive attribute panicked";
let msg = "proc_macro_derive attribute panicked";
let mut err = ecx.struct_span_fatal(span, msg);
if let Some(s) = e.downcast_ref::<String>() {
err.help(&format!("message: {}", s));
@ -100,7 +100,7 @@ impl MultiItemModifier for CustomDerive {
Ok(new_items) => new_items,
Err(_) => {
// FIXME: handle this better
let msg = "custom derive produced unparseable tokens";
let msg = "proc_macro_derive produced unparseable tokens";
ecx.struct_span_fatal(span, msg).emit();
panic!(FatalError);
}

View file

@ -163,7 +163,7 @@ pub fn expand_derive(cx: &mut ExtCtxt,
if is_builtin_trait(tname) || {
let derive_mode = ast::Path::from_ident(titem.span, ast::Ident::with_empty_ctxt(tname));
cx.resolver.resolve_macro(cx.current_expansion.mark, &derive_mode, false).map(|ext| {
if let SyntaxExtension::CustomDerive(_) = *ext { true } else { false }
if let SyntaxExtension::ProcMacroDerive(_) = *ext { true } else { false }
}).unwrap_or(false)
} {
return true;
@ -249,7 +249,7 @@ pub fn expand_derive(cx: &mut ExtCtxt,
..mitem.span
};
if let SyntaxExtension::CustomDerive(ref ext) = *ext {
if let SyntaxExtension::ProcMacroDerive(ref ext) = *ext {
return ext.expand(cx, span, &mitem, item);
} else {
unreachable!()

View file

@ -27,7 +27,7 @@ use syntax_pos::{Span, DUMMY_SP};
use deriving;
struct CustomDerive {
struct ProcMacroDerive {
trait_name: ast::Name,
function_name: Ident,
span: Span,
@ -40,7 +40,7 @@ struct AttrProcMacro {
}
struct CollectProcMacros<'a> {
derives: Vec<CustomDerive>,
derives: Vec<ProcMacroDerive>,
attr_macros: Vec<AttrProcMacro>,
in_root: bool,
handler: &'a errors::Handler,
@ -176,7 +176,7 @@ impl<'a> CollectProcMacros<'a> {
};
if self.in_root && item.vis == ast::Visibility::Public {
self.derives.push(CustomDerive {
self.derives.push(ProcMacroDerive {
span: item.span,
trait_name: trait_name,
function_name: item.ident,
@ -319,7 +319,7 @@ impl<'a> Visitor<'a> for CollectProcMacros<'a> {
// }
// }
fn mk_registrar(cx: &mut ExtCtxt,
custom_derives: &[CustomDerive],
custom_derives: &[ProcMacroDerive],
custom_attrs: &[AttrProcMacro]) -> P<ast::Item> {
let eid = cx.codemap().record_expansion(ExpnInfo {
call_site: DUMMY_SP,

View file

@ -16,7 +16,7 @@ extern crate derive_bad;
#[derive(
A
)]
//~^^ ERROR: custom derive produced unparseable tokens
//~^^ ERROR: proc_macro_derive produced unparseable tokens
struct A;
fn main() {}

View file

@ -14,7 +14,7 @@
extern crate derive_panic;
#[derive(A)]
//~^ ERROR: custom derive attribute panicked
//~^ ERROR: proc_macro_derive attribute panicked
//~| HELP: message: nope!
struct Foo;

View file

@ -13,7 +13,7 @@
#![feature(rustc_attrs)]
extern crate derive_a;
//~^ WARN custom derive crates and `#[no_link]` crates have no effect without `#[macro_use]`
//~^ WARN proc macro crates and `#[no_link]` crates have no effect without `#[macro_use]`
#[rustc_error]
fn main() {} //~ ERROR compilation successful

View file

@ -12,7 +12,7 @@
#[no_link]
extern crate empty_struct;
//~^ WARN custom derive crates and `#[no_link]` crates have no effect without `#[macro_use]`
//~^ WARN proc macro crates and `#[no_link]` crates have no effect without `#[macro_use]`
fn main() {
empty_struct::XEmpty1; //~ ERROR cannot find value `XEmpty1` in module `empty_struct`

View file

@ -1,4 +1,4 @@
error: custom derive attribute panicked
error: proc_macro_derive attribute panicked
--> $DIR/issue-36935.rs:17:15
|
17 | #[derive(Foo, Bar)]