Skip to content

Commit

Permalink
extra: minor cleanup of Zero and Default syntax extension
Browse files Browse the repository at this point in the history
  • Loading branch information
erickt committed Sep 18, 2013
1 parent 5ab843f commit 1a90f24
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
8 changes: 3 additions & 5 deletions src/libsyntax/ext/deriving/default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,7 @@ fn default_substructure(cx: @ExtCtxt, span: Span, substr: &Substructure) -> @Exp
cx.ident_of("Default"),
cx.ident_of("default")
];
let default_call = || {
cx.expr_call_global(span, default_ident.clone(), ~[])
};
let default_call = cx.expr_call_global(span, default_ident.clone(), ~[]);

return match *substr.fields {
StaticStruct(_, ref summary) => {
Expand All @@ -58,13 +56,13 @@ fn default_substructure(cx: @ExtCtxt, span: Span, substr: &Substructure) -> @Exp
if count == 0 {
cx.expr_ident(span, substr.type_ident)
} else {
let exprs = vec::from_fn(count, |_| default_call());
let exprs = vec::from_elem(count, default_call);
cx.expr_call_ident(span, substr.type_ident, exprs)
}
}
Right(ref fields) => {
let default_fields = do fields.map |ident| {
cx.field_imm(span, *ident, default_call())
cx.field_imm(span, *ident, default_call)
};
cx.expr_struct_ident(span, substr.type_ident, default_fields)
}
Expand Down
8 changes: 3 additions & 5 deletions src/libsyntax/ext/deriving/zero.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,7 @@ fn zero_substructure(cx: @ExtCtxt, span: Span, substr: &Substructure) -> @Expr {
cx.ident_of("Zero"),
cx.ident_of("zero")
];
let zero_call = || {
cx.expr_call_global(span, zero_ident.clone(), ~[])
};
let zero_call = cx.expr_call_global(span, zero_ident.clone(), ~[]);

return match *substr.fields {
StaticStruct(_, ref summary) => {
Expand All @@ -73,13 +71,13 @@ fn zero_substructure(cx: @ExtCtxt, span: Span, substr: &Substructure) -> @Expr {
if count == 0 {
cx.expr_ident(span, substr.type_ident)
} else {
let exprs = vec::from_fn(count, |_| zero_call());
let exprs = vec::from_elem(count, zero_call);
cx.expr_call_ident(span, substr.type_ident, exprs)
}
}
Right(ref fields) => {
let zero_fields = do fields.map |ident| {
cx.field_imm(span, *ident, zero_call())
cx.field_imm(span, *ident, zero_call)
};
cx.expr_struct_ident(span, substr.type_ident, zero_fields)
}
Expand Down

25 comments on commit 1a90f24

@bors
Copy link
Contributor

@bors bors commented on 1a90f24 Sep 18, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from alexcrichton
at erickt@1a90f24

@bors
Copy link
Contributor

@bors bors commented on 1a90f24 Sep 18, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging erickt/rust/master = 1a90f24 into auto

@bors
Copy link
Contributor

@bors bors commented on 1a90f24 Sep 18, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

erickt/rust/master = 1a90f24 merged ok, testing candidate = 7b7186c2

@bors
Copy link
Contributor

@bors bors commented on 1a90f24 Sep 18, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on 1a90f24 Sep 19, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from alexcrichton
at erickt@1a90f24

@bors
Copy link
Contributor

@bors bors commented on 1a90f24 Sep 19, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging erickt/rust/master = 1a90f24 into auto

@bors
Copy link
Contributor

@bors bors commented on 1a90f24 Sep 19, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

erickt/rust/master = 1a90f24 merged ok, testing candidate = 0f3849df

@bors
Copy link
Contributor

@bors bors commented on 1a90f24 Sep 19, 2013

@bors
Copy link
Contributor

@bors bors commented on 1a90f24 Sep 19, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from alexcrichton
at erickt@1a90f24

@bors
Copy link
Contributor

@bors bors commented on 1a90f24 Sep 19, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging erickt/rust/master = 1a90f24 into auto

@bors
Copy link
Contributor

@bors bors commented on 1a90f24 Sep 19, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

erickt/rust/master = 1a90f24 merged ok, testing candidate = cea37ab2

@bors
Copy link
Contributor

@bors bors commented on 1a90f24 Sep 19, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from alexcrichton
at erickt@1a90f24

@bors
Copy link
Contributor

@bors bors commented on 1a90f24 Sep 19, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging erickt/rust/master = 1a90f24 into auto

@bors
Copy link
Contributor

@bors bors commented on 1a90f24 Sep 19, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

erickt/rust/master = 1a90f24 merged ok, testing candidate = ac3f0016

@bors
Copy link
Contributor

@bors bors commented on 1a90f24 Sep 19, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from alexcrichton
at erickt@1a90f24

@bors
Copy link
Contributor

@bors bors commented on 1a90f24 Sep 19, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging erickt/rust/master = 1a90f24 into auto

@bors
Copy link
Contributor

@bors bors commented on 1a90f24 Sep 19, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

erickt/rust/master = 1a90f24 merged ok, testing candidate = 3a4c5525

@bors
Copy link
Contributor

@bors bors commented on 1a90f24 Sep 19, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from alexcrichton
at erickt@1a90f24

@bors
Copy link
Contributor

@bors bors commented on 1a90f24 Sep 19, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging erickt/rust/master = 1a90f24 into auto

@bors
Copy link
Contributor

@bors bors commented on 1a90f24 Sep 19, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

erickt/rust/master = 1a90f24 merged ok, testing candidate = 755f622

@bors
Copy link
Contributor

@bors bors commented on 1a90f24 Sep 19, 2013

@bors
Copy link
Contributor

@bors bors commented on 1a90f24 Sep 19, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = 755f622

Please sign in to comment.