diff options
| author | Niko Matsakis <niko@alum.mit.edu> | 2012-08-08 12:58:22 -0700 |
|---|---|---|
| committer | Niko Matsakis <niko@alum.mit.edu> | 2012-08-09 18:26:50 -0700 |
| commit | 1b2d91c79da93461563428d25ae09bbeb59ed292 (patch) | |
| tree | 3a9bd4db41536f3cc05107d448a11fc4dd7355cf /src/libcore | |
| parent | fe8c8ad5827e0156490d78257b5e33cf9bc1281a (diff) | |
de-mode-ify infer and some parts of typeck
also, fix bug in the various lint passes that fn() was considered not suitable for the default mode
Diffstat (limited to 'src/libcore')
| -rw-r--r-- | src/libcore/result.rs | 6 | ||||
| -rw-r--r-- | src/libcore/vec.rs | 6 |
2 files changed, 9 insertions, 3 deletions
diff --git a/src/libcore/result.rs b/src/libcore/result.rs index 42a4b671a39..762191842b8 100644 --- a/src/libcore/result.rs +++ b/src/libcore/result.rs @@ -250,7 +250,7 @@ impl<T: copy, E: copy> result<T, E> { * } */ fn map_vec<T,U:copy,V:copy>( - ts: ~[T], op: fn(T) -> result<V,U>) -> result<~[V],U> { + ts: &[T], op: fn(T) -> result<V,U>) -> result<~[V],U> { let mut vs: ~[V] = ~[]; vec::reserve(vs, vec::len(ts)); @@ -284,7 +284,7 @@ fn map_opt<T,U:copy,V:copy>( * used in 'careful' code contexts where it is both appropriate and easy * to accommodate an error like the vectors being of different lengths. */ -fn map_vec2<S,T,U:copy,V:copy>(ss: ~[S], ts: ~[T], +fn map_vec2<S,T,U:copy,V:copy>(ss: &[S], ts: &[T], op: fn(S,T) -> result<V,U>) -> result<~[V],U> { assert vec::same_length(ss, ts); @@ -307,7 +307,7 @@ fn map_vec2<S,T,U:copy,V:copy>(ss: ~[S], ts: ~[T], * error. This could be implemented using `map2()` but it is more efficient * on its own as no result vector is built. */ -fn iter_vec2<S,T,U:copy>(ss: ~[S], ts: ~[T], +fn iter_vec2<S,T,U:copy>(ss: &[S], ts: &[T], op: fn(S,T) -> result<(),U>) -> result<(),U> { assert vec::same_length(ss, ts); diff --git a/src/libcore/vec.rs b/src/libcore/vec.rs index c104bdbc17a..5e756918d30 100644 --- a/src/libcore/vec.rs +++ b/src/libcore/vec.rs @@ -17,6 +17,7 @@ export capacity; export len; export from_fn; export from_elem; +export from_slice; export build, build_sized; export to_mut; export from_mut; @@ -211,6 +212,11 @@ pure fn from_elem<T: copy>(n_elts: uint, t: T) -> ~[T] { return v; } +/// Creates a new unique vector with the same contents as the slice +pure fn from_slice<T: copy>(t: &[T]) -> ~[T] { + from_fn(t.len(), |i| t[i]) +} + /** * Builds a vector by calling a provided function with an argument * function that pushes an element to the back of a vector. |
