]> git.lizzy.rs Git - rust.git/commitdiff
'Borrow' stack closures rather than copying them (e.g., "|x|f(x)"), in prep for makin...
authorBen Blum <bblum@andrew.cmu.edu>
Sat, 22 Jun 2013 00:08:35 +0000 (20:08 -0400)
committerBen Blum <bblum@andrew.cmu.edu>
Sat, 29 Jun 2013 08:39:34 +0000 (04:39 -0400)
28 files changed:
src/libextra/fun_treemap.rs
src/libextra/rope.rs
src/libextra/sort.rs
src/libextra/sync.rs
src/libextra/test.rs
src/libextra/treemap.rs
src/libextra/workcache.rs
src/librustc/metadata/filesearch.rs
src/librustc/metadata/tydecode.rs
src/librustc/middle/borrowck/move_data.rs
src/librustc/middle/mem_categorization.rs
src/librustc/middle/trans/base.rs
src/librustc/middle/ty.rs
src/librustc/middle/typeck/check/regionmanip.rs
src/librustc/middle/typeck/infer/mod.rs
src/libstd/hashmap.rs
src/libstd/iterator.rs
src/libstd/os.rs
src/libstd/str.rs
src/libstd/task/spawn.rs
src/libstd/to_bytes.rs
src/libstd/trie.rs
src/libstd/vec.rs
src/libsyntax/ast_util.rs
src/libsyntax/ext/base.rs
src/libsyntax/ext/deriving/iter_bytes.rs
src/libsyntax/ext/deriving/rand.rs
src/test/compile-fail/regions-creating-enums.rs

index eb8c27e9902b5bb047b247f49e5dc0ab5143236a..5906e809c98561dc936d397f7b99248609704f0a 100644 (file)
@@ -66,9 +66,9 @@ pub fn traverse<K, V: Copy>(m: Treemap<K, V>, f: &fn(&K, &V)) {
         // matches to me, so I changed it. but that may be a
         // de-optimization -- tjc
         Node(@ref k, @ref v, left, right) => {
-            traverse(left, f);
+            traverse(left, |k,v| f(k,v));
             f(k, v);
-            traverse(right, f);
+            traverse(right, |k,v| f(k,v));
         }
     }
 }
index fed73256c002c18164e7eff2d24d373edffaf28b..71393ff9fae20116358dec064bb67795b8e38805 100644 (file)
@@ -1078,7 +1078,7 @@ pub fn cmp(a: @Node, b: @Node) -> int {
 
     pub fn loop_chars(node: @Node, it: &fn(c: char) -> bool) -> bool {
         return loop_leaves(node,|leaf| {
-            leaf.content.slice(leaf.byte_offset, leaf.byte_len).iter().all(it)
+            leaf.content.slice(leaf.byte_offset, leaf.byte_len).iter().all(|c| it(c))
         });
     }
 
@@ -1101,7 +1101,7 @@ pub fn loop_leaves(node: @Node, it: &fn(Leaf) -> bool) -> bool{
         loop {
             match (*current) {
               Leaf(x) => return it(x),
-              Concat(ref x) => if loop_leaves(x.left, it) { //non tail call
+              Concat(ref x) => if loop_leaves(x.left, |l| it(l)) { //non tail call
                 current = x.right;       //tail call
               } else {
                 return false;
index 6befd49e8afdfb02a59a18ab6d7daeb9810ae828..10dbe2326d76236441cbca0283884a1627e949e5 100644 (file)
@@ -42,7 +42,8 @@ fn merge_sort_<T:Copy>(v: &[T], slice: Slice, le: Le<T>)
         let mid = v_len / 2 + begin;
         let a = (begin, mid);
         let b = (mid, end);
-        return merge(le, merge_sort_(v, a, le), merge_sort_(v, b, le));
+        return merge(|x,y| le(x,y), merge_sort_(v, a, |x,y| le(x,y)),
+                                    merge_sort_(v, b, |x,y| le(x,y)));
     }
 
     fn merge<T:Copy>(le: Le<T>, a: &[T], b: &[T]) -> ~[T] {
@@ -83,10 +84,10 @@ fn qsort<T>(arr: &mut [T], left: uint,
             right: uint, compare_func: Le<T>) {
     if right > left {
         let pivot = (left + right) / 2u;
-        let new_pivot = part::<T>(arr, left, right, pivot, compare_func);
+        let new_pivot = part::<T>(arr, left, right, pivot, |x,y| compare_func(x,y));
         if new_pivot != 0u {
             // Need to do this check before recursing due to overflow
-            qsort::<T>(arr, left, new_pivot - 1u, compare_func);
+            qsort::<T>(arr, left, new_pivot - 1u, |x,y| compare_func(x,y));
         }
         qsort::<T>(arr, new_pivot + 1u, right, compare_func);
     }
index 3908b61381b78bb18f3980e211b78991f371510d..9c6be901d980a87e051d52e0d4065f50e2c41b67 100644 (file)
@@ -563,7 +563,9 @@ pub fn write<U>(&self, blk: &fn() -> U) -> U {
                 (&self.order_lock).acquire();
                 do (&self.access_lock).access_waitqueue {
                     (&self.order_lock).release();
-                    task::rekillable(blk)
+                    do task::rekillable {
+                        blk()
+                    }
                 }
             }
         }
@@ -1182,12 +1184,12 @@ fn lock_rwlock_in_mode(x: &RWlock, mode: RWlockMode, blk: &fn()) {
             Write => x.write(blk),
             Downgrade =>
                 do x.write_downgrade |mode| {
-                    (&mode).write(blk);
+                    do mode.write { blk() };
                 },
             DowngradeRead =>
                 do x.write_downgrade |mode| {
                     let mode = x.downgrade(mode);
-                    (&mode).read(blk);
+                    do mode.read { blk() };
                 },
         }
     }
@@ -1340,10 +1342,10 @@ fn test_rwlock_cond_broadcast_helper(num_waiters: uint,
         fn lock_cond(x: &RWlock, downgrade: bool, blk: &fn(c: &Condvar)) {
             if downgrade {
                 do x.write_downgrade |mode| {
-                    (&mode).write_cond(blk)
+                    do mode.write_cond |c| { blk(c) }
                 }
             } else {
-                x.write_cond(blk)
+                do x.write_cond |c| { blk(c) }
             }
         }
         let x = ~RWlock();
index 209b46809ce31d24308ba8dbb2a96cc140f601d0..50ca96e6e21df12d77a8b6bd8685b7356d6ee4e1 100644 (file)
@@ -678,7 +678,7 @@ fn round_up(n: u64) -> u64 {
 
         // Initial bench run to get ballpark figure.
         let mut n = 1_u64;
-        self.bench_n(n, f);
+        self.bench_n(n, |x| f(x));
 
         while n < 1_000_000_000 &&
             self.ns_elapsed() < 1_000_000_000 {
@@ -694,7 +694,7 @@ fn round_up(n: u64) -> u64 {
 
             n = u64::max(u64::min(n+n/2, 100*last), last+1);
             n = round_up(n);
-            self.bench_n(n, f);
+            self.bench_n(n, |x| f(x));
         }
     }
 
@@ -714,7 +714,7 @@ pub fn auto_bench(&mut self, f: &fn(&mut BenchHarness)) -> ~[f64] {
                                             magnitude * 2);
 
             let samples = do vec::from_fn(n_samples) |_| {
-                self.bench_n(n_iter as u64, f);
+                self.bench_n(n_iter as u64, |x| f(x));
                 self.ns_per_iter() as f64
             };
 
index 4622b8c7284841b2e065193796899580e3f6c374..d546b48f81751de633212096e320690c376d9b8a 100644 (file)
@@ -511,14 +511,14 @@ pub fn new(key: K, value: V) -> TreeNode<K, V> {
 
 fn each<'r, K: TotalOrd, V>(node: &'r Option<~TreeNode<K, V>>,
                             f: &fn(&'r K, &'r V) -> bool) -> bool {
-    node.iter().advance(|x| each(&x.left, f) && f(&x.key, &x.value) &&
-                            each(&x.right, f))
+    node.iter().advance(|x| each(&x.left,  |k,v| f(k,v)) && f(&x.key, &x.value) &&
+                            each(&x.right, |k,v| f(k,v)))
 }
 
 fn each_reverse<'r, K: TotalOrd, V>(node: &'r Option<~TreeNode<K, V>>,
                                     f: &fn(&'r K, &'r V) -> bool) -> bool {
-    node.iter().advance(|x| each_reverse(&x.right, f) && f(&x.key, &x.value) &&
-                            each_reverse(&x.left, f))
+    node.iter().advance(|x| each_reverse(&x.right, |k,v| f(k,v)) && f(&x.key, &x.value) &&
+                            each_reverse(&x.left,  |k,v| f(k,v)))
 }
 
 fn mutate_values<'r, K: TotalOrd, V>(node: &'r mut Option<~TreeNode<K, V>>,
@@ -527,9 +527,9 @@ fn mutate_values<'r, K: TotalOrd, V>(node: &'r mut Option<~TreeNode<K, V>>,
     match *node {
       Some(~TreeNode{key: ref key, value: ref mut value, left: ref mut left,
                      right: ref mut right, _}) => {
-        if !mutate_values(left, f) { return false }
+        if !mutate_values(left,  |k,v| f(k,v)) { return false }
         if !f(key, value) { return false }
-        if !mutate_values(right, f) { return false }
+        if !mutate_values(right, |k,v| f(k,v)) { return false }
       }
       None => return false
     }
index 567f9eda2fbae460159a8c2e6c81b35a9c876732..4d4f3c3a49b0141bf6e15b71662be6ffdefa6de7 100644 (file)
@@ -107,7 +107,7 @@ struct WorkKey {
 impl to_bytes::IterBytes for WorkKey {
     #[inline]
     fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) -> bool {
-        self.kind.iter_bytes(lsb0, f) && self.name.iter_bytes(lsb0, f)
+        self.kind.iter_bytes(lsb0, |b| f(b)) && self.name.iter_bytes(lsb0, |b| f(b))
     }
 }
 
index 6268932ba9958a3f06265091ba7ca85b8d4e4775..abfb5f7d4d4bf5369abf37f88616133bb9997715 100644 (file)
@@ -48,7 +48,7 @@ fn for_each_lib_search_path(&self, f: &fn(&Path) -> bool) -> bool {
             debug!("filesearch: searching additional lib search paths [%?]",
                    self.addl_lib_search_paths.len());
             // a little weird
-            self.addl_lib_search_paths.iter().advance(f);
+            self.addl_lib_search_paths.iter().advance(|path| f(path));
 
             debug!("filesearch: searching target lib path");
             if !f(&make_target_lib_path(self.sysroot,
index 1ec5c983f624819bc697666cf6c21de838317ae8..22786581073443b1bd7503dd197000a1dd16e861 100644 (file)
@@ -189,11 +189,11 @@ fn parse_trait_store(st: &mut PState) -> ty::TraitStore {
 fn parse_substs(st: &mut PState, conv: conv_did) -> ty::substs {
     let self_r = parse_opt(st, |st| parse_region(st) );
 
-    let self_ty = parse_opt(st, |st| parse_ty(st, conv) );
+    let self_ty = parse_opt(st, |st| parse_ty(st, |x,y| conv(x,y)) );
 
     assert_eq!(next(st), '[');
     let mut params: ~[ty::t] = ~[];
-    while peek(st) != ']' { params.push(parse_ty(st, conv)); }
+    while peek(st) != ']' { params.push(parse_ty(st, |x,y| conv(x,y))); }
     st.pos = st.pos + 1u;
 
     return ty::substs {
@@ -270,8 +270,8 @@ fn parse_str(st: &mut PState, term: char) -> ~str {
 }
 
 fn parse_trait_ref(st: &mut PState, conv: conv_did) -> ty::TraitRef {
-    let def = parse_def(st, NominalType, conv);
-    let substs = parse_substs(st, conv);
+    let def = parse_def(st, NominalType, |x,y| conv(x,y));
+    let substs = parse_substs(st, |x,y| conv(x,y));
     ty::TraitRef {def_id: def, substs: substs}
 }
 
@@ -301,18 +301,18 @@ fn parse_ty(st: &mut PState, conv: conv_did) -> ty::t {
       'c' => return ty::mk_char(),
       't' => {
         assert_eq!(next(st), '[');
-        let def = parse_def(st, NominalType, conv);
-        let substs = parse_substs(st, conv);
+        let def = parse_def(st, NominalType, |x,y| conv(x,y));
+        let substs = parse_substs(st, |x,y| conv(x,y));
         assert_eq!(next(st), ']');
         return ty::mk_enum(st.tcx, def, substs);
       }
       'x' => {
         assert_eq!(next(st), '[');
-        let def = parse_def(st, NominalType, conv);
-        let substs = parse_substs(st, conv);
+        let def = parse_def(st, NominalType, |x,y| conv(x,y));
+        let substs = parse_substs(st, |x,y| conv(x,y));
         let store = parse_trait_store(st);
         let mt = parse_mutability(st);
-        let bounds = parse_bounds(st, conv);
+        let bounds = parse_bounds(st, |x,y| conv(x,y));
         assert_eq!(next(st), ']');
         return ty::mk_trait(st.tcx, def, substs, store, mt, bounds.builtin_bounds);
       }
@@ -346,7 +346,7 @@ fn parse_ty(st: &mut PState, conv: conv_did) -> ty::t {
       'T' => {
         assert_eq!(next(st), '[');
         let mut params = ~[];
-        while peek(st) != ']' { params.push(parse_ty(st, conv)); }
+        while peek(st) != ']' { params.push(parse_ty(st, |x,y| conv(x,y))); }
         st.pos = st.pos + 1u;
         return ty::mk_tup(st.tcx, params);
       }
@@ -380,15 +380,15 @@ fn parse_ty(st: &mut PState, conv: conv_did) -> ty::t {
         }
       }
       '"' => {
-        let _ = parse_def(st, TypeWithId, conv);
-        let inner = parse_ty(st, conv);
+        let _ = parse_def(st, TypeWithId, |x,y| conv(x,y));
+        let inner = parse_ty(st, |x,y| conv(x,y));
         inner
       }
       'B' => ty::mk_opaque_box(st.tcx),
       'a' => {
           assert_eq!(next(st), '[');
-          let did = parse_def(st, NominalType, conv);
-          let substs = parse_substs(st, conv);
+          let did = parse_def(st, NominalType, |x,y| conv(x,y));
+          let substs = parse_substs(st, |x,y| conv(x,y));
           assert_eq!(next(st), ']');
           return ty::mk_struct(st.tcx, did, substs);
       }
@@ -473,8 +473,8 @@ fn parse_closure_ty(st: &mut PState, conv: conv_did) -> ty::ClosureTy {
     let purity = parse_purity(next(st));
     let onceness = parse_onceness(next(st));
     let region = parse_region(st);
-    let bounds = parse_bounds(st, conv);
-    let sig = parse_sig(st, conv);
+    let bounds = parse_bounds(st, |x,y| conv(x,y));
+    let sig = parse_sig(st, |x,y| conv(x,y));
     ty::ClosureTy {
         purity: purity,
         sigil: sigil,
@@ -500,7 +500,7 @@ fn parse_sig(st: &mut PState, conv: conv_did) -> ty::FnSig {
     assert_eq!(next(st), '[');
     let mut inputs = ~[];
     while peek(st) != ']' {
-        inputs.push(parse_ty(st, conv));
+        inputs.push(parse_ty(st, |x,y| conv(x,y)));
     }
     st.pos += 1u; // eat the ']'
     let ret_ty = parse_ty(st, conv);
@@ -544,8 +544,8 @@ pub fn parse_type_param_def_data(data: &[u8], start: uint,
 }
 
 fn parse_type_param_def(st: &mut PState, conv: conv_did) -> ty::TypeParameterDef {
-    ty::TypeParameterDef {def_id: parse_def(st, NominalType, conv),
-                          bounds: @parse_bounds(st, conv)}
+    ty::TypeParameterDef {def_id: parse_def(st, NominalType, |x,y| conv(x,y)),
+                          bounds: @parse_bounds(st, |x,y| conv(x,y))}
 }
 
 fn parse_bounds(st: &mut PState, conv: conv_did) -> ty::ParamBounds {
@@ -571,7 +571,7 @@ fn parse_bounds(st: &mut PState, conv: conv_did) -> ty::ParamBounds {
                 param_bounds.builtin_bounds.add(ty::BoundSized);
             }
             'I' => {
-                param_bounds.trait_bounds.push(@parse_trait_ref(st, conv));
+                param_bounds.trait_bounds.push(@parse_trait_ref(st, |x,y| conv(x,y)));
             }
             '.' => {
                 return param_bounds;
index 7396dc1bd7bff0c66e8d439d14c6ebc4a3b35d99..623dbbd61b244cf1971fa4984fb95e3dca3f3d88 100644 (file)
@@ -411,7 +411,7 @@ fn each_extending_path(&self,
 
         let mut p = self.path(index).first_child;
         while p != InvalidMovePathIndex {
-            if !self.each_extending_path(p, f) {
+            if !self.each_extending_path(p, |x| f(x)) {
                 return false;
             }
             p = self.path(p).next_sibling;
index 52c01fa76476bb6b3204b1c395032b49a671b1c9..a2907e9912092ff8a2ac53463d6a6d67ca0e3bb3 100644 (file)
@@ -890,7 +890,7 @@ pub fn cat_pattern(&self,
                                 pat, downcast_cmt, subpat_ty,
                                 InteriorField(PositionalField(i)));
 
-                        self.cat_pattern(subcmt, subpat, op);
+                        self.cat_pattern(subcmt, subpat, |x,y| op(x,y));
                     }
                 }
                 Some(&ast::def_fn(*)) |
@@ -901,12 +901,12 @@ pub fn cat_pattern(&self,
                             self.cat_imm_interior(
                                 pat, cmt, subpat_ty,
                                 InteriorField(PositionalField(i)));
-                        self.cat_pattern(cmt_field, subpat, op);
+                        self.cat_pattern(cmt_field, subpat, |x,y| op(x,y));
                     }
                 }
                 Some(&ast::def_static(*)) => {
                     for subpats.iter().advance |&subpat| {
-                        self.cat_pattern(cmt, subpat, op);
+                        self.cat_pattern(cmt, subpat, |x,y| op(x,y));
                     }
                 }
                 _ => {
@@ -930,7 +930,7 @@ pub fn cat_pattern(&self,
             for field_pats.iter().advance |fp| {
                 let field_ty = self.pat_ty(fp.pat); // see (*)
                 let cmt_field = self.cat_field(pat, cmt, fp.ident, field_ty);
-                self.cat_pattern(cmt_field, fp.pat, op);
+                self.cat_pattern(cmt_field, fp.pat, |x,y| op(x,y));
             }
           }
 
@@ -942,7 +942,7 @@ pub fn cat_pattern(&self,
                     self.cat_imm_interior(
                         pat, cmt, subpat_ty,
                         InteriorField(PositionalField(i)));
-                self.cat_pattern(subcmt, subpat, op);
+                self.cat_pattern(subcmt, subpat, |x,y| op(x,y));
             }
           }
 
@@ -956,15 +956,15 @@ pub fn cat_pattern(&self,
           ast::pat_vec(ref before, slice, ref after) => {
               let elt_cmt = self.cat_index(pat, cmt, 0);
               for before.iter().advance |&before_pat| {
-                  self.cat_pattern(elt_cmt, before_pat, op);
+                  self.cat_pattern(elt_cmt, before_pat, |x,y| op(x,y));
               }
               for slice.iter().advance |&slice_pat| {
                   let slice_ty = self.pat_ty(slice_pat);
                   let slice_cmt = self.cat_rvalue(pat, slice_ty);
-                  self.cat_pattern(slice_cmt, slice_pat, op);
+                  self.cat_pattern(slice_cmt, slice_pat, |x,y| op(x,y));
               }
               for after.iter().advance |&after_pat| {
-                  self.cat_pattern(elt_cmt, after_pat, op);
+                  self.cat_pattern(elt_cmt, after_pat, |x,y| op(x,y));
               }
           }
 
index efa69ab5e625bd6d36cbe82cf25b69e2cb77344b..d9fea12134684b98b135cf3b4d0e88c6bde1298d 100644 (file)
@@ -674,7 +674,7 @@ fn iter_variant(cx: block, repr: &adt::Repr, av: ValueRef,
                                     int::to_str(variant.disr_val));
                       let variant_cx =
                           iter_variant(variant_cx, repr, av, *variant,
-                                       substs.tps, f);
+                                       substs.tps, |x,y,z| f(x,y,z));
                       match adt::trans_case(cx, repr, variant.disr_val) {
                           _match::single_result(r) => {
                               AddCase(llswitch, r.val, variant_cx.llbb)
index a990e4c70a94cbd5c0036264bc1017eecdbe7580..9f9127663af78dab2037713d695de129e1147360 100644 (file)
@@ -1241,15 +1241,15 @@ pub fn maybe_walk_ty(ty: t, f: &fn(t) -> bool) {
       }
       ty_enum(_, ref substs) | ty_struct(_, ref substs) |
       ty_trait(_, ref substs, _, _, _) => {
-        for (*substs).tps.iter().advance |subty| { maybe_walk_ty(*subty, f); }
+        for (*substs).tps.iter().advance |subty| { maybe_walk_ty(*subty, |x| f(x)); }
       }
-      ty_tup(ref ts) => { for ts.iter().advance |tt| { maybe_walk_ty(*tt, f); } }
+      ty_tup(ref ts) => { for ts.iter().advance |tt| { maybe_walk_ty(*tt, |x| f(x)); } }
       ty_bare_fn(ref ft) => {
-        for ft.sig.inputs.iter().advance |a| { maybe_walk_ty(*a, f); }
+        for ft.sig.inputs.iter().advance |a| { maybe_walk_ty(*a, |x| f(x)); }
         maybe_walk_ty(ft.sig.output, f);
       }
       ty_closure(ref ft) => {
-        for ft.sig.inputs.iter().advance |a| { maybe_walk_ty(*a, f); }
+        for ft.sig.inputs.iter().advance |a| { maybe_walk_ty(*a, |x| f(x)); }
         maybe_walk_ty(ft.sig.output, f);
       }
     }
@@ -1331,7 +1331,7 @@ fn fold_substs(substs: &substs, fldop: &fn(t) -> t) -> substs {
 
 // Folds types from the bottom up.
 pub fn fold_ty(cx: ctxt, t0: t, fldop: &fn(t) -> t) -> t {
-    let sty = fold_sty(&get(t0).sty, |t| fold_ty(cx, fldop(t), fldop));
+    let sty = fold_sty(&get(t0).sty, |t| fold_ty(cx, fldop(t), |t| fldop(t)));
     fldop(mk_t(cx, sty))
 }
 
@@ -1345,8 +1345,8 @@ pub fn walk_regions_and_ty(
         fold_regions_and_ty(
             cx, ty,
             |r| { walkr(r); r },
-            |t| { walk_regions_and_ty(cx, t, walkr, walkt); t },
-            |t| { walk_regions_and_ty(cx, t, walkr, walkt); t });
+            |t| { walk_regions_and_ty(cx, t, |r| walkr(r), |t| walkt(t)); t },
+            |t| { walk_regions_and_ty(cx, t, |r| walkr(r), |t| walkt(t)); t });
     }
 }
 
@@ -1426,8 +1426,8 @@ fn do_fold(cx: ctxt, ty: t, in_fn: bool,
         fold_regions_and_ty(
             cx, ty,
             |r| fldr(r, in_fn),
-            |t| do_fold(cx, t, true, fldr),
-            |t| do_fold(cx, t, in_fn, fldr))
+            |t| do_fold(cx, t, true,  |r,b| fldr(r,b)),
+            |t| do_fold(cx, t, in_fn, |r,b| fldr(r,b)))
     }
     do_fold(cx, ty, false, fldr)
 }
@@ -2374,7 +2374,7 @@ pub fn type_structurally_contains(cx: ctxt,
         for (*enum_variants(cx, did)).iter().advance |variant| {
             for variant.args.iter().advance |aty| {
                 let sty = subst(cx, substs, *aty);
-                if type_structurally_contains(cx, sty, test) { return true; }
+                if type_structurally_contains(cx, sty, |x| test(x)) { return true; }
             }
         }
         return false;
@@ -2383,14 +2383,14 @@ pub fn type_structurally_contains(cx: ctxt,
         let r = lookup_struct_fields(cx, did);
         for r.iter().advance |field| {
             let ft = lookup_field_type(cx, did, field.id, substs);
-            if type_structurally_contains(cx, ft, test) { return true; }
+            if type_structurally_contains(cx, ft, |x| test(x)) { return true; }
         }
         return false;
       }
 
       ty_tup(ref ts) => {
         for ts.iter().advance |tt| {
-            if type_structurally_contains(cx, *tt, test) { return true; }
+            if type_structurally_contains(cx, *tt, |x| test(x)) { return true; }
         }
         return false;
       }
index 160737142c8ca75e47c44333d6a3ba32c7a15490..fb79a7c3c994e1f978a5596528cad68c65e10214 100644 (file)
@@ -112,7 +112,7 @@ fn append_isr(isr: isr_alist,
             // kinds of types.  This had already caused me several
             // bugs so I decided to switch over.
             do ty::fold_regions(tcx, *ty) |r, in_fn| {
-                if !in_fn { isr = append_isr(isr, to_r, r); }
+                if !in_fn { isr = append_isr(isr, |br| to_r(br), r); }
                 r
             };
 
@@ -211,18 +211,18 @@ fn walk_ty(tcx: ty::ctxt,
         match ty::get(ty).sty {
             ty::ty_rptr(r, ref mt) |
             ty::ty_evec(ref mt, ty::vstore_slice(r)) => {
-                relate(*the_stack, r, relate_op);
+                relate(*the_stack, r, |x,y| relate_op(x,y));
                 the_stack.push(r);
-                walk_ty(tcx, the_stack, mt.ty, relate_op);
+                walk_ty(tcx, the_stack, mt.ty, |x,y| relate_op(x,y));
                 the_stack.pop();
             }
             _ => {
                 ty::fold_regions_and_ty(
                     tcx,
                     ty,
-                    |r| { relate(*the_stack, r, relate_op); r },
-                    |t| { walk_ty(tcx, the_stack, t, relate_op); t },
-                    |t| { walk_ty(tcx, the_stack, t, relate_op); t });
+                    |r| { relate(     *the_stack, r, |x,y| relate_op(x,y)); r },
+                    |t| { walk_ty(tcx, the_stack, t, |x,y| relate_op(x,y)); t },
+                    |t| { walk_ty(tcx, the_stack, t, |x,y| relate_op(x,y)); t });
             }
         }
     }
index 1bfe452f25e09a54448abb6a6ed8ed228a2d66a1..3e2d4a71dfbe9a430fd4dd3d57c2a4689025a8dc 100644 (file)
@@ -582,7 +582,7 @@ pub fn commit<T,E>(@mut self, f: &fn() -> Result<T,E>) -> Result<T,E> {
 
         debug!("commit()");
         do indent {
-            let r = self.try(f);
+            let r = self.try(|| f());
 
             self.ty_var_bindings.bindings.truncate(0);
             self.int_var_bindings.bindings.truncate(0);
@@ -836,6 +836,6 @@ pub fn fold_regions_in_sig(
     fldr: &fn(r: ty::Region, in_fn: bool) -> ty::Region) -> ty::FnSig
 {
     do ty::fold_sig(fn_sig) |t| {
-        ty::fold_regions(tcx, t, fldr)
+        ty::fold_regions(tcx, t, |r, in_fn| fldr(r, in_fn))
     }
 }
index bfa0f2fa124d222173bf569639dfa893f355daf5..7f9fb6ad9380f71e31ab52e440d48e9041ef1f03 100644 (file)
@@ -671,7 +671,7 @@ fn difference(&self, other: &HashSet<T>, f: &fn(&T) -> bool) -> bool {
     fn symmetric_difference(&self,
                             other: &HashSet<T>,
                             f: &fn(&T) -> bool) -> bool {
-        self.difference(other, f) && other.difference(self, f)
+        self.difference(other, |t| f(t)) && other.difference(self, |t| f(t))
     }
 
     /// Visit the values representing the intersection
@@ -681,7 +681,8 @@ fn intersection(&self, other: &HashSet<T>, f: &fn(&T) -> bool) -> bool {
 
     /// Visit the values representing the union
     fn union(&self, other: &HashSet<T>, f: &fn(&T) -> bool) -> bool {
-        self.iter().advance(f) && other.iter().advance(|v| self.contains(v) || f(v))
+        self.iter().advance(|t| f(t)) &&
+            other.iter().advance(|v| self.contains(v) || f(v))
     }
 }
 
index 765bf3b36f2850b833995f84b31d5446cac9b026..976ca8bae7a87ca681a897d5cd67a980dc83d6b1 100644 (file)
@@ -964,7 +964,7 @@ fn next(&mut self) -> Option<B> {
                     return Some(x)
                 }
             }
-            match self.iter.next().map_consume(self.f) {
+            match self.iter.next().map_consume(|x| (self.f)(x)) {
                 None => return None,
                 next => self.subiter = next,
             }
index 400a93ee28f4e667a9e6d97e4c63746b2c94dfdc..1fbcda12dce14ba98e47ceaa02b03e8e6288b33f 100644 (file)
@@ -595,7 +595,7 @@ pub fn walk_dir(p: &Path, f: &fn(&Path) -> bool) -> bool {
     let r = list_dir(p);
     r.iter().advance(|q| {
         let path = &p.push(*q);
-        f(path) && (!path_is_dir(path) || walk_dir(path, f))
+        f(path) && (!path_is_dir(path) || walk_dir(path, |p| f(p)))
     })
 }
 
index 2144afc0fbd1858d6390f11c87e9b4d728428293..e47800d70c6b56953558dd88662d5d1916802960 100644 (file)
@@ -463,7 +463,7 @@ enum LengthLimit {
         cont
     };
 
-    ss.iter().enumerate().advance(machine);
+    ss.iter().enumerate().advance(|x| machine(x));
 
     // Let the automaton 'run out' by supplying trailing whitespace
     let mut fake_i = ss.len();
@@ -761,7 +761,7 @@ fn as_c_str<T>(self, f: &fn(*libc::c_char) -> T) -> T {
             // NB: len includes the trailing null.
             assert!(len > 0);
             if unsafe { *(ptr::offset(buf,len-1)) != 0 } {
-                to_owned(self).as_c_str(f)
+                to_owned(self).as_c_str(|s| f(s))
             } else {
                 f(buf as *libc::c_char)
             }
index 8f06fede05722d794f1a172c7cc727f47f0d50c3..c932a9660c2fd0f7f36933e79a0820890161851f 100644 (file)
@@ -230,11 +230,15 @@ fn iterate(ancestors:       &AncestorList,
         // 'do_continue'  - Did the forward_blk succeed at this point? (i.e.,
         //                  should we recurse? or should our callers unwind?)
 
+        let forward_blk = Cell::new(forward_blk);
+
         // The map defaults to None, because if ancestors is None, we're at
         // the end of the list, which doesn't make sense to coalesce.
         return do (**ancestors).map_default((None,false)) |ancestor_arc| {
             // NB: Takes a lock! (this ancestor node)
             do access_ancestors(ancestor_arc) |nobe| {
+                // Argh, but we couldn't give it to coalesce() otherwise.
+                let forward_blk = forward_blk.take();
                 // Check monotonicity
                 assert!(last_generation > nobe.generation);
                 /*##########################################################*
index 6f0c615d007c2050227815618c3433dab867ea05..d6e92dd679ea17b27f84f095087da72d5b0f8f52 100644 (file)
@@ -232,7 +232,8 @@ impl<A:IterBytes,B:IterBytes> IterBytes for (A,B) {
   #[inline]
   fn iter_bytes(&self, lsb0: bool, f: Cb) -> bool {
     match *self {
-      (ref a, ref b) => { a.iter_bytes(lsb0, f) && b.iter_bytes(lsb0, f) }
+      (ref a, ref b) => { a.iter_bytes(lsb0, |b| f(b)) &&
+                          b.iter_bytes(lsb0, |b| f(b)) }
     }
   }
 }
@@ -242,7 +243,9 @@ impl<A:IterBytes,B:IterBytes,C:IterBytes> IterBytes for (A,B,C) {
   fn iter_bytes(&self, lsb0: bool, f: Cb) -> bool {
     match *self {
       (ref a, ref b, ref c) => {
-        a.iter_bytes(lsb0, f) && b.iter_bytes(lsb0, f) && c.iter_bytes(lsb0, f)
+        a.iter_bytes(lsb0, |b| f(b)) &&
+        b.iter_bytes(lsb0, |b| f(b)) &&
+        c.iter_bytes(lsb0, |b| f(b))
       }
     }
   }
@@ -296,7 +299,7 @@ impl<A:IterBytes> IterBytes for Option<A> {
     #[inline]
     fn iter_bytes(&self, lsb0: bool, f: Cb) -> bool {
         match *self {
-          Some(ref a) => 0u8.iter_bytes(lsb0, f) && a.iter_bytes(lsb0, f),
+          Some(ref a) => 0u8.iter_bytes(lsb0, |b| f(b)) && a.iter_bytes(lsb0, |b| f(b)),
           None => 1u8.iter_bytes(lsb0, f)
         }
     }
index 8f70c75439a016c121c31f41b6c9bacbb9a4b6e3..b9b03ea56619e523f4ab49926a24c5c0f75a0be7 100644 (file)
@@ -251,7 +251,7 @@ impl<T> TrieNode<T> {
     fn each<'a>(&'a self, f: &fn(&uint, &'a T) -> bool) -> bool {
         for uint::range(0, self.children.len()) |idx| {
             match self.children[idx] {
-                Internal(ref x) => if !x.each(f) { return false },
+                Internal(ref x) => if !x.each(|i,t| f(i,t)) { return false },
                 External(k, ref v) => if !f(&k, v) { return false },
                 Nothing => ()
             }
@@ -262,7 +262,7 @@ fn each<'a>(&'a self, f: &fn(&uint, &'a T) -> bool) -> bool {
     fn each_reverse<'a>(&'a self, f: &fn(&uint, &'a T) -> bool) -> bool {
         for uint::range_rev(self.children.len(), 0) |idx| {
             match self.children[idx - 1] {
-                Internal(ref x) => if !x.each_reverse(f) { return false },
+                Internal(ref x) => if !x.each_reverse(|i,t| f(i,t)) { return false },
                 External(k, ref v) => if !f(&k, v) { return false },
                 Nothing => ()
             }
@@ -273,7 +273,7 @@ fn each_reverse<'a>(&'a self, f: &fn(&uint, &'a T) -> bool) -> bool {
     fn mutate_values<'a>(&'a mut self, f: &fn(&uint, &mut T) -> bool) -> bool {
         for self.children.mut_iter().advance |child| {
             match *child {
-                Internal(ref mut x) => if !x.mutate_values(f) {
+                Internal(ref mut x) => if !x.mutate_values(|i,t| f(i,t)) {
                     return false
                 },
                 External(k, ref mut v) => if !f(&k, v) { return false },
index 8555d99255d5a98493ed8f9eb37db48b3994f2ab..4e7943f7cfd2b72b9402701b99f7b8cc947c861c 100644 (file)
@@ -191,7 +191,7 @@ pub fn split<T:Copy>(v: &[T], f: &fn(t: &T) -> bool) -> ~[~[T]] {
     let mut start = 0u;
     let mut result = ~[];
     while start < ln {
-        match position_between(v, start, ln, f) {
+        match position_between(v, start, ln, |t| f(t)) {
             None => break,
             Some(i) => {
                 result.push(v.slice(start, i).to_owned());
@@ -215,7 +215,7 @@ pub fn splitn<T:Copy>(v: &[T], n: uint, f: &fn(t: &T) -> bool) -> ~[~[T]] {
     let mut count = n;
     let mut result = ~[];
     while start < ln && count > 0u {
-        match position_between(v, start, ln, f) {
+        match position_between(v, start, ln, |t| f(t)) {
             None => break,
             Some(i) => {
                 result.push(v.slice(start, i).to_owned());
@@ -240,7 +240,7 @@ pub fn rsplit<T:Copy>(v: &[T], f: &fn(t: &T) -> bool) -> ~[~[T]] {
     let mut end = ln;
     let mut result = ~[];
     while end > 0 {
-        match rposition_between(v, 0, end, f) {
+        match rposition_between(v, 0, end, |t| f(t)) {
             None => break,
             Some(i) => {
                 result.push(v.slice(i + 1, end).to_owned());
@@ -265,7 +265,7 @@ pub fn rsplitn<T:Copy>(v: &[T], n: uint, f: &fn(t: &T) -> bool) -> ~[~[T]] {
     let mut count = n;
     let mut result = ~[];
     while end > 0u && count > 0u {
-        match rposition_between(v, 0u, end, f) {
+        match rposition_between(v, 0u, end, |t| f(t)) {
             None => break,
             Some(i) => {
                 result.push(v.slice(i + 1u, end).to_owned());
index 6e21ceb64c431c2d289c0e61da03f14ee7b17a2f..9439f45be21bf3d96dad70ec1035d54cc1ae3aa1 100644 (file)
@@ -535,18 +535,18 @@ pub fn walk_pat(pat: @pat, it: &fn(@pat) -> bool) -> bool {
     match pat.node {
         pat_ident(_, _, Some(p)) => walk_pat(p, it),
         pat_struct(_, ref fields, _) => {
-            fields.iter().advance(|f| walk_pat(f.pat, it))
+            fields.iter().advance(|f| walk_pat(f.pat, |p| it(p)))
         }
         pat_enum(_, Some(ref s)) | pat_tup(ref s) => {
-            s.iter().advance(|&p| walk_pat(p, it))
+            s.iter().advance(|&p| walk_pat(p, |p| it(p)))
         }
         pat_box(s) | pat_uniq(s) | pat_region(s) => {
             walk_pat(s, it)
         }
         pat_vec(ref before, ref slice, ref after) => {
-            before.iter().advance(|&p| walk_pat(p, it)) &&
-                slice.iter().advance(|&p| walk_pat(p, it)) &&
-                after.iter().advance(|&p| walk_pat(p, it))
+            before.iter().advance(|&p| walk_pat(p, |p| it(p))) &&
+                slice.iter().advance(|&p| walk_pat(p, |p| it(p))) &&
+                after.iter().advance(|&p| walk_pat(p, |p| it(p)))
         }
         pat_wild | pat_lit(_) | pat_range(_, _) | pat_ident(_, _, _) |
         pat_enum(_, _) => {
index 282a28ff9e07df289a8f2a6f69ee8833267e290f..78fdb99753d40bda9eb801cb24f9db8cf040485b 100644 (file)
@@ -509,7 +509,7 @@ fn insert_into_frame(&mut self, key: K, ext: @V, n: K, pred: &fn(&@V)->bool) {
                 }
             },
             ConsMapChain (~ref mut map, rest) => {
-                if satisfies_pred(map,&n,pred) {
+                if satisfies_pred(map,&n,|v|pred(v)) {
                     map.insert(key,ext);
                 } else {
                     rest.insert_into_frame(key,ext,n,pred)
index 8403234f8925222850d4f56420cff13a883ddc09..15fb6ee9ff77aa5f2ee9513ec968447b027bcfc3 100644 (file)
@@ -43,15 +43,21 @@ pub fn expand_deriving_iter_bytes(cx: @ExtCtxt,
 }
 
 fn iter_bytes_substructure(cx: @ExtCtxt, span: span, substr: &Substructure) -> @expr {
-    let lsb0_f = match substr.nonself_args {
-        [l, f] => ~[l, f],
+    let (lsb0, f)= match substr.nonself_args {
+        [l, f] => (l, f),
         _ => cx.span_bug(span, "Incorrect number of arguments in `deriving(IterBytes)`")
     };
+    // Build the "explicitly borrowed" stack closure, "|_buf| f(_buf)".
+    let blk_arg = cx.ident_of("_buf");
+    let borrowed_f =
+        cx.lambda_expr_1(span, cx.expr_call(span, f, ~[cx.expr_ident(span, blk_arg)]),
+                         blk_arg);
+
     let iter_bytes_ident = substr.method_ident;
     let call_iterbytes = |thing_expr| {
         cx.expr_method_call(span,
                               thing_expr, iter_bytes_ident,
-                              copy lsb0_f)
+                              ~[lsb0, borrowed_f])
     };
     let mut exprs = ~[];
     let fields;
index dfbc028ddf6afa6833aa2832856b0760460c1520..19aa29a62a9c02510c653d14184e19f52a76a194 100644 (file)
@@ -99,7 +99,7 @@ fn rand_substructure(cx: @ExtCtxt, span: span, substr: &Substructure) -> @expr {
                     (ident, ref summary) => {
                         cx.arm(span,
                                ~[ pat ],
-                               rand_thing(cx, span, ident, summary, rand_call))
+                               rand_thing(cx, span, ident, summary, || rand_call()))
                     }
                 }
             };
index 2ab0c14b49b656d743dcc60ce2aedc8a66693e70..c2d8427d5eb39fed8fa1b238f745238723039bc5 100644 (file)
@@ -33,8 +33,8 @@ fn map_nums(x: &ast, f: &fn(uint) -> uint) -> &ast {
         return &num(f(x)); //~ ERROR borrowed value does not live long enough
       }
       add(x, y) => {
-        let m_x = map_nums(x, f);
-        let m_y = map_nums(y, f);
+        let m_x = map_nums(x, |z| f(z));
+        let m_y = map_nums(y, |z| f(z));
         return &add(m_x, m_y);  //~ ERROR borrowed value does not live long enough
       }
     }