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 {
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)));
}
"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
///
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),
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)
}
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);
}
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,
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()
}
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()
}
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));
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);
}
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;
..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!()
use deriving;
-struct CustomDerive {
+struct ProcMacroDerive {
trait_name: ast::Name,
function_name: Ident,
span: Span,
}
struct CollectProcMacros<'a> {
- derives: Vec<CustomDerive>,
+ derives: Vec<ProcMacroDerive>,
attr_macros: Vec<AttrProcMacro>,
in_root: bool,
handler: &'a errors::Handler,
};
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,
// }
// }
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,
#[derive(
A
)]
-//~^^ ERROR: custom derive produced unparseable tokens
+//~^^ ERROR: proc_macro_derive produced unparseable tokens
struct A;
fn main() {}
extern crate derive_panic;
#[derive(A)]
-//~^ ERROR: custom derive attribute panicked
+//~^ ERROR: proc_macro_derive attribute panicked
//~| HELP: message: nope!
struct Foo;
#![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
#[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`
-error: custom derive attribute panicked
+error: proc_macro_derive attribute panicked
--> $DIR/issue-36935.rs:17:15
|
17 | #[derive(Foo, Bar)]