From 5e7469cfe18583dbacfdd4a1db424068f8ae69a5 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Tue, 2 Dec 2014 14:46:01 -0500 Subject: libsyntax: fix fallout --- src/libsyntax/ext/deriving/clone.rs | 2 +- src/libsyntax/lib.rs | 1 + src/libsyntax/owned_slice.rs | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) (limited to 'src/libsyntax') diff --git a/src/libsyntax/ext/deriving/clone.rs b/src/libsyntax/ext/deriving/clone.rs index fccc67bf220..f6b8c00e761 100644 --- a/src/libsyntax/ext/deriving/clone.rs +++ b/src/libsyntax/ext/deriving/clone.rs @@ -60,7 +60,7 @@ fn cs_clone( cx.ident_of("Clone"), cx.ident_of("clone"), ]; - let subcall = |field: &FieldInfo| { + let subcall = |&: field: &FieldInfo| { let args = vec![cx.expr_addr_of(field.span, field.self_.clone())]; cx.expr_call_global(field.span, fn_path.clone(), args) diff --git a/src/libsyntax/lib.rs b/src/libsyntax/lib.rs index ea305642f66..5d5b56d444f 100644 --- a/src/libsyntax/lib.rs +++ b/src/libsyntax/lib.rs @@ -25,6 +25,7 @@ #![allow(unknown_features)] #![feature(macro_rules, globs, default_type_params, phase, slicing_syntax)] #![feature(quote, unsafe_destructor, import_shadowing)] +#![feature(unboxed_closures)] extern crate arena; extern crate fmt_macros; diff --git a/src/libsyntax/owned_slice.rs b/src/libsyntax/owned_slice.rs index 43b428b5a1c..8e418e46921 100644 --- a/src/libsyntax/owned_slice.rs +++ b/src/libsyntax/owned_slice.rs @@ -49,7 +49,7 @@ impl OwnedSlice { self.into_vec().into_iter() } - pub fn map(&self, f: |&T| -> U) -> OwnedSlice { + pub fn map U>(&self, f: F) -> OwnedSlice { self.iter().map(f).collect() } } -- cgit 1.4.1-3-g733a5 From 0dac05dd627612232403c07ca8bd6d3376eec64a Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Mon, 8 Dec 2014 13:28:32 -0500 Subject: libsyntax: use unboxed closures --- src/libsyntax/ast_map/blocks.rs | 15 ++-- src/libsyntax/ast_map/mod.rs | 12 ++- src/libsyntax/ast_util.rs | 11 +-- src/libsyntax/attr.rs | 7 +- src/libsyntax/codemap.rs | 4 +- src/libsyntax/config.rs | 82 +++++++++++++----- src/libsyntax/diagnostic.rs | 4 +- src/libsyntax/diagnostics/plugin.rs | 12 ++- src/libsyntax/ext/deriving/bounds.rs | 13 +-- src/libsyntax/ext/deriving/clone.rs | 12 +-- src/libsyntax/ext/deriving/cmp/eq.rs | 12 +-- src/libsyntax/ext/deriving/cmp/ord.rs | 12 +-- src/libsyntax/ext/deriving/cmp/totaleq.rs | 12 +-- src/libsyntax/ext/deriving/cmp/totalord.rs | 12 +-- src/libsyntax/ext/deriving/decodable.rs | 26 +++--- src/libsyntax/ext/deriving/default.rs | 12 +-- src/libsyntax/ext/deriving/encodable.rs | 12 +-- src/libsyntax/ext/deriving/generic/mod.rs | 62 ++++++++------ src/libsyntax/ext/deriving/hash.rs | 12 +-- src/libsyntax/ext/deriving/primitive.rs | 12 +-- src/libsyntax/ext/deriving/rand.rs | 28 +++--- src/libsyntax/ext/deriving/show.rs | 12 +-- src/libsyntax/ext/deriving/zero.rs | 12 +-- src/libsyntax/ext/expand.rs | 12 +-- src/libsyntax/ext/mtwt.rs | 12 ++- src/libsyntax/fold.rs | 6 +- src/libsyntax/parse/lexer/mod.rs | 8 +- src/libsyntax/parse/parser.rs | 132 ++++++++++++++++------------- src/libsyntax/print/pprust.rs | 30 ++++--- src/libsyntax/ptr.rs | 8 +- src/libsyntax/util/parser_testing.rs | 4 +- src/libsyntax/util/small_vector.rs | 2 +- 32 files changed, 377 insertions(+), 245 deletions(-) (limited to 'src/libsyntax') diff --git a/src/libsyntax/ast_map/blocks.rs b/src/libsyntax/ast_map/blocks.rs index 639a33a8063..75f69f2f6d0 100644 --- a/src/libsyntax/ast_map/blocks.rs +++ b/src/libsyntax/ast_map/blocks.rs @@ -181,22 +181,23 @@ impl<'a> FnLikeNode<'a> { } pub fn kind(self) -> visit::FnKind<'a> { - let item = |p: ItemFnParts<'a>| -> visit::FnKind<'a> { + let item = |: p: ItemFnParts<'a>| -> visit::FnKind<'a> { visit::FkItemFn(p.ident, p.generics, p.style, p.abi) }; - let closure = |_: ClosureParts| { + let closure = |: _: ClosureParts| { visit::FkFnBlock }; - let method = |m: &'a ast::Method| { + let method = |: m: &'a ast::Method| { visit::FkMethod(m.pe_ident(), m.pe_generics(), m) }; self.handle(item, method, closure) } - fn handle(self, - item_fn: |ItemFnParts<'a>| -> A, - method: |&'a ast::Method| -> A, - closure: |ClosureParts<'a>| -> A) -> A { + fn handle(self, item_fn: I, method: M, closure: C) -> A where + I: FnOnce(ItemFnParts<'a>) -> A, + M: FnOnce(&'a ast::Method) -> A, + C: FnOnce(ClosureParts<'a>) -> A, + { match self.node { ast_map::NodeItem(i) => match i.node { ast::ItemFn(ref decl, style, abi, ref generics, ref block) => diff --git a/src/libsyntax/ast_map/mod.rs b/src/libsyntax/ast_map/mod.rs index 2c985f403f8..907ac6b19fc 100644 --- a/src/libsyntax/ast_map/mod.rs +++ b/src/libsyntax/ast_map/mod.rs @@ -424,7 +424,9 @@ impl<'ast> Map<'ast> { } } - pub fn with_path(&self, id: NodeId, f: |PathElems| -> T) -> T { + pub fn with_path(&self, id: NodeId, f: F) -> T where + F: FnOnce(PathElems) -> T, + { self.with_path_next(id, None, f) } @@ -438,7 +440,9 @@ impl<'ast> Map<'ast> { }) } - fn with_path_next(&self, id: NodeId, next: LinkedPath, f: |PathElems| -> T) -> T { + fn with_path_next(&self, id: NodeId, next: LinkedPath, f: F) -> T where + F: FnOnce(PathElems) -> T, + { let parent = self.get_parent(id); let parent = match self.find_entry(id) { Some(EntryForeignItem(..)) | Some(EntryVariant(..)) => { @@ -470,7 +474,9 @@ impl<'ast> Map<'ast> { /// Given a node ID and a closure, apply the closure to the array /// of attributes associated with the AST corresponding to the Node ID - pub fn with_attrs(&self, id: NodeId, f: |Option<&[Attribute]>| -> T) -> T { + pub fn with_attrs(&self, id: NodeId, f: F) -> T where + F: FnOnce(Option<&[Attribute]>) -> T, + { let attrs = match self.get(id) { NodeItem(i) => Some(i.attrs.as_slice()), NodeForeignItem(fi) => Some(fi.attrs.as_slice()), diff --git a/src/libsyntax/ast_util.rs b/src/libsyntax/ast_util.rs index eec3f69ee64..7579972c6d8 100644 --- a/src/libsyntax/ast_util.rs +++ b/src/libsyntax/ast_util.rs @@ -602,6 +602,7 @@ pub fn compute_id_range_for_fn_body(fk: visit::FnKind, id_visitor.operation.result } +// FIXME(#19596) unbox `it` pub fn walk_pat(pat: &Pat, it: |&Pat| -> bool) -> bool { if !it(pat) { return false; @@ -632,21 +633,21 @@ pub fn walk_pat(pat: &Pat, it: |&Pat| -> bool) -> bool { } pub trait EachViewItem { - fn each_view_item(&self, f: |&ast::ViewItem| -> bool) -> bool; + fn each_view_item(&self, f: F) -> bool where F: FnMut(&ast::ViewItem) -> bool; } -struct EachViewItemData<'a> { - callback: |&ast::ViewItem|: 'a -> bool, +struct EachViewItemData where F: FnMut(&ast::ViewItem) -> bool { + callback: F, } -impl<'a, 'v> Visitor<'v> for EachViewItemData<'a> { +impl<'v, F> Visitor<'v> for EachViewItemData where F: FnMut(&ast::ViewItem) -> bool { fn visit_view_item(&mut self, view_item: &ast::ViewItem) { let _ = (self.callback)(view_item); } } impl EachViewItem for ast::Crate { - fn each_view_item(&self, f: |&ast::ViewItem| -> bool) -> bool { + fn each_view_item(&self, f: F) -> bool where F: FnMut(&ast::ViewItem) -> bool { let mut visit = EachViewItemData { callback: f, }; diff --git a/src/libsyntax/attr.rs b/src/libsyntax/attr.rs index 5894a88ece6..8248eae4b8c 100644 --- a/src/libsyntax/attr.rs +++ b/src/libsyntax/attr.rs @@ -115,7 +115,8 @@ impl AttrMetaMethods for P { pub trait AttributeMethods { fn meta<'a>(&'a self) -> &'a MetaItem; - fn with_desugared_doc(&self, f: |&Attribute| -> T) -> T; + fn with_desugared_doc(&self, f: F) -> T where + F: FnOnce(&Attribute) -> T; } impl AttributeMethods for Attribute { @@ -127,7 +128,9 @@ impl AttributeMethods for Attribute { /// Convert self to a normal #[doc="foo"] comment, if it is a /// comment like `///` or `/** */`. (Returns self unchanged for /// non-sugared doc attributes.) - fn with_desugared_doc(&self, f: |&Attribute| -> T) -> T { + fn with_desugared_doc(&self, f: F) -> T where + F: FnOnce(&Attribute) -> T, + { if self.node.is_sugared_doc { let comment = self.value_str().unwrap(); let meta = mk_name_value_item_str( diff --git a/src/libsyntax/codemap.rs b/src/libsyntax/codemap.rs index 7f2becf8201..d2fe667339c 100644 --- a/src/libsyntax/codemap.rs +++ b/src/libsyntax/codemap.rs @@ -568,7 +568,9 @@ impl CodeMap { ExpnId(expansions.len().to_u32().expect("too many ExpnInfo's!") - 1) } - pub fn with_expn_info(&self, id: ExpnId, f: |Option<&ExpnInfo>| -> T) -> T { + pub fn with_expn_info(&self, id: ExpnId, f: F) -> T where + F: FnOnce(Option<&ExpnInfo>) -> T, + { match id { NO_EXPANSION => f(None), ExpnId(i) => f(Some(&(*self.expansions.borrow())[i as uint])) diff --git a/src/libsyntax/config.rs b/src/libsyntax/config.rs index 4f718555d53..87426dce918 100644 --- a/src/libsyntax/config.rs +++ b/src/libsyntax/config.rs @@ -19,8 +19,8 @@ use util::small_vector::SmallVector; /// A folder that strips out items that do not belong in the current /// configuration. -struct Context<'a> { - in_cfg: |attrs: &[ast::Attribute]|: 'a -> bool, +struct Context where F: FnMut(&[ast::Attribute]) -> bool { + in_cfg: F, } // Support conditional compilation by transforming the AST, stripping out @@ -30,7 +30,7 @@ pub fn strip_unconfigured_items(diagnostic: &SpanHandler, krate: ast::Crate) -> strip_items(krate, |attrs| in_cfg(diagnostic, config.as_slice(), attrs)) } -impl<'a> fold::Folder for Context<'a> { +impl fold::Folder for Context where F: FnMut(&[ast::Attribute]) -> bool { fn fold_mod(&mut self, module: ast::Mod) -> ast::Mod { fold_mod(self, module) } @@ -54,16 +54,20 @@ impl<'a> fold::Folder for Context<'a> { } } -pub fn strip_items(krate: ast::Crate, - in_cfg: |attrs: &[ast::Attribute]| -> bool) - -> ast::Crate { +pub fn strip_items(krate: ast::Crate, in_cfg: F) -> ast::Crate where + F: FnMut(&[ast::Attribute]) -> bool, +{ let mut ctxt = Context { in_cfg: in_cfg, }; ctxt.fold_crate(krate) } -fn filter_view_item(cx: &mut Context, view_item: ast::ViewItem) -> Option { +fn filter_view_item(cx: &mut Context, + view_item: ast::ViewItem) + -> Option where + F: FnMut(&[ast::Attribute]) -> bool +{ if view_item_in_cfg(cx, &view_item) { Some(view_item) } else { @@ -71,7 +75,11 @@ fn filter_view_item(cx: &mut Context, view_item: ast::ViewItem) -> Option ast::Mod { +fn fold_mod(cx: &mut Context, + ast::Mod {inner, + view_items, items}: ast::Mod) -> ast::Mod where + F: FnMut(&[ast::Attribute]) -> bool +{ ast::Mod { inner: inner, view_items: view_items.into_iter().filter_map(|a| { @@ -83,8 +91,11 @@ fn fold_mod(cx: &mut Context, ast::Mod {inner, view_items, items}: ast::Mod) -> } } -fn filter_foreign_item(cx: &mut Context, item: P) - -> Option> { +fn filter_foreign_item(cx: &mut Context, + item: P) + -> Option> where + F: FnMut(&[ast::Attribute]) -> bool +{ if foreign_item_in_cfg(cx, &*item) { Some(item) } else { @@ -92,8 +103,11 @@ fn filter_foreign_item(cx: &mut Context, item: P) } } -fn fold_foreign_mod(cx: &mut Context, ast::ForeignMod {abi, view_items, items}: ast::ForeignMod) - -> ast::ForeignMod { +fn fold_foreign_mod(cx: &mut Context, + ast::ForeignMod {abi, view_items, items}: ast::ForeignMod) + -> ast::ForeignMod where + F: FnMut(&[ast::Attribute]) -> bool +{ ast::ForeignMod { abi: abi, view_items: view_items.into_iter().filter_map(|a| { @@ -105,7 +119,9 @@ fn fold_foreign_mod(cx: &mut Context, ast::ForeignMod {abi, view_items, items}: } } -fn fold_item(cx: &mut Context, item: P) -> SmallVector> { +fn fold_item(cx: &mut Context, item: P) -> SmallVector> where + F: FnMut(&[ast::Attribute]) -> bool +{ if item_in_cfg(cx, &*item) { SmallVector::one(item.map(|i| cx.fold_item_simple(i))) } else { @@ -113,7 +129,9 @@ fn fold_item(cx: &mut Context, item: P) -> SmallVector> } } -fn fold_item_underscore(cx: &mut Context, item: ast::Item_) -> ast::Item_ { +fn fold_item_underscore(cx: &mut Context, item: ast::Item_) -> ast::Item_ where + F: FnMut(&[ast::Attribute]) -> bool +{ let item = match item { ast::ItemImpl(a, b, c, impl_items) => { let impl_items = impl_items.into_iter() @@ -166,7 +184,9 @@ fn fold_item_underscore(cx: &mut Context, item: ast::Item_) -> ast::Item_ { fold::noop_fold_item_underscore(item, cx) } -fn fold_struct(cx: &mut Context, def: P) -> P { +fn fold_struct(cx: &mut Context, def: P) -> P where + F: FnMut(&[ast::Attribute]) -> bool +{ def.map(|ast::StructDef { fields, ctor_id }| { ast::StructDef { fields: fields.into_iter().filter(|m| { @@ -177,7 +197,9 @@ fn fold_struct(cx: &mut Context, def: P) -> P { }) } -fn retain_stmt(cx: &mut Context, stmt: &ast::Stmt) -> bool { +fn retain_stmt(cx: &mut Context, stmt: &ast::Stmt) -> bool where + F: FnMut(&[ast::Attribute]) -> bool +{ match stmt.node { ast::StmtDecl(ref decl, _) => { match decl.node { @@ -191,7 +213,9 @@ fn retain_stmt(cx: &mut Context, stmt: &ast::Stmt) -> bool { } } -fn fold_block(cx: &mut Context, b: P) -> P { +fn fold_block(cx: &mut Context, b: P) -> P where + F: FnMut(&[ast::Attribute]) -> bool +{ b.map(|ast::Block {id, view_items, stmts, expr, rules, span}| { let resulting_stmts: Vec> = stmts.into_iter().filter(|a| retain_stmt(cx, &**a)).collect(); @@ -212,7 +236,9 @@ fn fold_block(cx: &mut Context, b: P) -> P { }) } -fn fold_expr(cx: &mut Context, expr: P) -> P { +fn fold_expr(cx: &mut Context, expr: P) -> P where + F: FnMut(&[ast::Attribute]) -> bool +{ expr.map(|ast::Expr {id, span, node}| { fold::noop_fold_expr(ast::Expr { id: id, @@ -229,19 +255,27 @@ fn fold_expr(cx: &mut Context, expr: P) -> P { }) } -fn item_in_cfg(cx: &mut Context, item: &ast::Item) -> bool { +fn item_in_cfg(cx: &mut Context, item: &ast::Item) -> bool where + F: FnMut(&[ast::Attribute]) -> bool +{ return (cx.in_cfg)(item.attrs.as_slice()); } -fn foreign_item_in_cfg(cx: &mut Context, item: &ast::ForeignItem) -> bool { +fn foreign_item_in_cfg(cx: &mut Context, item: &ast::ForeignItem) -> bool where + F: FnMut(&[ast::Attribute]) -> bool +{ return (cx.in_cfg)(item.attrs.as_slice()); } -fn view_item_in_cfg(cx: &mut Context, item: &ast::ViewItem) -> bool { +fn view_item_in_cfg(cx: &mut Context, item: &ast::ViewItem) -> bool where + F: FnMut(&[ast::Attribute]) -> bool +{ return (cx.in_cfg)(item.attrs.as_slice()); } -fn trait_method_in_cfg(cx: &mut Context, meth: &ast::TraitItem) -> bool { +fn trait_method_in_cfg(cx: &mut Context, meth: &ast::TraitItem) -> bool where + F: FnMut(&[ast::Attribute]) -> bool +{ match *meth { ast::RequiredMethod(ref meth) => (cx.in_cfg)(meth.attrs.as_slice()), ast::ProvidedMethod(ref meth) => (cx.in_cfg)(meth.attrs.as_slice()), @@ -249,7 +283,9 @@ fn trait_method_in_cfg(cx: &mut Context, meth: &ast::TraitItem) -> bool { } } -fn impl_item_in_cfg(cx: &mut Context, impl_item: &ast::ImplItem) -> bool { +fn impl_item_in_cfg(cx: &mut Context, impl_item: &ast::ImplItem) -> bool where + F: FnMut(&[ast::Attribute]) -> bool +{ match *impl_item { ast::MethodImplItem(ref meth) => (cx.in_cfg)(meth.attrs.as_slice()), ast::TypeImplItem(ref typ) => (cx.in_cfg)(typ.attrs.as_slice()), diff --git a/src/libsyntax/diagnostic.rs b/src/libsyntax/diagnostic.rs index bbda80bd96c..3a816987922 100644 --- a/src/libsyntax/diagnostic.rs +++ b/src/libsyntax/diagnostic.rs @@ -581,7 +581,9 @@ fn print_macro_backtrace(w: &mut EmitterWriter, cs.map_or(Ok(()), |call_site| print_macro_backtrace(w, cm, call_site)) } -pub fn expect(diag: &SpanHandler, opt: Option, msg: || -> String) -> T { +pub fn expect(diag: &SpanHandler, opt: Option, msg: M) -> T where + M: FnOnce() -> String, +{ match opt { Some(t) => t, None => diag.handler().bug(msg().as_slice()), diff --git a/src/libsyntax/diagnostics/plugin.rs b/src/libsyntax/diagnostics/plugin.rs index 2be11a236d3..cb2a1f8acd8 100644 --- a/src/libsyntax/diagnostics/plugin.rs +++ b/src/libsyntax/diagnostics/plugin.rs @@ -25,14 +25,18 @@ thread_local!(static USED_DIAGNOSTICS: RefCell> = { RefCell::new(HashMap::new()) }) -fn with_registered_diagnostics(f: |&mut HashMap>| -> T) -> T { - REGISTERED_DIAGNOSTICS.with(|slot| { +fn with_registered_diagnostics(f: F) -> T where + F: FnOnce(&mut HashMap>) -> T, +{ + REGISTERED_DIAGNOSTICS.with(move |slot| { f(&mut *slot.borrow_mut()) }) } -fn with_used_diagnostics(f: |&mut HashMap| -> T) -> T { - USED_DIAGNOSTICS.with(|slot| { +fn with_used_diagnostics(f: F) -> T where + F: FnOnce(&mut HashMap) -> T, +{ + USED_DIAGNOSTICS.with(move |slot| { f(&mut *slot.borrow_mut()) }) } diff --git a/src/libsyntax/ext/deriving/bounds.rs b/src/libsyntax/ext/deriving/bounds.rs index 0595b0bc7f4..3145b3bb1a4 100644 --- a/src/libsyntax/ext/deriving/bounds.rs +++ b/src/libsyntax/ext/deriving/bounds.rs @@ -15,12 +15,13 @@ use ext::deriving::generic::*; use ext::deriving::generic::ty::*; use ptr::P; -pub fn expand_deriving_bound(cx: &mut ExtCtxt, - span: Span, - mitem: &MetaItem, - item: &Item, - push: |P|) { - +pub fn expand_deriving_bound(cx: &mut ExtCtxt, + span: Span, + mitem: &MetaItem, + item: &Item, + push: F) where + F: FnOnce(P), +{ let name = match mitem.node { MetaWord(ref tname) => { match tname.get() { diff --git a/src/libsyntax/ext/deriving/clone.rs b/src/libsyntax/ext/deriving/clone.rs index f6b8c00e761..a34764221b3 100644 --- a/src/libsyntax/ext/deriving/clone.rs +++ b/src/libsyntax/ext/deriving/clone.rs @@ -17,11 +17,13 @@ use ext::deriving::generic::ty::*; use parse::token::InternedString; use ptr::P; -pub fn expand_deriving_clone(cx: &mut ExtCtxt, - span: Span, - mitem: &MetaItem, - item: &Item, - push: |P|) { +pub fn expand_deriving_clone(cx: &mut ExtCtxt, + span: Span, + mitem: &MetaItem, + item: &Item, + push: F) where + F: FnOnce(P), +{ let inline = cx.meta_word(span, InternedString::new("inline")); let attrs = vec!(cx.attribute(span, inline)); let trait_def = TraitDef { diff --git a/src/libsyntax/ext/deriving/cmp/eq.rs b/src/libsyntax/ext/deriving/cmp/eq.rs index 7727bb824db..c8bf5ec326c 100644 --- a/src/libsyntax/ext/deriving/cmp/eq.rs +++ b/src/libsyntax/ext/deriving/cmp/eq.rs @@ -17,11 +17,13 @@ use ext::deriving::generic::ty::*; use parse::token::InternedString; use ptr::P; -pub fn expand_deriving_eq(cx: &mut ExtCtxt, - span: Span, - mitem: &MetaItem, - item: &Item, - push: |P|) { +pub fn expand_deriving_eq(cx: &mut ExtCtxt, + span: Span, + mitem: &MetaItem, + item: &Item, + push: F) where + F: FnOnce(P), +{ // structures are equal if all fields are equal, and non equal, if // any fields are not equal or if the enum variants are different fn cs_eq(cx: &mut ExtCtxt, span: Span, substr: &Substructure) -> P { diff --git a/src/libsyntax/ext/deriving/cmp/ord.rs b/src/libsyntax/ext/deriving/cmp/ord.rs index 1bd55b5d504..bd1962de56e 100644 --- a/src/libsyntax/ext/deriving/cmp/ord.rs +++ b/src/libsyntax/ext/deriving/cmp/ord.rs @@ -20,11 +20,13 @@ use ext::deriving::generic::ty::*; use parse::token::InternedString; use ptr::P; -pub fn expand_deriving_ord(cx: &mut ExtCtxt, - span: Span, - mitem: &MetaItem, - item: &Item, - push: |P|) { +pub fn expand_deriving_ord(cx: &mut ExtCtxt, + span: Span, + mitem: &MetaItem, + item: &Item, + push: F) where + F: FnOnce(P), +{ macro_rules! md ( ($name:expr, $op:expr, $equal:expr) => { { let inline = cx.meta_word(span, InternedString::new("inline")); diff --git a/src/libsyntax/ext/deriving/cmp/totaleq.rs b/src/libsyntax/ext/deriving/cmp/totaleq.rs index ecee2008254..2b986bea122 100644 --- a/src/libsyntax/ext/deriving/cmp/totaleq.rs +++ b/src/libsyntax/ext/deriving/cmp/totaleq.rs @@ -17,11 +17,13 @@ use ext::deriving::generic::ty::*; use parse::token::InternedString; use ptr::P; -pub fn expand_deriving_totaleq(cx: &mut ExtCtxt, - span: Span, - mitem: &MetaItem, - item: &Item, - push: |P|) { +pub fn expand_deriving_totaleq(cx: &mut ExtCtxt, + span: Span, + mitem: &MetaItem, + item: &Item, + push: F) where + F: FnOnce(P), +{ fn cs_total_eq_assert(cx: &mut ExtCtxt, span: Span, substr: &Substructure) -> P { cs_same_method(|cx, span, exprs| { // create `a.(); b.(); c.(); ...` diff --git a/src/libsyntax/ext/deriving/cmp/totalord.rs b/src/libsyntax/ext/deriving/cmp/totalord.rs index 6900773f44d..a2bf46f41fc 100644 --- a/src/libsyntax/ext/deriving/cmp/totalord.rs +++ b/src/libsyntax/ext/deriving/cmp/totalord.rs @@ -18,11 +18,13 @@ use ext::deriving::generic::ty::*; use parse::token::InternedString; use ptr::P; -pub fn expand_deriving_totalord(cx: &mut ExtCtxt, - span: Span, - mitem: &MetaItem, - item: &Item, - push: |P|) { +pub fn expand_deriving_totalord(cx: &mut ExtCtxt, + span: Span, + mitem: &MetaItem, + item: &Item, + push: F) where + F: FnOnce(P), +{ let inline = cx.meta_word(span, InternedString::new("inline")); let attrs = vec!(cx.attribute(span, inline)); let trait_def = TraitDef { diff --git a/src/libsyntax/ext/deriving/decodable.rs b/src/libsyntax/ext/deriving/decodable.rs index e3cf2b68752..0a8d59da896 100644 --- a/src/libsyntax/ext/deriving/decodable.rs +++ b/src/libsyntax/ext/deriving/decodable.rs @@ -21,11 +21,13 @@ use parse::token::InternedString; use parse::token; use ptr::P; -pub fn expand_deriving_decodable(cx: &mut ExtCtxt, - span: Span, - mitem: &MetaItem, - item: &Item, - push: |P|) { +pub fn expand_deriving_decodable(cx: &mut ExtCtxt, + span: Span, + mitem: &MetaItem, + item: &Item, + push: F) where + F: FnOnce(P), +{ let trait_def = TraitDef { span: span, attributes: Vec::new(), @@ -155,12 +157,14 @@ fn decodable_substructure(cx: &mut ExtCtxt, trait_span: Span, /// Create a decoder for a single enum variant/struct: /// - `outer_pat_path` is the path to this enum variant/struct /// - `getarg` should retrieve the `uint`-th field with name `@str`. -fn decode_static_fields(cx: &mut ExtCtxt, - trait_span: Span, - outer_pat_path: ast::Path, - fields: &StaticFields, - getarg: |&mut ExtCtxt, Span, InternedString, uint| -> P) - -> P { +fn decode_static_fields(cx: &mut ExtCtxt, + trait_span: Span, + outer_pat_path: ast::Path, + fields: &StaticFields, + mut getarg: F) + -> P where + F: FnMut(&mut ExtCtxt, Span, InternedString, uint) -> P, +{ match *fields { Unnamed(ref fields) => { let path_expr = cx.expr_path(outer_pat_path); diff --git a/src/libsyntax/ext/deriving/default.rs b/src/libsyntax/ext/deriving/default.rs index f4a66414d89..b3621490ce3 100644 --- a/src/libsyntax/ext/deriving/default.rs +++ b/src/libsyntax/ext/deriving/default.rs @@ -17,11 +17,13 @@ use ext::deriving::generic::ty::*; use parse::token::InternedString; use ptr::P; -pub fn expand_deriving_default(cx: &mut ExtCtxt, - span: Span, - mitem: &MetaItem, - item: &Item, - push: |P|) { +pub fn expand_deriving_default(cx: &mut ExtCtxt, + span: Span, + mitem: &MetaItem, + item: &Item, + push: F) where + F: FnOnce(P), +{ let inline = cx.meta_word(span, InternedString::new("inline")); let attrs = vec!(cx.attribute(span, inline)); let trait_def = TraitDef { diff --git a/src/libsyntax/ext/deriving/encodable.rs b/src/libsyntax/ext/deriving/encodable.rs index 62f3b5d01b4..30851ebeaae 100644 --- a/src/libsyntax/ext/deriving/encodable.rs +++ b/src/libsyntax/ext/deriving/encodable.rs @@ -97,11 +97,13 @@ use ext::deriving::generic::ty::*; use parse::token; use ptr::P; -pub fn expand_deriving_encodable(cx: &mut ExtCtxt, - span: Span, - mitem: &MetaItem, - item: &Item, - push: |P|) { +pub fn expand_deriving_encodable(cx: &mut ExtCtxt, + span: Span, + mitem: &MetaItem, + item: &Item, + push: F) where + F: FnOnce(P), +{ let trait_def = TraitDef { span: span, attributes: Vec::new(), 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|) { + pub fn expand(&self, + cx: &mut ExtCtxt, + mitem: &ast::MetaItem, + item: &ast::Item, + push: F) where + F: FnOnce(P), + { 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, P, &[P]| -> P, - base: P, - enum_nonmatch_f: EnumNonMatchCollapsedFunc, - cx: &mut ExtCtxt, - trait_span: Span, - substructure: &Substructure) - -> P { +pub fn cs_fold(use_foldl: bool, + mut f: F, + base: P, + enum_nonmatch_f: EnumNonMatchCollapsedFunc, + cx: &mut ExtCtxt, + trait_span: Span, + substructure: &Substructure) + -> P where + F: FnMut(&mut ExtCtxt, Span, P, P, &[P]) -> P, +{ 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, - enum_nonmatch_f: EnumNonMatchCollapsedFunc, - cx: &mut ExtCtxt, - trait_span: Span, - substructure: &Substructure) - -> P { +pub fn cs_same_method(f: F, + enum_nonmatch_f: EnumNonMatchCollapsedFunc, + cx: &mut ExtCtxt, + trait_span: Span, + substructure: &Substructure) + -> P where + F: FnOnce(&mut ExtCtxt, Span, Vec>) -> P, +{ 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, /// 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, P| -> P, - base: P, - enum_nonmatch_f: EnumNonMatchCollapsedFunc, - cx: &mut ExtCtxt, - trait_span: Span, - substructure: &Substructure) - -> P { +pub fn cs_same_method_fold(use_foldl: bool, + mut f: F, + base: P, + enum_nonmatch_f: EnumNonMatchCollapsedFunc, + cx: &mut ExtCtxt, + trait_span: Span, + substructure: &Substructure) + -> P where + F: FnMut(&mut ExtCtxt, Span, P, P) -> P, +{ cs_same_method( |cx, span, vals| { if use_foldl { diff --git a/src/libsyntax/ext/deriving/hash.rs b/src/libsyntax/ext/deriving/hash.rs index b7f11c25825..4e59124a129 100644 --- a/src/libsyntax/ext/deriving/hash.rs +++ b/src/libsyntax/ext/deriving/hash.rs @@ -17,11 +17,13 @@ use ext::deriving::generic::ty::*; use parse::token::InternedString; use ptr::P; -pub fn expand_deriving_hash(cx: &mut ExtCtxt, - span: Span, - mitem: &MetaItem, - item: &Item, - push: |P|) { +pub fn expand_deriving_hash(cx: &mut ExtCtxt, + span: Span, + mitem: &MetaItem, + item: &Item, + push: F) where + F: FnOnce(P), +{ let (path, generics, args) = if cx.ecfg.deriving_hash_type_parameter { (Path::new_(vec!("std", "hash", "Hash"), None, diff --git a/src/libsyntax/ext/deriving/primitive.rs b/src/libsyntax/ext/deriving/primitive.rs index cd2d98b70f1..8abd846373a 100644 --- a/src/libsyntax/ext/deriving/primitive.rs +++ b/src/libsyntax/ext/deriving/primitive.rs @@ -18,11 +18,13 @@ use ext::deriving::generic::ty::*; use parse::token::InternedString; use ptr::P; -pub fn expand_deriving_from_primitive(cx: &mut ExtCtxt, - span: Span, - mitem: &MetaItem, - item: &Item, - push: |P|) { +pub fn expand_deriving_from_primitive(cx: &mut ExtCtxt, + span: Span, + mitem: &MetaItem, + item: &Item, + push: F) where + F: FnOnce(P), +{ let inline = cx.meta_word(span, InternedString::new("inline")); let attrs = vec!(cx.attribute(span, inline)); let trait_def = TraitDef { diff --git a/src/libsyntax/ext/deriving/rand.rs b/src/libsyntax/ext/deriving/rand.rs index c4e64d58c29..4f6e4d1fb3c 100644 --- a/src/libsyntax/ext/deriving/rand.rs +++ b/src/libsyntax/ext/deriving/rand.rs @@ -17,11 +17,13 @@ use ext::deriving::generic::*; use ext::deriving::generic::ty::*; use ptr::P; -pub fn expand_deriving_rand(cx: &mut ExtCtxt, - span: Span, - mitem: &MetaItem, - item: &Item, - push: |P|) { +pub fn expand_deriving_rand(cx: &mut ExtCtxt, + span: Span, + mitem: &MetaItem, + item: &Item, + push: F) where + F: FnOnce(P), +{ let trait_def = TraitDef { span: span, attributes: Vec::new(), @@ -64,7 +66,7 @@ fn rand_substructure(cx: &mut ExtCtxt, trait_span: Span, substr: &Substructure) cx.ident_of("Rand"), cx.ident_of("rand") ); - let rand_call = |cx: &mut ExtCtxt, span| { + let mut rand_call = |&mut: cx: &mut ExtCtxt, span| { cx.expr_call_global(span, rand_ident.clone(), vec!(rng.clone())) @@ -133,12 +135,14 @@ fn rand_substructure(cx: &mut ExtCtxt, trait_span: Span, substr: &Substructure) _ => cx.bug("Non-static method in `deriving(Rand)`") }; - fn rand_thing(cx: &mut ExtCtxt, - trait_span: Span, - ctor_path: ast::Path, - summary: &StaticFields, - rand_call: |&mut ExtCtxt, Span| -> P) - -> P { + fn rand_thing(cx: &mut ExtCtxt, + trait_span: Span, + ctor_path: ast::Path, + summary: &StaticFields, + mut rand_call: F) + -> P where + F: FnMut(&mut ExtCtxt, Span) -> P, + { let path = cx.expr_path(ctor_path.clone()); match *summary { Unnamed(ref fields) => { diff --git a/src/libsyntax/ext/deriving/show.rs b/src/libsyntax/ext/deriving/show.rs index 322a84eaa2b..a68b521bbc9 100644 --- a/src/libsyntax/ext/deriving/show.rs +++ b/src/libsyntax/ext/deriving/show.rs @@ -21,11 +21,13 @@ use ptr::P; use std::collections::HashMap; -pub fn expand_deriving_show(cx: &mut ExtCtxt, - span: Span, - mitem: &MetaItem, - item: &Item, - push: |P|) { +pub fn expand_deriving_show(cx: &mut ExtCtxt, + span: Span, + mitem: &MetaItem, + item: &Item, + push: F) where + F: FnOnce(P), +{ // &mut ::std::fmt::Formatter let fmtr = Ptr(box Literal(Path::new(vec!("std", "fmt", "Formatter"))), Borrowed(None, ast::MutMutable)); diff --git a/src/libsyntax/ext/deriving/zero.rs b/src/libsyntax/ext/deriving/zero.rs index 7f265b529ff..ea32549cad2 100644 --- a/src/libsyntax/ext/deriving/zero.rs +++ b/src/libsyntax/ext/deriving/zero.rs @@ -17,11 +17,13 @@ use ext::deriving::generic::ty::*; use parse::token::InternedString; use ptr::P; -pub fn expand_deriving_zero(cx: &mut ExtCtxt, - span: Span, - mitem: &MetaItem, - item: &Item, - push: |P|) { +pub fn expand_deriving_zero(cx: &mut ExtCtxt, + span: Span, + mitem: &MetaItem, + item: &Item, + push: F) where + F: FnOnce(P), +{ let inline = cx.meta_word(span, InternedString::new("inline")); let attrs = vec!(cx.attribute(span, inline)); let trait_def = TraitDef { diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index a697d332d16..9c4e85f16ff 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -238,11 +238,13 @@ pub fn expand_expr(e: P, fld: &mut MacroExpander) -> P { /// of expansion and the mark which must be applied to the result. /// Our current interface doesn't allow us to apply the mark to the /// result until after calling make_expr, make_items, etc. -fn expand_mac_invoc(mac: ast::Mac, span: codemap::Span, - parse_thunk: |Box|->Option, - mark_thunk: |T,Mrk|->T, - fld: &mut MacroExpander) - -> Option +fn expand_mac_invoc(mac: ast::Mac, span: codemap::Span, + parse_thunk: F, + mark_thunk: G, + fld: &mut MacroExpander) + -> Option where + F: FnOnce(Box) -> Option, + G: FnOnce(T, Mrk) -> T, { match mac.node { // it would almost certainly be cleaner to pass the whole diff --git a/src/libsyntax/ext/mtwt.rs b/src/libsyntax/ext/mtwt.rs index 48120b575ac..a4e06aeaf63 100644 --- a/src/libsyntax/ext/mtwt.rs +++ b/src/libsyntax/ext/mtwt.rs @@ -105,9 +105,11 @@ pub fn apply_renames(renames: &RenameList, ctxt: SyntaxContext) -> SyntaxContext } /// Fetch the SCTable from TLS, create one if it doesn't yet exist. -pub fn with_sctable(op: |&SCTable| -> T) -> T { +pub fn with_sctable(op: F) -> T where + F: FnOnce(&SCTable) -> T, +{ thread_local!(static SCTABLE_KEY: SCTable = new_sctable_internal()) - SCTABLE_KEY.with(|slot| op(slot)) + SCTABLE_KEY.with(move |slot| op(slot)) } // Make a fresh syntax context table with EmptyCtxt in slot zero @@ -167,12 +169,14 @@ type ResolveTable = HashMap<(Name,SyntaxContext),Name>; // okay, I admit, putting this in TLS is not so nice: // fetch the SCTable from TLS, create one if it doesn't yet exist. -fn with_resolve_table_mut(op: |&mut ResolveTable| -> T) -> T { +fn with_resolve_table_mut(op: F) -> T where + F: FnOnce(&mut ResolveTable) -> T, +{ thread_local!(static RESOLVE_TABLE_KEY: RefCell = { RefCell::new(HashMap::new()) }) - RESOLVE_TABLE_KEY.with(|slot| op(&mut *slot.borrow_mut())) + RESOLVE_TABLE_KEY.with(move |slot| op(&mut *slot.borrow_mut())) } /// Resolve a syntax object to a name, per MTWT. diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index 69e311c57f5..0318dd5b0cd 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -32,11 +32,11 @@ use std::rc::Rc; // This could have a better place to live. pub trait MoveMap { - fn move_map(self, f: |T| -> T) -> Self; + fn move_map(self, f: F) -> Self where F: FnMut(T) -> T; } impl MoveMap for Vec { - fn move_map(mut self, f: |T| -> T) -> Vec { + fn move_map(mut self, mut f: F) -> Vec where F: FnMut(T) -> T { for p in self.iter_mut() { unsafe { // FIXME(#5016) this shouldn't need to zero to be safe. @@ -48,7 +48,7 @@ impl MoveMap for Vec { } impl MoveMap for OwnedSlice { - fn move_map(self, f: |T| -> T) -> OwnedSlice { + fn move_map(self, f: F) -> OwnedSlice where F: FnMut(T) -> T { OwnedSlice::from_vec(self.into_vec().move_map(f)) } } diff --git a/src/libsyntax/parse/lexer/mod.rs b/src/libsyntax/parse/lexer/mod.rs index 4c15fae9feb..50c7258fe1c 100644 --- a/src/libsyntax/parse/lexer/mod.rs +++ b/src/libsyntax/parse/lexer/mod.rs @@ -244,7 +244,9 @@ impl<'a> StringReader<'a> { /// Calls `f` with a string slice of the source text spanning from `start` /// up to but excluding `self.last_pos`, meaning the slice does not include /// the character `self.curr`. - pub fn with_str_from(&self, start: BytePos, f: |s: &str| -> T) -> T { + pub fn with_str_from(&self, start: BytePos, f: F) -> T where + F: FnOnce(&str) -> T, + { self.with_str_from_to(start, self.last_pos, f) } @@ -264,7 +266,9 @@ impl<'a> StringReader<'a> { /// Calls `f` with a string slice of the source text spanning from `start` /// up to but excluding `end`. - fn with_str_from_to(&self, start: BytePos, end: BytePos, f: |s: &str| -> T) -> T { + fn with_str_from_to(&self, start: BytePos, end: BytePos, f: F) -> T where + F: FnOnce(&str) -> T, + { f(self.filemap.src.slice( self.byte_offset(start).to_uint(), self.byte_offset(end).to_uint())) diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 92c7380a61d..8c44f9fdf26 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -718,11 +718,12 @@ impl<'a> Parser<'a> { } /// Parse a sequence bracketed by `|` and `|`, stopping before the `|`. - fn parse_seq_to_before_or( - &mut self, - sep: &token::Token, - f: |&mut Parser| -> T) - -> Vec { + fn parse_seq_to_before_or(&mut self, + sep: &token::Token, + mut f: F) + -> Vec where + F: FnMut(&mut Parser) -> T, + { let mut first = true; let mut vector = Vec::new(); while self.token != token::BinOp(token::Or) && @@ -769,10 +770,12 @@ impl<'a> Parser<'a> { } } - pub fn parse_seq_to_before_gt_or_return(&mut self, - sep: Option, - f: |&mut Parser| -> Option) - -> (OwnedSlice, bool) { + pub fn parse_seq_to_before_gt_or_return(&mut self, + sep: Option, + mut f: F) + -> (OwnedSlice, bool) where + F: FnMut(&mut Parser) -> Option, + { let mut v = Vec::new(); // This loop works by alternating back and forth between parsing types // and commas. For example, given a string `A, B,>`, the parser would @@ -802,28 +805,34 @@ impl<'a> Parser<'a> { /// Parse a sequence bracketed by '<' and '>', stopping /// before the '>'. - pub fn parse_seq_to_before_gt(&mut self, - sep: Option, - f: |&mut Parser| -> T) - -> OwnedSlice { + pub fn parse_seq_to_before_gt(&mut self, + sep: Option, + mut f: F) + -> OwnedSlice where + F: FnMut(&mut Parser) -> T, + { let (result, returned) = self.parse_seq_to_before_gt_or_return(sep, |p| Some(f(p))); assert!(!returned); return result; } - pub fn parse_seq_to_gt(&mut self, - sep: Option, - f: |&mut Parser| -> T) - -> OwnedSlice { + pub fn parse_seq_to_gt(&mut self, + sep: Option, + f: F) + -> OwnedSlice where + F: FnMut(&mut Parser) -> T, + { let v = self.parse_seq_to_before_gt(sep, f); self.expect_gt(); return v; } - pub fn parse_seq_to_gt_or_return(&mut self, - sep: Option, - f: |&mut Parser| -> Option) - -> (OwnedSlice, bool) { + pub fn parse_seq_to_gt_or_return(&mut self, + sep: Option, + f: F) + -> (OwnedSlice, bool) where + F: FnMut(&mut Parser) -> Option, + { let (v, returned) = self.parse_seq_to_before_gt_or_return(sep, f); if !returned { self.expect_gt(); @@ -834,12 +843,13 @@ impl<'a> Parser<'a> { /// Parse a sequence, including the closing delimiter. The function /// f must consume tokens until reaching the next separator or /// closing bracket. - pub fn parse_seq_to_end( - &mut self, - ket: &token::Token, - sep: SeqSep, - f: |&mut Parser| -> T) - -> Vec { + pub fn parse_seq_to_end(&mut self, + ket: &token::Token, + sep: SeqSep, + f: F) + -> Vec where + F: FnMut(&mut Parser) -> T, + { let val = self.parse_seq_to_before_end(ket, sep, f); self.bump(); val @@ -848,12 +858,13 @@ impl<'a> Parser<'a> { /// Parse a sequence, not including the closing delimiter. The function /// f must consume tokens until reaching the next separator or /// closing bracket. - pub fn parse_seq_to_before_end( - &mut self, - ket: &token::Token, - sep: SeqSep, - f: |&mut Parser| -> T) - -> Vec { + pub fn parse_seq_to_before_end(&mut self, + ket: &token::Token, + sep: SeqSep, + mut f: F) + -> Vec where + F: FnMut(&mut Parser) -> T, + { let mut first: bool = true; let mut v = vec!(); while self.token != *ket { @@ -873,13 +884,14 @@ impl<'a> Parser<'a> { /// Parse a sequence, including the closing delimiter. The function /// f must consume tokens until reaching the next separator or /// closing bracket. - pub fn parse_unspanned_seq( - &mut self, - bra: &token::Token, - ket: &token::Token, - sep: SeqSep, - f: |&mut Parser| -> T) - -> Vec { + pub fn parse_unspanned_seq(&mut self, + bra: &token::Token, + ket: &token::Token, + sep: SeqSep, + f: F) + -> Vec where + F: FnMut(&mut Parser) -> T, + { self.expect(bra); let result = self.parse_seq_to_before_end(ket, sep, f); self.bump(); @@ -888,13 +900,14 @@ impl<'a> Parser<'a> { /// Parse a sequence parameter of enum variant. For consistency purposes, /// these should not be empty. - pub fn parse_enum_variant_seq( - &mut self, - bra: &token::Token, - ket: &token::Token, - sep: SeqSep, - f: |&mut Parser| -> T) - -> Vec { + pub fn parse_enum_variant_seq(&mut self, + bra: &token::Token, + ket: &token::Token, + sep: SeqSep, + f: F) + -> Vec where + F: FnMut(&mut Parser) -> T, + { let result = self.parse_unspanned_seq(bra, ket, sep, f); if result.is_empty() { let last_span = self.last_span; @@ -906,13 +919,14 @@ impl<'a> Parser<'a> { // NB: Do not use this function unless you actually plan to place the // spanned list in the AST. - pub fn parse_seq( - &mut self, - bra: &token::Token, - ket: &token::Token, - sep: SeqSep, - f: |&mut Parser| -> T) - -> Spanned > { + pub fn parse_seq(&mut self, + bra: &token::Token, + ket: &token::Token, + sep: SeqSep, + f: F) + -> Spanned> where + F: FnMut(&mut Parser) -> T, + { let lo = self.span.lo; self.expect(bra); let result = self.parse_seq_to_before_end(ket, sep, f); @@ -972,8 +986,9 @@ impl<'a> Parser<'a> { } return (4 - self.buffer_start) + self.buffer_end; } - pub fn look_ahead(&mut self, distance: uint, f: |&token::Token| -> R) - -> R { + pub fn look_ahead(&mut self, distance: uint, f: F) -> R where + F: FnOnce(&token::Token) -> R, + { let dist = distance as int; while self.buffer_length() < dist { self.buffer[self.buffer_end as uint] = self.reader.real_token(); @@ -4285,8 +4300,9 @@ impl<'a> Parser<'a> { /// Parse the argument list and result type of a function /// that may have a self type. - fn parse_fn_decl_with_self(&mut self, parse_arg_fn: |&mut Parser| -> Arg) - -> (ExplicitSelf, P) { + fn parse_fn_decl_with_self(&mut self, parse_arg_fn: F) -> (ExplicitSelf, P) where + F: FnMut(&mut Parser) -> Arg, + { fn maybe_parse_borrowed_explicit_self(this: &mut Parser) -> ast::ExplicitSelf_ { // The following things are possible to see here: diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 26373d00aaf..6d8b8dcb8ba 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -165,7 +165,9 @@ impl<'a> State<'a> { } } -pub fn to_string(f: |&mut State| -> IoResult<()>) -> String { +pub fn to_string(f: F) -> String where + F: FnOnce(&mut State) -> IoResult<()>, +{ use std::raw::TraitObject; let mut s = rust_printer(box Vec::new()); f(&mut s).unwrap(); @@ -426,8 +428,10 @@ pub mod with_hygiene { // This function is the trick that all the rest of the routines // hang on. - pub fn to_string_hyg(f: |&mut super::State| -> IoResult<()>) -> String { - super::to_string(|s| { + pub fn to_string_hyg(f: F) -> String where + F: FnOnce(&mut super::State) -> IoResult<()>, + { + super::to_string(move |s| { s.encode_idents_with_hygiene = true; f(s) }) @@ -580,9 +584,9 @@ impl<'a> State<'a> { word(&mut self.s, "*/") } - pub fn commasep(&mut self, b: Breaks, elts: &[T], - op: |&mut State, &T| -> IoResult<()>) - -> IoResult<()> { + pub fn commasep(&mut self, b: Breaks, elts: &[T], mut op: F) -> IoResult<()> where + F: FnMut(&mut State, &T) -> IoResult<()>, + { try!(self.rbox(0u, b)); let mut first = true; for elt in elts.iter() { @@ -593,12 +597,14 @@ impl<'a> State<'a> { } - pub fn commasep_cmnt( - &mut self, - b: Breaks, - elts: &[T], - op: |&mut State, &T| -> IoResult<()>, - get_span: |&T| -> codemap::Span) -> IoResult<()> { + pub fn commasep_cmnt(&mut self, + b: Breaks, + elts: &[T], + mut op: F, + mut get_span: G) -> IoResult<()> where + F: FnMut(&mut State, &T) -> IoResult<()>, + G: FnMut(&T) -> codemap::Span, + { try!(self.rbox(0u, b)); let len = elts.len(); let mut i = 0u; diff --git a/src/libsyntax/ptr.rs b/src/libsyntax/ptr.rs index 1b231ed861b..1b3ebde2461 100644 --- a/src/libsyntax/ptr.rs +++ b/src/libsyntax/ptr.rs @@ -56,12 +56,16 @@ pub fn P(value: T) -> P { impl P { /// Move out of the pointer. /// Intended for chaining transformations not covered by `map`. - pub fn and_then(self, f: |T| -> U) -> U { + pub fn and_then(self, f: F) -> U where + F: FnOnce(T) -> U, + { f(*self.ptr) } /// Transform the inner value, consuming `self` and producing a new `P`. - pub fn map(mut self, f: |T| -> T) -> P { + pub fn map(mut self, f: F) -> P where + F: FnOnce(T) -> T, + { unsafe { let p = &mut *self.ptr; // FIXME(#5016) this shouldn't need to zero to be safe. diff --git a/src/libsyntax/util/parser_testing.rs b/src/libsyntax/util/parser_testing.rs index c1ea8f60b82..83bbff8473d 100644 --- a/src/libsyntax/util/parser_testing.rs +++ b/src/libsyntax/util/parser_testing.rs @@ -31,7 +31,9 @@ pub fn string_to_parser<'a>(ps: &'a ParseSess, source_str: String) -> Parser<'a> source_str) } -fn with_error_checking_parse(s: String, f: |&mut Parser| -> T) -> T { +fn with_error_checking_parse(s: String, f: F) -> T where + F: FnOnce(&mut Parser) -> T, +{ let ps = new_parse_sess(); let mut p = string_to_parser(&ps, s); let x = f(&mut p); diff --git a/src/libsyntax/util/small_vector.rs b/src/libsyntax/util/small_vector.rs index d56e4f70449..8d050e34abf 100644 --- a/src/libsyntax/util/small_vector.rs +++ b/src/libsyntax/util/small_vector.rs @@ -171,7 +171,7 @@ impl Iterator for MoveItems { } impl MoveMap for SmallVector { - fn move_map(self, f: |T| -> T) -> SmallVector { + fn move_map(self, mut f: F) -> SmallVector where F: FnMut(T) -> T { let repr = match self.repr { Zero => Zero, One(v) => One(f(v)), -- cgit 1.4.1-3-g733a5