Skip to content

Commit 9edc7de

Browse files
committed
syntax: Change deriving methods to take a &mut FnMut(P<Item>)
This allows #[derive(...)]` to create more than one impl
1 parent 6557f4b commit 9edc7de

File tree

15 files changed

+98
-116
lines changed

15 files changed

+98
-116
lines changed

src/libsyntax/ext/deriving/bounds.rs

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,20 @@ use ext::deriving::generic::*;
1515
use ext::deriving::generic::ty::*;
1616
use ptr::P;
1717

18-
pub fn expand_deriving_unsafe_bound<F>(cx: &mut ExtCtxt,
19-
span: Span,
20-
_: &MetaItem,
21-
_: &Item,
22-
_: F) where
23-
F: FnOnce(P<Item>),
18+
pub fn expand_deriving_unsafe_bound(cx: &mut ExtCtxt,
19+
span: Span,
20+
_: &MetaItem,
21+
_: &Item,
22+
_: &mut FnMut(P<Item>))
2423
{
2524
cx.span_err(span, "this unsafe trait should be implemented explicitly");
2625
}
2726

28-
pub fn expand_deriving_copy<F>(cx: &mut ExtCtxt,
29-
span: Span,
30-
mitem: &MetaItem,
31-
item: &Item,
32-
push: F) where
33-
F: FnOnce(P<Item>),
27+
pub fn expand_deriving_copy(cx: &mut ExtCtxt,
28+
span: Span,
29+
mitem: &MetaItem,
30+
item: &Item,
31+
push: &mut FnMut(P<Item>))
3432
{
3533
let path = Path::new(vec![
3634
if cx.use_std { "std" } else { "core" },
@@ -48,5 +46,5 @@ pub fn expand_deriving_copy<F>(cx: &mut ExtCtxt,
4846
associated_types: Vec::new(),
4947
};
5048

51-
trait_def.expand(cx, mitem, item, push)
49+
trait_def.expand(cx, mitem, item, push);
5250
}

src/libsyntax/ext/deriving/clone.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,11 @@ use ext::deriving::generic::ty::*;
1717
use parse::token::InternedString;
1818
use ptr::P;
1919

20-
pub fn expand_deriving_clone<F>(cx: &mut ExtCtxt,
21-
span: Span,
22-
mitem: &MetaItem,
23-
item: &Item,
24-
push: F) where
25-
F: FnOnce(P<Item>),
20+
pub fn expand_deriving_clone(cx: &mut ExtCtxt,
21+
span: Span,
22+
mitem: &MetaItem,
23+
item: &Item,
24+
push: &mut FnMut(P<Item>))
2625
{
2726
let inline = cx.meta_word(span, InternedString::new("inline"));
2827
let attrs = vec!(cx.attribute(span, inline));

src/libsyntax/ext/deriving/cmp/eq.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,11 @@ use ext::deriving::generic::ty::*;
1717
use parse::token::InternedString;
1818
use ptr::P;
1919

20-
pub fn expand_deriving_eq<F>(cx: &mut ExtCtxt,
21-
span: Span,
22-
mitem: &MetaItem,
23-
item: &Item,
24-
push: F) where
25-
F: FnOnce(P<Item>),
20+
pub fn expand_deriving_eq(cx: &mut ExtCtxt,
21+
span: Span,
22+
mitem: &MetaItem,
23+
item: &Item,
24+
push: &mut FnMut(P<Item>))
2625
{
2726
fn cs_total_eq_assert(cx: &mut ExtCtxt, span: Span, substr: &Substructure) -> P<Expr> {
2827
cs_same_method(|cx, span, exprs| {

src/libsyntax/ext/deriving/cmp/ord.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,11 @@ use ext::deriving::generic::ty::*;
1818
use parse::token::InternedString;
1919
use ptr::P;
2020

21-
pub fn expand_deriving_totalord<F>(cx: &mut ExtCtxt,
22-
span: Span,
23-
mitem: &MetaItem,
24-
item: &Item,
25-
push: F) where
26-
F: FnOnce(P<Item>),
21+
pub fn expand_deriving_ord(cx: &mut ExtCtxt,
22+
span: Span,
23+
mitem: &MetaItem,
24+
item: &Item,
25+
push: &mut FnMut(P<Item>))
2726
{
2827
let inline = cx.meta_word(span, InternedString::new("inline"));
2928
let attrs = vec!(cx.attribute(span, inline));

src/libsyntax/ext/deriving/cmp/partial_eq.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,11 @@ use ext::deriving::generic::ty::*;
1717
use parse::token::InternedString;
1818
use ptr::P;
1919

20-
pub fn expand_deriving_partial_eq<F>(cx: &mut ExtCtxt,
21-
span: Span,
22-
mitem: &MetaItem,
23-
item: &Item,
24-
push: F) where
25-
F: FnOnce(P<Item>),
20+
pub fn expand_deriving_partial_eq(cx: &mut ExtCtxt,
21+
span: Span,
22+
mitem: &MetaItem,
23+
item: &Item,
24+
push: &mut FnMut(P<Item>))
2625
{
2726
// structures are equal if all fields are equal, and non equal, if
2827
// any fields are not equal or if the enum variants are different

src/libsyntax/ext/deriving/cmp/partial_ord.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,11 @@ use ext::deriving::generic::ty::*;
2020
use parse::token::InternedString;
2121
use ptr::P;
2222

23-
pub fn expand_deriving_partial_ord<F>(cx: &mut ExtCtxt,
24-
span: Span,
25-
mitem: &MetaItem,
26-
item: &Item,
27-
push: F) where
28-
F: FnOnce(P<Item>),
23+
pub fn expand_deriving_partial_ord(cx: &mut ExtCtxt,
24+
span: Span,
25+
mitem: &MetaItem,
26+
item: &Item,
27+
push: &mut FnMut(P<Item>))
2928
{
3029
macro_rules! md {
3130
($name:expr, $op:expr, $equal:expr) => { {

src/libsyntax/ext/deriving/decodable.rs

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,33 +21,30 @@ use parse::token::InternedString;
2121
use parse::token;
2222
use ptr::P;
2323

24-
pub fn expand_deriving_rustc_decodable<F>(cx: &mut ExtCtxt,
25-
span: Span,
26-
mitem: &MetaItem,
27-
item: &Item,
28-
push: F) where
29-
F: FnOnce(P<Item>),
24+
pub fn expand_deriving_rustc_decodable(cx: &mut ExtCtxt,
25+
span: Span,
26+
mitem: &MetaItem,
27+
item: &Item,
28+
push: &mut FnMut(P<Item>))
3029
{
3130
expand_deriving_decodable_imp(cx, span, mitem, item, push, "rustc_serialize")
3231
}
3332

34-
pub fn expand_deriving_decodable<F>(cx: &mut ExtCtxt,
35-
span: Span,
36-
mitem: &MetaItem,
37-
item: &Item,
38-
push: F) where
39-
F: FnOnce(P<Item>),
33+
pub fn expand_deriving_decodable(cx: &mut ExtCtxt,
34+
span: Span,
35+
mitem: &MetaItem,
36+
item: &Item,
37+
push: &mut FnMut(P<Item>))
4038
{
4139
expand_deriving_decodable_imp(cx, span, mitem, item, push, "serialize")
4240
}
4341

44-
fn expand_deriving_decodable_imp<F>(cx: &mut ExtCtxt,
45-
span: Span,
46-
mitem: &MetaItem,
47-
item: &Item,
48-
push: F,
49-
krate: &'static str) where
50-
F: FnOnce(P<Item>),
42+
fn expand_deriving_decodable_imp(cx: &mut ExtCtxt,
43+
span: Span,
44+
mitem: &MetaItem,
45+
item: &Item,
46+
push: &mut FnMut(P<Item>),
47+
krate: &'static str)
5148
{
5249
if !cx.use_std {
5350
// FIXME(#21880): lift this requirement.

src/libsyntax/ext/deriving/default.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,11 @@ use ext::deriving::generic::ty::*;
1717
use parse::token::InternedString;
1818
use ptr::P;
1919

20-
pub fn expand_deriving_default<F>(cx: &mut ExtCtxt,
21-
span: Span,
22-
mitem: &MetaItem,
23-
item: &Item,
24-
push: F) where
25-
F: FnOnce(P<Item>),
20+
pub fn expand_deriving_default(cx: &mut ExtCtxt,
21+
span: Span,
22+
mitem: &MetaItem,
23+
item: &Item,
24+
push: &mut FnMut(P<Item>))
2625
{
2726
let inline = cx.meta_word(span, InternedString::new("inline"));
2827
let attrs = vec!(cx.attribute(span, inline));

src/libsyntax/ext/deriving/encodable.rs

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -97,33 +97,30 @@ use ext::deriving::generic::ty::*;
9797
use parse::token;
9898
use ptr::P;
9999

100-
pub fn expand_deriving_rustc_encodable<F>(cx: &mut ExtCtxt,
101-
span: Span,
102-
mitem: &MetaItem,
103-
item: &Item,
104-
push: F) where
105-
F: FnOnce(P<Item>),
100+
pub fn expand_deriving_rustc_encodable(cx: &mut ExtCtxt,
101+
span: Span,
102+
mitem: &MetaItem,
103+
item: &Item,
104+
push: &mut FnMut(P<Item>))
106105
{
107106
expand_deriving_encodable_imp(cx, span, mitem, item, push, "rustc_serialize")
108107
}
109108

110-
pub fn expand_deriving_encodable<F>(cx: &mut ExtCtxt,
111-
span: Span,
112-
mitem: &MetaItem,
113-
item: &Item,
114-
push: F) where
115-
F: FnOnce(P<Item>),
109+
pub fn expand_deriving_encodable(cx: &mut ExtCtxt,
110+
span: Span,
111+
mitem: &MetaItem,
112+
item: &Item,
113+
push: &mut FnMut(P<Item>))
116114
{
117115
expand_deriving_encodable_imp(cx, span, mitem, item, push, "serialize")
118116
}
119117

120-
fn expand_deriving_encodable_imp<F>(cx: &mut ExtCtxt,
121-
span: Span,
122-
mitem: &MetaItem,
123-
item: &Item,
124-
push: F,
125-
krate: &'static str) where
126-
F: FnOnce(P<Item>),
118+
fn expand_deriving_encodable_imp(cx: &mut ExtCtxt,
119+
span: Span,
120+
mitem: &MetaItem,
121+
item: &Item,
122+
push: &mut FnMut(P<Item>),
123+
krate: &'static str)
127124
{
128125
if !cx.use_std {
129126
// FIXME(#21880): lift this requirement.

src/libsyntax/ext/deriving/generic/mod.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -375,12 +375,11 @@ fn find_type_parameters(ty: &ast::Ty, ty_param_names: &[ast::Name]) -> Vec<P<ast
375375
}
376376

377377
impl<'a> TraitDef<'a> {
378-
pub fn expand<F>(&self,
379-
cx: &mut ExtCtxt,
380-
mitem: &ast::MetaItem,
381-
item: &ast::Item,
382-
push: F) where
383-
F: FnOnce(P<ast::Item>),
378+
pub fn expand(&self,
379+
cx: &mut ExtCtxt,
380+
mitem: &ast::MetaItem,
381+
item: &ast::Item,
382+
push: &mut FnMut(P<ast::Item>))
384383
{
385384
let newitem = match item.node {
386385
ast::ItemStruct(ref struct_def, ref generics) => {

src/libsyntax/ext/deriving/hash.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,11 @@ use ext::deriving::generic::*;
1616
use ext::deriving::generic::ty::*;
1717
use ptr::P;
1818

19-
pub fn expand_deriving_hash<F>(cx: &mut ExtCtxt,
20-
span: Span,
21-
mitem: &MetaItem,
22-
item: &Item,
23-
push: F) where
24-
F: FnOnce(P<Item>),
19+
pub fn expand_deriving_hash(cx: &mut ExtCtxt,
20+
span: Span,
21+
mitem: &MetaItem,
22+
item: &Item,
23+
push: &mut FnMut(P<Item>))
2524
{
2625

2726
let path = Path::new_(pathvec_std!(cx, core::hash::Hash), None,

src/libsyntax/ext/deriving/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ fn expand_derive(cx: &mut ExtCtxt,
118118
}
119119

120120
macro_rules! derive_traits {
121-
($( $name:expr => $func:path, )*) => {
121+
($( $name:expr => $func:path, )+) => {
122122
pub fn register_all(env: &mut SyntaxEnv) {
123123
// Define the #[derive_*] extensions.
124124
$({
@@ -132,21 +132,21 @@ macro_rules! derive_traits {
132132
item: &Item,
133133
push: &mut FnMut(P<Item>)) {
134134
warn_if_deprecated(ecx, sp, $name);
135-
$func(ecx, sp, mitem, item, |i| push(i));
135+
$func(ecx, sp, mitem, item, push);
136136
}
137137
}
138138

139139
env.insert(intern(concat!("derive_", $name)),
140140
Decorator(Box::new(DeriveExtension)));
141-
})*
141+
})+
142142

143143
env.insert(intern("derive"),
144144
Modifier(Box::new(expand_derive)));
145145
}
146146

147147
fn is_builtin_trait(name: &str) -> bool {
148148
match name {
149-
$( $name )|* => true,
149+
$( $name )|+ => true,
150150
_ => false,
151151
}
152152
}

src/libsyntax/ext/deriving/primitive.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,11 @@ use ext::deriving::generic::ty::*;
1818
use parse::token::InternedString;
1919
use ptr::P;
2020

21-
pub fn expand_deriving_from_primitive<F>(cx: &mut ExtCtxt,
22-
span: Span,
23-
mitem: &MetaItem,
24-
item: &Item,
25-
push: F) where
26-
F: FnOnce(P<Item>),
21+
pub fn expand_deriving_from_primitive(cx: &mut ExtCtxt,
22+
span: Span,
23+
mitem: &MetaItem,
24+
item: &Item,
25+
push: &mut FnMut(P<Item>))
2726
{
2827
let inline = cx.meta_word(span, InternedString::new("inline"));
2928
let attrs = vec!(cx.attribute(span, inline));

src/libsyntax/ext/deriving/show.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,11 @@ use ext::deriving::generic::ty::*;
1818
use parse::token;
1919
use ptr::P;
2020

21-
pub fn expand_deriving_show<F>(cx: &mut ExtCtxt,
22-
span: Span,
23-
mitem: &MetaItem,
24-
item: &Item,
25-
push: F) where
26-
F: FnOnce(P<Item>),
21+
pub fn expand_deriving_show(cx: &mut ExtCtxt,
22+
span: Span,
23+
mitem: &MetaItem,
24+
item: &Item,
25+
push: &mut FnMut(P<Item>))
2726
{
2827
// &mut ::std::fmt::Formatter
2928
let fmtr = Ptr(box Literal(path_std!(cx, core::fmt::Formatter)),

src/test/auxiliary/custom_derive_plugin.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,5 +70,5 @@ fn expand(cx: &mut ExtCtxt,
7070
],
7171
};
7272

73-
trait_def.expand(cx, mitem, item, |i| push(i))
73+
trait_def.expand(cx, mitem, item, push)
7474
}

0 commit comments

Comments
 (0)