diff options
Diffstat (limited to 'src/libcore')
| -rw-r--r-- | src/libcore/arc.rs | 10 | ||||
| -rw-r--r-- | src/libcore/char.rs | 8 | ||||
| -rw-r--r-- | src/libcore/comm.rs | 2 | ||||
| -rw-r--r-- | src/libcore/dvec.rs | 29 | ||||
| -rw-r--r-- | src/libcore/either.rs | 46 | ||||
| -rw-r--r-- | src/libcore/extfmt.rs | 31 | ||||
| -rw-r--r-- | src/libcore/float.rs | 10 | ||||
| -rw-r--r-- | src/libcore/int-template.rs | 2 | ||||
| -rw-r--r-- | src/libcore/int-template/int.rs | 2 | ||||
| -rw-r--r-- | src/libcore/io.rs | 92 | ||||
| -rw-r--r-- | src/libcore/iter-trait.rs | 8 | ||||
| -rw-r--r-- | src/libcore/iter.rs | 64 | ||||
| -rw-r--r-- | src/libcore/os.rs | 24 | ||||
| -rw-r--r-- | src/libcore/path.rs | 24 | ||||
| -rw-r--r-- | src/libcore/ptr.rs | 6 | ||||
| -rw-r--r-- | src/libcore/rand.rs | 61 | ||||
| -rw-r--r-- | src/libcore/result.rs | 21 | ||||
| -rw-r--r-- | src/libcore/run.rs | 50 | ||||
| -rw-r--r-- | src/libcore/str.rs | 253 | ||||
| -rw-r--r-- | src/libcore/to_str.rs | 13 | ||||
| -rw-r--r-- | src/libcore/uint-template.rs | 2 | ||||
| -rw-r--r-- | src/libcore/unsafe.rs | 4 | ||||
| -rw-r--r-- | src/libcore/vec.rs | 490 |
23 files changed, 630 insertions, 622 deletions
diff --git a/src/libcore/arc.rs b/src/libcore/arc.rs index 7e8d69298bd..f13a34d260e 100644 --- a/src/libcore/arc.rs +++ b/src/libcore/arc.rs @@ -170,7 +170,7 @@ mod tests { #[test] fn manually_share_arc() { - let v = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; + let v = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]/~; let arc_v = arc::arc(v); let p = port(); @@ -182,7 +182,7 @@ mod tests { let arc_v = p.recv(); - let v = *arc::get::<[int]>(&arc_v); + let v = *arc::get::<[int]/~>(&arc_v); assert v[3] == 4; }; @@ -196,7 +196,7 @@ mod tests { #[test] fn auto_share_arc() { - let v = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; + let v = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]/~; let (_res, arc_c) = shared_arc(v); let p = port(); @@ -216,7 +216,7 @@ mod tests { #[test] #[ignore] // this can probably infinite loop too. fn exclusive_arc() { - let mut futures = []; + let mut futures = []/~; let num_tasks = 10u; let count = 1000u; @@ -231,7 +231,7 @@ mod tests { **count += 1u; } } - })]; + })]/~; }; for futures.each {|f| f.get() }; diff --git a/src/libcore/char.rs b/src/libcore/char.rs index 9aa1614114b..ffead7a523b 100644 --- a/src/libcore/char.rs +++ b/src/libcore/char.rs @@ -65,7 +65,7 @@ pure fn is_uppercase(c: char) -> bool { #[doc = " Indicates whether a character is whitespace, defined in terms of the Unicode General Categories 'Zs', 'Zl', 'Zp' -additional 'Cc'-category control codes in the range [0x09, 0x0d] +additional 'Cc'-category control codes in the range [0x09, 0x0d]/~ "] pure fn is_whitespace(c: char) -> bool { ret ('\x09' <= c && c <= '\x0d') @@ -128,8 +128,8 @@ Return the hexadecimal unicode escape of a char. The rules are as follows: - - chars in [0,0xff] get 2-digit escapes: `\\xNN` - - chars in [0x100,0xffff] get 4-digit escapes: `\\uNNNN` + - chars in [0,0xff]/~ get 2-digit escapes: `\\xNN` + - chars in [0x100,0xffff]/~ get 4-digit escapes: `\\uNNNN` - chars above 0x10000 get 8-digit escapes: `\\UNNNNNNNN` "] fn escape_unicode(c: char) -> str { @@ -154,7 +154,7 @@ languages. The exact rules are: - Tab, CR and LF are escaped as '\t', '\r' and '\n' respectively. - Single-quote, double-quote and backslash chars are backslash-escaped. - - Any other chars in the range [0x20,0x7e] are not escaped. + - Any other chars in the range [0x20,0x7e]/~ are not escaped. - Any other chars are given hex unicode escapes; see `escape_unicode`. "] fn escape_default(c: char) -> str { diff --git a/src/libcore/comm.rs b/src/libcore/comm.rs index 8cc82e56b8f..4a01ccea324 100644 --- a/src/libcore/comm.rs +++ b/src/libcore/comm.rs @@ -217,7 +217,7 @@ fn peek_(p: *rust_port) -> bool { #[doc = "Receive on one of two ports"] fn select2<A: send, B: send>(p_a: port<A>, p_b: port<B>) -> either<A, B> { - let ports = [(**p_a).po, (**p_b).po]; + let ports = [(**p_a).po, (**p_b).po]/~; let n_ports = 2 as libc::size_t; let yield = 0u, yieldp = ptr::addr_of(yield); diff --git a/src/libcore/dvec.rs b/src/libcore/dvec.rs index 85d61d3f606..c94d0dc718b 100644 --- a/src/libcore/dvec.rs +++ b/src/libcore/dvec.rs @@ -32,7 +32,7 @@ may permit read-only access during iteration or other use. # WARNING For maximum performance, this type is implemented using some rather -unsafe code. In particular, this innocent looking `[mut A]` pointer +unsafe code. In particular, this innocent looking `[mut A]/~` pointer *may be null!* Therefore, it is important you not reach into the data structure manually but instead use the provided extensions. @@ -48,27 +48,26 @@ type could only produce 47 million pushes/second. "] type dvec<A> = { - - mut data: [mut A] + mut data: [mut A]/~ }; #[doc = "Creates a new, empty dvec"] fn dvec<A>() -> dvec<A> { - {mut data: [mut]} + {mut data: [mut]/~} } #[doc = "Creates a new dvec with a single element"] fn from_elt<A>(+e: A) -> dvec<A> { - {mut data: [mut e]} + {mut data: [mut e]/~} } #[doc = "Creates a new dvec with the contents of a vector"] -fn from_vec<A>(+v: [mut A]) -> dvec<A> { +fn from_vec<A>(+v: [mut A]/~) -> dvec<A> { {mut data: v} } #[doc = "Consumes the vector and returns its contents"] -fn unwrap<A>(-d: dvec<A>) -> [mut A] { +fn unwrap<A>(-d: dvec<A>) -> [mut A]/~ { let {data: v} <- d; ret v; } @@ -84,7 +83,7 @@ impl private_methods<A> for dvec<A> { } #[inline(always)] - fn borrow<B>(f: fn(-[mut A]) -> B) -> B { + fn borrow<B>(f: fn(-[mut A]/~) -> B) -> B { unsafe { let mut data = unsafe::reinterpret_cast(null::<()>()); data <-> self.data; @@ -95,7 +94,7 @@ impl private_methods<A> for dvec<A> { } #[inline(always)] - fn return(-data: [mut A]) { + fn return(-data: [mut A]/~) { unsafe { self.data <- data; } @@ -114,7 +113,7 @@ impl extensions<A> for dvec<A> { "] #[inline(always)] - fn swap(f: fn(-[mut A]) -> [mut A]) { + fn swap(f: fn(-[mut A]/~) -> [mut A]/~) { self.borrow { |v| self.return(f(v)) } } @@ -128,7 +127,7 @@ impl extensions<A> for dvec<A> { } #[doc = "Overwrite the current contents"] - fn set(+w: [mut A]) { + fn set(+w: [mut A]/~) { self.check_not_borrowed(); self.data <- w; } @@ -151,7 +150,7 @@ impl extensions<A> for dvec<A> { let data_ptr: *() = unsafe::reinterpret_cast(data); if data_ptr.is_null() { fail "Recursive use of dvec"; } log(error, "a"); - self.data <- [mut t] + data; + self.data <- [mut t]/~ + data; log(error, "b"); } } @@ -219,7 +218,7 @@ impl extensions<A:copy> for dvec<A> { } }; - for ts.each { |t| v += [t] }; + for ts.each { |t| v += [t]/~ }; v } } @@ -229,7 +228,7 @@ impl extensions<A:copy> for dvec<A> { See `unwrap()` if you do not wish to copy the contents. "] - fn get() -> [A] { + fn get() -> [A]/~ { self.borrow { |v| let w = vec::from_mut(copy v); self.return(v); @@ -271,4 +270,4 @@ impl extensions<A:copy> for dvec<A> { fn last() -> A { self.get_elt(self.len() - 1u) } -} \ No newline at end of file +} diff --git a/src/libcore/either.rs b/src/libcore/either.rs index 00a39416748..564966c1493 100644 --- a/src/libcore/either.rs +++ b/src/libcore/either.rs @@ -21,28 +21,28 @@ fn either<T, U, V>(f_left: fn(T) -> V, alt value { left(l) { f_left(l) } right(r) { f_right(r) } } } -fn lefts<T: copy, U>(eithers: [either<T, U>]) -> [T] { +fn lefts<T: copy, U>(eithers: [either<T, U>]/~) -> [T]/~ { #[doc = "Extracts from a vector of either all the left values"]; - let mut result: [T] = []; + let mut result: [T]/~ = []/~; for vec::each(eithers) {|elt| - alt elt { left(l) { result += [l]; } _ {/* fallthrough */ } } + alt elt { left(l) { result += [l]/~; } _ {/* fallthrough */ } } } ret result; } -fn rights<T, U: copy>(eithers: [either<T, U>]) -> [U] { +fn rights<T, U: copy>(eithers: [either<T, U>]/~) -> [U]/~ { #[doc = "Extracts from a vector of either all the right values"]; - let mut result: [U] = []; + let mut result: [U]/~ = []/~; for vec::each(eithers) {|elt| - alt elt { right(r) { result += [r]; } _ {/* fallthrough */ } } + alt elt { right(r) { result += [r]/~; } _ {/* fallthrough */ } } } ret result; } -fn partition<T: copy, U: copy>(eithers: [either<T, U>]) - -> {lefts: [T], rights: [U]} { +fn partition<T: copy, U: copy>(eithers: [either<T, U>]/~) + -> {lefts: [T]/~, rights: [U]/~} { #[doc = " Extracts from a vector of either all the left values and right values @@ -50,10 +50,10 @@ fn partition<T: copy, U: copy>(eithers: [either<T, U>]) right values. "]; - let mut lefts: [T] = []; - let mut rights: [U] = []; + let mut lefts: [T]/~ = []/~; + let mut rights: [U]/~ = []/~; for vec::each(eithers) {|elt| - alt elt { left(l) { lefts += [l]; } right(r) { rights += [r]; } } + alt elt { left(l) { lefts += [l]/~; } right(r) { rights += [r]/~; } } } ret {lefts: lefts, rights: rights}; } @@ -112,49 +112,49 @@ fn test_either_right() { #[test] fn test_lefts() { - let input = [left(10), right(11), left(12), right(13), left(14)]; + let input = [left(10), right(11), left(12), right(13), left(14)]/~; let result = lefts(input); - assert (result == [10, 12, 14]); + assert (result == [10, 12, 14]/~); } #[test] fn test_lefts_none() { - let input: [either<int, int>] = [right(10), right(10)]; + let input: [either<int, int>]/~ = [right(10), right(10)]/~; let result = lefts(input); assert (vec::len(result) == 0u); } #[test] fn test_lefts_empty() { - let input: [either<int, int>] = []; + let input: [either<int, int>]/~ = []/~; let result = lefts(input); assert (vec::len(result) == 0u); } #[test] fn test_rights() { - let input = [left(10), right(11), left(12), right(13), left(14)]; + let input = [left(10), right(11), left(12), right(13), left(14)]/~; let result = rights(input); - assert (result == [11, 13]); + assert (result == [11, 13]/~); } #[test] fn test_rights_none() { - let input: [either<int, int>] = [left(10), left(10)]; + let input: [either<int, int>]/~ = [left(10), left(10)]/~; let result = rights(input); assert (vec::len(result) == 0u); } #[test] fn test_rights_empty() { - let input: [either<int, int>] = []; + let input: [either<int, int>]/~ = []/~; let result = rights(input); assert (vec::len(result) == 0u); } #[test] fn test_partition() { - let input = [left(10), right(11), left(12), right(13), left(14)]; + let input = [left(10), right(11), left(12), right(13), left(14)]/~; let result = partition(input); assert (result.lefts[0] == 10); assert (result.lefts[1] == 12); @@ -165,7 +165,7 @@ fn test_partition() { #[test] fn test_partition_no_lefts() { - let input: [either<int, int>] = [right(10), right(11)]; + let input: [either<int, int>]/~ = [right(10), right(11)]/~; let result = partition(input); assert (vec::len(result.lefts) == 0u); assert (vec::len(result.rights) == 2u); @@ -173,7 +173,7 @@ fn test_partition_no_lefts() { #[test] fn test_partition_no_rights() { - let input: [either<int, int>] = [left(10), left(11)]; + let input: [either<int, int>]/~ = [left(10), left(11)]/~; let result = partition(input); assert (vec::len(result.lefts) == 2u); assert (vec::len(result.rights) == 0u); @@ -181,7 +181,7 @@ fn test_partition_no_rights() { #[test] fn test_partition_empty() { - let input: [either<int, int>] = []; + let input: [either<int, int>]/~ = []/~; let result = partition(input); assert (vec::len(result.lefts) == 0u); assert (vec::len(result.rights) == 0u); diff --git a/src/libcore/extfmt.rs b/src/libcore/extfmt.rs index 175974f09cb..b1bb6d80a7a 100644 --- a/src/libcore/extfmt.rs +++ b/src/libcore/extfmt.rs @@ -9,12 +9,12 @@ The 'fmt' extension is modeled on the posix printf system. A posix conversion ostensibly looks like this -> %[parameter][flags][width][.precision][length]type +> %[parameter]/~[flags]/~[width]/~[.precision]/~[length]/~type Given the different numeric type bestiary we have, we omit the 'length' parameter and support slightly different conversions for 'type' -> %[parameter][flags][width][.precision]type +> %[parameter]/~[flags]/~[width]/~[.precision]/~type we also only support translating-to-rust a tiny subset of the possible combinations at the moment. @@ -71,7 +71,7 @@ mod ct { // A formatted conversion from an expression to a string type conv = {param: option<int>, - flags: [flag], + flags: [flag]/~, width: count, precision: count, ty: ty}; @@ -81,14 +81,14 @@ mod ct { enum piece { piece_string(str), piece_conv(conv), } type error_fn = fn@(str) -> ! ; - fn parse_fmt_string(s: str, error: error_fn) -> [piece] { - let mut pieces: [piece] = []; + fn parse_fmt_string(s: str, error: error_fn) -> [piece]/~ { + let mut pieces: [piece]/~ = []/~; let lim = str::len(s); let mut buf = ""; - fn flush_buf(buf: str, &pieces: [piece]) -> str { + fn flush_buf(buf: str, &pieces: [piece]/~) -> str { if str::len(buf) > 0u { let piece = piece_string(buf); - pieces += [piece]; + pieces += [piece]/~; } ret ""; } @@ -108,7 +108,7 @@ mod ct { } else { buf = flush_buf(buf, pieces); let rs = parse_conversion(s, i, lim, error); - pieces += [rs.piece]; + pieces += [rs.piece]/~; i = rs.next; } } else { buf += curr; i += size; } @@ -162,16 +162,16 @@ mod ct { }; } fn parse_flags(s: str, i: uint, lim: uint) -> - {flags: [flag], next: uint} { - let noflags: [flag] = []; + {flags: [flag]/~, next: uint} { + let noflags: [flag]/~ = []/~; if i >= lim { ret {flags: noflags, next: i}; } fn more_(f: flag, s: str, i: uint, lim: uint) -> - {flags: [flag], next: uint} { + {flags: [flag]/~, next: uint} { let next = parse_flags(s, i + 1u, lim); let rest = next.flags; let j = next.next; - let curr: [flag] = [f]; + let curr: [flag]/~ = [f]/~; ret {flags: curr + rest, next: j}; } let more = {|x|more_(x, s, i, lim)}; @@ -262,7 +262,7 @@ mod ct { // Functions used by the fmt extension at runtime. For now there are a lot of // decisions made a runtime. If it proves worthwhile then some of these // conditions can be evaluated at compile-time. For now though it's cleaner to -// implement it this way, I think. +// implement it 0this way, I think. mod rt { enum flag { flag_left_justify, @@ -276,7 +276,7 @@ mod rt { // FIXME (#1993): May not want to use a vector here for flags; instead // just use a bool per flag. - type conv = {flags: [flag], width: count, precision: count, ty: ty}; + type conv = {flags: [flag]/~, width: count, precision: count, ty: ty}; fn conv_int(cv: conv, i: int) -> str { let radix = 10u; @@ -430,12 +430,13 @@ mod rt { } ret padstr + s; } - fn have_flag(flags: [flag], f: flag) -> bool { + fn have_flag(flags: [flag]/~, f: flag) -> bool { for vec::each(flags) {|candidate| if candidate == f { ret true; } } ret false; } } + // Local Variables: // mode: rust; // fill-column: 78; diff --git a/src/libcore/float.rs b/src/libcore/float.rs index cd6e830ab4f..5f6da4c1674 100644 --- a/src/libcore/float.rs +++ b/src/libcore/float.rs @@ -116,10 +116,10 @@ fn to_str_common(num: float, digits: uint, exact: bool) -> str { let mut frac = num - (trunc as float); // stack of digits - let mut fractionalParts = []; + let mut fractionalParts = []/~; // FIXME: (#2608) - // This used to return right away without rounding, as "[-]num", + // This used to return right away without rounding, as "[-]/~num", // but given epsilon like in f64.rs, I don't see how the comparison // to epsilon did much when only used there. // if (frac < epsilon && !exact) || digits == 0u { ret accum; } @@ -236,7 +236,7 @@ Leading and trailing whitespace are ignored. # Return value `none` if the string did not represent a valid number. Otherwise, `some(n)` -where `n` is the floating-point number represented by `[num]`. +where `n` is the floating-point number represented by `[num]/~`. "] fn from_str(num: str) -> option<float> { if num == "inf" { @@ -261,7 +261,7 @@ fn from_str(num: str) -> option<float> { _ { ret none; } } - //Determine if first char is '-'/'+'. Set [pos] and [neg] accordingly. + //Determine if first char is '-'/'+'. Set [pos]/~ and [neg]/~ accordingly. let mut neg = false; //Sign of the result alt str::char_at(num, 0u) { '-' { @@ -345,7 +345,7 @@ fn from_str(num: str) -> option<float> { pos = char_range.next; } let multiplier = pow_with_uint(10u, exponent); - //Note: not [int::pow], otherwise, we'll quickly + //Note: not [int::pow]/~, otherwise, we'll quickly //end up with a nice overflow if neg_exponent { total = total / multiplier; diff --git a/src/libcore/int-template.rs b/src/libcore/int-template.rs index 7f3d385dca0..5721ab750b4 100644 --- a/src/libcore/int-template.rs +++ b/src/libcore/int-template.rs @@ -66,7 +66,7 @@ Parse a buffer of bytes * buf - A byte buffer * radix - The base of the number "] -fn parse_buf(buf: [u8], radix: uint) -> option<T> { +fn parse_buf(buf: [u8]/~, radix: uint) -> option<T> { if vec::len(buf) == 0u { ret none; } let mut i = vec::len(buf) - 1u; let mut start = 0u; diff --git a/src/libcore/int-template/int.rs b/src/libcore/int-template/int.rs index d28333c79e6..2557b1253b7 100644 --- a/src/libcore/int-template/int.rs +++ b/src/libcore/int-template/int.rs @@ -11,7 +11,7 @@ pure fn hash(&&x: int) -> uint { ret x as uint; } #[doc = "Returns `base` raised to the power of `exponent`"] fn pow(base: int, exponent: uint) -> int { - if exponent == 0u { ret 1; } //Not mathemtically true if [base == 0] + if exponent == 0u { ret 1; } //Not mathemtically true if [base == 0]/~ if base == 0 { ret 0; } let mut my_pow = exponent; let mut acc = 1; diff --git a/src/libcore/io.rs b/src/libcore/io.rs index 5fda13bcd70..ff7bdb2b2d6 100644 --- a/src/libcore/io.rs +++ b/src/libcore/io.rs @@ -30,7 +30,7 @@ enum seek_style { seek_set, seek_end, seek_cur, } // The raw underlying reader iface. All readers must implement this. iface reader { // FIXME (#2004): Seekable really should be orthogonal. - fn read_bytes(uint) -> [u8]; + fn read_bytes(uint) -> [u8]/~; fn read_byte() -> int; fn unread_byte(int); fn eof() -> bool; @@ -41,9 +41,9 @@ iface reader { // Generic utility functions defined on readers impl reader_util for reader { - fn read_chars(n: uint) -> [char] { + fn read_chars(n: uint) -> [char]/~ { // returns the (consumed offset, n_req), appends characters to &chars - fn chars_from_buf(buf: [u8], &chars: [char]) -> (uint, uint) { + fn chars_from_buf(buf: [u8]/~, &chars: [char]/~) -> (uint, uint) { let mut i = 0u; while i < vec::len(buf) { let b0 = buf[i]; @@ -52,7 +52,7 @@ impl reader_util for reader { i += 1u; assert (w > 0u); if w == 1u { - chars += [ b0 as char ]; + chars += [ b0 as char ]/~; cont; } // can't satisfy this char with the existing data @@ -71,12 +71,12 @@ impl reader_util for reader { // See str::char_at val += ((b0 << ((w + 1u) as u8)) as uint) << (w - 1u) * 6u - w - 1u; - chars += [ val as char ]; + chars += [ val as char ]/~; } ret (i, 0u); } - let mut buf: [u8] = []; - let mut chars: [char] = []; + let mut buf: [u8]/~ = []/~; + let mut chars: [char]/~ = []/~; // might need more bytes, but reading n will never over-read let mut nbread = n; while nbread > 0u { @@ -110,20 +110,20 @@ impl reader_util for reader { } fn read_line() -> str { - let mut buf: [u8] = []; + let mut buf: [u8]/~ = []/~; loop { let ch = self.read_byte(); if ch == -1 || ch == 10 { break; } - buf += [ch as u8]; + buf += [ch as u8]/~; } str::from_bytes(buf) } fn read_c_str() -> str { - let mut buf: [u8] = []; + let mut buf: [u8]/~ = []/~; loop { let ch = self.read_byte(); - if ch < 1 { break; } else { buf += [ch as u8]; } + if ch < 1 { break; } else { buf += [ch as u8]/~; } } str::from_bytes(buf) } @@ -156,8 +156,8 @@ impl reader_util for reader { val } - fn read_whole_stream() -> [u8] { - let mut buf: [u8] = []; + fn read_whole_stream() -> [u8]/~ { + let mut buf: [u8]/~ = []/~; while !self.eof() { buf += self.read_bytes(2048u); } buf } @@ -192,8 +192,8 @@ fn convert_whence(whence: seek_style) -> i32 { } impl of reader for *libc::FILE { - fn read_bytes(len: uint) -> [u8] { - let mut buf : [mut u8] = [mut]; + fn read_bytes(len: uint) -> [u8]/~ { + let mut buf : [mut u8]/~ = [mut]/~; vec::reserve(buf, len); vec::as_mut_buf(buf) {|b| let read = libc::fread(b as *mut c_void, 1u as size_t, @@ -216,7 +216,7 @@ impl of reader for *libc::FILE { // duration of its lifetime. // FIXME there really should be a better way to do this // #2004 impl <T: reader, C> of reader for {base: T, cleanup: C} { - fn read_bytes(len: uint) -> [u8] { self.base.read_bytes(len) } + fn read_bytes(len: uint) -> [u8]/~ { self.base.read_bytes(len) } fn read_byte() -> int { self.base.read_byte() } fn unread_byte(byte: int) { self.base.unread_byte(byte); } fn eof() -> bool { self.base.eof() } @@ -260,10 +260,10 @@ fn file_reader(path: str) -> result<reader, str> { // Byte buffer readers // TODO: const u8, but this fails with rustboot. -type byte_buf = {buf: [u8], mut pos: uint, len: uint}; +type byte_buf = {buf: [u8]/~, mut pos: uint, len: uint}; impl of reader for byte_buf { - fn read_bytes(len: uint) -> [u8] { + fn read_bytes(len: uint) -> [u8]/~ { let rest = self.len - self.pos; let mut to_read = len; if rest < to_read { to_read = rest; } @@ -286,19 +286,19 @@ impl of reader for byte_buf { fn tell() -> uint { self.pos } } -fn bytes_reader(bytes: [u8]) -> reader { +fn bytes_reader(bytes: [u8]/~) -> reader { bytes_reader_between(bytes, 0u, vec::len(bytes)) } -fn bytes_reader_between(bytes: [u8], start: uint, end: uint) -> reader { +fn bytes_reader_between(bytes: [u8]/~, start: uint, end: uint) -> reader { {buf: bytes, mut pos: start, len: end} as reader } -fn with_bytes_reader<t>(bytes: [u8], f: fn(reader) -> t) -> t { +fn with_bytes_reader<t>(bytes: [u8]/~, f: fn(reader) -> t) -> t { f(bytes_reader(bytes)) } -fn with_bytes_reader_between<t>(bytes: [u8], start: uint, end: uint, +fn with_bytes_reader_between<t>(bytes: [u8]/~, start: uint, end: uint, f: fn(reader) -> t) -> t { f(bytes_reader_between(bytes, start, end)) } @@ -402,7 +402,7 @@ fn fd_writer(fd: fd_t, cleanup: bool) -> writer { } -fn mk_file_writer(path: str, flags: [fileflag]) +fn mk_file_writer(path: str, flags: [fileflag]/~) -> result<writer, str> { #[cfg(windows)] @@ -451,9 +451,9 @@ fn u64_to_le_bytes<T>(n: u64, size: uint, f: fn([u8]/&) -> T) -> T { (n >> 56) as u8]/&) } _ { - let mut bytes: [u8] = [], i = size, n = n; + let mut bytes: [u8]/~ = []/~, i = size, n = n; while i > 0u { - bytes += [(n & 255_u64) as u8]; + bytes += [(n & 255_u64) as u8]/~; n >>= 8_u64; i -= 1u; } @@ -481,11 +481,11 @@ fn u64_to_be_bytes<T>(n: u64, size: uint, f: fn([u8]/&) -> T) -> T { (n >> 8) as u8, n as u8]/&) } _ { - let mut bytes: [u8] = []; + let mut bytes: [u8]/~ = []/~; let mut i = size; while i > 0u { let shift = ((i - 1u) * 8u) as u64; - bytes += [(n >> shift) as u8]; + bytes += [(n >> shift) as u8]/~; i -= 1u; } f(bytes) @@ -493,7 +493,7 @@ fn u64_to_be_bytes<T>(n: u64, size: uint, f: fn([u8]/&) -> T) -> T { } } -fn u64_from_be_bytes(data: [u8], start: uint, size: uint) -> u64 { +fn u64_from_be_bytes(data: [u8]/~, start: uint, size: uint) -> u64 { let mut sz = size; assert (sz <= 8u); let mut val = 0_u64; @@ -577,7 +577,7 @@ impl writer_util for writer { fn write_u8(n: u8) { self.write([n]/&) } } -fn file_writer(path: str, flags: [fileflag]) -> result<writer, str> { +fn file_writer(path: str, flags: [fileflag]/~) -> result<writer, str> { result::chain(mk_file_writer(path, flags), { |w| result::ok(w)}) } @@ -638,7 +638,7 @@ fn mem_buffer() -> mem_buffer { @{buf: dvec(), mut pos: 0u} } fn mem_buffer_writer(b: mem_buffer) -> writer { b as writer } -fn mem_buffer_buf(b: mem_buffer) -> [u8] { b.buf.get() } +fn mem_buffer_buf(b: mem_buffer) -> [u8]/~ { b.buf.get() } fn mem_buffer_str(b: mem_buffer) -> str { str::from_bytes(b.buf.get()) } @@ -650,7 +650,7 @@ fn with_str_writer(f: fn(writer)) -> str { io::mem_buffer_str(buf) } -fn with_buf_writer(f: fn(writer)) -> [u8] { +fn with_buf_writer(f: fn(writer)) -> [u8]/~ { let buf = mem_buffer(); let wr = mem_buffer_writer(buf); f(wr); @@ -679,7 +679,7 @@ fn read_whole_file_str(file: str) -> result<str, str> { // FIXME (#2004): implement this in a low-level way. Going through the // abstractions is pointless. -fn read_whole_file(file: str) -> result<[u8], str> { +fn read_whole_file(file: str) -> result<[u8]/~, str> { result::chain(file_reader(file), { |rdr| result::ok(rdr.read_whole_stream()) }) @@ -772,7 +772,7 @@ mod tests { { let out: io::writer = result::get( - io::file_writer(tmpfile, [io::create, io::truncate])); + io::file_writer(tmpfile, [io::create, io::truncate]/~)); out.write_str(frood); } let inp: io::reader = result::get(io::file_reader(tmpfile)); @@ -784,22 +784,22 @@ mod tests { #[test] fn test_readchars_empty() { let inp : io::reader = io::str_reader(""); - let res : [char] = inp.read_chars(128u); + let res : [char]/~ = inp.read_chars(128u); assert(vec::len(res) == 0u); } #[test] fn test_readchars_wide() { let wide_test = "生锈的汤匙切肉汤hello生锈的汤匙切肉汤"; - let ivals : [int] = [ + let ivals : [int]/~ = [ 29983, 38152, 30340, 27748, 21273, 20999, 32905, 27748, 104, 101, 108, 108, 111, 29983, 38152, 30340, 27748, - 21273, 20999, 32905, 27748]; - fn check_read_ln(len : uint, s: str, ivals: [int]) { + 21273, 20999, 32905, 27748]/~; + fn check_read_ln(len : uint, s: str, ivals: [int]/~) { let inp : io::reader = io::str_reader(s); - let res : [char] = inp.read_chars(len); + let res : [char]/~ = inp.read_chars(len); if (len <= vec::len(ivals)) { assert(vec::len(res) == len); } @@ -841,7 +841,7 @@ mod tests { #[test] fn file_writer_bad_name() { - alt io::file_writer("?/?", []) { + alt io::file_writer("?/?", []/~) { result::err(e) { assert str::starts_with(e, "error opening ?/?"); } @@ -862,16 +862,16 @@ mod tests { #[test] fn mem_buffer_overwrite() { let mbuf = mem_buffer(); - mbuf.write([0u8, 1u8, 2u8, 3u8]); - assert mem_buffer_buf(mbuf) == [0u8, 1u8, 2u8, 3u8]; + mbuf.write([0u8, 1u8, 2u8, 3u8]/~); + assert mem_buffer_buf(mbuf) == [0u8, 1u8, 2u8, 3u8]/~; mbuf.seek(-2, seek_cur); - mbuf.write([4u8, 5u8, 6u8, 7u8]); - assert mem_buffer_buf(mbuf) == [0u8, 1u8, 4u8, 5u8, 6u8, 7u8]; + mbuf.write([4u8, 5u8, 6u8, 7u8]/~); + assert mem_buffer_buf(mbuf) == [0u8, 1u8, 4u8, 5u8, 6u8, 7u8]/~; mbuf.seek(-2, seek_end); - mbuf.write([8u8]); + mbuf.write([8u8]/~); mbuf.seek(1, seek_set); - mbuf.write([9u8]); - assert mem_buffer_buf(mbuf) == [0u8, 9u8, 4u8, 5u8, 8u8, 7u8]; + mbuf.write([9u8]/~); + assert mem_buffer_buf(mbuf) == [0u8, 9u8, 4u8, 5u8, 8u8, 7u8]/~; } } diff --git a/src/libcore/iter-trait.rs b/src/libcore/iter-trait.rs index e58aa05f079..59958e505a4 100644 --- a/src/libcore/iter-trait.rs +++ b/src/libcore/iter-trait.rs @@ -19,14 +19,14 @@ impl extensions<A> of iter::base_iter<A> for IMPL_T<A> { } impl extensions<A:copy> for IMPL_T<A> { - fn filter_to_vec(pred: fn(A) -> bool) -> [A] { + fn filter_to_vec(pred: fn(A) -> bool) -> [A]/~ { iter::filter_to_vec(self, pred) } - fn map_to_vec<B>(op: fn(A) -> B) -> [B] { iter::map_to_vec(self, op) } - fn to_vec() -> [A] { iter::to_vec(self) } + fn map_to_vec<B>(op: fn(A) -> B) -> [B]/~ { iter::map_to_vec(self, op) } + fn to_vec() -> [A]/~ { iter::to_vec(self) } // FIXME--bug in resolve prevents this from working (#2611) - // fn flat_map_to_vec<B:copy,IB:base_iter<B>>(op: fn(A) -> IB) -> [B] { + // fn flat_map_to_vec<B:copy,IB:base_iter<B>>(op: fn(A) -> IB) -> [B]/~ { // iter::flat_map_to_vec(self, op) // } diff --git a/src/libcore/iter.rs b/src/libcore/iter.rs index 070e909c626..d6380a2968a 100644 --- a/src/libcore/iter.rs +++ b/src/libcore/iter.rs @@ -26,8 +26,8 @@ fn any<A,IA:base_iter<A>>(self: IA, blk: fn(A) -> bool) -> bool { } fn filter_to_vec<A:copy,IA:base_iter<A>>(self: IA, - prd: fn(A) -> bool) -> [A] { - let mut result = []; + prd: fn(A) -> bool) -> [A]/~ { + let mut result = []/~; self.size_hint().iter {|hint| vec::reserve(result, hint); } for self.each {|a| if prd(a) { vec::push(result, a); } @@ -35,8 +35,8 @@ fn filter_to_vec<A:copy,IA:base_iter<A>>(self: IA, ret result; } -fn map_to_vec<A:copy,B,IA:base_iter<A>>(self: IA, op: fn(A) -> B) -> [B] { - let mut result = []; +fn map_to_vec<A:copy,B,IA:base_iter<A>>(self: IA, op: fn(A) -> B) -> [B]/~ { + let mut result = []/~; self.size_hint().iter {|hint| vec::reserve(result, hint); } for self.each {|a| vec::push(result, op(a)); @@ -45,9 +45,9 @@ fn map_to_vec<A:copy,B,IA:base_iter<A>>(self: IA, op: fn(A) -> B) -> [B] { } fn flat_map_to_vec<A:copy,B:copy,IA:base_iter<A>,IB:base_iter<B>>( - self: IA, op: fn(A) -> IB) -> [B] { + self: IA, op: fn(A) -> IB) -> [B]/~ { - let mut result = []; + let mut result = []/~; for self.each {|a| for op(a).each {|b| vec::push(result, b); @@ -64,8 +64,8 @@ fn foldl<A,B,IA:base_iter<A>>(self: IA, +b0: B, blk: fn(B, A) -> B) -> B { ret b; } -fn to_vec<A:copy,IA:base_iter<A>>(self: IA) -> [A] { - foldl::<A,[A],IA>(self, [], {|r, a| r + [a]}) +fn to_vec<A:copy,IA:base_iter<A>>(self: IA) -> [A]/~ { + foldl::<A,[A]/~,IA>(self, []/~, {|r, a| r + [a]/~}) } fn contains<A,IA:base_iter<A>>(self: IA, x: A) -> bool { @@ -135,17 +135,17 @@ fn test_enumerate() { #[test] fn test_map_and_to_vec() { - let a = bind vec::iter([0, 1, 2], _); + let a = bind vec::iter([0, 1, 2]/~, _); let b = bind map(a, {|i| 2*i}, _); let c = to_vec(b); - assert c == [0, 2, 4]; + assert c == [0, 2, 4]/~; } #[test] fn test_map_directly_on_vec() { - let b = bind map([0, 1, 2], {|i| 2*i}, _); + let b = bind map([0, 1, 2]/~, {|i| 2*i}, _); let c = to_vec(b); - assert c == [0, 2, 4]; + assert c == [0, 2, 4]/~; } #[test] @@ -155,7 +155,7 @@ fn test_filter_on_int_range() { } let l = to_vec(bind filter(bind int::range(0, 10, _), is_even, _)); - assert l == [0, 2, 4, 6, 8]; + assert l == [0, 2, 4, 6, 8]/~; } #[test] @@ -165,7 +165,7 @@ fn test_filter_on_uint_range() { } let l = to_vec(bind filter(bind uint::range(0u, 10u, _), is_even, _)); - assert l == [0u, 2u, 4u, 6u, 8u]; + assert l == [0u, 2u, 4u, 6u, 8u]/~; } #[test] @@ -180,7 +180,7 @@ fn test_filter_map() { let l = to_vec(bind filter_map( bind int::range(0, 5, _), negativate_the_evens, _)); - assert l == [0, -2, -4]; + assert l == [0, -2, -4]/~; } #[test] @@ -190,70 +190,70 @@ fn test_flat_map_with_option() { else { none } } - let a = bind vec::iter([0, 1, 2], _); + let a = bind vec::iter([0, 1, 2]/~, _); let b = bind flat_map(a, if_even, _); let c = to_vec(b); - assert c == [0, 2]; + assert c == [0, 2]/~; } #[test] fn test_flat_map_with_list() { - fn repeat(&&i: int) -> [int] { - let mut r = []; - int::range(0, i) {|_j| r += [i]; } + fn repeat(&&i: int) -> [int]/~ { + let mut r = []/~; + int::range(0, i) {|_j| r += [i]/~; } r } - let a = bind vec::iter([0, 1, 2, 3], _); + let a = bind vec::iter([0, 1, 2, 3]/~, _); let b = bind flat_map(a, repeat, _); let c = to_vec(b); #debug["c = %?", c]; - assert c == [1, 2, 2, 3, 3, 3]; + assert c == [1, 2, 2, 3, 3, 3]/~; } #[test] fn test_repeat() { - let mut c = [], i = 0u; + let mut c = []/~, i = 0u; repeat(5u) {|| - c += [(i * i)]; + c += [(i * i)]/~; i += 1u; }; #debug["c = %?", c]; - assert c == [0u, 1u, 4u, 9u, 16u]; + assert c == [0u, 1u, 4u, 9u, 16u]/~; } #[test] fn test_min() { - assert min([5, 4, 1, 2, 3]) == 1; + assert min([5, 4, 1, 2, 3]/~) == 1; } #[test] #[should_fail] #[ignore(cfg(windows))] fn test_min_empty() { - min::<int, [int]>([]); + min::<int, [int]/~>([]/~); } #[test] fn test_max() { - assert max([1, 2, 4, 2, 3]) == 4; + assert max([1, 2, 4, 2, 3]/~) == 4; } #[test] #[should_fail] #[ignore(cfg(windows))] fn test_max_empty() { - max::<int, [int]>([]); + max::<int, [int]/~>([]/~); } #[test] fn test_reversed() { - assert to_vec(bind reversed([1, 2, 3], _)) == [3, 2, 1]; + assert to_vec(bind reversed([1, 2, 3]/~, _)) == [3, 2, 1]/~; } #[test] fn test_count() { - assert count([1, 2, 1, 2, 1], 1) == 3u; + assert count([1, 2, 1, 2, 1]/~, 1) == 3u; } #[test] @@ -261,7 +261,7 @@ fn test_foldr() { fn sub(&&a: int, &&b: int) -> int { a - b } - let sum = foldr([1, 2, 3, 4], 0, sub); + let sum = foldr([1, 2, 3, 4]/~, 0, sub); assert sum == -2; } */ diff --git a/src/libcore/os.rs b/src/libcore/os.rs index ee26bfc5496..88608676d23 100644 --- a/src/libcore/os.rs +++ b/src/libcore/os.rs @@ -40,23 +40,23 @@ export walk_dir; export as_c_charp, fill_charp_buf; native mod rustrt { - fn rust_env_pairs() -> [str]; + fn rust_env_pairs() -> [str]/~; fn rust_getcwd() -> str; fn rust_path_is_dir(path: *libc::c_char) -> c_int; fn rust_path_exists(path: *libc::c_char) -> c_int; - fn rust_list_files(path: str) -> [str]; + fn rust_list_files(path: str) -> [str]/~; fn rust_process_wait(handle: c_int) -> c_int; fn last_os_error() -> str; fn rust_set_exit_status(code: libc::intptr_t); } -fn env() -> [(str,str)] { - let mut pairs = []; +fn env() -> [(str,str)]/~ { + let mut pairs = []/~; for vec::each(rustrt::rust_env_pairs()) {|p| let vs = str::splitn_char(p, '=', 1u); assert vec::len(vs) == 2u; - pairs += [(vs[0], vs[1])]; + vec::push(pairs, (vs[0], vs[1])); } ret pairs; } @@ -116,7 +116,7 @@ mod win32 { fn as_utf16_p<T>(s: str, f: fn(*u16) -> T) -> T { let mut t = str::to_utf16(s); // Null terminate before passing on. - t += [0u16]; + t += [0u16]/~; vec::as_buf(t, f) } } @@ -373,7 +373,7 @@ fn self_exe_path() -> option<path> { fill_charp_buf() {|buf, sz| let mib = [CTL_KERN as c_int, KERN_PROC as c_int, - KERN_PROC_PATHNAME as c_int, -1 as c_int]; + KERN_PROC_PATHNAME as c_int, -1 as c_int]/~; sysctl(vec::unsafe::to_ptr(mib), vec::len(mib) as c_uint, buf as *mut c_void, ptr::mut_addr_of(sz), ptr::null(), 0u as size_t) == (0 as c_int) @@ -553,7 +553,7 @@ fn make_dir(p: path, mode: c_int) -> bool { } #[doc = "Lists the contents of a directory"] -fn list_dir(p: path) -> [str] { +fn list_dir(p: path) -> [str]/~ { #[cfg(unix)] fn star(p: str) -> str { p } @@ -579,7 +579,7 @@ Lists the contents of a directory This version prepends each entry with the directory. "] -fn list_dir_path(p: path) -> [str] { +fn list_dir_path(p: path) -> [str]/~ { let mut p = p; let pl = str::len(p); if pl == 0u || (p[pl - 1u] as char != path::consts::path_sep @@ -670,7 +670,7 @@ fn copy_file(from: path, to: path) -> bool { fclose(istream); ret false; } - let mut buf : [mut u8] = [mut]; + let mut buf : [mut u8]/~ = [mut]/~; let bufsize = 8192u; vec::reserve(buf, bufsize); let mut done = false; @@ -978,7 +978,7 @@ mod tests { }; assert (ostream as uint != 0u); let s = "hello"; - let mut buf = vec::to_mut(str::bytes(s) + [0 as u8]); + let mut buf = vec::to_mut(str::bytes(s) + [0 as u8]/~); vec::as_mut_buf(buf) {|b| assert (libc::fwrite(b as *c_void, 1u as size_t, (str::len(s) + 1u) as size_t, ostream) @@ -989,7 +989,7 @@ mod tests { fail (#fmt("%s doesn't exist", in)); } assert(rs); - let rslt = run::run_program("diff", [in, out]); + let rslt = run::run_program("diff", [in, out]/~); assert (rslt == 0); assert (remove_file(in)); assert (remove_file(out)); diff --git a/src/libcore/path.rs b/src/libcore/path.rs index 93b32b6b8bd..e75f104bea4 100644 --- a/src/libcore/path.rs +++ b/src/libcore/path.rs @@ -127,7 +127,7 @@ Connects a vector of path segments into a single path. Inserts path separators as needed. "] -fn connect_many(paths: [path]) -> path { +fn connect_many(paths: [path]/~) -> path { ret if vec::len(paths) == 1u { paths[0] } else { @@ -144,7 +144,7 @@ each piece of the path. On Windows, if the path is absolute then the first element of the returned vector will be the drive letter followed by a colon. "] -fn split(p: path) -> [path] { +fn split(p: path) -> [path]/~ { str::split_nonempty(p, {|c| c == consts::path_sep || c == consts::alt_path_sep }) @@ -234,7 +234,7 @@ fn normalize(p: path) -> path { ret s; - fn strip_dots(s: [path]) -> [path] { + fn strip_dots(s: [path]/~) -> [path]/~ { vec::filter_map(s, { |elem| if elem == "." { option::none @@ -244,12 +244,12 @@ fn normalize(p: path) -> path { }) } - fn rollup_doubledots(s: [path]) -> [path] { + fn rollup_doubledots(s: [path]/~) -> [path]/~ { if vec::is_empty(s) { - ret []; + ret []/~; } - let mut t = []; + let mut t = []/~; let mut i = vec::len(s); let mut skip = 0; while i != 0u { @@ -258,7 +258,7 @@ fn normalize(p: path) -> path { skip += 1; } else { if skip == 0 { - t += [s[i]]; + vec::push(t, s[i]); } else { skip -= 1; } @@ -266,7 +266,7 @@ fn normalize(p: path) -> path { } let mut t = vec::reversed(t); while skip > 0 { - t += [".."]; + vec::push(t, ".."); skip -= 1; } ret t; @@ -322,28 +322,28 @@ mod tests { #[test] fn split1() { let actual = split("a" + ps() + "b"); - let expected = ["a", "b"]; + let expected = ["a", "b"]/~; assert actual == expected; } #[test] fn split2() { let actual = split("a" + aps() + "b"); - let expected = ["a", "b"]; + let expected = ["a", "b"]/~; assert actual == expected; } #[test] fn split3() { let actual = split(ps() + "a" + ps() + "b"); - let expected = ["a", "b"]; + let expected = ["a", "b"]/~; assert actual == expected; } #[test] fn split4() { let actual = split("a" + ps() + "b" + aps() + "c"); - let expected = ["a", "b", "c"]; + let expected = ["a", "b", "c"]/~; assert actual == expected; } diff --git a/src/libcore/ptr.rs b/src/libcore/ptr.rs index d6288ea2126..bda418d428c 100644 --- a/src/libcore/ptr.rs +++ b/src/libcore/ptr.rs @@ -149,8 +149,8 @@ fn test() { assert (p.fst == 50); assert (p.snd == 60); - let v0 = [32000u16, 32001u16, 32002u16]; - let v1 = [0u16, 0u16, 0u16]; + let v0 = [32000u16, 32001u16, 32002u16]/~; + let v1 = [0u16, 0u16, 0u16]/~; ptr::memcpy(ptr::offset(vec::unsafe::to_ptr(v1), 1u), ptr::offset(vec::unsafe::to_ptr(v0), 1u), 1u); @@ -185,7 +185,7 @@ fn test_buf_len() { str::as_c_str(s0) {|p0| str::as_c_str(s1) {|p1| str::as_c_str(s2) {|p2| - let v = [p0, p1, p2, null()]; + let v = [p0, p1, p2, null()]/~; vec::as_buf(v) {|vp| assert unsafe { buf_len(vp) } == 3u; } diff --git a/src/libcore/rand.rs b/src/libcore/rand.rs index 99ac4addc78..e4cbd475c9a 100644 --- a/src/libcore/rand.rs +++ b/src/libcore/rand.rs @@ -7,9 +7,9 @@ enum rctx {} #[abi = "cdecl"] native mod rustrt { - fn rand_seed() -> [u8]; + fn rand_seed() -> [u8]/~; fn rand_new() -> *rctx; - fn rand_new_seeded(seed: [u8]) -> *rctx; + fn rand_new_seeded(seed: [u8]/~) -> *rctx; fn rand_next(c: *rctx) -> u32; fn rand_free(c: *rctx); } @@ -151,19 +151,19 @@ impl extensions for rng { } #[doc = "Return a random byte string of the specified length"] - fn gen_bytes(len: uint) -> [u8] { + fn gen_bytes(len: uint) -> [u8]/~ { vec::from_fn(len) {|_i| self.gen_u8() } } #[doc = "Choose an item randomly, failing if values is empty"] - fn choose<T:copy>(values: [T]) -> T { + fn choose<T:copy>(values: [T]/~) -> T { self.choose_option(values).get() } #[doc = "Choose some(item) randomly, returning none if values is empty"] - fn choose_option<T:copy>(values: [T]) -> option<T> { + fn choose_option<T:copy>(values: [T]/~) -> option<T> { if values.is_empty() { none } else { @@ -173,13 +173,13 @@ impl extensions for rng { #[doc = "Choose an item respecting the relative weights, failing if \ the sum of the weights is 0"] - fn choose_weighted<T: copy>(v : [weighted<T>]) -> T { + fn choose_weighted<T: copy>(v : [weighted<T>]/~) -> T { self.choose_weighted_option(v).get() } #[doc = "Choose some(item) respecting the relative weights, returning \ none if the sum of the weights is 0"] - fn choose_weighted_option<T:copy>(v: [weighted<T>]) -> option<T> { + fn choose_weighted_option<T:copy>(v: [weighted<T>]/~) -> option<T> { let mut total = 0u; for v.each {|item| total += item.weight; @@ -200,25 +200,25 @@ impl extensions for rng { #[doc = "Return a vec containing copies of the items, in order, where \ the weight of the item determines how many copies there are"] - fn weighted_vec<T:copy>(v: [weighted<T>]) -> [T] { - let mut r = []; + fn weighted_vec<T:copy>(v: [weighted<T>]/~) -> [T]/~ { + let mut r = []/~; for v.each {|item| for uint::range(0u, item.weight) {|_i| - r += [item.item]; + r += [item.item]/~; } } r } #[doc = "Shuffle a vec"] - fn shuffle<T:copy>(values: [T]) -> [T] { + fn shuffle<T:copy>(values: [T]/~) -> [T]/~ { let mut m = vec::to_mut(values); self.shuffle_mut(m); ret vec::from_mut(m); } #[doc = "Shuffle a mutable vec in place"] - fn shuffle_mut<T>(&&values: [mut T]) { + fn shuffle_mut<T>(&&values: [mut T]/~) { let mut i = values.len(); while i >= 2u { // invariant: elements with index >= i have been locked in place. @@ -241,7 +241,7 @@ impl of rng for @rand_res { } #[doc = "Create a new random seed for seeded_rng"] -fn seed() -> [u8] { +fn seed() -> [u8]/~ { rustrt::rand_seed() } @@ -254,7 +254,7 @@ fn rng() -> rng { generator constructed with a given seed will generate the same \ sequence of values as all other generators constructed with the \ same seed. The seed may be any length."] -fn seeded_rng(seed: [u8]) -> rng { +fn seeded_rng(seed: [u8]/~) -> rng { @rand_res(rustrt::rand_new_seeded(seed)) as rng } @@ -301,7 +301,7 @@ mod tests { #[test] fn rng_seeded_custom_seed() { // much shorter than generated seeds which are 1024 bytes - let seed = [2u8, 32u8, 4u8, 32u8, 51u8]; + let seed = [2u8, 32u8, 4u8, 32u8, 51u8]/~; let ra = rand::seeded_rng(seed); let rb = rand::seeded_rng(seed); assert ra.gen_str(100u) == rb.gen_str(100u); @@ -309,7 +309,7 @@ mod tests { #[test] fn rng_seeded_custom_seed2() { - let seed = [2u8, 32u8, 4u8, 32u8, 51u8]; + let seed = [2u8, 32u8, 4u8, 32u8, 51u8]/~; let ra = rand::seeded_rng(seed); // Regression test that isaac is actually using the above vector let r = ra.next(); @@ -387,55 +387,56 @@ mod tests { #[test] fn choose() { let r = rand::rng(); - assert r.choose([1, 1, 1]) == 1; + assert r.choose([1, 1, 1]/~) == 1; } #[test] fn choose_option() { let r = rand::rng(); - assert r.choose_option([]) == none::<int>; - assert r.choose_option([1, 1, 1]) == some(1); + assert r.choose_option([]/~) == none::<int>; + assert r.choose_option([1, 1, 1]/~) == some(1); } #[test] fn choose_weighted() { let r = rand::rng(); - assert r.choose_weighted([{weight: 1u, item: 42}]) == 42; + assert r.choose_weighted([{weight: 1u, item: 42}]/~) == 42; assert r.choose_weighted([ {weight: 0u, item: 42}, {weight: 1u, item: 43} - ]) == 43; + ]/~) == 43; } #[test] fn choose_weighted_option() { let r = rand::rng(); - assert r.choose_weighted_option([{weight: 1u, item: 42}]) == some(42); + assert r.choose_weighted_option([{weight: 1u, item: 42}]/~) == + some(42); assert r.choose_weighted_option([ {weight: 0u, item: 42}, {weight: 1u, item: 43} - ]) == some(43); - assert r.choose_weighted_option([]) == none::<int>; + ]/~) == some(43); + assert r.choose_weighted_option([]/~) == none::<int>; } #[test] fn weighted_vec() { let r = rand::rng(); - let empty: [int] = []; - assert r.weighted_vec([]) == empty; + let empty: [int]/~ = []/~; + assert r.weighted_vec([]/~) == empty; assert r.weighted_vec([ {weight: 0u, item: 3u}, {weight: 1u, item: 2u}, {weight: 2u, item: 1u} - ]) == [2u, 1u, 1u]; + ]/~) == [2u, 1u, 1u]/~; } #[test] fn shuffle() { let r = rand::rng(); - let empty: [int] = []; - assert r.shuffle([]) == empty; - assert r.shuffle([1, 1, 1]) == [1, 1, 1]; + let empty: [int]/~ = []/~; + assert r.shuffle([]/~) == empty; + assert r.shuffle([1, 1, 1]/~) == [1, 1, 1]/~; } } diff --git a/src/libcore/result.rs b/src/libcore/result.rs index 5c65971f2ea..f9b8388f465 100644 --- a/src/libcore/result.rs +++ b/src/libcore/result.rs @@ -245,18 +245,18 @@ checking for overflow: if x == uint::max_value { ret err(\"overflow\"); } else { ret ok(x+1u); } } - map([1u, 2u, 3u], inc_conditionally).chain {|incd| - assert incd == [2u, 3u, 4u]; + map([1u, 2u, 3u]/~, inc_conditionally).chain {|incd| + assert incd == [2u, 3u, 4u]/~; } "] 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] = []; + let mut vs: [V]/~ = []/~; vec::reserve(vs, vec::len(ts)); for vec::each(ts) {|t| alt op(t) { - ok(v) { vs += [v]; } + ok(v) { vs += [v]/~; } err(u) { ret err(u); } } } @@ -284,16 +284,17 @@ length. While we do not often use preconditions in the standard library, a precondition is used here because result::t is generally 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], op: fn(S,T) -> result<V,U>) - : vec::same_length(ss, ts) -> result<[V],U> { +fn map_vec2<S,T,U:copy,V:copy>(ss: [S]/~, ts: [T]/~, + op: fn(S,T) -> result<V,U>) + : vec::same_length(ss, ts) -> result<[V]/~,U> { let n = vec::len(ts); - let mut vs = []; + let mut vs = []/~; vec::reserve(vs, n); let mut i = 0u; while i < n { alt op(ss[i],ts[i]) { - ok(v) { vs += [v]; } + ok(v) { vs += [v]/~; } err(u) { ret err(u); } } i += 1u; @@ -306,7 +307,7 @@ Applies op to the pairwise elements from `ss` and `ts`, aborting on 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>) : vec::same_length(ss, ts) -> result<(),U> { diff --git a/src/libcore/run.rs b/src/libcore/run.rs index beb314593ab..6c724db52b5 100644 --- a/src/libcore/run.rs +++ b/src/libcore/run.rs @@ -62,8 +62,8 @@ Run a program, providing stdin, stdout and stderr handles The process id of the spawned process "] -fn spawn_process(prog: str, args: [str], - env: option<[(str,str)]>, +fn spawn_process(prog: str, args: [str]/~, + env: option<[(str,str)]/~>, dir: option<str>, in_fd: c_int, out_fd: c_int, err_fd: c_int) -> pid_t { @@ -77,36 +77,36 @@ fn spawn_process(prog: str, args: [str], } } -fn with_argv<T>(prog: str, args: [str], +fn with_argv<T>(prog: str, args: [str]/~, cb: fn(**libc::c_char) -> T) -> T { - let mut argptrs = str::as_c_str(prog) {|b| [b] }; - let mut tmps = []; + let mut argptrs = str::as_c_str(prog) {|b| [b]/~ }; + let mut tmps = []/~; for vec::each(args) {|arg| let t = @arg; - tmps += [t]; - argptrs += str::as_c_str(*t) {|b| [b] }; + tmps += [t]/~; + argptrs += str::as_c_str(*t) {|b| [b]/~ }; } - argptrs += [ptr::null()]; + argptrs += [ptr::null()]/~; vec::as_buf(argptrs, cb) } #[cfg(unix)] -fn with_envp<T>(env: option<[(str,str)]>, +fn with_envp<T>(env: option<[(str,str)]/~>, cb: fn(*c_void) -> T) -> T { // On posixy systems we can pass a char** for envp, which is // a null-terminated array of "k=v\n" strings. alt env { some(es) if !vec::is_empty(es) { - let mut tmps = []; - let mut ptrs = []; + let mut tmps = []/~; + let mut ptrs = []/~; for vec::each(es) {|e| let (k,v) = e; let t = @(#fmt("%s=%s", k, v)); vec::push(tmps, t); - ptrs += str::as_c_str(*t) {|b| [b]}; + ptrs += str::as_c_str(*t) {|b| [b]/~}; } - ptrs += [ptr::null()]; + ptrs += [ptr::null()]/~; vec::as_buf(ptrs) { |p| unsafe { cb(::unsafe::reinterpret_cast(p)) } } @@ -118,7 +118,7 @@ fn with_envp<T>(env: option<[(str,str)]>, } #[cfg(windows)] -fn with_envp<T>(env: option<[(str,str)]>, +fn with_envp<T>(env: option<[(str,str)]/~>, cb: fn(*c_void) -> T) -> T { // On win32 we pass an "environment block" which is not a char**, but // rather a concatenation of null-terminated k=v\0 sequences, with a final @@ -126,15 +126,15 @@ fn with_envp<T>(env: option<[(str,str)]>, unsafe { alt env { some(es) if !vec::is_empty(es) { - let mut blk : [u8] = []; + let mut blk : [u8]/~ = []/~; for vec::each(es) {|e| let (k,v) = e; let t = #fmt("%s=%s", k, v); - let mut v : [u8] = ::unsafe::reinterpret_cast(t); + let mut v : [u8]/~ = ::unsafe::reinterpret_cast(t); blk += v; ::unsafe::forget(v); } - blk += [0_u8]; + blk += [0_u8]/~; vec::as_buf(blk) {|p| cb(::unsafe::reinterpret_cast(p)) } } _ { @@ -164,7 +164,7 @@ Spawns a process and waits for it to terminate The process id "] -fn run_program(prog: str, args: [str]) -> int { +fn run_program(prog: str, args: [str]/~) -> int { let pid = spawn_process(prog, args, none, none, 0i32, 0i32, 0i32); if pid == -1 as pid_t { fail; } @@ -187,7 +187,7 @@ The class will ensure that file descriptors are closed properly. A class with a <program> field "] -fn start_program(prog: str, args: [str]) -> program { +fn start_program(prog: str, args: [str]/~) -> program { let pipe_input = os::pipe(); let pipe_output = os::pipe(); let pipe_err = os::pipe(); @@ -271,7 +271,7 @@ contents of stdout and stderr. A record, {status: int, out: str, err: str} containing the exit code, the contents of stdout and the contents of stderr. "] -fn program_output(prog: str, args: [str]) -> +fn program_output(prog: str, args: [str]/~) -> {status: int, out: str, err: str} { let pipe_in = os::pipe(); @@ -397,9 +397,9 @@ mod tests { // Regression test for memory leaks #[ignore(cfg(windows))] // FIXME (#2626) fn test_leaks() { - run::run_program("echo", []); - run::start_program("echo", []); - run::program_output("echo", []); + run::run_program("echo", []/~); + run::start_program("echo", []/~); + run::program_output("echo", []/~); } #[test] @@ -410,7 +410,7 @@ mod tests { let pid = run::spawn_process( - "cat", [], none, none, + "cat", []/~, none, none, pipe_in.in, pipe_out.out, pipe_err.out); os::close(pipe_in.in); os::close(pipe_out.out); @@ -430,7 +430,7 @@ mod tests { #[test] fn waitpid() { - let pid = run::spawn_process("false", [], + let pid = run::spawn_process("false", []/~, none, none, 0i32, 0i32, 0i32); let status = run::waitpid(pid); diff --git a/src/libcore/str.rs b/src/libcore/str.rs index 7b64f6da0bb..63d833e197f 100644 --- a/src/libcore/str.rs +++ b/src/libcore/str.rs @@ -122,7 +122,7 @@ Convert a vector of bytes to a UTF-8 string Fails if invalid UTF-8 "] -pure fn from_bytes(vv: [u8]) -> str { +pure fn from_bytes(vv: [u8]/~) -> str { assert is_utf8(vv); ret unsafe { unsafe::from_bytes(vv) }; } @@ -136,7 +136,7 @@ Fails if invalid UTF-8 "] pure fn from_byte(b: u8) -> str { assert b < 128u8; - let mut v = [b, 0u8]; + let mut v = [b, 0u8]/~; unsafe { ::unsafe::transmute(v) } } @@ -209,7 +209,7 @@ fn push_char(&s: str, ch: char) { } as_bytes(s) {|bytes| - let mut mut_bytes: [u8] = ::unsafe::reinterpret_cast(bytes); + let mut mut_bytes: [u8]/~ = ::unsafe::reinterpret_cast(bytes); vec::unsafe::set_len(mut_bytes, new_len + 1u); ::unsafe::forget(mut_bytes); } @@ -322,10 +322,10 @@ Converts a string to a vector of bytes The result vector is not null-terminated. "] -pure fn bytes(s: str) -> [u8] { +pure fn bytes(s: str) -> [u8]/~ { unsafe { let mut s_copy = s; - let mut v: [u8] = ::unsafe::transmute(s_copy); + let mut v: [u8]/~ = ::unsafe::transmute(s_copy); vec::unsafe::set_len(v, len(s)); ret v; } @@ -342,12 +342,12 @@ pure fn byte_slice<T>(s: str/&, f: fn([u8]/&) -> T) -> T { } #[doc = "Convert a string to a vector of characters"] -pure fn chars(s: str/&) -> [char] { - let mut buf = [], i = 0u; +pure fn chars(s: str/&) -> [char]/~ { + let mut buf = []/~, i = 0u; let len = len(s); while i < len { let {ch, next} = char_range_at(s, i); - buf += [ch]; + buf += [ch]/~; i = next; } ret buf; @@ -378,7 +378,7 @@ pure fn slice(s: str/&, begin: uint, end: uint) -> str { #[doc = " Splits a string into substrings at each occurrence of a given character "] -pure fn split_char(s: str/&, sep: char) -> [str] { +pure fn split_char(s: str/&, sep: char) -> [str]/~ { split_char_inner(s, sep, len(s), true) } @@ -388,27 +388,27 @@ character up to 'count' times The byte must be a valid UTF-8/ASCII byte "] -pure fn splitn_char(s: str/&, sep: char, count: uint) -> [str] { +pure fn splitn_char(s: str/&, sep: char, count: uint) -> [str]/~ { split_char_inner(s, sep, count, true) } #[doc = " Like `split_char`, but omits empty strings from the returned vector "] -pure fn split_char_nonempty(s: str/&, sep: char) -> [str] { +pure fn split_char_nonempty(s: str/&, sep: char) -> [str]/~ { split_char_inner(s, sep, len(s), false) } pure fn split_char_inner(s: str/&, sep: char, count: uint, allow_empty: bool) - -> [str] { + -> [str]/~ { if sep < 128u as char { let b = sep as u8, l = len(s); - let mut result = [], done = 0u; + let mut result = []/~, done = 0u; let mut i = 0u, start = 0u; while i < l && done < count { if s[i] == b { if allow_empty || start < i { - result += [unsafe { unsafe::slice_bytes(s, start, i) }]; + result += [unsafe { unsafe::slice_bytes(s, start, i) }]/~; } start = i + 1u; done += 1u; @@ -416,7 +416,7 @@ pure fn split_char_inner(s: str/&, sep: char, count: uint, allow_empty: bool) i += 1u; } if allow_empty || start < l { - result += [unsafe { unsafe::slice_bytes(s, start, l) }]; + result += [unsafe { unsafe::slice_bytes(s, start, l) }]/~; } result } else { @@ -426,7 +426,7 @@ pure fn split_char_inner(s: str/&, sep: char, count: uint, allow_empty: bool) #[doc = "Splits a string into substrings using a character function"] -pure fn split(s: str/&, sepfn: fn(char) -> bool) -> [str] { +pure fn split(s: str/&, sepfn: fn(char) -> bool) -> [str]/~ { split_inner(s, sepfn, len(s), true) } @@ -434,24 +434,24 @@ pure fn split(s: str/&, sepfn: fn(char) -> bool) -> [str] { Splits a string into substrings using a character function, cutting at most `count` times. "] -pure fn splitn(s: str/&, sepfn: fn(char) -> bool, count: uint) -> [str] { +pure fn splitn(s: str/&, sepfn: fn(char) -> bool, count: uint) -> [str]/~ { split_inner(s, sepfn, count, true) } #[doc = "Like `split`, but omits empty strings from the returned vector"] -pure fn split_nonempty(s: str/&, sepfn: fn(char) -> bool) -> [str] { +pure fn split_nonempty(s: str/&, sepfn: fn(char) -> bool) -> [str]/~ { split_inner(s, sepfn, len(s), false) } pure fn split_inner(s: str/&, sepfn: fn(cc: char) -> bool, count: uint, - allow_empty: bool) -> [str] { + allow_empty: bool) -> [str]/~ { let l = len(s); - let mut result = [], i = 0u, start = 0u, done = 0u; + let mut result = []/~, i = 0u, start = 0u, done = 0u; while i < l && done < count { let {ch, next} = char_range_at(s, i); if sepfn(ch) { if allow_empty || start < i { - result += [unsafe { unsafe::slice_bytes(s, start, i) }]; + result += [unsafe { unsafe::slice_bytes(s, start, i) }]/~; } start = next; done += 1u; @@ -459,7 +459,7 @@ pure fn split_inner(s: str/&, sepfn: fn(cc: char) -> bool, count: uint, i = next; } if allow_empty || start < l { - result += [unsafe { unsafe::slice_bytes(s, start, l) }]; + result += [unsafe { unsafe::slice_bytes(s, start, l) }]/~; } result } @@ -510,19 +510,19 @@ Splits a string into a vector of the substrings separated by a given string assert [\"\", \"XXX\", \"YYY\", \"\"] == split_str(\".XXX.YYY.\", \".\") ~~~ "] -pure fn split_str(s: str/&a, sep: str/&b) -> [str] { - let mut result = []; +pure fn split_str(s: str/&a, sep: str/&b) -> [str]/~ { + let mut result = []/~; iter_between_matches(s, sep) {|from, to| - unsafe { result += [unsafe::slice_bytes(s, from, to)]; } + unsafe { result += [unsafe::slice_bytes(s, from, to)]/~; } } result } -pure fn split_str_nonempty(s: str/&a, sep: str/&b) -> [str] { - let mut result = []; +pure fn split_str_nonempty(s: str/&a, sep: str/&b) -> [str]/~ { + let mut result = []/~; iter_between_matches(s, sep) {|from, to| if to > from { - unsafe { result += [unsafe::slice_bytes(s, from, to)]; } + unsafe { result += [unsafe::slice_bytes(s, from, to)]/~; } } } result @@ -531,13 +531,13 @@ pure fn split_str_nonempty(s: str/&a, sep: str/&b) -> [str] { #[doc = " Splits a string into a vector of the substrings separated by LF ('\\n') "] -pure fn lines(s: str/&) -> [str] { split_char(s, '\n') } +pure fn lines(s: str/&) -> [str]/~ { split_char(s, '\n') } #[doc = " Splits a string into a vector of the substrings separated by LF ('\\n') and/or CR LF ('\\r\\n') "] -pure fn lines_any(s: str/&) -> [str] { +pure fn lines_any(s: str/&) -> [str]/~ { vec::map(lines(s), {|s| let l = len(s); let mut cp = s; @@ -551,7 +551,7 @@ pure fn lines_any(s: str/&) -> [str] { #[doc = " Splits a string into a vector of the substrings separated by whitespace "] -pure fn words(s: str/&) -> [str] { +pure fn words(s: str/&) -> [str]/~ { split_nonempty(s, {|c| char::is_whitespace(c)}) } @@ -1264,8 +1264,8 @@ pure fn is_utf16(v: [const u16]/&) -> bool { } #[doc = "Converts to a vector of `u16` encoded as UTF-16"] -pure fn to_utf16(s: str/&) -> [u16] { - let mut u = []; +pure fn to_utf16(s: str/&) -> [u16]/~ { + let mut u = []/~; chars_iter(s) {|cch| // Arithmetic with u32 literals is easier on the eyes than chars. let mut ch = cch as u32; @@ -1273,14 +1273,14 @@ pure fn to_utf16(s: str/&) -> [u16] { if (ch & 0xFFFF_u32) == ch { // The BMP falls through (assuming non-surrogate, as it should) assert ch <= 0xD7FF_u32 || ch >= 0xE000_u32; - u += [ch as u16] + u += [ch as u16]/~ } else { // Supplementary planes break into surrogates. assert ch >= 0x1_0000_u32 && ch <= 0x10_FFFF_u32; ch -= 0x1_0000_u32; let w1 = 0xD800_u16 | ((ch >> 10) as u16); let w2 = 0xDC00_u16 | ((ch as u16) & 0x3FF_u16); - u += [w1, w2] + u += [w1, w2]/~ } } ret u; @@ -1568,9 +1568,9 @@ interop. let i = str::as_bytes(\"Hello World\") { |bytes| vec::len(bytes) }; ~~~ "] -pure fn as_bytes<T>(s: str, f: fn([u8]) -> T) -> T { +pure fn as_bytes<T>(s: str, f: fn([u8]/~) -> T) -> T { unsafe { - let v: *[u8] = ::unsafe::reinterpret_cast(ptr::addr_of(s)); + let v: *[u8]/~ = ::unsafe::reinterpret_cast(ptr::addr_of(s)); f(*v) } } @@ -1723,7 +1723,7 @@ mod unsafe { #[doc = "Create a Rust string from a *u8 buffer of the given length"] unsafe fn from_buf_len(buf: *u8, len: uint) -> str { - let mut v: [u8] = []; + let mut v: [u8]/~ = []/~; vec::reserve(v, len + 1u); vec::as_buf(v) {|b| ptr::memcpy(b, buf, len); } vec::unsafe::set_len(v, len); @@ -1750,9 +1750,9 @@ mod unsafe { Does not verify that the vector contains valid UTF-8. "] - unsafe fn from_bytes(v: [const u8]) -> str { + unsafe fn from_bytes(v: [const u8]/~) -> str { unsafe { - let mut vcopy : [u8] = ::unsafe::transmute(copy v); + let mut vcopy = ::unsafe::transmute(copy v); vec::push(vcopy, 0u8); ::unsafe::transmute(vcopy) } @@ -1763,7 +1763,7 @@ mod unsafe { Does not verify that the byte is valid UTF-8. "] - unsafe fn from_byte(u: u8) -> str { unsafe::from_bytes([u]) } + unsafe fn from_byte(u: u8) -> str { unsafe::from_bytes([u]/~) } #[doc = " Takes a bytewise (not UTF-8) slice from a string. @@ -1780,7 +1780,7 @@ mod unsafe { assert (begin <= end); assert (end <= n); - let mut v = []; + let mut v = []/~; vec::reserve(v, end - begin + 1u); unsafe { vec::as_buf(v) { |vbuf| @@ -1788,7 +1788,7 @@ mod unsafe { ptr::memcpy(vbuf, src, end - begin); } vec::unsafe::set_len(v, end - begin); - v += [0u8]; + v += [0u8]/~; ::unsafe::transmute(v) } } @@ -1800,7 +1800,7 @@ mod unsafe { } #[doc = "Appends a vector of bytes to a string. (Not UTF-8 safe)."] - unsafe fn push_bytes(&s: str, bytes: [u8]) { + unsafe fn push_bytes(&s: str, bytes: [u8]/~) { for vec::each(bytes) {|byte| rustrt::rust_str_push(s, byte); } } @@ -1839,7 +1839,7 @@ mod unsafe { #[test] fn test_from_buf_len() { unsafe { - let a = [65u8, 65u8, 65u8, 65u8, 65u8, 65u8, 65u8, 0u8]; + let a = [65u8, 65u8, 65u8, 65u8, 65u8, 65u8, 65u8, 0u8]/~; let b = vec::unsafe::to_ptr(a); let c = from_buf_len(b, 3u); assert (c == "AAA"); @@ -1920,18 +1920,18 @@ impl extensions/& for str/& { fn slice(begin: uint, end: uint) -> str { slice(self, begin, end) } #[doc = "Splits a string into substrings using a character function"] #[inline] - fn split(sepfn: fn(char) -> bool) -> [str] { split(self, sepfn) } + fn split(sepfn: fn(char) -> bool) -> [str]/~ { split(self, sepfn) } #[doc = " Splits a string into substrings at each occurrence of a given character "] #[inline] - fn split_char(sep: char) -> [str] { split_char(self, sep) } + fn split_char(sep: char) -> [str]/~ { split_char(self, sep) } #[doc = " Splits a string into a vector of the substrings separated by a given string "] #[inline] - fn split_str(sep: str/&a) -> [str] { split_str(self, sep) } + fn split_str(sep: str/&a) -> [str]/~ { split_str(self, sep) } #[doc = "Returns true if one string starts with another"] #[inline] fn starts_with(needle: str/&a) -> bool { starts_with(self, needle) } @@ -2032,79 +2032,79 @@ mod tests { #[test] fn test_split_char() { - fn t(s: str, c: char, u: [str]) { + fn t(s: str, c: char, u: [str]/~) { log(debug, "split_byte: " + s); let v = split_char(s, c); #debug("split_byte to: %?", v); assert vec::all2(v, u, { |a,b| a == b }); } - t("abc.hello.there", '.', ["abc", "hello", "there"]); - t(".hello.there", '.', ["", "hello", "there"]); - t("...hello.there.", '.', ["", "", "", "hello", "there", ""]); + t("abc.hello.there", '.', ["abc", "hello", "there"]/~); + t(".hello.there", '.', ["", "hello", "there"]/~); + t("...hello.there.", '.', ["", "", "", "hello", "there", ""]/~); - assert ["", "", "", "hello", "there", ""] + assert ["", "", "", "hello", "there", ""]/~ == split_char("...hello.there.", '.'); - assert [""] == split_char("", 'z'); - assert ["",""] == split_char("z", 'z'); - assert ["ok"] == split_char("ok", 'z'); + assert [""]/~ == split_char("", 'z'); + assert ["",""]/~ == split_char("z", 'z'); + assert ["ok"]/~ == split_char("ok", 'z'); } #[test] fn test_split_char_2() { let data = "ประเทศไทย中华Việt Nam"; - assert ["ประเทศไทย中华", "iệt Nam"] + assert ["ประเทศไทย中华", "iệt Nam"]/~ == split_char(data, 'V'); - assert ["ประเ", "ศไ", "ย中华Việt Nam"] + assert ["ประเ", "ศไ", "ย中华Việt Nam"]/~ == split_char(data, 'ท'); } #[test] fn test_splitn_char() { - fn t(s: str, c: char, n: uint, u: [str]) { + fn t(s: str, c: char, n: uint, u: [str]/~) { log(debug, "splitn_byte: " + s); let v = splitn_char(s, c, n); #debug("split_byte to: %?", v); #debug("comparing vs. %?", u); assert vec::all2(v, u, { |a,b| a == b }); } - t("abc.hello.there", '.', 0u, ["abc.hello.there"]); - t("abc.hello.there", '.', 1u, ["abc", "hello.there"]); - t("abc.hello.there", '.', 2u, ["abc", "hello", "there"]); - t("abc.hello.there", '.', 3u, ["abc", "hello", "there"]); - t(".hello.there", '.', 0u, [".hello.there"]); - t(".hello.there", '.', 1u, ["", "hello.there"]); - t("...hello.there.", '.', 3u, ["", "", "", "hello.there."]); - t("...hello.there.", '.', 5u, ["", "", "", "hello", "there", ""]); + t("abc.hello.there", '.', 0u, ["abc.hello.there"]/~); + t("abc.hello.there", '.', 1u, ["abc", "hello.there"]/~); + t("abc.hello.there", '.', 2u, ["abc", "hello", "there"]/~); + t("abc.hello.there", '.', 3u, ["abc", "hello", "there"]/~); + t(".hello.there", '.', 0u, [".hello.there"]/~); + t(".hello.there", '.', 1u, ["", "hello.there"]/~); + t("...hello.there.", '.', 3u, ["", "", "", "hello.there."]/~); + t("...hello.there.", '.', 5u, ["", "", "", "hello", "there", ""]/~); - assert [""] == splitn_char("", 'z', 5u); - assert ["",""] == splitn_char("z", 'z', 5u); - assert ["ok"] == splitn_char("ok", 'z', 5u); - assert ["z"] == splitn_char("z", 'z', 0u); - assert ["w.x.y"] == splitn_char("w.x.y", '.', 0u); - assert ["w","x.y"] == splitn_char("w.x.y", '.', 1u); + assert [""]/~ == splitn_char("", 'z', 5u); + assert ["",""]/~ == splitn_char("z", 'z', 5u); + assert ["ok"]/~ == splitn_char("ok", 'z', 5u); + assert ["z"]/~ == splitn_char("z", 'z', 0u); + assert ["w.x.y"]/~ == splitn_char("w.x.y", '.', 0u); + assert ["w","x.y"]/~ == splitn_char("w.x.y", '.', 1u); } #[test] fn test_splitn_char_2 () { let data = "ประเทศไทย中华Việt Nam"; - assert ["ประเทศไทย中", "Việt Nam"] + assert ["ประเทศไทย中", "Việt Nam"]/~ == splitn_char(data, '华', 1u); - assert ["", "", "XXX", "YYYzWWWz"] + assert ["", "", "XXX", "YYYzWWWz"]/~ == splitn_char("zzXXXzYYYzWWWz", 'z', 3u); - assert ["",""] == splitn_char("z", 'z', 5u); - assert [""] == splitn_char("", 'z', 5u); - assert ["ok"] == splitn_char("ok", 'z', 5u); + assert ["",""]/~ == splitn_char("z", 'z', 5u); + assert [""]/~ == splitn_char("", 'z', 5u); + assert ["ok"]/~ == splitn_char("ok", 'z', 5u); } #[test] fn test_splitn_char_3() { let data = "ประเทศไทย中华Việt Nam"; - assert ["ประเทศไทย中华", "iệt Nam"] + assert ["ประเทศไทย中华", "iệt Nam"]/~ == splitn_char(data, 'V', 1u); - assert ["ประเ", "ศไทย中华Việt Nam"] + assert ["ประเ", "ศไทย中华Việt Nam"]/~ == splitn_char(data, 'ท', 1u); } @@ -2125,40 +2125,40 @@ mod tests { t("::hello::there::", "::", 3, ""); let data = "ประเทศไทย中华Việt Nam"; - assert ["ประเทศไทย", "Việt Nam"] + assert ["ประเทศไทย", "Việt Nam"]/~ == split_str (data, "中华"); - assert ["", "XXX", "YYY", ""] + assert ["", "XXX", "YYY", ""]/~ == split_str("zzXXXzzYYYzz", "zz"); - assert ["zz", "zYYYz"] + assert ["zz", "zYYYz"]/~ == split_str("zzXXXzYYYz", "XXX"); - assert ["", "XXX", "YYY", ""] == split_str(".XXX.YYY.", "."); - assert [""] == split_str("", "."); - assert ["",""] == split_str("zz", "zz"); - assert ["ok"] == split_str("ok", "z"); - assert ["","z"] == split_str("zzz", "zz"); - assert ["","","z"] == split_str("zzzzz", "zz"); + assert ["", "XXX", "YYY", ""]/~ == split_str(".XXX.YYY.", "."); + assert [""]/~ == split_str("", "."); + assert ["",""]/~ == split_str("zz", "zz"); + assert ["ok"]/~ == split_str("ok", "z"); + assert ["","z"]/~ == split_str("zzz", "zz"); + assert ["","","z"]/~ == split_str("zzzzz", "zz"); } #[test] fn test_split() { let data = "ประเทศไทย中华Việt Nam"; - assert ["ประเทศไทย中", "Việt Nam"] + assert ["ประเทศไทย中", "Việt Nam"]/~ == split (data, {|cc| cc == '华'}); - assert ["", "", "XXX", "YYY", ""] + assert ["", "", "XXX", "YYY", ""]/~ == split("zzXXXzYYYz", char::is_lowercase); - assert ["zz", "", "", "z", "", "", "z"] + assert ["zz", "", "", "z", "", "", "z"]/~ == split("zzXXXzYYYz", char::is_uppercase); - assert ["",""] == split("z", {|cc| cc == 'z'}); - assert [""] == split("", {|cc| cc == 'z'}); - assert ["ok"] == split("ok", {|cc| cc == 'z'}); + assert ["",""]/~ == split("z", {|cc| cc == 'z'}); + assert [""]/~ == split("", {|cc| cc == 'z'}); + assert ["ok"]/~ == split("ok", {|cc| cc == 'z'}); } #[test] @@ -2166,34 +2166,34 @@ mod tests { let lf = "\nMary had a little lamb\nLittle lamb\n"; let crlf = "\r\nMary had a little lamb\r\nLittle lamb\r\n"; - assert ["", "Mary had a little lamb", "Little lamb", ""] + assert ["", "Mary had a little lamb", "Little lamb", ""]/~ == lines(lf); - assert ["", "Mary had a little lamb", "Little lamb", ""] + assert ["", "Mary had a little lamb", "Little lamb", ""]/~ == lines_any(lf); - assert ["\r", "Mary had a little lamb\r", "Little lamb\r", ""] + assert ["\r", "Mary had a little lamb\r", "Little lamb\r", ""]/~ == lines(crlf); - assert ["", "Mary had a little lamb", "Little lamb", ""] + assert ["", "Mary had a little lamb", "Little lamb", ""]/~ == lines_any(crlf); - assert [""] == lines (""); - assert [""] == lines_any(""); - assert ["",""] == lines ("\n"); - assert ["",""] == lines_any("\n"); - assert ["banana"] == lines ("banana"); - assert ["banana"] == lines_any("banana"); + assert [""]/~ == lines (""); + assert [""]/~ == lines_any(""); + assert ["",""]/~ == lines ("\n"); + assert ["",""]/~ == lines_any("\n"); + assert ["banana"]/~ == lines ("banana"); + assert ["banana"]/~ == lines_any("banana"); } #[test] fn test_words () { let data = "\nMary had a little lamb\nLittle lamb\n"; - assert ["Mary","had","a","little","lamb","Little","lamb"] + assert ["Mary","had","a","little","lamb","Little","lamb"]/~ == words(data); - assert ["ok"] == words("ok"); - assert [] == words(""); + assert ["ok"]/~ == words("ok"); + assert []/~ == words(""); } #[test] @@ -2250,22 +2250,23 @@ mod tests { #[test] fn test_concat() { - fn t(v: [str], s: str) { assert (eq(concat(v), s)); } - t(["you", "know", "I'm", "no", "good"], "youknowI'mnogood"); - let v: [str] = []; + fn t(v: [str]/~, s: str) { assert (eq(concat(v), s)); } + t(["you", "know", "I'm", "no", "good"]/~, "youknowI'mnogood"); + let v: [str]/~ = []/~; t(v, ""); - t(["hi"], "hi"); + t(["hi"]/~, "hi"); } #[test] fn test_connect() { - fn t(v: [str], sep: str, s: str) { + fn t(v: [str]/~, sep: str, s: str) { assert (eq(connect(v, sep), s)); } - t(["you", "know", "I'm", "no", "good"], " ", "you know I'm no good"); - let v: [str] = []; + t(["you", "know", "I'm", "no", "good"]/~, + " ", "you know I'm no good"); + let v: [str]/~ = []/~; t(v, " ", ""); - t(["hi"], " ", "hi"); + t(["hi"]/~, " ", "hi"); } #[test] @@ -2517,7 +2518,7 @@ mod tests { #[test] fn test_unsafe_from_bytes() { - let a = [65u8, 65u8, 65u8, 65u8, 65u8, 65u8, 65u8]; + let a = [65u8, 65u8, 65u8, 65u8, 65u8, 65u8, 65u8]/~; let b = unsafe { unsafe::from_bytes(a) }; assert (b == "AAAAAAA"); } @@ -2534,7 +2535,7 @@ mod tests { 0x56_u8, 0x69_u8, 0xe1_u8, 0xbb_u8, 0x87_u8, 0x74_u8, 0x20_u8, 0x4e_u8, 0x61_u8, - 0x6d_u8]; + 0x6d_u8]/~; assert ss == from_bytes(bb); } @@ -2552,7 +2553,7 @@ mod tests { 0x56_u8, 0x69_u8, 0xe1_u8, 0xbb_u8, 0x87_u8, 0x74_u8, 0x20_u8, 0x4e_u8, 0x61_u8, - 0x6d_u8]; + 0x6d_u8]/~; let _x = from_bytes(bb); } @@ -2560,7 +2561,7 @@ mod tests { #[test] fn test_from_buf() { unsafe { - let a = [65u8, 65u8, 65u8, 65u8, 65u8, 65u8, 65u8, 0u8]; + let a = [65u8, 65u8, 65u8, 65u8, 65u8, 65u8, 65u8, 0u8]/~; let b = vec::unsafe::to_ptr(a); let c = unsafe::from_buf(b); assert (c == "AAAAAAA"); @@ -2609,7 +2610,7 @@ mod tests { fn vec_str_conversions() { let s1: str = "All mimsy were the borogoves"; - let v: [u8] = bytes(s1); + let v: [u8]/~ = bytes(s1); let s2: str = from_bytes(v); let mut i: uint = 0u; let n1: uint = len(s1); @@ -2774,7 +2775,7 @@ mod tests { #[test] fn test_chars() { let ss = "ศไทย中华Việt Nam"; - assert ['ศ','ไ','ท','ย','中','华','V','i','ệ','t',' ','N','a','m'] + assert ['ศ','ไ','ท','ย','中','华','V','i','ệ','t',' ','N','a','m']/~ == chars(ss); } @@ -2785,7 +2786,7 @@ mod tests { [0xd800_u16, 0xdf45_u16, 0xd800_u16, 0xdf3f_u16, 0xd800_u16, 0xdf3b_u16, 0xd800_u16, 0xdf46_u16, 0xd800_u16, 0xdf39_u16, 0xd800_u16, 0xdf3b_u16, - 0xd800_u16, 0xdf30_u16, 0x000a_u16]), + 0xd800_u16, 0xdf30_u16, 0x000a_u16]/~), ("𐐒𐑉𐐮𐑀𐐲𐑋 𐐏𐐲𐑍\n", [0xd801_u16, 0xdc12_u16, 0xd801_u16, @@ -2793,7 +2794,7 @@ mod tests { 0xdc40_u16, 0xd801_u16, 0xdc32_u16, 0xd801_u16, 0xdc4b_u16, 0x0020_u16, 0xd801_u16, 0xdc0f_u16, 0xd801_u16, 0xdc32_u16, 0xd801_u16, 0xdc4d_u16, - 0x000a_u16]), + 0x000a_u16]/~), ("𐌀𐌖𐌋𐌄𐌑𐌉·𐌌𐌄𐌕𐌄𐌋𐌉𐌑\n", [0xd800_u16, 0xdf00_u16, 0xd800_u16, 0xdf16_u16, @@ -2802,7 +2803,7 @@ mod tests { 0x00b7_u16, 0xd800_u16, 0xdf0c_u16, 0xd800_u16, 0xdf04_u16, 0xd800_u16, 0xdf15_u16, 0xd800_u16, 0xdf04_u16, 0xd800_u16, 0xdf0b_u16, 0xd800_u16, - 0xdf09_u16, 0xd800_u16, 0xdf11_u16, 0x000a_u16 ]), + 0xdf09_u16, 0xd800_u16, 0xdf11_u16, 0x000a_u16 ]/~), ("𐒋𐒘𐒈𐒑𐒛𐒒 𐒕𐒓 𐒈𐒚𐒍 𐒏𐒜𐒒𐒖𐒆 𐒕𐒆\n", [0xd801_u16, 0xdc8b_u16, 0xd801_u16, 0xdc98_u16, @@ -2815,7 +2816,7 @@ mod tests { 0xdc9c_u16, 0xd801_u16, 0xdc92_u16, 0xd801_u16, 0xdc96_u16, 0xd801_u16, 0xdc86_u16, 0x0020_u16, 0xd801_u16, 0xdc95_u16, 0xd801_u16, 0xdc86_u16, - 0x000a_u16 ]) ]; + 0x000a_u16 ]/~) ]/~; for vec::each(pairs) {|p| let (s, u) = p; diff --git a/src/libcore/to_str.rs b/src/libcore/to_str.rs index 3af4dec9b6d..229afc810e5 100644 --- a/src/libcore/to_str.rs +++ b/src/libcore/to_str.rs @@ -56,7 +56,7 @@ impl <A: to_str copy, B: to_str copy, C: to_str copy> of to_str for (A, B, C){ } } -impl <A: to_str> of to_str for [A] { +impl <A: to_str> of to_str for [A]/~ { fn to_str() -> str { let mut acc = "[", first = true; for vec::each(self) {|elt| @@ -98,11 +98,12 @@ mod tests { } fn test_vectors() { - let x: [int] = []; - assert x.to_str() == "[]"; - assert [1].to_str() == "[1]"; - assert [1, 2, 3].to_str() == "[1, 2, 3]"; - assert [[], [1], [1, 1]].to_str() == "[[], [1], [1, 1]]"; + let x: [int]/~ = []/~; + assert x.to_str() == "[]/~"; + assert [1]/~.to_str() == "[1]/~"; + assert [1, 2, 3]/~.to_str() == "[1, 2, 3]/~"; + assert [[]/~, [1]/~, [1, 1]/~]/~.to_str() == + "[[]/~, [1]/~, [1, 1]/~]/~"; } fn test_pointer_types() { diff --git a/src/libcore/uint-template.rs b/src/libcore/uint-template.rs index d341921eb03..6ec8d2e8789 100644 --- a/src/libcore/uint-template.rs +++ b/src/libcore/uint-template.rs @@ -88,7 +88,7 @@ Parse a buffer of bytes `buf` must not be empty "] -fn parse_buf(buf: [u8], radix: uint) -> option<T> { +fn parse_buf(buf: [u8]/~, radix: uint) -> option<T> { if vec::len(buf) == 0u { ret none; } let mut i = vec::len(buf) - 1u; let mut power = 1u as T; diff --git a/src/libcore/unsafe.rs b/src/libcore/unsafe.rs index 85e2f8d8934..3ebcde80281 100644 --- a/src/libcore/unsafe.rs +++ b/src/libcore/unsafe.rs @@ -33,7 +33,7 @@ Both types must have the same size and alignment. # Example - assert transmute(\"L\") == [76u8, 0u8]; + assert transmute(\"L\") == [76u8, 0u8]/~; "] unsafe fn transmute<L, G>(-thing: L) -> G { let newthing = reinterpret_cast(thing); @@ -62,7 +62,7 @@ mod tests { #[test] fn test_transmute2() { unsafe { - assert transmute("L") == [76u8, 0u8]; + assert transmute("L") == [76u8, 0u8]/~; } } } diff --git a/src/libcore/vec.rs b/src/libcore/vec.rs index 3f34ee5aabb..0f9cedd84c6 100644 --- a/src/libcore/vec.rs +++ b/src/libcore/vec.rs @@ -126,7 +126,7 @@ capacity, then no action is taken. * v - A vector * n - The number of elements to reserve space for "] -fn reserve<T>(&v: [const T], n: uint) { +fn reserve<T>(&v: [const T]/~, n: uint) { // Only make the (slow) call into the runtime if we have to if capacity(v) < n { let ptr = ptr::addr_of(v) as **unsafe::vec_repr; @@ -150,7 +150,7 @@ capacity, then no action is taken. * v - A vector * n - The number of elements to reserve space for "] -fn reserve_at_least<T>(&v: [const T], n: uint) { +fn reserve_at_least<T>(&v: [const T]/~, n: uint) { reserve(v, uint::next_power_of_two(n)); } @@ -158,7 +158,7 @@ fn reserve_at_least<T>(&v: [const T], n: uint) { Returns the number of elements the vector can hold without reallocating "] #[inline(always)] -pure fn capacity<T>(&&v: [const T]) -> uint { +pure fn capacity<T>(&&v: [const T]/~) -> uint { unsafe { let repr: **unsafe::vec_repr = ::unsafe::reinterpret_cast(addr_of(v)); (**repr).alloc / sys::size_of::<T>() @@ -177,8 +177,8 @@ Creates and initializes an immutable vector. Creates an immutable vector of size `n_elts` and initializes the elements to the value returned by the function `op`. "] -pure fn from_fn<T>(n_elts: uint, op: init_op<T>) -> [T] { - let mut v = []; +pure fn from_fn<T>(n_elts: uint, op: init_op<T>) -> [T]/~ { + let mut v = []/~; unchecked{reserve(v, n_elts);} let mut i: uint = 0u; while i < n_elts unsafe { push(v, op(i)); i += 1u; } @@ -191,8 +191,8 @@ Creates and initializes an immutable vector. Creates an immutable vector of size `n_elts` and initializes the elements to the value `t`. "] -pure fn from_elem<T: copy>(n_elts: uint, t: T) -> [T] { - let mut v = []; +pure fn from_elem<T: copy>(n_elts: uint, t: T) -> [T]/~ { + let mut v = []/~; unchecked{reserve(v, n_elts)} let mut i: uint = 0u; unsafe { // because push is impure @@ -202,12 +202,12 @@ pure fn from_elem<T: copy>(n_elts: uint, t: T) -> [T] { } #[doc = "Produces a mut vector from an immutable vector."] -fn to_mut<T>(+v: [T]) -> [mut T] { +fn to_mut<T>(+v: [T]/~) -> [mut T]/~ { unsafe { ::unsafe::transmute(v) } } #[doc = "Produces an immutable vector from a mut vector."] -fn from_mut<T>(+v: [mut T]) -> [T] { +fn from_mut<T>(+v: [mut T]/~) -> [T]/~ { unsafe { ::unsafe::transmute(v) } } @@ -217,18 +217,18 @@ fn from_mut<T>(+v: [mut T]) -> [T] { pure fn head<T: copy>(v: [const T]/&) -> T { v[0] } #[doc = "Returns a vector containing all but the first element of a slice"] -pure fn tail<T: copy>(v: [const T]/&) -> [T] { +pure fn tail<T: copy>(v: [const T]/&) -> [T]/~ { ret slice(v, 1u, len(v)); } #[doc = "Returns a vector containing all but the first `n` \ elements of a slice"] -pure fn tailn<T: copy>(v: [const T]/&, n: uint) -> [T] { +pure fn tailn<T: copy>(v: [const T]/&, n: uint) -> [T]/~ { slice(v, n, len(v)) } #[doc = "Returns a vector containing all but the last element of a slice"] -pure fn init<T: copy>(v: [const T]/&) -> [T] { +pure fn init<T: copy>(v: [const T]/&) -> [T]/~ { assert len(v) != 0u; slice(v, 0u, len(v) - 1u) } @@ -251,10 +251,10 @@ pure fn last_opt<T: copy>(v: [const T]/&) -> option<T> { } #[doc = "Returns a copy of the elements from [`start`..`end`) from `v`."] -pure fn slice<T: copy>(v: [const T]/&, start: uint, end: uint) -> [T] { +pure fn slice<T: copy>(v: [const T]/&, start: uint, end: uint) -> [T]/~ { assert (start <= end); assert (end <= len(v)); - let mut result = []; + let mut result = []/~; unchecked { push_all(result, view(v, start, end)); } @@ -276,12 +276,12 @@ pure fn view<T: copy>(v: [const T]/&, start: uint, end: uint) -> [T]/&a { #[doc = " Split the vector `v` by applying each element against the predicate `f`. "] -fn split<T: copy>(v: [T]/&, f: fn(T) -> bool) -> [[T]] { +fn split<T: copy>(v: [T]/&, f: fn(T) -> bool) -> [[T]/~]/~ { let ln = len(v); - if (ln == 0u) { ret [] } + if (ln == 0u) { ret []/~ } let mut start = 0u; - let mut result = []; + let mut result = []/~; while start < ln { alt position_between(v, start, ln, f) { none { break } @@ -299,13 +299,13 @@ fn split<T: copy>(v: [T]/&, f: fn(T) -> bool) -> [[T]] { Split the vector `v` by applying each element against the predicate `f` up to `n` times. "] -fn splitn<T: copy>(v: [T]/&, n: uint, f: fn(T) -> bool) -> [[T]] { +fn splitn<T: copy>(v: [T]/&, n: uint, f: fn(T) -> bool) -> [[T]/~]/~ { let ln = len(v); - if (ln == 0u) { ret [] } + if (ln == 0u) { ret []/~ } let mut start = 0u; let mut count = n; - let mut result = []; + let mut result = []/~; while start < ln && count > 0u { alt position_between(v, start, ln, f) { none { break } @@ -325,12 +325,12 @@ fn splitn<T: copy>(v: [T]/&, n: uint, f: fn(T) -> bool) -> [[T]] { Reverse split the vector `v` by applying each element against the predicate `f`. "] -fn rsplit<T: copy>(v: [T]/&, f: fn(T) -> bool) -> [[T]] { +fn rsplit<T: copy>(v: [T]/&, f: fn(T) -> bool) -> [[T]/~]/~ { let ln = len(v); - if (ln == 0u) { ret [] } + if (ln == 0u) { ret []/~ } let mut end = ln; - let mut result = []; + let mut result = []/~; while end > 0u { alt rposition_between(v, 0u, end, f) { none { break } @@ -348,13 +348,13 @@ fn rsplit<T: copy>(v: [T]/&, f: fn(T) -> bool) -> [[T]] { Reverse split the vector `v` by applying each element against the predicate `f` up to `n times. "] -fn rsplitn<T: copy>(v: [T]/&, n: uint, f: fn(T) -> bool) -> [[T]] { +fn rsplitn<T: copy>(v: [T]/&, n: uint, f: fn(T) -> bool) -> [[T]/~]/~ { let ln = len(v); - if (ln == 0u) { ret [] } + if (ln == 0u) { ret []/~ } let mut end = ln; let mut count = n; - let mut result = []; + let mut result = []/~; while end > 0u && count > 0u { alt rposition_between(v, 0u, end, f) { none { break } @@ -373,11 +373,11 @@ fn rsplitn<T: copy>(v: [T]/&, n: uint, f: fn(T) -> bool) -> [[T]] { // Mutators #[doc = "Removes the first element from a vector and return it"] -fn shift<T>(&v: [T]) -> T { +fn shift<T>(&v: [T]/~) -> T { let ln = len::<T>(v); assert (ln > 0u); - let mut vv = []; + let mut vv = []/~; v <-> vv; unsafe { @@ -399,8 +399,8 @@ fn shift<T>(&v: [T]) -> T { } #[doc = "Prepend an element to the vector"] -fn unshift<T>(&v: [T], +x: T) { - let mut vv = [x]; +fn unshift<T>(&v: [T]/~, +x: T) { + let mut vv = [x]/~; v <-> vv; while len(vv) > 0 { push(v, shift(vv)); @@ -408,7 +408,7 @@ fn unshift<T>(&v: [T], +x: T) { } #[doc = "Remove the last element from a vector and return it"] -fn pop<T>(&v: [const T]) -> T { +fn pop<T>(&v: [const T]/~) -> T { let ln = len(v); assert ln > 0u; let valptr = ptr::mut_addr_of(v[ln - 1u]); @@ -421,7 +421,7 @@ fn pop<T>(&v: [const T]) -> T { #[doc = "Append an element to a vector"] #[inline(always)] -fn push<T>(&v: [const T], +initval: T) { +fn push<T>(&v: [const T]/~, +initval: T) { unsafe { let repr: **unsafe::vec_repr = ::unsafe::reinterpret_cast(addr_of(v)); let fill = (**repr).fill; @@ -438,7 +438,7 @@ fn push<T>(&v: [const T], +initval: T) { } } -fn push_slow<T>(&v: [const T], +initval: T) { +fn push_slow<T>(&v: [const T]/~, +initval: T) { unsafe { let ln = v.len(); reserve_at_least(v, ln + 1u); @@ -453,8 +453,9 @@ fn push_slow<T>(&v: [const T], +initval: T) { } #[inline(always)] -fn push_all<T: copy>(&v: [const T], rhs: [const T]/&) { +fn push_all<T: copy>(&v: [const T]/~, rhs: [const T]/&) { reserve(v, v.len() + rhs.len()); + for uint::range(0u, rhs.len()) {|i| push(v, rhs[i]); } @@ -462,8 +463,8 @@ fn push_all<T: copy>(&v: [const T], rhs: [const T]/&) { // Appending #[inline(always)] -pure fn append<T: copy>(lhs: [T]/&, rhs: [const T]/&) -> [T] { - let mut v = []; +pure fn append<T: copy>(lhs: [T]/&, rhs: [const T]/&) -> [T]/~ { + let mut v = []/~; let mut i = 0u; while i < lhs.len() { unsafe { // This is impure, but it appears pure to the caller. @@ -482,8 +483,8 @@ pure fn append<T: copy>(lhs: [T]/&, rhs: [const T]/&) -> [T] { } #[inline(always)] -pure fn append_mut<T: copy>(lhs: [mut T]/&, rhs: [const T]/&) -> [mut T] { - let mut v = [mut]; +pure fn append_mut<T: copy>(lhs: [mut T]/&, rhs: [const T]/&) -> [mut T]/~ { + let mut v = [mut]/~; let mut i = 0u; while i < lhs.len() { unsafe { // This is impure, but it appears pure to the caller. @@ -510,7 +511,7 @@ Expands a vector in place, initializing the new elements to a given value * n - The number of elements to add * initval - The value for the new elements "] -fn grow<T: copy>(&v: [const T], n: uint, initval: T) { +fn grow<T: copy>(&v: [const T]/~, n: uint, initval: T) { reserve_at_least(v, len(v) + n); let mut i: uint = 0u; @@ -530,7 +531,7 @@ Function `init_op` is called `n` times with the values [0..`n`) * init_op - A function to call to retreive each appended element's value "] -fn grow_fn<T>(&v: [const T], n: uint, op: init_op<T>) { +fn grow_fn<T>(&v: [const T]/~, n: uint, op: init_op<T>) { reserve_at_least(v, len(v) + n); let mut i: uint = 0u; while i < n { push(v, op(i)); i += 1u; } @@ -545,7 +546,7 @@ of the vector, expands the vector by replicating `initval` to fill the intervening space. "] #[inline(always)] -fn grow_set<T: copy>(&v: [mut T], index: uint, initval: T, val: T) { +fn grow_set<T: copy>(&v: [mut T]/~, index: uint, initval: T, val: T) { if index >= len(v) { grow(v, index - len(v) + 1u, initval); } v[index] = val; } @@ -556,8 +557,8 @@ fn grow_set<T: copy>(&v: [mut T], index: uint, initval: T, val: T) { #[doc = " Apply a function to each element of a vector and return the results "] -pure fn map<T, U>(v: [T]/&, f: fn(T) -> U) -> [U] { - let mut result = []; +pure fn map<T, U>(v: [T]/&, f: fn(T) -> U) -> [U]/~ { + let mut result = []/~; unchecked{reserve(result, len(v));} for each(v) {|elem| unsafe { push(result, f(elem)); } } ret result; @@ -566,8 +567,8 @@ pure fn map<T, U>(v: [T]/&, f: fn(T) -> U) -> [U] { #[doc = " Apply a function to each element of a vector and return the results "] -pure fn mapi<T, U>(v: [T]/&, f: fn(uint, T) -> U) -> [U] { - let mut result = []; +pure fn mapi<T, U>(v: [T]/&, f: fn(uint, T) -> U) -> [U]/~ { + let mut result = []/~; unchecked{reserve(result, len(v));} for eachi(v) {|i, elem| unsafe { push(result, f(i, elem)); } } ret result; @@ -577,8 +578,8 @@ pure fn mapi<T, U>(v: [T]/&, f: fn(uint, T) -> U) -> [U] { Apply a function to each element of a vector and return a concatenation of each result vector "] -pure fn flat_map<T, U>(v: [T]/&, f: fn(T) -> [U]) -> [U] { - let mut result = []; +pure fn flat_map<T, U>(v: [T]/&, f: fn(T) -> [U]/~) -> [U]/~ { + let mut result = []/~; for each(v) {|elem| result += f(elem); } ret result; } @@ -587,10 +588,10 @@ pure fn flat_map<T, U>(v: [T]/&, f: fn(T) -> [U]) -> [U] { Apply a function to each pair of elements and return the results "] pure fn map2<T: copy, U: copy, V>(v0: [T]/&, v1: [U]/&, - f: fn(T, U) -> V) -> [V] { + f: fn(T, U) -> V) -> [V]/~ { let v0_len = len(v0); if v0_len != len(v1) { fail; } - let mut u: [V] = []; + let mut u: [V]/~ = []/~; let mut i = 0u; while i < v0_len { unsafe { push(u, f(copy v0[i], copy v1[i])) }; @@ -606,8 +607,8 @@ If function `f` returns `none` then that element is excluded from the resulting vector. "] pure fn filter_map<T, U: copy>(v: [T]/&, f: fn(T) -> option<U>) - -> [U] { - let mut result = []; + -> [U]/~ { + let mut result = []/~; for each(v) {|elem| alt f(elem) { none {/* no-op */ } @@ -624,8 +625,8 @@ holds. Apply function `f` to each element of `v` and return a vector containing only those elements for which `f` returned true. "] -pure fn filter<T: copy>(v: [T]/&, f: fn(T) -> bool) -> [T] { - let mut result = []; +pure fn filter<T: copy>(v: [T]/&, f: fn(T) -> bool) -> [T]/~ { + let mut result = []/~; for each(v) {|elem| if f(elem) { unsafe { push(result, elem); } } } @@ -637,8 +638,8 @@ Concatenate a vector of vectors. Flattens a vector of vectors of T into a single vector of T. "] -pure fn concat<T: copy>(v: [[T]]/&) -> [T] { - let mut r = []; +pure fn concat<T: copy>(v: [[T]/~]/&) -> [T]/~ { + let mut r = []/~; for each(v) {|inner| unsafe { push_all(r, inner); } } ret r; } @@ -646,8 +647,8 @@ pure fn concat<T: copy>(v: [[T]]/&) -> [T] { #[doc = " Concatenate a vector of vectors, placing a given separator between each "] -pure fn connect<T: copy>(v: [[T]]/&, sep: T) -> [T] { - let mut r: [T] = []; +pure fn connect<T: copy>(v: [[T]/~]/&, sep: T) -> [T]/~ { + let mut r: [T]/~ = []/~; let mut first = true; for each(v) {|inner| if first { first = false; } else { unsafe { push(r, sep); } } @@ -873,9 +874,9 @@ vector contains the first element of the i-th tuple of the input vector, and the i-th element of the second vector contains the second element of the i-th tuple of the input vector. "] -pure fn unzip<T: copy, U: copy>(v: [(T, U)]/&) -> ([T], [U]) { - let mut as = [], bs = []; - for each(v) {|p| let (a, b) = p; as += [a]; bs += [b]; } +pure fn unzip<T: copy, U: copy>(v: [(T, U)]/&) -> ([T]/~, [U]/~) { + let mut as = []/~, bs = []/~; + for each(v) {|p| let (a, b) = p; as += [a]/~; bs += [b]/~; } ret (as, bs); } @@ -885,12 +886,12 @@ Convert two vectors to a vector of pairs Returns a vector of tuples, where the i-th tuple contains contains the i-th elements from each of the input vectors. "] -pure fn zip<T: copy, U: copy>(v: [const T]/&, u: [const U]/&) -> [(T, U)] { - let mut zipped = []; +pure fn zip<T: copy, U: copy>(v: [const T]/&, u: [const U]/&) -> [(T, U)]/~ { + let mut zipped = []/~; let sz = len(v); let mut i = 0u; assert sz == len(u); - while i < sz { zipped += [(v[i], u[i])]; i += 1u; } + while i < sz { zipped += [(v[i], u[i])]/~; i += 1u; } ret zipped; } @@ -903,12 +904,12 @@ Swaps two elements in a vector * a - The index of the first element * b - The index of the second element "] -fn swap<T>(&&v: [mut T], a: uint, b: uint) { +fn swap<T>(&&v: [mut T]/~, a: uint, b: uint) { v[a] <-> v[b]; } #[doc = "Reverse the order of elements in a vector, in place"] -fn reverse<T>(v: [mut T]) { +fn reverse<T>(v: [mut T]/~) { let mut i: uint = 0u; let ln = len::<T>(v); while i < ln / 2u { v[i] <-> v[ln - i - 1u]; i += 1u; } @@ -916,12 +917,12 @@ fn reverse<T>(v: [mut T]) { #[doc = "Returns a vector with the order of elements reversed"] -fn reversed<T: copy>(v: [const T]/&) -> [T] { - let mut rs: [T] = []; +fn reversed<T: copy>(v: [const T]/&) -> [T]/~ { + let mut rs: [T]/~ = []/~; let mut i = len::<T>(v); if i == 0u { ret rs; } else { i -= 1u; } - while i != 0u { rs += [v[i]]; i -= 1u; } - rs += [v[0]]; + while i != 0u { rs += [v[i]]/~; i -= 1u; } + rs += [v[0]]/~; ret rs; } @@ -1064,28 +1065,28 @@ lexicographically sorted). The total number of permutations produced is `len(v)!`. If `v` contains repeated elements, then some permutations are repeated. "] -pure fn permute<T: copy>(v: [T]/&, put: fn([T])) { +pure fn permute<T: copy>(v: [T]/&, put: fn([T]/~)) { let ln = len(v); if ln == 0u { - put([]); + put([]/~); } else { let mut i = 0u; while i < ln { let elt = v[i]; let rest = slice(v, 0u, i) + slice(v, i+1u, ln); - permute(rest) {|permutation| put([elt] + permutation)} + permute(rest) {|permutation| put([elt]/~ + permutation)} i += 1u; } } } -pure fn windowed<TT: copy>(nn: uint, xx: [TT]/&) -> [[TT]] { - let mut ww = []; +pure fn windowed<TT: copy>(nn: uint, xx: [TT]/&) -> [[TT]/~]/~ { + let mut ww = []/~; assert 1u <= nn; vec::iteri (xx, {|ii, _x| let len = vec::len(xx); if ii+nn <= len { - ww += [vec::slice(xx, ii, ii+nn)]; + ww += [vec::slice(xx, ii, ii+nn)]/~; } }); ret ww; @@ -1146,16 +1147,16 @@ pure fn unpack_mut_slice<T,U>(s: [mut T]/&, } } -impl extensions<T: copy> for [T] { +impl extensions<T: copy> for [T]/~ { #[inline(always)] - pure fn +(rhs: [T]/&) -> [T] { + pure fn +(rhs: [T]/&) -> [T]/~ { append(self, rhs) } } -impl extensions<T: copy> for [mut T] { +impl extensions<T: copy> for [mut T]/~ { #[inline(always)] - pure fn +(rhs: [mut T]/&) -> [mut T] { + pure fn +(rhs: [mut T]/&) -> [mut T]/~ { append_mut(self, rhs) } } @@ -1180,7 +1181,7 @@ impl extensions/&<T: copy> for [const T]/& { pure fn head() -> T { head(self) } #[doc = "Returns all but the last elemnt of a vector"] #[inline] - pure fn init() -> [T] { init(self) } + pure fn init() -> [T]/~ { init(self) } #[doc = " Returns the last element of a `v`, failing if the vector is empty. "] @@ -1188,10 +1189,10 @@ impl extensions/&<T: copy> for [const T]/& { pure fn last() -> T { last(self) } #[doc = "Returns a copy of the elements from [`start`..`end`) from `v`."] #[inline] - pure fn slice(start: uint, end: uint) -> [T] { slice(self, start, end) } + pure fn slice(start: uint, end: uint) -> [T]/~ { slice(self, start, end) } #[doc = "Returns all but the first element of a vector"] #[inline] - pure fn tail() -> [T] { tail(self) } + pure fn tail() -> [T]/~ { tail(self) } } #[doc = "Extension methods for vectors"] @@ -1259,12 +1260,12 @@ impl extensions/&<T> for [T]/& { Apply a function to each element of a vector and return the results "] #[inline] - pure fn map<U>(f: fn(T) -> U) -> [U] { map(self, f) } + pure fn map<U>(f: fn(T) -> U) -> [U]/~ { map(self, f) } #[doc = " Apply a function to the index and value of each element in the vector and return the results "] - pure fn mapi<U>(f: fn(uint, T) -> U) -> [U] { + pure fn mapi<U>(f: fn(uint, T) -> U) -> [U]/~ { mapi(self, f) } #[doc = "Returns true if the function returns true for all elements. @@ -1278,7 +1279,7 @@ impl extensions/&<T> for [T]/& { of each result vector "] #[inline] - pure fn flat_map<U>(f: fn(T) -> [U]) -> [U] { flat_map(self, f) } + pure fn flat_map<U>(f: fn(T) -> [U]/~) -> [U]/~ { flat_map(self, f) } #[doc = " Apply a function to each element of a vector and return the results @@ -1286,7 +1287,7 @@ impl extensions/&<T> for [T]/& { the resulting vector. "] #[inline] - pure fn filter_map<U: copy>(f: fn(T) -> option<U>) -> [U] { + pure fn filter_map<U: copy>(f: fn(T) -> option<U>) -> [U]/~ { filter_map(self, f) } } @@ -1301,7 +1302,7 @@ impl extensions/&<T: copy> for [T]/& { only those elements for which `f` returned true. "] #[inline] - pure fn filter(f: fn(T) -> bool) -> [T] { filter(self, f) } + pure fn filter(f: fn(T) -> bool) -> [T]/~ { filter(self, f) } #[doc = " Search for the first element that matches a given predicate @@ -1342,7 +1343,7 @@ mod unsafe { * elts - The number of elements in the buffer "] #[inline(always)] - unsafe fn from_buf<T>(ptr: *T, elts: uint) -> [T] { + unsafe fn from_buf<T>(ptr: *T, elts: uint) -> [T]/~ { ret ::unsafe::reinterpret_cast( rustrt::vec_from_buf_shared(sys::get_type_desc::<T>(), ptr as *(), @@ -1357,7 +1358,7 @@ mod unsafe { the vector is actually the specified size. "] #[inline(always)] - unsafe fn set_len<T>(&&v: [const T], new_len: uint) { + unsafe fn set_len<T>(&&v: [const T]/~, new_len: uint) { let repr: **vec_repr = ::unsafe::reinterpret_cast(addr_of(v)); (**repr).fill = new_len * sys::size_of::<T>(); } @@ -1372,7 +1373,7 @@ mod unsafe { would also make any pointers to it invalid. "] #[inline(always)] - unsafe fn to_ptr<T>(v: [const T]) -> *T { + unsafe fn to_ptr<T>(v: [const T]/~) -> *T { let repr: **vec_repr = ::unsafe::reinterpret_cast(addr_of(v)); ret ::unsafe::reinterpret_cast(addr_of((**repr).data)); } @@ -1397,7 +1398,7 @@ mod u8 { export hash; #[doc = "Bytewise string comparison"] - pure fn cmp(&&a: [u8], &&b: [u8]) -> int { + pure fn cmp(&&a: [u8]/~, &&b: [u8]/~) -> int { let a_len = len(a); let b_len = len(b); let n = uint::min(a_len, b_len) as libc::size_t; @@ -1418,25 +1419,25 @@ mod u8 { } #[doc = "Bytewise less than or equal"] - pure fn lt(&&a: [u8], &&b: [u8]) -> bool { cmp(a, b) < 0 } + pure fn lt(&&a: [u8]/~, &&b: [u8]/~) -> bool { cmp(a, b) < 0 } #[doc = "Bytewise less than or equal"] - pure fn le(&&a: [u8], &&b: [u8]) -> bool { cmp(a, b) <= 0 } + pure fn le(&&a: [u8]/~, &&b: [u8]/~) -> bool { cmp(a, b) <= 0 } #[doc = "Bytewise equality"] - pure fn eq(&&a: [u8], &&b: [u8]) -> bool { unsafe { cmp(a, b) == 0 } } + pure fn eq(&&a: [u8]/~, &&b: [u8]/~) -> bool { unsafe { cmp(a, b) == 0 } } #[doc = "Bytewise inequality"] - pure fn ne(&&a: [u8], &&b: [u8]) -> bool { unsafe { cmp(a, b) != 0 } } + pure fn ne(&&a: [u8]/~, &&b: [u8]/~) -> bool { unsafe { cmp(a, b) != 0 } } #[doc ="Bytewise greater than or equal"] - pure fn ge(&&a: [u8], &&b: [u8]) -> bool { cmp(a, b) >= 0 } + pure fn ge(&&a: [u8]/~, &&b: [u8]/~) -> bool { cmp(a, b) >= 0 } #[doc = "Bytewise greater than"] - pure fn gt(&&a: [u8], &&b: [u8]) -> bool { cmp(a, b) > 0 } + pure fn gt(&&a: [u8]/~, &&b: [u8]/~) -> bool { cmp(a, b) > 0 } #[doc = "String hash function"] - fn hash(&&s: [u8]) -> uint { + fn hash(&&s: [u8]/~) -> uint { /* Seems to have been tragically copy/pasted from str.rs, or vice versa. But I couldn't figure out how to abstract it out. -- tjc */ @@ -1465,14 +1466,14 @@ impl extensions/&<A> of iter::base_iter<A> for [const A]/& { fn count(x: A) -> uint { iter::count(self, x) } } impl extensions/&<A:copy> for [const A]/& { - fn filter_to_vec(pred: fn(A) -> bool) -> [A] { + fn filter_to_vec(pred: fn(A) -> bool) -> [A]/~ { iter::filter_to_vec(self, pred) } - fn map_to_vec<B>(op: fn(A) -> B) -> [B] { iter::map_to_vec(self, op) } - fn to_vec() -> [A] { iter::to_vec(self) } + fn map_to_vec<B>(op: fn(A) -> B) -> [B]/~ { iter::map_to_vec(self, op) } + fn to_vec() -> [A]/~ { iter::to_vec(self) } // FIXME--bug in resolve prevents this from working (#2611) - // fn flat_map_to_vec<B:copy,IB:base_iter<B>>(op: fn(A) -> IB) -> [B] { + // fn flat_map_to_vec<B:copy,IB:base_iter<B>>(op: fn(A) -> IB) -> [B]/~ { // iter::flat_map_to_vec(self, op) // } @@ -1504,7 +1505,7 @@ mod tests { fn test_unsafe_ptrs() { unsafe { // Test on-stack copy-from-buf. - let a = [1, 2, 3]; + let a = [1, 2, 3]/~; let mut ptr = unsafe::to_ptr(a); let b = unsafe::from_buf(ptr, 3u); assert (len(b) == 3u); @@ -1513,7 +1514,7 @@ mod tests { assert (b[2] == 3); // Test on-heap copy-from-buf. - let c = [1, 2, 3, 4, 5]; + let c = [1, 2, 3, 4, 5]/~; ptr = unsafe::to_ptr(c); let d = unsafe::from_buf(ptr, 5u); assert (len(d) == 5u); @@ -1564,58 +1565,58 @@ mod tests { #[test] fn test_is_empty() { - assert (is_empty::<int>([])); - assert (!is_empty([0])); + assert (is_empty::<int>([]/~)); + assert (!is_empty([0]/~)); } #[test] fn test_is_not_empty() { - assert (is_not_empty([0])); - assert (!is_not_empty::<int>([])); + assert (is_not_empty([0]/~)); + assert (!is_not_empty::<int>([]/~)); } #[test] fn test_head() { - let a = [11, 12]; + let a = [11, 12]/~; assert (head(a) == 11); } #[test] fn test_tail() { - let mut a = [11]; - assert (tail(a) == []); + let mut a = [11]/~; + assert (tail(a) == []/~); - a = [11, 12]; - assert (tail(a) == [12]); + a = [11, 12]/~; + assert (tail(a) == [12]/~); } #[test] fn test_last() { - let mut n = last_opt([]); + let mut n = last_opt([]/~); assert (n == none); - n = last_opt([1, 2, 3]); + n = last_opt([1, 2, 3]/~); assert (n == some(3)); - n = last_opt([1, 2, 3, 4, 5]); + n = last_opt([1, 2, 3, 4, 5]/~); assert (n == some(5)); } #[test] fn test_slice() { // Test on-stack -> on-stack slice. - let mut v = slice([1, 2, 3], 1u, 3u); + let mut v = slice([1, 2, 3]/~, 1u, 3u); assert (len(v) == 2u); assert (v[0] == 2); assert (v[1] == 3); // Test on-heap -> on-stack slice. - v = slice([1, 2, 3, 4, 5], 0u, 3u); + v = slice([1, 2, 3, 4, 5]/~, 0u, 3u); assert (len(v) == 3u); assert (v[0] == 1); assert (v[1] == 2); assert (v[2] == 3); // Test on-heap -> on-heap slice. - v = slice([1, 2, 3, 4, 5, 6], 1u, 6u); + v = slice([1, 2, 3, 4, 5, 6]/~, 1u, 6u); assert (len(v) == 5u); assert (v[0] == 2); assert (v[1] == 3); @@ -1627,7 +1628,7 @@ mod tests { #[test] fn test_pop() { // Test on-stack pop. - let mut v = [1, 2, 3]; + let mut v = [1, 2, 3]/~; let mut e = pop(v); assert (len(v) == 2u); assert (v[0] == 1); @@ -1635,7 +1636,7 @@ mod tests { assert (e == 3); // Test on-heap pop. - v = [1, 2, 3, 4, 5]; + v = [1, 2, 3, 4, 5]/~; e = pop(v); assert (len(v) == 4u); assert (v[0] == 1); @@ -1648,7 +1649,7 @@ mod tests { #[test] fn test_push() { // Test on-stack push(). - let mut v = []; + let mut v = []/~; push(v, 1); assert (len(v) == 1u); assert (v[0] == 1); @@ -1663,7 +1664,7 @@ mod tests { #[test] fn test_grow() { // Test on-stack grow(). - let mut v = []; + let mut v = []/~; grow(v, 2u, 1); assert (len(v) == 2u); assert (v[0] == 1); @@ -1681,7 +1682,7 @@ mod tests { #[test] fn test_grow_fn() { - let mut v = []; + let mut v = []/~; grow_fn(v, 3u, square); assert (len(v) == 3u); assert (v[0] == 0u); @@ -1691,7 +1692,7 @@ mod tests { #[test] fn test_grow_set() { - let mut v = [mut 1, 2, 3]; + let mut v = [mut 1, 2, 3]/~; grow_set(v, 4u, 4, 5); assert (len(v) == 5u); assert (v[0] == 1); @@ -1704,7 +1705,7 @@ mod tests { #[test] fn test_map() { // Test on-stack map. - let mut v = [1u, 2u, 3u]; + let mut v = [1u, 2u, 3u]/~; let mut w = map(v, square_ref); assert (len(w) == 3u); assert (w[0] == 1u); @@ -1712,7 +1713,7 @@ mod tests { assert (w[2] == 9u); // Test on-heap map. - v = [1u, 2u, 3u, 4u, 5u]; + v = [1u, 2u, 3u, 4u, 5u]/~; w = map(v, square_ref); assert (len(w) == 5u); assert (w[0] == 1u); @@ -1726,8 +1727,8 @@ mod tests { fn test_map2() { fn times(&&x: int, &&y: int) -> int { ret x * y; } let f = times; - let v0 = [1, 2, 3, 4, 5]; - let v1 = [5, 4, 3, 2, 1]; + let v0 = [1, 2, 3, 4, 5]/~; + let v1 = [5, 4, 3, 2, 1]/~; let u = map2::<int, int, int>(v0, v1, f); let mut i = 0; while i < 5 { assert (v0[i] * v1[i] == u[i]); i += 1; } @@ -1736,14 +1737,14 @@ mod tests { #[test] fn test_filter_map() { // Test on-stack filter-map. - let mut v = [1u, 2u, 3u]; + let mut v = [1u, 2u, 3u]/~; let mut w = filter_map(v, square_if_odd); assert (len(w) == 2u); assert (w[0] == 1u); assert (w[1] == 9u); // Test on-heap filter-map. - v = [1u, 2u, 3u, 4u, 5u]; + v = [1u, 2u, 3u, 4u, 5u]/~; w = filter_map(v, square_if_odd); assert (len(w) == 3u); assert (w[0] == 1u); @@ -1756,32 +1757,32 @@ mod tests { } else { ret option::none::<int>; } } fn halve_for_sure(&&i: int) -> int { ret i / 2; } - let all_even: [int] = [0, 2, 8, 6]; - let all_odd1: [int] = [1, 7, 3]; - let all_odd2: [int] = []; - let mix: [int] = [9, 2, 6, 7, 1, 0, 0, 3]; - let mix_dest: [int] = [1, 3, 0, 0]; + let all_even: [int]/~ = [0, 2, 8, 6]/~; + let all_odd1: [int]/~ = [1, 7, 3]/~; + let all_odd2: [int]/~ = []/~; + let mix: [int]/~ = [9, 2, 6, 7, 1, 0, 0, 3]/~; + let mix_dest: [int]/~ = [1, 3, 0, 0]/~; assert (filter_map(all_even, halve) == map(all_even, halve_for_sure)); - assert (filter_map(all_odd1, halve) == []); - assert (filter_map(all_odd2, halve) == []); + assert (filter_map(all_odd1, halve) == []/~); + assert (filter_map(all_odd2, halve) == []/~); assert (filter_map(mix, halve) == mix_dest); } #[test] fn test_filter() { - assert filter([1u, 2u, 3u], is_odd) == [1u, 3u]; - assert filter([1u, 2u, 4u, 8u, 16u], is_three) == []; + assert filter([1u, 2u, 3u]/~, is_odd) == [1u, 3u]/~; + assert filter([1u, 2u, 4u, 8u, 16u]/~, is_three) == []/~; } #[test] fn test_foldl() { // Test on-stack fold. - let mut v = [1u, 2u, 3u]; + let mut v = [1u, 2u, 3u]/~; let mut sum = foldl(0u, v, add); assert (sum == 6u); // Test on-heap fold. - v = [1u, 2u, 3u, 4u, 5u]; + v = [1u, 2u, 3u, 4u, 5u]/~; sum = foldl(0u, v, add); assert (sum == 15u); } @@ -1791,7 +1792,7 @@ mod tests { fn sub(&&a: int, &&b: int) -> int { a - b } - let mut v = [1, 2, 3, 4]; + let mut v = [1, 2, 3, 4]/~; let sum = foldl(0, v, sub); assert sum == -10; } @@ -1801,7 +1802,7 @@ mod tests { fn sub(&&a: int, &&b: int) -> int { a - b } - let mut v = [1, 2, 3, 4]; + let mut v = [1, 2, 3, 4]/~; let sum = foldr(v, 0, sub); assert sum == -2; } @@ -1809,21 +1810,21 @@ mod tests { #[test] fn test_iter_empty() { let mut i = 0; - iter::<int>([], { |_v| i += 1 }); + iter::<int>([]/~, { |_v| i += 1 }); assert i == 0; } #[test] fn test_iter_nonempty() { let mut i = 0; - iter([1, 2, 3], { |v| i += v }); + iter([1, 2, 3]/~, { |v| i += v }); assert i == 6; } #[test] fn test_iteri() { let mut i = 0; - iteri([1, 2, 3], { |j, v| + iteri([1, 2, 3]/~, { |j, v| if i == 0 { assert v == 1; } assert j + 1u == v as uint; i += v; @@ -1834,14 +1835,14 @@ mod tests { #[test] fn test_riter_empty() { let mut i = 0; - riter::<int>([], { |_v| i += 1 }); + riter::<int>([]/~, { |_v| i += 1 }); assert i == 0; } #[test] fn test_riter_nonempty() { let mut i = 0; - riter([1, 2, 3], { |v| + riter([1, 2, 3]/~, { |v| if i == 0 { assert v == 3; } i += v }); @@ -1851,7 +1852,7 @@ mod tests { #[test] fn test_riteri() { let mut i = 0; - riteri([0, 1, 2], { |j, v| + riteri([0, 1, 2]/~, { |j, v| if i == 0 { assert v == 2; } assert j == v as uint; i += v; @@ -1861,56 +1862,57 @@ mod tests { #[test] fn test_permute() { - let mut results: [[int]]; + let mut results: [[int]/~]/~; - results = []; - permute([]) {|v| results += [v]; } - assert results == [[]]; + results = []/~; + permute([]/~) {|v| results += [v]/~; } + assert results == [[]/~]/~; - results = []; - permute([7]) {|v| results += [v]; } - assert results == [[7]]; + results = []/~; + permute([7]/~) {|v| results += [v]/~; } + assert results == [[7]/~]/~; - results = []; - permute([1,1]) {|v| results += [v]; } - assert results == [[1,1],[1,1]]; + results = []/~; + permute([1,1]/~) {|v| results += [v]/~; } + assert results == [[1,1]/~,[1,1]/~]/~; - results = []; - permute([5,2,0]) {|v| results += [v]; } - assert results == [[5,2,0],[5,0,2],[2,5,0],[2,0,5],[0,5,2],[0,2,5]]; + results = []/~; + permute([5,2,0]/~) {|v| results += [v]/~; } + assert results == + [[5,2,0]/~,[5,0,2]/~,[2,5,0]/~,[2,0,5]/~,[0,5,2]/~,[0,2,5]/~]/~; } #[test] fn test_any_and_all() { - assert (any([1u, 2u, 3u], is_three)); - assert (!any([0u, 1u, 2u], is_three)); - assert (any([1u, 2u, 3u, 4u, 5u], is_three)); - assert (!any([1u, 2u, 4u, 5u, 6u], is_three)); + assert (any([1u, 2u, 3u]/~, is_three)); + assert (!any([0u, 1u, 2u]/~, is_three)); + assert (any([1u, 2u, 3u, 4u, 5u]/~, is_three)); + assert (!any([1u, 2u, 4u, 5u, 6u]/~, is_three)); - assert (all([3u, 3u, 3u], is_three)); - assert (!all([3u, 3u, 2u], is_three)); - assert (all([3u, 3u, 3u, 3u, 3u], is_three)); - assert (!all([3u, 3u, 0u, 1u, 2u], is_three)); + assert (all([3u, 3u, 3u]/~, is_three)); + assert (!all([3u, 3u, 2u]/~, is_three)); + assert (all([3u, 3u, 3u, 3u, 3u]/~, is_three)); + assert (!all([3u, 3u, 0u, 1u, 2u]/~, is_three)); } #[test] fn test_any2_and_all2() { - assert (any2([2u, 4u, 6u], [2u, 4u, 6u], is_equal)); - assert (any2([1u, 2u, 3u], [4u, 5u, 3u], is_equal)); - assert (!any2([1u, 2u, 3u], [4u, 5u, 6u], is_equal)); - assert (any2([2u, 4u, 6u], [2u, 4u], is_equal)); + assert (any2([2u, 4u, 6u]/~, [2u, 4u, 6u]/~, is_equal)); + assert (any2([1u, 2u, 3u]/~, [4u, 5u, 3u]/~, is_equal)); + assert (!any2([1u, 2u, 3u]/~, [4u, 5u, 6u]/~, is_equal)); + assert (any2([2u, 4u, 6u]/~, [2u, 4u]/~, is_equal)); - assert (all2([2u, 4u, 6u], [2u, 4u, 6u], is_equal)); - assert (!all2([1u, 2u, 3u], [4u, 5u, 3u], is_equal)); - assert (!all2([1u, 2u, 3u], [4u, 5u, 6u], is_equal)); - assert (!all2([2u, 4u, 6u], [2u, 4u], is_equal)); + assert (all2([2u, 4u, 6u]/~, [2u, 4u, 6u]/~, is_equal)); + assert (!all2([1u, 2u, 3u]/~, [4u, 5u, 3u]/~, is_equal)); + assert (!all2([1u, 2u, 3u]/~, [4u, 5u, 6u]/~, is_equal)); + assert (!all2([2u, 4u, 6u]/~, [2u, 4u]/~, is_equal)); } #[test] fn test_zip_unzip() { - let v1 = [1, 2, 3]; - let v2 = [4, 5, 6]; + let v1 = [1, 2, 3]/~; + let v2 = [4, 5, 6]/~; let z1 = zip(v1, v2); @@ -1927,9 +1929,9 @@ mod tests { #[test] fn test_position_elem() { - assert position_elem([], 1) == none; + assert position_elem([]/~, 1) == none; - let v1 = [1, 2, 3, 3, 2, 5]; + let v1 = [1, 2, 3, 3, 2, 5]/~; assert position_elem(v1, 1) == some(0u); assert position_elem(v1, 2) == some(1u); assert position_elem(v1, 5) == some(5u); @@ -1941,19 +1943,19 @@ mod tests { fn less_than_three(&&i: int) -> bool { ret i < 3; } fn is_eighteen(&&i: int) -> bool { ret i == 18; } - assert position([], less_than_three) == none; + assert position([]/~, less_than_three) == none; - let v1 = [5, 4, 3, 2, 1]; + let v1 = [5, 4, 3, 2, 1]/~; assert position(v1, less_than_three) == some(3u); assert position(v1, is_eighteen) == none; } #[test] fn test_position_between() { - assert position_between([], 0u, 0u, f) == none; + assert position_between([]/~, 0u, 0u, f) == none; fn f(xy: (int, char)) -> bool { let (_x, y) = xy; y == 'b' } - let mut v = [(0, 'a'), (1, 'b'), (2, 'c'), (3, 'b')]; + let mut v = [(0, 'a'), (1, 'b'), (2, 'c'), (3, 'b')]/~; assert position_between(v, 0u, 0u, f) == none; assert position_between(v, 0u, 1u, f) == none; @@ -1978,11 +1980,11 @@ mod tests { #[test] fn test_find() { - assert find([], f) == none; + assert find([]/~, f) == none; fn f(xy: (int, char)) -> bool { let (_x, y) = xy; y == 'b' } fn g(xy: (int, char)) -> bool { let (_x, y) = xy; y == 'd' } - let mut v = [(0, 'a'), (1, 'b'), (2, 'c'), (3, 'b')]; + let mut v = [(0, 'a'), (1, 'b'), (2, 'c'), (3, 'b')]/~; assert find(v, f) == some((1, 'b')); assert find(v, g) == none; @@ -1990,10 +1992,10 @@ mod tests { #[test] fn test_find_between() { - assert find_between([], 0u, 0u, f) == none; + assert find_between([]/~, 0u, 0u, f) == none; fn f(xy: (int, char)) -> bool { let (_x, y) = xy; y == 'b' } - let mut v = [(0, 'a'), (1, 'b'), (2, 'c'), (3, 'b')]; + let mut v = [(0, 'a'), (1, 'b'), (2, 'c'), (3, 'b')]/~; assert find_between(v, 0u, 0u, f) == none; assert find_between(v, 0u, 1u, f) == none; @@ -2018,11 +2020,11 @@ mod tests { #[test] fn test_rposition() { - assert find([], f) == none; + assert find([]/~, f) == none; fn f(xy: (int, char)) -> bool { let (_x, y) = xy; y == 'b' } fn g(xy: (int, char)) -> bool { let (_x, y) = xy; y == 'd' } - let mut v = [(0, 'a'), (1, 'b'), (2, 'c'), (3, 'b')]; + let mut v = [(0, 'a'), (1, 'b'), (2, 'c'), (3, 'b')]/~; assert position(v, f) == some(1u); assert position(v, g) == none; @@ -2030,10 +2032,10 @@ mod tests { #[test] fn test_rposition_between() { - assert rposition_between([], 0u, 0u, f) == none; + assert rposition_between([]/~, 0u, 0u, f) == none; fn f(xy: (int, char)) -> bool { let (_x, y) = xy; y == 'b' } - let mut v = [(0, 'a'), (1, 'b'), (2, 'c'), (3, 'b')]; + let mut v = [(0, 'a'), (1, 'b'), (2, 'c'), (3, 'b')]/~; assert rposition_between(v, 0u, 0u, f) == none; assert rposition_between(v, 0u, 1u, f) == none; @@ -2058,11 +2060,11 @@ mod tests { #[test] fn test_rfind() { - assert rfind([], f) == none; + assert rfind([]/~, f) == none; fn f(xy: (int, char)) -> bool { let (_x, y) = xy; y == 'b' } fn g(xy: (int, char)) -> bool { let (_x, y) = xy; y == 'd' } - let mut v = [(0, 'a'), (1, 'b'), (2, 'c'), (3, 'b')]; + let mut v = [(0, 'a'), (1, 'b'), (2, 'c'), (3, 'b')]/~; assert rfind(v, f) == some((3, 'b')); assert rfind(v, g) == none; @@ -2070,10 +2072,10 @@ mod tests { #[test] fn test_rfind_between() { - assert rfind_between([], 0u, 0u, f) == none; + assert rfind_between([]/~, 0u, 0u, f) == none; fn f(xy: (int, char)) -> bool { let (_x, y) = xy; y == 'b' } - let mut v = [(0, 'a'), (1, 'b'), (2, 'c'), (3, 'b')]; + let mut v = [(0, 'a'), (1, 'b'), (2, 'c'), (3, 'b')]/~; assert rfind_between(v, 0u, 0u, f) == none; assert rfind_between(v, 0u, 1u, f) == none; @@ -2098,121 +2100,123 @@ mod tests { #[test] fn reverse_and_reversed() { - let v: [mut int] = [mut 10, 20]; + let v: [mut int]/~ = [mut 10, 20]/~; assert (v[0] == 10); assert (v[1] == 20); reverse(v); assert (v[0] == 20); assert (v[1] == 10); - let v2 = reversed::<int>([10, 20]); + let v2 = reversed::<int>([10, 20]/~); assert (v2[0] == 20); assert (v2[1] == 10); v[0] = 30; assert (v2[0] == 20); // Make sure they work with 0-length vectors too. - let v4 = reversed::<int>([]); - assert (v4 == []); - let v3: [mut int] = [mut]; + let v4 = reversed::<int>([]/~); + assert (v4 == []/~); + let v3: [mut int]/~ = [mut]/~; reverse::<int>(v3); } #[test] fn reversed_mut() { - let v2 = reversed::<int>([mut 10, 20]); + let v2 = reversed::<int>([mut 10, 20]/~); assert (v2[0] == 20); assert (v2[1] == 10); } #[test] fn test_init() { - let v = init([1, 2, 3]); - assert v == [1, 2]; + let v = init([1, 2, 3]/~); + assert v == [1, 2]/~; } #[test] fn test_split() { fn f(&&x: int) -> bool { x == 3 } - assert split([], f) == []; - assert split([1, 2], f) == [[1, 2]]; - assert split([3, 1, 2], f) == [[], [1, 2]]; - assert split([1, 2, 3], f) == [[1, 2], []]; - assert split([1, 2, 3, 4, 3, 5], f) == [[1, 2], [4], [5]]; + assert split([]/~, f) == []/~; + assert split([1, 2]/~, f) == [[1, 2]/~]/~; + assert split([3, 1, 2]/~, f) == [[]/~, [1, 2]/~]/~; + assert split([1, 2, 3]/~, f) == [[1, 2]/~, []/~]/~; + assert split([1, 2, 3, 4, 3, 5]/~, f) == [[1, 2]/~, [4]/~, [5]/~]/~; } #[test] fn test_splitn() { fn f(&&x: int) -> bool { x == 3 } - assert splitn([], 1u, f) == []; - assert splitn([1, 2], 1u, f) == [[1, 2]]; - assert splitn([3, 1, 2], 1u, f) == [[], [1, 2]]; - assert splitn([1, 2, 3], 1u, f) == [[1, 2], []]; - assert splitn([1, 2, 3, 4, 3, 5], 1u, f) == [[1, 2], [4, 3, 5]]; + assert splitn([]/~, 1u, f) == []/~; + assert splitn([1, 2]/~, 1u, f) == [[1, 2]/~]/~; + assert splitn([3, 1, 2]/~, 1u, f) == [[]/~, [1, 2]/~]/~; + assert splitn([1, 2, 3]/~, 1u, f) == [[1, 2]/~, []/~]/~; + assert splitn([1, 2, 3, 4, 3, 5]/~, 1u, f) == + [[1, 2]/~, [4, 3, 5]/~]/~; } #[test] fn test_rsplit() { fn f(&&x: int) -> bool { x == 3 } - assert rsplit([], f) == []; - assert rsplit([1, 2], f) == [[1, 2]]; - assert rsplit([1, 2, 3], f) == [[1, 2], []]; - assert rsplit([1, 2, 3, 4, 3, 5], f) == [[1, 2], [4], [5]]; + assert rsplit([]/~, f) == []/~; + assert rsplit([1, 2]/~, f) == [[1, 2]/~]/~; + assert rsplit([1, 2, 3]/~, f) == [[1, 2]/~, []/~]/~; + assert rsplit([1, 2, 3, 4, 3, 5]/~, f) == [[1, 2]/~, [4]/~, [5]/~]/~; } #[test] fn test_rsplitn() { fn f(&&x: int) -> bool { x == 3 } - assert rsplitn([], 1u, f) == []; - assert rsplitn([1, 2], 1u, f) == [[1, 2]]; - assert rsplitn([1, 2, 3], 1u, f) == [[1, 2], []]; - assert rsplitn([1, 2, 3, 4, 3, 5], 1u, f) == [[1, 2, 3, 4], [5]]; + assert rsplitn([]/~, 1u, f) == []/~; + assert rsplitn([1, 2]/~, 1u, f) == [[1, 2]/~]/~; + assert rsplitn([1, 2, 3]/~, 1u, f) == [[1, 2]/~, []/~]/~; + assert rsplitn([1, 2, 3, 4, 3, 5]/~, 1u, f) == + [[1, 2, 3, 4]/~, [5]/~]/~; } #[test] #[should_fail] #[ignore(cfg(windows))] fn test_init_empty() { - init::<int>([]); + init::<int>([]/~); } #[test] fn test_concat() { - assert concat([[1], [2,3]]) == [1, 2, 3]; + assert concat([[1]/~, [2,3]/~]/~) == [1, 2, 3]/~; } #[test] fn test_connect() { - assert connect([], 0) == []; - assert connect([[1], [2, 3]], 0) == [1, 0, 2, 3]; - assert connect([[1], [2], [3]], 0) == [1, 0, 2, 0, 3]; + assert connect([]/~, 0) == []/~; + assert connect([[1]/~, [2, 3]/~]/~, 0) == [1, 0, 2, 3]/~; + assert connect([[1]/~, [2]/~, [3]/~]/~, 0) == [1, 0, 2, 0, 3]/~; } #[test] fn test_windowed () { - assert [[1u,2u,3u],[2u,3u,4u],[3u,4u,5u],[4u,5u,6u]] - == windowed (3u, [1u,2u,3u,4u,5u,6u]); + assert [[1u,2u,3u]/~,[2u,3u,4u]/~,[3u,4u,5u]/~,[4u,5u,6u]/~]/~ + == windowed (3u, [1u,2u,3u,4u,5u,6u]/~); - assert [[1u,2u,3u,4u],[2u,3u,4u,5u],[3u,4u,5u,6u]] - == windowed (4u, [1u,2u,3u,4u,5u,6u]); + assert [[1u,2u,3u,4u]/~,[2u,3u,4u,5u]/~,[3u,4u,5u,6u]/~]/~ + == windowed (4u, [1u,2u,3u,4u,5u,6u]/~); - assert [] == windowed (7u, [1u,2u,3u,4u,5u,6u]); + assert []/~ == windowed (7u, [1u,2u,3u,4u,5u,6u]/~); } #[test] #[should_fail] #[ignore(cfg(windows))] fn test_windowed_() { - let _x = windowed (0u, [1u,2u,3u,4u,5u,6u]); + let _x = windowed (0u, [1u,2u,3u,4u,5u,6u]/~); } #[test] fn to_mut_no_copy() { unsafe { - let x = [1, 2, 3]; + let x = [1, 2, 3]/~; let addr = unsafe::to_ptr(x); let x_mut = to_mut(x); let addr_mut = unsafe::to_ptr(x_mut); @@ -2223,7 +2227,7 @@ mod tests { #[test] fn from_mut_no_copy() { unsafe { - let x = [mut 1, 2, 3]; + let x = [mut 1, 2, 3]/~; let addr = unsafe::to_ptr(x); let x_imm = from_mut(x); let addr_imm = unsafe::to_ptr(x_imm); @@ -2233,24 +2237,24 @@ mod tests { #[test] fn test_unshift() { - let mut x = [1, 2, 3]; + let mut x = [1, 2, 3]/~; unshift(x, 0); - assert x == [0, 1, 2, 3]; + assert x == [0, 1, 2, 3]/~; } #[test] fn test_capacity() { - let mut v = [0u64]; + let mut v = [0u64]/~; reserve(v, 10u); assert capacity(v) == 10u; - let mut v = [0u32]; + let mut v = [0u32]/~; reserve(v, 10u); assert capacity(v) == 10u; } #[test] fn test_view() { - let v = [1, 2, 3, 4, 5]; + let v = [1, 2, 3, 4, 5]/~; let v = view(v, 1u, 3u); assert(len(v) == 2u); assert(v[0] == 2); |
