args: Vec::new(),
ret_ty: Self,
attributes: attrs,
- combine_substructure: combine_substructure(|c, s, sub| {
+ combine_substructure: combine_substructure(box |c, s, sub| {
cs_clone("Clone", c, s, sub)
}),
}
cx.expr_binary(span, ast::BiAnd, subexpr, eq)
},
cx.expr_bool(span, true),
- |cx, span, _, _| cx.expr_bool(span, false),
+ box |cx, span, _, _| cx.expr_bool(span, false),
cx, span, substr)
}
fn cs_ne(cx: &mut ExtCtxt, span: Span, substr: &Substructure) -> P<Expr> {
cx.expr_binary(span, ast::BiOr, subexpr, eq)
},
cx.expr_bool(span, false),
- |cx, span, _, _| cx.expr_bool(span, true),
+ box |cx, span, _, _| cx.expr_bool(span, true),
cx, span, substr)
}
args: vec!(borrowed_self()),
ret_ty: Literal(Path::new(vec!("bool"))),
attributes: attrs,
- combine_substructure: combine_substructure(|a, b, c| {
+ combine_substructure: combine_substructure(box |a, b, c| {
$f(a, b, c)
})
}
args: vec!(borrowed_self()),
ret_ty: Literal(Path::new(vec!("bool"))),
attributes: attrs,
- combine_substructure: combine_substructure(|cx, span, substr| {
+ combine_substructure: combine_substructure(box |cx, span, substr| {
cs_op($op, $equal, cx, span, substr)
})
}
args: vec![borrowed_self()],
ret_ty: ret_ty,
attributes: attrs,
- combine_substructure: combine_substructure(|cx, span, substr| {
+ combine_substructure: combine_substructure(box |cx, span, substr| {
cs_partial_cmp(cx, span, substr)
})
};
cx.expr_block(cx.block(span, vec!(assign), Some(if_)))
},
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 {
cx.span_bug(span, "not exactly 2 arguments in `deriving(PartialOrd)`")
} else {
cx.expr_binary(span, ast::BiOr, cmp, and)
},
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 {
cx.span_bug(span, "not exactly 2 arguments in `deriving(PartialOrd)`")
} else {
let block = cx.block(span, stmts, None);
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,
span,
substr)
args: vec!(),
ret_ty: nil_ty(),
attributes: attrs,
- combine_substructure: combine_substructure(|a, b, c| {
+ combine_substructure: combine_substructure(box |a, b, c| {
cs_total_eq_assert(a, b, c)
})
}
args: vec!(borrowed_self()),
ret_ty: Literal(Path::new(vec!("std", "cmp", "Ordering"))),
attributes: attrs,
- combine_substructure: combine_substructure(|a, b, c| {
+ combine_substructure: combine_substructure(box |a, b, c| {
cs_cmp(a, b, c)
}),
}
cx.expr_block(cx.block(span, vec!(assign), Some(if_)))
},
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 {
cx.span_bug(span, "not exactly 2 arguments in `deriving(Ord)`")
} else {
true
)),
attributes: Vec::new(),
- combine_substructure: combine_substructure(|a, b, c| {
+ combine_substructure: combine_substructure(box |a, b, c| {
decodable_substructure(a, b, c, krate)
}),
})
args: Vec::new(),
ret_ty: Self,
attributes: attrs,
- combine_substructure: combine_substructure(|a, b, c| {
+ combine_substructure: combine_substructure(box |a, b, c| {
default_substructure(a, b, c)
})
})
true
)),
attributes: Vec::new(),
- combine_substructure: combine_substructure(|a, b, c| {
+ combine_substructure: combine_substructure(box |a, b, c| {
encodable_substructure(a, b, c)
}),
})
/// Combine the values of all the fields together. The last argument is
/// all the fields of all the structures.
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
/// identifiers (one for each `Self` argument, which could be any of 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.
pub type EnumNonMatchCollapsedFunc<'a> =
- |&mut ExtCtxt,
- Span,
- (&[Ident], &[Ident]),
- &[P<Expr>]|: 'a
- -> P<Expr>;
+ Box<FnMut(&mut ExtCtxt, Span, (&[Ident], &[Ident]), &[P<Expr>]) -> P<Expr> + 'a>;
pub fn combine_substructure<'a>(f: CombineSubstructureFunc<'a>)
-> RefCell<CombineSubstructureFunc<'a>> {
};
let mut f = self.combine_substructure.borrow_mut();
let f: &mut CombineSubstructureFunc = &mut *f;
- (*f)(cx, trait_.span, &substructure)
+ f.call_mut((cx, trait_.span, &substructure))
}
fn get_ret_ty(&self,
pub fn cs_fold<F>(use_foldl: bool,
mut f: F,
base: P<Expr>,
- enum_nonmatch_f: EnumNonMatchCollapsedFunc,
+ mut enum_nonmatch_f: EnumNonMatchCollapsedFunc,
cx: &mut ExtCtxt,
trait_span: Span,
substructure: &Substructure)
}
},
EnumNonMatchingCollapsed(ref all_args, _, tuple) =>
- enum_nonmatch_f(cx, trait_span, (all_args[], tuple),
- substructure.nonself_args),
+ enum_nonmatch_f.call_mut((cx, trait_span, (all_args[], tuple),
+ substructure.nonself_args)),
StaticEnum(..) | StaticStruct(..) => {
cx.span_bug(trait_span, "static function in `derive`")
}
/// ```
#[inline]
pub fn cs_same_method<F>(f: F,
- enum_nonmatch_f: EnumNonMatchCollapsedFunc,
+ mut enum_nonmatch_f: EnumNonMatchCollapsedFunc,
cx: &mut ExtCtxt,
trait_span: Span,
substructure: &Substructure)
f(cx, trait_span, called)
},
EnumNonMatchingCollapsed(ref all_self_args, _, tuple) =>
- enum_nonmatch_f(cx, trait_span, (all_self_args[], tuple),
- substructure.nonself_args),
+ enum_nonmatch_f.call_mut((cx, trait_span, (all_self_args[], tuple),
+ substructure.nonself_args)),
StaticEnum(..) | StaticStruct(..) => {
cx.span_bug(trait_span, "static function in `derive`")
}
args: vec!(Ptr(box Literal(args), Borrowed(None, MutMutable))),
ret_ty: nil_ty(),
attributes: attrs,
- combine_substructure: combine_substructure(|a, b, c| {
+ combine_substructure: combine_substructure(box |a, b, c| {
hash_substructure(a, b, c)
})
}
true)),
// #[inline] liable to cause code-bloat
attributes: attrs.clone(),
- combine_substructure: combine_substructure(|c, s, sub| {
+ combine_substructure: combine_substructure(box |c, s, sub| {
cs_from("i64", c, s, sub)
}),
},
true)),
// #[inline] liable to cause code-bloat
attributes: attrs,
- combine_substructure: combine_substructure(|c, s, sub| {
+ combine_substructure: combine_substructure(box |c, s, sub| {
cs_from("u64", c, s, sub)
}),
})
),
ret_ty: Self,
attributes: Vec::new(),
- combine_substructure: combine_substructure(|a, b, c| {
+ combine_substructure: combine_substructure(box |a, b, c| {
rand_substructure(a, b, c)
})
}
args: vec!(fmtr),
ret_ty: Literal(Path::new(vec!("std", "fmt", "Result"))),
attributes: Vec::new(),
- combine_substructure: combine_substructure(|a, b, c| {
+ combine_substructure: combine_substructure(box |a, b, c| {
show_substructure(a, b, c)
})
}