extra: minor cleanup of Zero and Default syntax extension
This commit is contained in:
parent
5ab843fbc3
commit
1a90f24bbd
|
@ -47,9 +47,7 @@ fn default_substructure(cx: @ExtCtxt, span: Span, substr: &Substructure) -> @Exp
|
||||||
cx.ident_of("Default"),
|
cx.ident_of("Default"),
|
||||||
cx.ident_of("default")
|
cx.ident_of("default")
|
||||||
];
|
];
|
||||||
let default_call = || {
|
let default_call = cx.expr_call_global(span, default_ident.clone(), ~[]);
|
||||||
cx.expr_call_global(span, default_ident.clone(), ~[])
|
|
||||||
};
|
|
||||||
|
|
||||||
return match *substr.fields {
|
return match *substr.fields {
|
||||||
StaticStruct(_, ref summary) => {
|
StaticStruct(_, ref summary) => {
|
||||||
|
@ -58,13 +56,13 @@ fn default_substructure(cx: @ExtCtxt, span: Span, substr: &Substructure) -> @Exp
|
||||||
if count == 0 {
|
if count == 0 {
|
||||||
cx.expr_ident(span, substr.type_ident)
|
cx.expr_ident(span, substr.type_ident)
|
||||||
} else {
|
} 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)
|
cx.expr_call_ident(span, substr.type_ident, exprs)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Right(ref fields) => {
|
Right(ref fields) => {
|
||||||
let default_fields = do fields.map |ident| {
|
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)
|
cx.expr_struct_ident(span, substr.type_ident, default_fields)
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,9 +62,7 @@ fn zero_substructure(cx: @ExtCtxt, span: Span, substr: &Substructure) -> @Expr {
|
||||||
cx.ident_of("Zero"),
|
cx.ident_of("Zero"),
|
||||||
cx.ident_of("zero")
|
cx.ident_of("zero")
|
||||||
];
|
];
|
||||||
let zero_call = || {
|
let zero_call = cx.expr_call_global(span, zero_ident.clone(), ~[]);
|
||||||
cx.expr_call_global(span, zero_ident.clone(), ~[])
|
|
||||||
};
|
|
||||||
|
|
||||||
return match *substr.fields {
|
return match *substr.fields {
|
||||||
StaticStruct(_, ref summary) => {
|
StaticStruct(_, ref summary) => {
|
||||||
|
@ -73,13 +71,13 @@ fn zero_substructure(cx: @ExtCtxt, span: Span, substr: &Substructure) -> @Expr {
|
||||||
if count == 0 {
|
if count == 0 {
|
||||||
cx.expr_ident(span, substr.type_ident)
|
cx.expr_ident(span, substr.type_ident)
|
||||||
} else {
|
} 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)
|
cx.expr_call_ident(span, substr.type_ident, exprs)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Right(ref fields) => {
|
Right(ref fields) => {
|
||||||
let zero_fields = do fields.map |ident| {
|
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)
|
cx.expr_struct_ident(span, substr.type_ident, zero_fields)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue