syntax: remove remaining boxed closures
This commit is contained in:
parent
37f62ae1c0
commit
07a8e7cfb5
13 changed files with 29 additions and 33 deletions
|
@ -40,7 +40,7 @@ pub fn expand_deriving_clone<F>(cx: &mut ExtCtxt,
|
||||||
args: Vec::new(),
|
args: Vec::new(),
|
||||||
ret_ty: Self,
|
ret_ty: Self,
|
||||||
attributes: attrs,
|
attributes: attrs,
|
||||||
combine_substructure: combine_substructure(|c, s, sub| {
|
combine_substructure: combine_substructure(box |c, s, sub| {
|
||||||
cs_clone("Clone", c, s, sub)
|
cs_clone("Clone", c, s, sub)
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,7 +40,7 @@ pub fn expand_deriving_eq<F>(cx: &mut ExtCtxt,
|
||||||
cx.expr_binary(span, ast::BiAnd, subexpr, eq)
|
cx.expr_binary(span, ast::BiAnd, subexpr, eq)
|
||||||
},
|
},
|
||||||
cx.expr_bool(span, true),
|
cx.expr_bool(span, true),
|
||||||
|cx, span, _, _| cx.expr_bool(span, false),
|
box |cx, span, _, _| cx.expr_bool(span, false),
|
||||||
cx, span, substr)
|
cx, span, substr)
|
||||||
}
|
}
|
||||||
fn cs_ne(cx: &mut ExtCtxt, span: Span, substr: &Substructure) -> P<Expr> {
|
fn cs_ne(cx: &mut ExtCtxt, span: Span, substr: &Substructure) -> P<Expr> {
|
||||||
|
@ -57,7 +57,7 @@ pub fn expand_deriving_eq<F>(cx: &mut ExtCtxt,
|
||||||
cx.expr_binary(span, ast::BiOr, subexpr, eq)
|
cx.expr_binary(span, ast::BiOr, subexpr, eq)
|
||||||
},
|
},
|
||||||
cx.expr_bool(span, false),
|
cx.expr_bool(span, false),
|
||||||
|cx, span, _, _| cx.expr_bool(span, true),
|
box |cx, span, _, _| cx.expr_bool(span, true),
|
||||||
cx, span, substr)
|
cx, span, substr)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -72,7 +72,7 @@ pub fn expand_deriving_eq<F>(cx: &mut ExtCtxt,
|
||||||
args: vec!(borrowed_self()),
|
args: vec!(borrowed_self()),
|
||||||
ret_ty: Literal(Path::new(vec!("bool"))),
|
ret_ty: Literal(Path::new(vec!("bool"))),
|
||||||
attributes: attrs,
|
attributes: attrs,
|
||||||
combine_substructure: combine_substructure(|a, b, c| {
|
combine_substructure: combine_substructure(box |a, b, c| {
|
||||||
$f(a, b, c)
|
$f(a, b, c)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,7 +38,7 @@ pub fn expand_deriving_ord<F>(cx: &mut ExtCtxt,
|
||||||
args: vec!(borrowed_self()),
|
args: vec!(borrowed_self()),
|
||||||
ret_ty: Literal(Path::new(vec!("bool"))),
|
ret_ty: Literal(Path::new(vec!("bool"))),
|
||||||
attributes: attrs,
|
attributes: attrs,
|
||||||
combine_substructure: combine_substructure(|cx, span, substr| {
|
combine_substructure: combine_substructure(box |cx, span, substr| {
|
||||||
cs_op($op, $equal, cx, span, substr)
|
cs_op($op, $equal, cx, span, substr)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -61,7 +61,7 @@ pub fn expand_deriving_ord<F>(cx: &mut ExtCtxt,
|
||||||
args: vec![borrowed_self()],
|
args: vec![borrowed_self()],
|
||||||
ret_ty: ret_ty,
|
ret_ty: ret_ty,
|
||||||
attributes: attrs,
|
attributes: attrs,
|
||||||
combine_substructure: combine_substructure(|cx, span, substr| {
|
combine_substructure: combine_substructure(box |cx, span, substr| {
|
||||||
cs_partial_cmp(cx, span, substr)
|
cs_partial_cmp(cx, span, substr)
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
|
@ -174,7 +174,7 @@ pub fn cs_partial_cmp(cx: &mut ExtCtxt, span: Span,
|
||||||
cx.expr_block(cx.block(span, vec!(assign), Some(if_)))
|
cx.expr_block(cx.block(span, vec!(assign), Some(if_)))
|
||||||
},
|
},
|
||||||
equals_expr.clone(),
|
equals_expr.clone(),
|
||||||
|cx, span, (self_args, tag_tuple), _non_self_args| {
|
box |cx, span, (self_args, tag_tuple), _non_self_args| {
|
||||||
if self_args.len() != 2 {
|
if self_args.len() != 2 {
|
||||||
cx.span_bug(span, "not exactly 2 arguments in `deriving(PartialOrd)`")
|
cx.span_bug(span, "not exactly 2 arguments in `deriving(PartialOrd)`")
|
||||||
} else {
|
} else {
|
||||||
|
@ -222,7 +222,7 @@ fn cs_op(less: bool, equal: bool, cx: &mut ExtCtxt,
|
||||||
cx.expr_binary(span, ast::BiOr, cmp, and)
|
cx.expr_binary(span, ast::BiOr, cmp, and)
|
||||||
},
|
},
|
||||||
cx.expr_bool(span, equal),
|
cx.expr_bool(span, equal),
|
||||||
|cx, span, (self_args, tag_tuple), _non_self_args| {
|
box |cx, span, (self_args, tag_tuple), _non_self_args| {
|
||||||
if self_args.len() != 2 {
|
if self_args.len() != 2 {
|
||||||
cx.span_bug(span, "not exactly 2 arguments in `deriving(PartialOrd)`")
|
cx.span_bug(span, "not exactly 2 arguments in `deriving(PartialOrd)`")
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -32,7 +32,7 @@ pub fn expand_deriving_totaleq<F>(cx: &mut ExtCtxt,
|
||||||
let block = cx.block(span, stmts, None);
|
let block = cx.block(span, stmts, None);
|
||||||
cx.expr_block(block)
|
cx.expr_block(block)
|
||||||
},
|
},
|
||||||
|cx, sp, _, _| cx.span_bug(sp, "non matching enums in deriving(Eq)?"),
|
box |cx, sp, _, _| cx.span_bug(sp, "non matching enums in deriving(Eq)?"),
|
||||||
cx,
|
cx,
|
||||||
span,
|
span,
|
||||||
substr)
|
substr)
|
||||||
|
@ -57,7 +57,7 @@ pub fn expand_deriving_totaleq<F>(cx: &mut ExtCtxt,
|
||||||
args: vec!(),
|
args: vec!(),
|
||||||
ret_ty: nil_ty(),
|
ret_ty: nil_ty(),
|
||||||
attributes: attrs,
|
attributes: attrs,
|
||||||
combine_substructure: combine_substructure(|a, b, c| {
|
combine_substructure: combine_substructure(box |a, b, c| {
|
||||||
cs_total_eq_assert(a, b, c)
|
cs_total_eq_assert(a, b, c)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,7 +41,7 @@ pub fn expand_deriving_totalord<F>(cx: &mut ExtCtxt,
|
||||||
args: vec!(borrowed_self()),
|
args: vec!(borrowed_self()),
|
||||||
ret_ty: Literal(Path::new(vec!("std", "cmp", "Ordering"))),
|
ret_ty: Literal(Path::new(vec!("std", "cmp", "Ordering"))),
|
||||||
attributes: attrs,
|
attributes: attrs,
|
||||||
combine_substructure: combine_substructure(|a, b, c| {
|
combine_substructure: combine_substructure(box |a, b, c| {
|
||||||
cs_cmp(a, b, c)
|
cs_cmp(a, b, c)
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
|
@ -130,7 +130,7 @@ pub fn cs_cmp(cx: &mut ExtCtxt, span: Span,
|
||||||
cx.expr_block(cx.block(span, vec!(assign), Some(if_)))
|
cx.expr_block(cx.block(span, vec!(assign), Some(if_)))
|
||||||
},
|
},
|
||||||
cx.expr_path(equals_path.clone()),
|
cx.expr_path(equals_path.clone()),
|
||||||
|cx, span, (self_args, tag_tuple), _non_self_args| {
|
box |cx, span, (self_args, tag_tuple), _non_self_args| {
|
||||||
if self_args.len() != 2 {
|
if self_args.len() != 2 {
|
||||||
cx.span_bug(span, "not exactly 2 arguments in `deriving(Ord)`")
|
cx.span_bug(span, "not exactly 2 arguments in `deriving(Ord)`")
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -76,7 +76,7 @@ fn expand_deriving_decodable_imp<F>(cx: &mut ExtCtxt,
|
||||||
true
|
true
|
||||||
)),
|
)),
|
||||||
attributes: Vec::new(),
|
attributes: Vec::new(),
|
||||||
combine_substructure: combine_substructure(|a, b, c| {
|
combine_substructure: combine_substructure(box |a, b, c| {
|
||||||
decodable_substructure(a, b, c, krate)
|
decodable_substructure(a, b, c, krate)
|
||||||
}),
|
}),
|
||||||
})
|
})
|
||||||
|
|
|
@ -40,7 +40,7 @@ pub fn expand_deriving_default<F>(cx: &mut ExtCtxt,
|
||||||
args: Vec::new(),
|
args: Vec::new(),
|
||||||
ret_ty: Self,
|
ret_ty: Self,
|
||||||
attributes: attrs,
|
attributes: attrs,
|
||||||
combine_substructure: combine_substructure(|a, b, c| {
|
combine_substructure: combine_substructure(box |a, b, c| {
|
||||||
default_substructure(a, b, c)
|
default_substructure(a, b, c)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -152,7 +152,7 @@ fn expand_deriving_encodable_imp<F>(cx: &mut ExtCtxt,
|
||||||
true
|
true
|
||||||
)),
|
)),
|
||||||
attributes: Vec::new(),
|
attributes: Vec::new(),
|
||||||
combine_substructure: combine_substructure(|a, b, c| {
|
combine_substructure: combine_substructure(box |a, b, c| {
|
||||||
encodable_substructure(a, b, c)
|
encodable_substructure(a, b, c)
|
||||||
}),
|
}),
|
||||||
})
|
})
|
||||||
|
|
|
@ -312,7 +312,7 @@ pub enum SubstructureFields<'a> {
|
||||||
/// Combine the values of all the fields together. The last argument is
|
/// Combine the values of all the fields together. The last argument is
|
||||||
/// all the fields of all the structures.
|
/// all the fields of all the structures.
|
||||||
pub type CombineSubstructureFunc<'a> =
|
pub type CombineSubstructureFunc<'a> =
|
||||||
|&mut ExtCtxt, Span, &Substructure|: 'a -> P<Expr>;
|
Box<FnMut(&mut ExtCtxt, Span, &Substructure) -> P<Expr> + 'a>;
|
||||||
|
|
||||||
/// Deal with non-matching enum variants. The tuple is a list of
|
/// Deal with non-matching enum variants. The tuple is a list of
|
||||||
/// identifiers (one for each `Self` argument, which could be any of the
|
/// identifiers (one for each `Self` argument, which could be any of the
|
||||||
|
@ -320,11 +320,7 @@ pub type CombineSubstructureFunc<'a> =
|
||||||
/// holding the variant index value for each of the `Self` arguments. The
|
/// holding the variant index value for each of the `Self` arguments. The
|
||||||
/// last argument is all the non-`Self` args of the method being derived.
|
/// last argument is all the non-`Self` args of the method being derived.
|
||||||
pub type EnumNonMatchCollapsedFunc<'a> =
|
pub type EnumNonMatchCollapsedFunc<'a> =
|
||||||
|&mut ExtCtxt,
|
Box<FnMut(&mut ExtCtxt, Span, (&[Ident], &[Ident]), &[P<Expr>]) -> P<Expr> + 'a>;
|
||||||
Span,
|
|
||||||
(&[Ident], &[Ident]),
|
|
||||||
&[P<Expr>]|: 'a
|
|
||||||
-> P<Expr>;
|
|
||||||
|
|
||||||
pub fn combine_substructure<'a>(f: CombineSubstructureFunc<'a>)
|
pub fn combine_substructure<'a>(f: CombineSubstructureFunc<'a>)
|
||||||
-> RefCell<CombineSubstructureFunc<'a>> {
|
-> RefCell<CombineSubstructureFunc<'a>> {
|
||||||
|
@ -606,7 +602,7 @@ impl<'a> MethodDef<'a> {
|
||||||
};
|
};
|
||||||
let mut f = self.combine_substructure.borrow_mut();
|
let mut f = self.combine_substructure.borrow_mut();
|
||||||
let f: &mut CombineSubstructureFunc = &mut *f;
|
let f: &mut CombineSubstructureFunc = &mut *f;
|
||||||
(*f)(cx, trait_.span, &substructure)
|
f.call_mut((cx, trait_.span, &substructure))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_ret_ty(&self,
|
fn get_ret_ty(&self,
|
||||||
|
@ -1341,7 +1337,7 @@ impl<'a> TraitDef<'a> {
|
||||||
pub fn cs_fold<F>(use_foldl: bool,
|
pub fn cs_fold<F>(use_foldl: bool,
|
||||||
mut f: F,
|
mut f: F,
|
||||||
base: P<Expr>,
|
base: P<Expr>,
|
||||||
enum_nonmatch_f: EnumNonMatchCollapsedFunc,
|
mut enum_nonmatch_f: EnumNonMatchCollapsedFunc,
|
||||||
cx: &mut ExtCtxt,
|
cx: &mut ExtCtxt,
|
||||||
trait_span: Span,
|
trait_span: Span,
|
||||||
substructure: &Substructure)
|
substructure: &Substructure)
|
||||||
|
@ -1369,8 +1365,8 @@ pub fn cs_fold<F>(use_foldl: bool,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
EnumNonMatchingCollapsed(ref all_args, _, tuple) =>
|
EnumNonMatchingCollapsed(ref all_args, _, tuple) =>
|
||||||
enum_nonmatch_f(cx, trait_span, (all_args[], tuple),
|
enum_nonmatch_f.call_mut((cx, trait_span, (all_args[], tuple),
|
||||||
substructure.nonself_args),
|
substructure.nonself_args)),
|
||||||
StaticEnum(..) | StaticStruct(..) => {
|
StaticEnum(..) | StaticStruct(..) => {
|
||||||
cx.span_bug(trait_span, "static function in `derive`")
|
cx.span_bug(trait_span, "static function in `derive`")
|
||||||
}
|
}
|
||||||
|
@ -1387,7 +1383,7 @@ pub fn cs_fold<F>(use_foldl: bool,
|
||||||
/// ```
|
/// ```
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn cs_same_method<F>(f: F,
|
pub fn cs_same_method<F>(f: F,
|
||||||
enum_nonmatch_f: EnumNonMatchCollapsedFunc,
|
mut enum_nonmatch_f: EnumNonMatchCollapsedFunc,
|
||||||
cx: &mut ExtCtxt,
|
cx: &mut ExtCtxt,
|
||||||
trait_span: Span,
|
trait_span: Span,
|
||||||
substructure: &Substructure)
|
substructure: &Substructure)
|
||||||
|
@ -1409,8 +1405,8 @@ pub fn cs_same_method<F>(f: F,
|
||||||
f(cx, trait_span, called)
|
f(cx, trait_span, called)
|
||||||
},
|
},
|
||||||
EnumNonMatchingCollapsed(ref all_self_args, _, tuple) =>
|
EnumNonMatchingCollapsed(ref all_self_args, _, tuple) =>
|
||||||
enum_nonmatch_f(cx, trait_span, (all_self_args[], tuple),
|
enum_nonmatch_f.call_mut((cx, trait_span, (all_self_args[], tuple),
|
||||||
substructure.nonself_args),
|
substructure.nonself_args)),
|
||||||
StaticEnum(..) | StaticStruct(..) => {
|
StaticEnum(..) | StaticStruct(..) => {
|
||||||
cx.span_bug(trait_span, "static function in `derive`")
|
cx.span_bug(trait_span, "static function in `derive`")
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,7 +55,7 @@ pub fn expand_deriving_hash<F>(cx: &mut ExtCtxt,
|
||||||
args: vec!(Ptr(box Literal(args), Borrowed(None, MutMutable))),
|
args: vec!(Ptr(box Literal(args), Borrowed(None, MutMutable))),
|
||||||
ret_ty: nil_ty(),
|
ret_ty: nil_ty(),
|
||||||
attributes: attrs,
|
attributes: attrs,
|
||||||
combine_substructure: combine_substructure(|a, b, c| {
|
combine_substructure: combine_substructure(box |a, b, c| {
|
||||||
hash_substructure(a, b, c)
|
hash_substructure(a, b, c)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,7 +46,7 @@ pub fn expand_deriving_from_primitive<F>(cx: &mut ExtCtxt,
|
||||||
true)),
|
true)),
|
||||||
// #[inline] liable to cause code-bloat
|
// #[inline] liable to cause code-bloat
|
||||||
attributes: attrs.clone(),
|
attributes: attrs.clone(),
|
||||||
combine_substructure: combine_substructure(|c, s, sub| {
|
combine_substructure: combine_substructure(box |c, s, sub| {
|
||||||
cs_from("i64", c, s, sub)
|
cs_from("i64", c, s, sub)
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
|
@ -62,7 +62,7 @@ pub fn expand_deriving_from_primitive<F>(cx: &mut ExtCtxt,
|
||||||
true)),
|
true)),
|
||||||
// #[inline] liable to cause code-bloat
|
// #[inline] liable to cause code-bloat
|
||||||
attributes: attrs,
|
attributes: attrs,
|
||||||
combine_substructure: combine_substructure(|c, s, sub| {
|
combine_substructure: combine_substructure(box |c, s, sub| {
|
||||||
cs_from("u64", c, s, sub)
|
cs_from("u64", c, s, sub)
|
||||||
}),
|
}),
|
||||||
})
|
})
|
||||||
|
|
|
@ -45,7 +45,7 @@ pub fn expand_deriving_rand<F>(cx: &mut ExtCtxt,
|
||||||
),
|
),
|
||||||
ret_ty: Self,
|
ret_ty: Self,
|
||||||
attributes: Vec::new(),
|
attributes: Vec::new(),
|
||||||
combine_substructure: combine_substructure(|a, b, c| {
|
combine_substructure: combine_substructure(box |a, b, c| {
|
||||||
rand_substructure(a, b, c)
|
rand_substructure(a, b, c)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,7 +46,7 @@ pub fn expand_deriving_show<F>(cx: &mut ExtCtxt,
|
||||||
args: vec!(fmtr),
|
args: vec!(fmtr),
|
||||||
ret_ty: Literal(Path::new(vec!("std", "fmt", "Result"))),
|
ret_ty: Literal(Path::new(vec!("std", "fmt", "Result"))),
|
||||||
attributes: Vec::new(),
|
attributes: Vec::new(),
|
||||||
combine_substructure: combine_substructure(|a, b, c| {
|
combine_substructure: combine_substructure(box |a, b, c| {
|
||||||
show_substructure(a, b, c)
|
show_substructure(a, b, c)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue