Skip to content

Commit bcf859c

Browse files
Rename CustomDerive to ProcMacroDerive for macros 1.1
1 parent 6690cfe commit bcf859c

File tree

12 files changed

+31
-27
lines changed

12 files changed

+31
-27
lines changed

src/librustc_metadata/creader.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,7 @@ impl<'a> CrateLoader<'a> {
577577
use proc_macro::TokenStream;
578578
use proc_macro::__internal::Registry;
579579
use rustc_back::dynamic_lib::DynamicLibrary;
580-
use syntax_ext::deriving::custom::CustomDerive;
580+
use syntax_ext::deriving::custom::ProcMacroDerive;
581581
use syntax_ext::proc_macro_impl::AttrProcMacro;
582582

583583
let path = match dylib {
@@ -609,8 +609,8 @@ impl<'a> CrateLoader<'a> {
609609
expand: fn(TokenStream) -> TokenStream,
610610
attributes: &[&'static str]) {
611611
let attrs = attributes.iter().cloned().map(Symbol::intern).collect();
612-
let derive = SyntaxExtension::CustomDerive(
613-
Box::new(CustomDerive::new(expand, attrs))
612+
let derive = SyntaxExtension::ProcMacroDerive(
613+
Box::new(ProcMacroDerive::new(expand, attrs))
614614
);
615615
self.0.push((Symbol::intern(trait_name), Rc::new(derive)));
616616
}

src/librustc_resolve/build_reduced_graph.rs

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

src/libsyntax/ext/base.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,11 @@ pub enum SyntaxExtension {
510510
///
511511
IdentTT(Box<IdentMacroExpander>, Option<Span>, bool),
512512

513-
CustomDerive(Box<MultiItemModifier>),
513+
/// An attribute-like procedural macro. TokenStream -> TokenStream.
514+
/// The input is the annotated item.
515+
/// Allows generating code to implement a Trait for a given struct
516+
/// or enum item.
517+
ProcMacroDerive(Box<MultiItemModifier>),
514518

515519
/// An attribute-like procedural macro that derives a builtin trait.
516520
BuiltinDerive(BuiltinDeriveFn),

src/libsyntax/ext/expand.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
370370
let tok_result = mac.expand(self.cx, attr.span, attr_toks, item_toks);
371371
self.parse_expansion(tok_result, kind, name, attr.span)
372372
}
373-
SyntaxExtension::CustomDerive(..) | SyntaxExtension::BuiltinDerive(..) => {
373+
SyntaxExtension::ProcMacroDerive(..) | SyntaxExtension::BuiltinDerive(..) => {
374374
self.cx.span_err(attr.span, &format!("`{}` is a derive mode", name));
375375
kind.dummy(attr.span)
376376
}
@@ -440,7 +440,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
440440
return kind.dummy(span);
441441
}
442442

443-
SyntaxExtension::CustomDerive(..) | SyntaxExtension::BuiltinDerive(..) => {
443+
SyntaxExtension::ProcMacroDerive(..) | SyntaxExtension::BuiltinDerive(..) => {
444444
self.cx.span_err(path.span, &format!("`{}` is a derive mode", extname));
445445
return kind.dummy(span);
446446
}

src/libsyntax_ext/deriving/custom.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,18 @@ impl<'a> Visitor<'a> for MarkAttrs<'a> {
3232
fn visit_mac(&mut self, _mac: &Mac) {}
3333
}
3434

35-
pub struct CustomDerive {
35+
pub struct ProcMacroDerive {
3636
inner: fn(TokenStream) -> TokenStream,
3737
attrs: Vec<ast::Name>,
3838
}
3939

40-
impl CustomDerive {
41-
pub fn new(inner: fn(TokenStream) -> TokenStream, attrs: Vec<ast::Name>) -> CustomDerive {
42-
CustomDerive { inner: inner, attrs: attrs }
40+
impl ProcMacroDerive {
41+
pub fn new(inner: fn(TokenStream) -> TokenStream, attrs: Vec<ast::Name>) -> ProcMacroDerive {
42+
ProcMacroDerive { inner: inner, attrs: attrs }
4343
}
4444
}
4545

46-
impl MultiItemModifier for CustomDerive {
46+
impl MultiItemModifier for ProcMacroDerive {
4747
fn expand(&self,
4848
ecx: &mut ExtCtxt,
4949
span: Span,
@@ -54,7 +54,7 @@ impl MultiItemModifier for CustomDerive {
5454
Annotatable::Item(item) => item,
5555
Annotatable::ImplItem(_) |
5656
Annotatable::TraitItem(_) => {
57-
ecx.span_err(span, "custom derive attributes may only be \
57+
ecx.span_err(span, "proc_macro_derive attributes may only be \
5858
applied to struct/enum items");
5959
return Vec::new()
6060
}
@@ -63,7 +63,7 @@ impl MultiItemModifier for CustomDerive {
6363
ItemKind::Struct(..) |
6464
ItemKind::Enum(..) => {},
6565
_ => {
66-
ecx.span_err(span, "custom derive attributes may only be \
66+
ecx.span_err(span, "proc_macro_derive attributes may only be \
6767
applied to struct/enum items");
6868
return Vec::new()
6969
}
@@ -81,7 +81,7 @@ impl MultiItemModifier for CustomDerive {
8181
let stream = match res {
8282
Ok(stream) => stream,
8383
Err(e) => {
84-
let msg = "custom derive attribute panicked";
84+
let msg = "proc_macro_derive attribute panicked";
8585
let mut err = ecx.struct_span_fatal(span, msg);
8686
if let Some(s) = e.downcast_ref::<String>() {
8787
err.help(&format!("message: {}", s));
@@ -100,7 +100,7 @@ impl MultiItemModifier for CustomDerive {
100100
Ok(new_items) => new_items,
101101
Err(_) => {
102102
// FIXME: handle this better
103-
let msg = "custom derive produced unparseable tokens";
103+
let msg = "proc_macro_derive produced unparseable tokens";
104104
ecx.struct_span_fatal(span, msg).emit();
105105
panic!(FatalError);
106106
}

src/libsyntax_ext/deriving/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ pub fn expand_derive(cx: &mut ExtCtxt,
163163
if is_builtin_trait(tname) || {
164164
let derive_mode = ast::Path::from_ident(titem.span, ast::Ident::with_empty_ctxt(tname));
165165
cx.resolver.resolve_macro(cx.current_expansion.mark, &derive_mode, false).map(|ext| {
166-
if let SyntaxExtension::CustomDerive(_) = *ext { true } else { false }
166+
if let SyntaxExtension::ProcMacroDerive(_) = *ext { true } else { false }
167167
}).unwrap_or(false)
168168
} {
169169
return true;
@@ -249,7 +249,7 @@ pub fn expand_derive(cx: &mut ExtCtxt,
249249
..mitem.span
250250
};
251251

252-
if let SyntaxExtension::CustomDerive(ref ext) = *ext {
252+
if let SyntaxExtension::ProcMacroDerive(ref ext) = *ext {
253253
return ext.expand(cx, span, &mitem, item);
254254
} else {
255255
unreachable!()

src/libsyntax_ext/proc_macro_registrar.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use syntax_pos::{Span, DUMMY_SP};
2727

2828
use deriving;
2929

30-
struct CustomDerive {
30+
struct ProcMacroDerive {
3131
trait_name: ast::Name,
3232
function_name: Ident,
3333
span: Span,
@@ -40,7 +40,7 @@ struct AttrProcMacro {
4040
}
4141

4242
struct CollectProcMacros<'a> {
43-
derives: Vec<CustomDerive>,
43+
derives: Vec<ProcMacroDerive>,
4444
attr_macros: Vec<AttrProcMacro>,
4545
in_root: bool,
4646
handler: &'a errors::Handler,
@@ -176,7 +176,7 @@ impl<'a> CollectProcMacros<'a> {
176176
};
177177

178178
if self.in_root && item.vis == ast::Visibility::Public {
179-
self.derives.push(CustomDerive {
179+
self.derives.push(ProcMacroDerive {
180180
span: item.span,
181181
trait_name: trait_name,
182182
function_name: item.ident,
@@ -319,7 +319,7 @@ impl<'a> Visitor<'a> for CollectProcMacros<'a> {
319319
// }
320320
// }
321321
fn mk_registrar(cx: &mut ExtCtxt,
322-
custom_derives: &[CustomDerive],
322+
custom_derives: &[ProcMacroDerive],
323323
custom_attrs: &[AttrProcMacro]) -> P<ast::Item> {
324324
let eid = cx.codemap().record_expansion(ExpnInfo {
325325
call_site: DUMMY_SP,

src/test/compile-fail-fulldeps/proc-macro/derive-bad.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ extern crate derive_bad;
1616
#[derive(
1717
A
1818
)]
19-
//~^^ ERROR: custom derive produced unparseable tokens
19+
//~^^ ERROR: proc_macro_derive produced unparseable tokens
2020
struct A;
2121

2222
fn main() {}

src/test/compile-fail-fulldeps/proc-macro/load-panic.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
extern crate derive_panic;
1515

1616
#[derive(A)]
17-
//~^ ERROR: custom derive attribute panicked
17+
//~^ ERROR: proc_macro_derive attribute panicked
1818
//~| HELP: message: nope!
1919
struct Foo;
2020

src/test/compile-fail-fulldeps/proc-macro/no-macro-use-attr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#![feature(rustc_attrs)]
1414

1515
extern crate derive_a;
16-
//~^ WARN custom derive crates and `#[no_link]` crates have no effect without `#[macro_use]`
16+
//~^ WARN proc macro crates and `#[no_link]` crates have no effect without `#[macro_use]`
1717

1818
#[rustc_error]
1919
fn main() {} //~ ERROR compilation successful

src/test/compile-fail/no-link.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
#[no_link]
1414
extern crate empty_struct;
15-
//~^ WARN custom derive crates and `#[no_link]` crates have no effect without `#[macro_use]`
15+
//~^ WARN proc macro crates and `#[no_link]` crates have no effect without `#[macro_use]`
1616

1717
fn main() {
1818
empty_struct::XEmpty1; //~ ERROR cannot find value `XEmpty1` in module `empty_struct`

src/test/ui/custom-derive/issue-36935.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: custom derive attribute panicked
1+
error: proc_macro_derive attribute panicked
22
--> $DIR/issue-36935.rs:17:15
33
|
44
17 | #[derive(Foo, Bar)]

0 commit comments

Comments
 (0)