diff options
| author | Niko Matsakis <niko@alum.mit.edu> | 2012-08-23 14:46:59 -0700 |
|---|---|---|
| committer | Niko Matsakis <niko@alum.mit.edu> | 2012-08-23 18:54:08 -0700 |
| commit | a08f3a7d4d937c2b26c8a29edabe7fb089d0b5f7 (patch) | |
| tree | 778e2d94eca68fd3e579b2ad8ac2725602afe340 /src/libcore | |
| parent | 83e7c869bdfadf0ed8aca92e76fc5073b63402e2 (diff) | |
| download | rust-a08f3a7d4d937c2b26c8a29edabe7fb089d0b5f7.tar.gz rust-a08f3a7d4d937c2b26c8a29edabe7fb089d0b5f7.zip | |
More complete fix to #3162 (borrowck bug related to access to rec fields)
Diffstat (limited to 'src/libcore')
| -rw-r--r-- | src/libcore/task.rs | 10 | ||||
| -rw-r--r-- | src/libcore/vec.rs | 19 |
2 files changed, 23 insertions, 6 deletions
diff --git a/src/libcore/task.rs b/src/libcore/task.rs index 16b4e681051..863efc79d4a 100644 --- a/src/libcore/task.rs +++ b/src/libcore/task.rs @@ -851,12 +851,10 @@ fn each_ancestor(list: &mut AncestorList, do with_parent_tg(&mut nobe.parent_group) |tg_opt| { // Decide whether this group is dead. Note that the // group being *dead* is disjoint from it *failing*. - match *tg_opt { - some(ref tg) => { - nobe_is_dead = taskgroup_is_dead(tg); - }, - none => { } - } + nobe_is_dead = match *tg_opt { + some(ref tg) => taskgroup_is_dead(tg), + none => nobe_is_dead + }; // Call iterator block. (If the group is dead, it's // safe to skip it. This will leave our *rust_task // hanging around in the group even after it's freed, diff --git a/src/libcore/vec.rs b/src/libcore/vec.rs index 15db86f937d..c6be27c4b77 100644 --- a/src/libcore/vec.rs +++ b/src/libcore/vec.rs @@ -75,6 +75,7 @@ export swap; export reverse; export reversed; export iter, iter_between, each, eachi, reach, reachi; +export each_mut, each_const; export iter2; export iteri; export riter; @@ -1174,6 +1175,24 @@ pure fn each<T>(v: &[T], f: fn(T) -> bool) { } } +/// Like `each()`, but for the case where you have +/// a vector with mutable contents and you would like +/// to mutate the contents as you iterate. +#[inline(always)] +pure fn each_mut<T>(v: &[mut T], f: fn(elem: &mut T) -> bool) { + do vec::as_mut_buf(v) |p, n| { + let mut n = n; + let mut p = p; + while n > 0u { + unsafe { + if !f(&mut *p) { break; } + p = ptr::mut_offset(p, 1u); + } + n -= 1u; + } + } +} + /** * Iterates over a vector's elements and indices * |
