diff options
| author | Jorge Aparicio <japaricious@gmail.com> | 2014-12-08 13:28:32 -0500 |
|---|---|---|
| committer | Jorge Aparicio <japaricious@gmail.com> | 2014-12-13 17:03:47 -0500 |
| commit | 0dac05dd627612232403c07ca8bd6d3376eec64a (patch) | |
| tree | 656a23a7314866c8fa5cc6ca787111db41d90834 /src/libsyntax/ext/deriving/generic | |
| parent | 2160427900ea675e494274d42a8d8485724f440e (diff) | |
| download | rust-0dac05dd627612232403c07ca8bd6d3376eec64a.tar.gz rust-0dac05dd627612232403c07ca8bd6d3376eec64a.zip | |
libsyntax: use unboxed closures
Diffstat (limited to 'src/libsyntax/ext/deriving/generic')
| -rw-r--r-- | src/libsyntax/ext/deriving/generic/mod.rs | 62 |
1 files changed, 35 insertions, 27 deletions
diff --git a/src/libsyntax/ext/deriving/generic/mod.rs b/src/libsyntax/ext/deriving/generic/mod.rs index cf3b3ad9051..a75be40604e 100644 --- a/src/libsyntax/ext/deriving/generic/mod.rs +++ b/src/libsyntax/ext/deriving/generic/mod.rs @@ -333,11 +333,13 @@ pub fn combine_substructure<'a>(f: CombineSubstructureFunc<'a>) impl<'a> TraitDef<'a> { - pub fn expand(&self, - cx: &mut ExtCtxt, - mitem: &ast::MetaItem, - item: &ast::Item, - push: |P<ast::Item>|) { + pub fn expand<F>(&self, + cx: &mut ExtCtxt, + mitem: &ast::MetaItem, + item: &ast::Item, + push: F) where + F: FnOnce(P<ast::Item>), + { let newitem = match item.node { ast::ItemStruct(ref struct_def, ref generics) => { self.expand_struct_def(cx, @@ -1309,14 +1311,16 @@ impl<'a> TraitDef<'a> { /// Fold the fields. `use_foldl` controls whether this is done /// left-to-right (`true`) or right-to-left (`false`). -pub fn cs_fold(use_foldl: bool, - f: |&mut ExtCtxt, Span, P<Expr>, P<Expr>, &[P<Expr>]| -> P<Expr>, - base: P<Expr>, - enum_nonmatch_f: EnumNonMatchCollapsedFunc, - cx: &mut ExtCtxt, - trait_span: Span, - substructure: &Substructure) - -> P<Expr> { +pub fn cs_fold<F>(use_foldl: bool, + mut f: F, + base: P<Expr>, + enum_nonmatch_f: EnumNonMatchCollapsedFunc, + cx: &mut ExtCtxt, + trait_span: Span, + substructure: &Substructure) + -> P<Expr> where + F: FnMut(&mut ExtCtxt, Span, P<Expr>, P<Expr>, &[P<Expr>]) -> P<Expr>, +{ match *substructure.fields { EnumMatching(_, _, ref all_fields) | Struct(ref all_fields) => { if use_foldl { @@ -1355,12 +1359,14 @@ pub fn cs_fold(use_foldl: bool, /// self_2.method(__arg_1_2, __arg_2_2)]) /// ``` #[inline] -pub fn cs_same_method(f: |&mut ExtCtxt, Span, Vec<P<Expr>>| -> P<Expr>, - enum_nonmatch_f: EnumNonMatchCollapsedFunc, - cx: &mut ExtCtxt, - trait_span: Span, - substructure: &Substructure) - -> P<Expr> { +pub fn cs_same_method<F>(f: F, + enum_nonmatch_f: EnumNonMatchCollapsedFunc, + cx: &mut ExtCtxt, + trait_span: Span, + substructure: &Substructure) + -> P<Expr> where + F: FnOnce(&mut ExtCtxt, Span, Vec<P<Expr>>) -> P<Expr>, +{ match *substructure.fields { EnumMatching(_, _, ref all_fields) | Struct(ref all_fields) => { // call self_n.method(other_1_n, other_2_n, ...) @@ -1388,14 +1394,16 @@ pub fn cs_same_method(f: |&mut ExtCtxt, Span, Vec<P<Expr>>| -> P<Expr>, /// fields. `use_foldl` controls whether this is done left-to-right /// (`true`) or right-to-left (`false`). #[inline] -pub fn cs_same_method_fold(use_foldl: bool, - f: |&mut ExtCtxt, Span, P<Expr>, P<Expr>| -> P<Expr>, - base: P<Expr>, - enum_nonmatch_f: EnumNonMatchCollapsedFunc, - cx: &mut ExtCtxt, - trait_span: Span, - substructure: &Substructure) - -> P<Expr> { +pub fn cs_same_method_fold<F>(use_foldl: bool, + mut f: F, + base: P<Expr>, + enum_nonmatch_f: EnumNonMatchCollapsedFunc, + cx: &mut ExtCtxt, + trait_span: Span, + substructure: &Substructure) + -> P<Expr> where + F: FnMut(&mut ExtCtxt, Span, P<Expr>, P<Expr>) -> P<Expr>, +{ cs_same_method( |cx, span, vals| { if use_foldl { |
