'Borrow' stack closures rather than copying them (e.g., "|x|f(x)"), in prep for making them noncopyable.

This commit is contained in:
Ben Blum 2013-06-21 20:08:35 -04:00
parent 89110fdf55
commit ff4ab9e147
28 changed files with 118 additions and 101 deletions

View 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));
}
}
}

View File

@ -1078,7 +1078,7 @@ pub mod node {
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 mod node {
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;

View File

@ -42,7 +42,8 @@ pub fn merge_sort<T:Copy>(v: &[T], le: Le<T>) -> ~[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);
}

View File

@ -563,7 +563,9 @@ impl RWlock {
(&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 @@ mod tests {
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 @@ mod tests {
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();

View File

@ -678,7 +678,7 @@ impl BenchHarness {
// 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 @@ impl BenchHarness {
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 @@ impl BenchHarness {
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
};

View File

@ -511,14 +511,14 @@ impl<K: TotalOrd, 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
}

View 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))
}
}

View File

@ -48,7 +48,7 @@ pub fn mk_filesearch(maybe_sysroot: &Option<@Path>,
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,

View 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;

View File

@ -411,7 +411,7 @@ impl MoveData {
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;

View File

@ -890,7 +890,7 @@ impl mem_categorization_ctxt {
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 @@ impl mem_categorization_ctxt {
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 @@ impl mem_categorization_ctxt {
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 @@ impl mem_categorization_ctxt {
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 @@ impl mem_categorization_ctxt {
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));
}
}

View File

@ -674,7 +674,7 @@ pub fn iter_structural_ty(cx: block, av: ValueRef, t: ty::t,
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)

View 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_sty(sty: &sty, fldop: &fn(t) -> t) -> sty {
// 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 @@ pub fn fold_regions(
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;
}

View File

@ -112,7 +112,7 @@ pub fn replace_bound_regions_in_fn_sig(
// 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 @@ pub fn relate_nested_regions(
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 });
}
}
}

View File

@ -582,7 +582,7 @@ impl InferCtxt {
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))
}
}

View File

@ -671,7 +671,7 @@ impl<T:Hash + Eq> Set<T> for HashSet<T> {
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 @@ impl<T:Hash + Eq> Set<T> for HashSet<T> {
/// 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))
}
}

View File

@ -964,7 +964,7 @@ impl<'self, A, T: Iterator<A>, B, U: Iterator<B>> Iterator<B> for
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,
}

View 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)))
})
}

View File

@ -463,7 +463,7 @@ pub fn each_split_within<'a>(ss: &'a str,
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 @@ impl<'self> StrUtil for &'self str {
// 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)
}

View File

@ -230,11 +230,15 @@ fn each_ancestor(list: &mut 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);
/*##########################################################*

View 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)
}
}

View 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 @@ impl<T> TrieNode<T> {
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 @@ impl<T> TrieNode<T> {
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 },

View 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());

View 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(_, _) => {

View File

@ -509,7 +509,7 @@ impl <K: Eq + Hash + IterBytes ,V: Copy> MapChain<K,V>{
}
},
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)

View 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;

View 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()))
}
}
};

View 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
}
}