diff options
| author | Brian Anderson <banderson@mozilla.com> | 2012-08-03 19:59:04 -0700 |
|---|---|---|
| committer | Brian Anderson <banderson@mozilla.com> | 2012-08-05 22:08:09 -0700 |
| commit | 025d86624de982cdab7e6b13600fec1499c02b56 (patch) | |
| tree | 96ba196f8a420c52e6034acd14f323d3d2239e29 /src/libcore | |
| parent | c9d27693796fe4ced8568e11aa465750f743097b (diff) | |
| download | rust-025d86624de982cdab7e6b13600fec1499c02b56.tar.gz rust-025d86624de982cdab7e6b13600fec1499c02b56.zip | |
Switch alts to use arrows
Diffstat (limited to 'src/libcore')
| -rw-r--r-- | src/libcore/bool.rs | 6 | ||||
| -rw-r--r-- | src/libcore/char.rs | 24 | ||||
| -rw-r--r-- | src/libcore/comm.rs | 4 | ||||
| -rw-r--r-- | src/libcore/dlist.rs | 60 | ||||
| -rw-r--r-- | src/libcore/either.rs | 31 | ||||
| -rw-r--r-- | src/libcore/extfmt.rs | 65 | ||||
| -rw-r--r-- | src/libcore/float.rs | 46 | ||||
| -rw-r--r-- | src/libcore/future.rs | 6 | ||||
| -rw-r--r-- | src/libcore/int-template.rs | 4 | ||||
| -rw-r--r-- | src/libcore/io.rs | 68 | ||||
| -rw-r--r-- | src/libcore/iter-trait/option.rs | 8 | ||||
| -rw-r--r-- | src/libcore/iter.rs | 16 | ||||
| -rw-r--r-- | src/libcore/option.rs | 23 | ||||
| -rw-r--r-- | src/libcore/os.rs | 32 | ||||
| -rw-r--r-- | src/libcore/path.rs | 10 | ||||
| -rw-r--r-- | src/libcore/pipes.rs | 150 | ||||
| -rw-r--r-- | src/libcore/priv.rs | 4 | ||||
| -rw-r--r-- | src/libcore/result.rs | 86 | ||||
| -rw-r--r-- | src/libcore/run.rs | 20 | ||||
| -rw-r--r-- | src/libcore/send_map.rs | 12 | ||||
| -rw-r--r-- | src/libcore/str.rs | 60 | ||||
| -rw-r--r-- | src/libcore/task.rs | 63 | ||||
| -rw-r--r-- | src/libcore/uint-template.rs | 8 | ||||
| -rw-r--r-- | src/libcore/unicode.rs | 134 | ||||
| -rw-r--r-- | src/libcore/vec.rs | 20 |
25 files changed, 453 insertions, 507 deletions
diff --git a/src/libcore/bool.rs b/src/libcore/bool.rs index 83e7ebec860..91b268bc703 100644 --- a/src/libcore/bool.rs +++ b/src/libcore/bool.rs @@ -40,9 +40,9 @@ pure fn is_false(v: bool) -> bool { !v } /// Parse logic value from `s` pure fn from_str(s: ~str) -> option<bool> { alt check s { - ~"true" { some(true) } - ~"false" { some(false) } - _ { none } + ~"true" => some(true), + ~"false" => some(false), + _ => none } } diff --git a/src/libcore/char.rs b/src/libcore/char.rs index 5849d19d8c1..97a484b491f 100644 --- a/src/libcore/char.rs +++ b/src/libcore/char.rs @@ -114,10 +114,10 @@ pure fn is_digit(c: char) -> bool { */ pure fn to_digit(c: char, radix: uint) -> option<uint> { let val = alt c { - '0' to '9' { c as uint - ('0' as uint) } - 'a' to 'z' { c as uint + 10u - ('a' as uint) } - 'A' to 'Z' { c as uint + 10u - ('A' as uint) } - _ { return none; } + '0' to '9' => c as uint - ('0' as uint), + 'a' to 'z' => c as uint + 10u - ('a' as uint), + 'A' to 'Z' => c as uint + 10u - ('A' as uint), + _ => return none }; if val < radix { some(val) } else { none } @@ -159,14 +159,14 @@ fn escape_unicode(c: char) -> ~str { */ fn escape_default(c: char) -> ~str { alt c { - '\t' { ~"\\t" } - '\r' { ~"\\r" } - '\n' { ~"\\n" } - '\\' { ~"\\\\" } - '\'' { ~"\\'" } - '"' { ~"\\\"" } - '\x20' to '\x7e' { str::from_char(c) } - _ { escape_unicode(c) } + '\t' => ~"\\t", + '\r' => ~"\\r", + '\n' => ~"\\n", + '\\' => ~"\\\\", + '\'' => ~"\\'", + '"' => ~"\\\"", + '\x20' to '\x7e' => str::from_char(c), + _ => escape_unicode(c) } } diff --git a/src/libcore/comm.rs b/src/libcore/comm.rs index fd1067241a8..86bcfad89dd 100644 --- a/src/libcore/comm.rs +++ b/src/libcore/comm.rs @@ -410,8 +410,8 @@ fn test_select2_stress() { let mut bs = 0; for iter::repeat(msgs * times * 2u) { alt check select2(po_a, po_b) { - either::left(~"a") { as += 1 } - either::right(~"b") { bs += 1 } + either::left(~"a") => as += 1, + either::right(~"b") => bs += 1 } } diff --git a/src/libcore/dlist.rs b/src/libcore/dlist.rs index ae75c04da72..7b9d4432e54 100644 --- a/src/libcore/dlist.rs +++ b/src/libcore/dlist.rs @@ -27,30 +27,22 @@ enum dlist<T> = @{ impl private_methods<T> for dlist_node<T> { pure fn assert_links() { alt self.next { - some(neighbour) { - alt neighbour.prev { - some(me) { - if !box::ptr_eq(*self, *me) { - fail ~"Asymmetric next-link in dlist node." - } - } - none { fail ~"One-way next-link in dlist node." } - } + some(neighbour) => alt neighbour.prev { + some(me) => if !box::ptr_eq(*self, *me) { + fail ~"Asymmetric next-link in dlist node." + } + none => fail ~"One-way next-link in dlist node." } - none { } + none => () } alt self.prev { - some(neighbour) { - alt neighbour.next { - some(me) { - if !box::ptr_eq(*me, *self) { - fail ~"Asymmetric prev-link in dlist node." - } - } - none { fail ~"One-way prev-link in dlist node." } - } + some(neighbour) => alt neighbour.next { + some(me) => if !box::ptr_eq(*me, *self) { + fail ~"Asymmetric prev-link in dlist node." + } + none => fail ~"One-way prev-link in dlist node." } - none { } + none => () } } } @@ -64,8 +56,8 @@ impl extensions<T> for dlist_node<T> { /// Get the next node in the list, failing if there isn't one. pure fn next_node() -> dlist_node<T> { alt self.next_link() { - some(nobe) { nobe } - none { fail ~"This dlist node has no next neighbour." } + some(nobe) => nobe, + none => fail ~"This dlist node has no next neighbour." } } /// Get the previous node in the list, if there is one. @@ -76,8 +68,8 @@ impl extensions<T> for dlist_node<T> { /// Get the previous node in the list, failing if there isn't one. pure fn prev_node() -> dlist_node<T> { alt self.prev_link() { - some(nobe) { nobe } - none { fail ~"This dlist node has no previous neighbour." } + some(nobe) => nobe, + none => fail ~"This dlist node has no previous neighbour." } } } @@ -147,12 +139,12 @@ impl private_methods<T> for dlist<T> { #[inline(always)] fn link(+before: dlist_link<T>, +after: dlist_link<T>) { alt before { - some(neighbour) { neighbour.next = after; } - none { self.hd = after; } + some(neighbour) => neighbour.next = after, + none => self.hd = after } alt after { - some(neighbour) { neighbour.prev = before; } - none { self.tl = before; } + some(neighbour) => neighbour.prev = before, + none => self.tl = before } } // Remove a node from the list. @@ -295,19 +287,15 @@ impl extensions<T> for dlist<T> { /// Get the node at the list's head, failing if empty. O(1). pure fn head_n() -> dlist_node<T> { alt self.hd { - some(nobe) { nobe } - none { - fail ~"Attempted to get the head of an empty dlist." - } + some(nobe) => nobe, + none => fail ~"Attempted to get the head of an empty dlist." } } /// Get the node at the list's tail, failing if empty. O(1). pure fn tail_n() -> dlist_node<T> { alt self.tl { - some(nobe) { nobe } - none { - fail ~"Attempted to get the tail of an empty dlist." - } + some(nobe) => nobe, + none => fail ~"Attempted to get the tail of an empty dlist." } } diff --git a/src/libcore/either.rs b/src/libcore/either.rs index 64a7abd0f35..d07b126bb5d 100644 --- a/src/libcore/either.rs +++ b/src/libcore/either.rs @@ -18,7 +18,10 @@ fn either<T, U, V>(f_left: fn(T) -> V, * result is returned. */ - alt value { left(l) { f_left(l) } right(r) { f_right(r) } } + alt value { + left(l) => f_left(l), + right(r) => f_right(r) + } } fn lefts<T: copy, U>(eithers: ~[either<T, U>]) -> ~[T] { @@ -26,7 +29,10 @@ fn lefts<T: copy, U>(eithers: ~[either<T, U>]) -> ~[T] { let mut result: ~[T] = ~[]; for vec::each(eithers) |elt| { - alt elt { left(l) { vec::push(result, l); } _ {/* fallthrough */ } } + alt elt { + left(l) => vec::push(result, l), + _ => { /* fallthrough */ } + } } return result; } @@ -36,7 +42,10 @@ fn rights<T, U: copy>(eithers: ~[either<T, U>]) -> ~[U] { let mut result: ~[U] = ~[]; for vec::each(eithers) |elt| { - alt elt { right(r) { vec::push(result, r); } _ {/* fallthrough */ } } + alt elt { + right(r) => vec::push(result, r), + _ => { /* fallthrough */ } + } } return result; } @@ -54,8 +63,8 @@ fn partition<T: copy, U: copy>(eithers: ~[either<T, U>]) let mut rights: ~[U] = ~[]; for vec::each(eithers) |elt| { alt elt { - left(l) { vec::push(lefts, l); } - right(r) { vec::push(rights, r); } + left(l) => vec::push(lefts, l), + right(r) => vec::push(rights, r) } } return {lefts: lefts, rights: rights}; @@ -65,8 +74,8 @@ pure fn flip<T: copy, U: copy>(eith: either<T, U>) -> either<U, T> { //! Flips between left and right of a given either alt eith { - right(r) { left(r) } - left(l) { right(l) } + right(r) => left(r), + left(l) => right(l) } } @@ -80,21 +89,21 @@ pure fn to_result<T: copy, U: copy>( */ alt eith { - right(r) { result::ok(r) } - left(l) { result::err(l) } + right(r) => result::ok(r), + left(l) => result::err(l) } } pure fn is_left<T, U>(eith: either<T, U>) -> bool { //! Checks whether the given value is a left - alt eith { left(_) { true } _ { false } } + alt eith { left(_) => true, _ => false } } pure fn is_right<T, U>(eith: either<T, U>) -> bool { //! Checks whether the given value is a right - alt eith { right(_) { true } _ { false } } + alt eith { right(_) => true, _ => false } } #[test] diff --git a/src/libcore/extfmt.rs b/src/libcore/extfmt.rs index 49313295edc..251bc2d18e1 100644 --- a/src/libcore/extfmt.rs +++ b/src/libcore/extfmt.rs @@ -123,8 +123,8 @@ mod ct { if !('0' as u8 <= c && c <= '9' as u8) { return option::none; } let n = (c - ('0' as u8)) as uint; return alt peek_num(s, i + 1u, lim) { - none { some({num: n, next: i + 1u}) } - some(next) { + none => some({num: n, next: i + 1u}), + some(next) => { let m = next.num; let j = next.next; some({num: n * 10u + m, next: j}) @@ -151,8 +151,8 @@ mod ct { if i >= lim { return {param: none, next: i}; } let num = peek_num(s, i, lim); return alt num { - none { {param: none, next: i} } - some(t) { + none => {param: none, next: i}, + some(t) => { let n = t.num; let j = t.next; if j < lim && s[j] == '$' as u8 { @@ -196,15 +196,16 @@ mod ct { let param = parse_parameter(s, i + 1u, lim); let j = param.next; alt param.param { - none { {count: count_is_next_param, next: j} } - some(n) { {count: count_is_param(n), next: j} } + none => {count: count_is_next_param, next: j}, + some(n) => {count: count_is_param(n), next: j} } } else { let num = peek_num(s, i, lim); alt num { - none { {count: count_implied, next: i} } - some(num) { - {count: count_is(num.num as int), next: num.next} + none => {count: count_implied, next: i}, + some(num) => { + count: count_is(num.num as int), + next: num.next } } }; @@ -220,8 +221,8 @@ mod ct { // If there were no digits specified, i.e. the precision // was ".", then the precision is 0 alt count.count { - count_implied { {count: count_is(0), next: count.next} } - _ { count } + count_implied => {count: count_is(0), next: count.next}, + _ => count } } else { {count: count_implied, next: i} }; } @@ -294,11 +295,11 @@ mod rt { let prec = get_int_precision(cv); let mut rs = alt cv.ty { - ty_default { uint_to_str_prec(u, 10u, prec) } - ty_hex_lower { uint_to_str_prec(u, 16u, prec) } - ty_hex_upper { str::to_upper(uint_to_str_prec(u, 16u, prec)) } - ty_bits { uint_to_str_prec(u, 2u, prec) } - ty_octal { uint_to_str_prec(u, 8u, prec) } + ty_default => uint_to_str_prec(u, 10u, prec), + ty_hex_lower => uint_to_str_prec(u, 16u, prec), + ty_hex_upper => str::to_upper(uint_to_str_prec(u, 16u, prec)), + ty_bits => uint_to_str_prec(u, 2u, prec), + ty_octal => uint_to_str_prec(u, 8u, prec) }; return unchecked { pad(cv, rs, pad_unsigned) }; } @@ -316,19 +317,19 @@ mod rt { // For strings, precision is the maximum characters // displayed let mut unpadded = alt cv.precision { - count_implied { s.to_unique() } - count_is(max) { - if max as uint < str::char_len(s) { - str::substr(s, 0u, max as uint) - } else { s.to_unique() } + count_implied => s.to_unique(), + count_is(max) => if max as uint < str::char_len(s) { + str::substr(s, 0u, max as uint) + } else { + s.to_unique() } }; return unchecked { pad(cv, unpadded, pad_nozero) }; } pure fn conv_float(cv: conv, f: float) -> ~str { let (to_str, digits) = alt cv.precision { - count_is(c) { (float::to_str_exact, c as uint) } - count_implied { (float::to_str, 6u) } + count_is(c) => (float::to_str_exact, c as uint), + count_implied => (float::to_str, 6u) }; let mut s = unchecked { to_str(f, digits) }; if 0.0 <= f { @@ -371,15 +372,15 @@ mod rt { } pure fn get_int_precision(cv: conv) -> uint { return alt cv.precision { - count_is(c) { c as uint } - count_implied { 1u } + count_is(c) => c as uint, + count_implied => 1u }; } enum pad_mode { pad_signed, pad_unsigned, pad_nozero, pad_float } fn pad(cv: conv, &s: ~str, mode: pad_mode) -> ~str { let uwidth : uint = alt cv.width { - count_implied { return s; } - count_is(width) { + count_implied => return s, + count_is(width) => { // FIXME: width should probably be uint (see Issue #1996) width as uint } @@ -393,13 +394,13 @@ mod rt { return s + padstr; } let {might_zero_pad, signed} = alt mode { - pad_nozero { {might_zero_pad:false, signed:false} } - pad_signed { {might_zero_pad:true, signed:true } } - pad_float { {might_zero_pad:true, signed:true } } - pad_unsigned { {might_zero_pad:true, signed:false} } + pad_nozero => {might_zero_pad:false, signed:false}, + pad_signed => {might_zero_pad:true, signed:true }, + pad_float => {might_zero_pad:true, signed:true}, + pad_unsigned => {might_zero_pad:true, signed:false} }; pure fn have_precision(cv: conv) -> bool { - return alt cv.precision { count_implied { false } _ { true } }; + return alt cv.precision { count_implied => false, _ => true }; } let zero_padding = { if might_zero_pad && have_flag(cv.flags, flag_left_zero_pad) && diff --git a/src/libcore/float.rs b/src/libcore/float.rs index e9dd26d23ce..02133205be9 100644 --- a/src/libcore/float.rs +++ b/src/libcore/float.rs @@ -257,21 +257,21 @@ fn from_str(num: ~str) -> option<float> { //The string must start with one of the following characters. alt str::char_at(num, 0u) { - '-' | '+' | '0' to '9' | '.' {} - _ { return none; } + '-' | '+' | '0' to '9' | '.' => (), + _ => return none } //Determine if first char is '-'/'+'. Set [pos] and [neg] accordingly. let mut neg = false; //Sign of the result alt str::char_at(num, 0u) { - '-' { + '-' => { neg = true; pos = 1u; } - '+' { + '+' => { pos = 1u; } - _ {} + _ => () } //Examine the following chars until '.', 'e', 'E' @@ -280,16 +280,12 @@ fn from_str(num: ~str) -> option<float> { c = char_range.ch; pos = char_range.next; alt c { - '0' to '9' { + '0' to '9' => { total = total * 10f; total += ((c as int) - ('0' as int)) as float; } - '.' | 'e' | 'E' { - break; - } - _ { - return none; - } + '.' | 'e' | 'E' => break, + _ => return none } } @@ -300,16 +296,12 @@ fn from_str(num: ~str) -> option<float> { c = char_range.ch; pos = char_range.next; alt c { - '0' | '1' | '2' | '3' | '4' | '5' | '6'| '7' | '8' | '9' { + '0' | '1' | '2' | '3' | '4' | '5' | '6'| '7' | '8' | '9' => { decimal /= 10f; total += (((c as int) - ('0' as int)) as float)*decimal; } - 'e' | 'E' { - break; - } - _ { - return none; - } + 'e' | 'E' => break, + _ => return none } } } @@ -321,26 +313,24 @@ fn from_str(num: ~str) -> option<float> { let char_range = str::char_range_at(num, pos); c = char_range.ch; alt c { - '+' { + '+' => { pos = char_range.next; } - '-' { + '-' => { pos = char_range.next; neg_exponent = true; } - _ {} + _ => () } while(pos < len) { let char_range = str::char_range_at(num, pos); c = char_range.ch; alt c { - '0' | '1' | '2' | '3' | '4' | '5' | '6'| '7' | '8' | '9' { + '0' | '1' | '2' | '3' | '4' | '5' | '6'| '7' | '8' | '9' => { exponent *= 10u; exponent += ((c as uint) - ('0' as uint)); } - _ { - break; - } + _ => break } pos = char_range.next; } @@ -458,8 +448,8 @@ fn test_from_str() { assert from_str(~"-inf") == some(neg_infinity); // note: NaN != NaN, hence this slightly complex test alt from_str(~"NaN") { - some(f) { assert is_NaN(f); } - none { fail; } + some(f) => assert is_NaN(f), + none => fail } assert from_str(~"") == none; diff --git a/src/libcore/future.rs b/src/libcore/future.rs index 43b0a4047b6..1f6b259c467 100644 --- a/src/libcore/future.rs +++ b/src/libcore/future.rs @@ -78,7 +78,7 @@ fn from_port<A:send>(-port: future_pipe::client::waiting<A>) -> future<A> { port_ <-> *port; let port = option::unwrap(port_); alt recv(port) { - future_pipe::completed(data) { move_it!{data} } + future_pipe::completed(data) => move_it!{data} } } } @@ -120,8 +120,8 @@ fn with<A,B>(future: future<A>, blk: fn(A) -> B) -> B { //! Work with the value without copying it let v = alt copy future.v { - either::left(v) { v } - either::right(f) { + either::left(v) => v, + either::right(f) => { let v = @f(); future.v = either::left(v); v diff --git a/src/libcore/int-template.rs b/src/libcore/int-template.rs index 1cd1480ec43..02ef14c5366 100644 --- a/src/libcore/int-template.rs +++ b/src/libcore/int-template.rs @@ -145,8 +145,8 @@ fn parse_buf(buf: ~[u8], radix: uint) -> option<T> { let mut n = 0 as T; loop { alt char::to_digit(buf[i] as char, radix) { - some(d) { n += (d as T) * power; } - none { return none; } + some(d) => n += (d as T) * power, + none => return none } power *= radix as T; if i <= start { return some(n); } diff --git a/src/libcore/io.rs b/src/libcore/io.rs index c20aaf14530..cf2c51625d8 100644 --- a/src/libcore/io.rs +++ b/src/libcore/io.rs @@ -197,9 +197,9 @@ impl reader_util for reader { fn convert_whence(whence: seek_style) -> i32 { return alt whence { - seek_set { 0i32 } - seek_cur { 1i32 } - seek_end { 2i32 } + seek_set => 0i32, + seek_cur => 1i32, + seek_end => 2i32 }; } @@ -441,10 +441,10 @@ fn mk_file_writer(path: ~str, flags: ~[fileflag]) let mut fflags: c_int = wb(); for vec::each(flags) |f| { alt f { - append { fflags |= O_APPEND as c_int; } - create { fflags |= O_CREAT as c_int; } - truncate { fflags |= O_TRUNC as c_int; } - no_flag { } + append => fflags |= O_APPEND as c_int, + create => fflags |= O_CREAT as c_int, + truncate => fflags |= O_TRUNC as c_int, + no_flag => () } } let fd = do os::as_c_charp(path) |pathbuf| { @@ -461,22 +461,22 @@ fn mk_file_writer(path: ~str, flags: ~[fileflag]) fn u64_to_le_bytes<T>(n: u64, size: uint, f: fn(v: &[u8]) -> T) -> T { assert size <= 8u; alt size { - 1u { f(&[n as u8]) } - 2u { f(&[n as u8, - (n >> 8) as u8]) } - 4u { f(&[n as u8, + 1u => f(&[n as u8]), + 2u => f(&[n as u8, + (n >> 8) as u8]), + 4u => f(&[n as u8, (n >> 8) as u8, (n >> 16) as u8, - (n >> 24) as u8]) } - 8u { f(&[n as u8, + (n >> 24) as u8]), + 8u => f(&[n as u8, (n >> 8) as u8, (n >> 16) as u8, (n >> 24) as u8, (n >> 32) as u8, (n >> 40) as u8, (n >> 48) as u8, - (n >> 56) as u8]) } - _ { + (n >> 56) as u8]), + _ => { let mut bytes: ~[u8] = ~[], i = size, n = n; while i > 0u { @@ -492,22 +492,22 @@ fn u64_to_le_bytes<T>(n: u64, size: uint, f: fn(v: &[u8]) -> T) -> T { fn u64_to_be_bytes<T>(n: u64, size: uint, f: fn(v: &[u8]) -> T) -> T { assert size <= 8u; alt size { - 1u { f(&[n as u8]) } - 2u { f(&[(n >> 8) as u8, - n as u8]) } - 4u { f(&[(n >> 24) as u8, + 1u => f(&[n as u8]), + 2u => f(&[(n >> 8) as u8, + n as u8]), + 4u => f(&[(n >> 24) as u8, (n >> 16) as u8, (n >> 8) as u8, - n as u8]) } - 8u { f(&[(n >> 56) as u8, + n as u8]), + 8u => f(&[(n >> 56) as u8, (n >> 48) as u8, (n >> 40) as u8, (n >> 32) as u8, (n >> 24) as u8, (n >> 16) as u8, (n >> 8) as u8, - n as u8]) } - _ { + n as u8]), + _ => { let mut bytes: ~[u8] = ~[]; let mut i = size; while i > 0u { @@ -718,9 +718,9 @@ fn seek_in_buf(offset: int, pos: uint, len: uint, whence: seek_style) -> let mut bpos = pos as int; let blen = len as int; alt whence { - seek_set { bpos = offset; } - seek_cur { bpos += offset; } - seek_end { bpos = blen + offset; } + seek_set => bpos = offset, + seek_cur => bpos += offset, + seek_end => bpos = blen + offset } if bpos < 0 { bpos = 0; } else if bpos > blen { bpos = blen; } return bpos as uint; @@ -768,8 +768,8 @@ mod fsync { new(-arg: arg<t>) { self.arg <- arg; } drop { alt self.arg.opt_level { - option::none { } - option::some(level) { + option::none => (), + option::some(level) => { // fail hard if not succesful assert(self.arg.fsync_fn(self.arg.val, level) != -1); } @@ -892,30 +892,30 @@ mod tests { #[test] fn file_reader_not_exist() { alt io::file_reader(~"not a file") { - result::err(e) { + result::err(e) => { assert e == ~"error opening not a file"; } - result::ok(_) { fail; } + result::ok(_) => fail } } #[test] fn file_writer_bad_name() { alt io::file_writer(~"?/?", ~[]) { - result::err(e) { + result::err(e) => { assert str::starts_with(e, ~"error opening ?/?"); } - result::ok(_) { fail; } + result::ok(_) => fail } } #[test] fn buffered_file_writer_bad_name() { alt io::buffered_file_writer(~"?/?") { - result::err(e) { + result::err(e) => { assert e == ~"error opening ?/?"; } - result::ok(_) { fail; } + result::ok(_) => fail } } diff --git a/src/libcore/iter-trait/option.rs b/src/libcore/iter-trait/option.rs index 87763b273da..a150afa36e1 100644 --- a/src/libcore/iter-trait/option.rs +++ b/src/libcore/iter-trait/option.rs @@ -2,14 +2,14 @@ type IMPL_T<A> = option<A>; pure fn EACH<A>(self: IMPL_T<A>, f: fn(A) -> bool) { alt self { - none { } - some(a) { f(a); } + none => (), + some(a) => { f(a); } } } fn SIZE_HINT<A>(self: IMPL_T<A>) -> option<uint> { alt self { - none { some(0u) } - some(_) { some(1u) } + none => some(0u), + some(_) => some(1u) } } diff --git a/src/libcore/iter.rs b/src/libcore/iter.rs index 0e635eeb002..541c19aa3a5 100644 --- a/src/libcore/iter.rs +++ b/src/libcore/iter.rs @@ -136,32 +136,32 @@ fn repeat(times: uint, blk: fn() -> bool) { fn min<A:copy,IA:base_iter<A>>(self: IA) -> A { alt do foldl::<A,option<A>,IA>(self, none) |a, b| { alt a { - some(a_) if a_ < b { + some(a_) if a_ < b => { // FIXME (#2005): Not sure if this is successfully optimized to // a move a } - _ { some(b) } + _ => some(b) } } { - some(val) { val } - none { fail ~"min called on empty iterator" } + some(val) => val, + none => fail ~"min called on empty iterator" } } fn max<A:copy,IA:base_iter<A>>(self: IA) -> A { alt do foldl::<A,option<A>,IA>(self, none) |a, b| { alt a { - some(a_) if a_ > b { + some(a_) if a_ > b => { // FIXME (#2005): Not sure if this is successfully optimized to // a move. a } - _ { some(b) } + _ => some(b) } } { - some(val) { val } - none { fail ~"max called on empty iterator" } + some(val) => val, + none => fail ~"max called on empty iterator" } } diff --git a/src/libcore/option.rs b/src/libcore/option.rs index 935d22fbaae..b2ae670ec05 100644 --- a/src/libcore/option.rs +++ b/src/libcore/option.rs @@ -23,7 +23,10 @@ pure fn get<T: copy>(opt: option<T>) -> T { * Fails if the value equals `none` */ - alt opt { some(x) { return x; } none { fail ~"option::get none"; } } + alt opt { + some(x) => return x, + none => fail ~"option::get none" + } } pure fn expect<T: copy>(opt: option<T>, reason: ~str) -> T { @@ -34,13 +37,13 @@ pure fn expect<T: copy>(opt: option<T>, reason: ~str) -> T { Fails if the value equals `none` "]; - alt opt { some(x) { x } none { fail reason; } } + alt opt { some(x) => x, none => fail reason } } pure fn map<T, U>(opt: option<T>, f: fn(T) -> U) -> option<U> { //! Maps a `some` value from one type to another - alt opt { some(x) { some(f(x)) } none { none } } + alt opt { some(x) => some(f(x)), none => none } } pure fn map_consume<T, U>(-opt: option<T>, f: fn(-T) -> U) -> option<U> { @@ -57,7 +60,7 @@ pure fn chain<T, U>(opt: option<T>, f: fn(T) -> option<U>) -> option<U> { * function that returns an option. */ - alt opt { some(x) { f(x) } none { none } } + alt opt { some(x) => f(x), none => none } } #[inline(always)] @@ -73,7 +76,7 @@ pure fn while_some<T>(+x: option<T>, blk: fn(+T) -> option<T>) { pure fn is_none<T>(opt: option<T>) -> bool { //! Returns true if the option equals `none` - alt opt { none { true } some(_) { false } } + alt opt { none => true, some(_) => false } } pure fn is_some<T>(opt: option<T>) -> bool { @@ -85,19 +88,19 @@ pure fn is_some<T>(opt: option<T>) -> bool { pure fn get_default<T: copy>(opt: option<T>, def: T) -> T { //! Returns the contained value or a default - alt opt { some(x) { x } none { def } } + alt opt { some(x) => x, none => def } } pure fn map_default<T, U>(opt: option<T>, +def: U, f: fn(T) -> U) -> U { //! Applies a function to the contained value or returns a default - alt opt { none { def } some(t) { f(t) } } + alt opt { none => def, some(t) => f(t) } } pure fn iter<T>(opt: option<T>, f: fn(T)) { //! Performs an operation on the contained value or does nothing - alt opt { none { } some(t) { f(t); } } + alt opt { none => (), some(t) => f(t) } } #[inline(always)] @@ -111,8 +114,8 @@ pure fn unwrap<T>(-opt: option<T>) -> T { unsafe { let addr = alt opt { - some(x) { ptr::addr_of(x) } - none { fail ~"option::unwrap none" } + some(x) => ptr::addr_of(x), + none => fail ~"option::unwrap none" }; let liberated_value = unsafe::reinterpret_cast(*addr); unsafe::forget(opt); diff --git a/src/libcore/os.rs b/src/libcore/os.rs index a2e3ca02bc3..fba4e7acac5 100644 --- a/src/libcore/os.rs +++ b/src/libcore/os.rs @@ -179,18 +179,16 @@ mod global_env { do priv::weaken_task |weak_po| { loop { alt comm::select2(msg_po, weak_po) { - either::left(msg_getenv(n, resp_ch)) { + either::left(msg_getenv(n, resp_ch)) => { comm::send(resp_ch, impl::getenv(n)) } - either::left(msg_setenv(n, v, resp_ch)) { + either::left(msg_setenv(n, v, resp_ch)) => { comm::send(resp_ch, impl::setenv(n, v)) } - either::left(msg_env(resp_ch)) { + either::left(msg_env(resp_ch)) => { comm::send(resp_ch, impl::env()) } - either::right(_) { - break; - } + either::right(_) => break } } } @@ -286,8 +284,8 @@ fn fsync_fd(fd: c_int, level: io::fsync::level) -> c_int { import libc::funcs::posix01::unistd::*; alt level { io::fsync::fsync - | io::fsync::fullfsync { return fsync(fd); } - io::fsync::fdatasync { return fdatasync(fd); } + | io::fsync::fullfsync => return fsync(fd), + io::fsync::fdatasync => return fdatasync(fd) } } @@ -297,8 +295,8 @@ fn fsync_fd(fd: c_int, level: io::fsync::level) -> c_int { import libc::funcs::posix88::fcntl::*; import libc::funcs::posix01::unistd::*; alt level { - io::fsync::fsync { return fsync(fd); } - _ { + io::fsync::fsync => return fsync(fd), + _ => { // According to man fnctl, the ok retval is only specified to be !=-1 if (fcntl(F_FULLFSYNC as c_int, fd) == -1 as c_int) { return -1 as c_int; } @@ -443,16 +441,12 @@ fn self_exe_path() -> option<path> { */ fn homedir() -> option<path> { return alt getenv(~"HOME") { - some(p) { - if !str::is_empty(p) { - some(p) - } else { - secondary() - } - } - none { - secondary() + some(p) => if !str::is_empty(p) { + some(p) + } else { + secondary() } + none => secondary() }; #[cfg(unix)] diff --git a/src/libcore/path.rs b/src/libcore/path.rs index beccdcf0538..dc541b14a4b 100644 --- a/src/libcore/path.rs +++ b/src/libcore/path.rs @@ -64,11 +64,11 @@ fn split_dirname_basename (pp: path) -> {dirname: ~str, basename: ~str} { alt str::rfind(pp, |ch| ch == consts::path_sep || ch == consts::alt_path_sep ) { - some(i) { - {dirname: str::slice(pp, 0u, i), - basename: str::slice(pp, i + 1u, str::len(pp))} - } - none { {dirname: ~".", basename: pp} } + some(i) => { + dirname: str::slice(pp, 0u, i), + basename: str::slice(pp, i + 1u, str::len(pp)) + }, + none => {dirname: ~".", basename: pp} } } diff --git a/src/libcore/pipes.rs b/src/libcore/pipes.rs index af7f7983a8a..f13ee96768a 100644 --- a/src/libcore/pipes.rs +++ b/src/libcore/pipes.rs @@ -120,9 +120,9 @@ struct packet_header { assert self.state != blocked || self.blocked_task != none; self.blocked_task = none; alt swap_state_acq(self.state, empty) { - empty | blocked { } - terminated { self.state = terminated; } - full { self.state = full; } + empty | blocked => (), + terminated => self.state = terminated, + full => self.state = full } } @@ -310,27 +310,25 @@ fn send<T: send, Tbuffer: send>(-p: send_packet_buffered<T, Tbuffer>, p.payload <- some(payload); let old_state = swap_state_rel(p.header.state, full); alt old_state { - empty { + empty => { // Yay, fastpath. // The receiver will eventually clean this up. //unsafe { forget(p); } } - full { fail ~"duplicate send" } - blocked { + full => fail ~"duplicate send", + blocked => { debug!{"waking up task for %?", p_}; alt p.header.blocked_task { - some(task) { - rustrt::task_signal_event( - task, ptr::addr_of(p.header) as *libc::c_void); - } - none { debug!{"just kidding!"} } + some(task) => rustrt::task_signal_event( + task, ptr::addr_of(p.header) as *libc::c_void), + none => debug!{"just kidding!"} } // The receiver will eventually clean this up. //unsafe { forget(p); } } - terminated { + terminated => { // The receiver will never receive this. Rely on drop_glue // to clean everything up. } @@ -367,7 +365,7 @@ fn try_recv<T: send, Tbuffer: send>(-p: recv_packet_buffered<T, Tbuffer>) let old_state = swap_state_acq(p.header.state, blocked); alt old_state { - empty { + empty => { debug!{"no data available on %?, going to sleep.", p_}; if count == 0 { wait_event(this); @@ -383,19 +381,17 @@ fn try_recv<T: send, Tbuffer: send>(-p: recv_packet_buffered<T, Tbuffer>) } debug!{"woke up, p.state = %?", copy p.header.state}; } - blocked { - if first { - fail ~"blocking on already blocked packet" - } + blocked => if first { + fail ~"blocking on already blocked packet" } - full { + full => { let mut payload = none; payload <-> p.payload; p.header.blocked_task = none; p.header.state = empty; return some(option::unwrap(payload)) } - terminated { + terminated => { // This assert detects when we've accidentally unsafely // casted too big of a number to a state. assert old_state == terminated; @@ -409,9 +405,9 @@ fn try_recv<T: send, Tbuffer: send>(-p: recv_packet_buffered<T, Tbuffer>) /// Returns true if messages are available. pure fn peek<T: send, Tb: send>(p: recv_packet_buffered<T, Tb>) -> bool { alt unsafe {(*p.header()).state} { - empty { false } - blocked { fail ~"peeking on blocked packet" } - full | terminated { true } + empty => false, + blocked => fail ~"peeking on blocked packet", + full | terminated => true } } @@ -425,11 +421,11 @@ impl peek<T: send, Tb: send> for recv_packet_buffered<T, Tb> { fn sender_terminate<T: send>(p: *packet<T>) { let p = unsafe { &*p }; alt swap_state_rel(p.header.state, terminated) { - empty { + empty => { // The receiver will eventually clean up. //unsafe { forget(p) } } - blocked { + blocked => { // wake up the target alt p.header.blocked_task { some(target) => @@ -441,11 +437,11 @@ fn sender_terminate<T: send>(p: *packet<T>) { // The receiver will eventually clean up. //unsafe { forget(p) } } - full { + full => { // This is impossible fail ~"you dun goofed" } - terminated { + terminated => { // I have to clean up, use drop_glue } } @@ -456,15 +452,15 @@ fn receiver_terminate<T: send>(p: *packet<T>) { let p = unsafe { &*p }; assert p.header.blocked_task == none; alt swap_state_rel(p.header.state, terminated) { - empty { + empty => { // the sender will clean up //unsafe { forget(p) } } - blocked { + blocked => { // this shouldn't happen. fail ~"terminating a blocked packet" } - terminated | full { + terminated | full => { // I have to clean up, use drop_glue } } @@ -490,14 +486,14 @@ fn wait_many(pkts: &[*packet_header]) -> uint { let p = unsafe { &*p }; let old = p.mark_blocked(this); alt old { - full | terminated { + full | terminated => { data_avail = true; ready_packet = i; (*p).state = old; break; } - blocked { fail ~"blocking on blocked packet" } - empty { } + blocked => fail ~"blocking on blocked packet", + empty => () } } @@ -507,13 +503,11 @@ fn wait_many(pkts: &[*packet_header]) -> uint { let pos = vec::position(pkts, |p| p == event); alt pos { - some(i) { + some(i) => { ready_packet = i; data_avail = true; } - none { - debug!{"ignoring spurious event, %?", event}; - } + none => debug!{"ignoring spurious event, %?", event} } } @@ -569,9 +563,9 @@ fn select2<A: send, Ab: send, B: send, Bb: send>( unsafe { alt i { - 0 { left((try_recv(a), b)) } - 1 { right((a, try_recv(b))) } - _ { fail ~"select2 return an invalid packet" } + 0 => left((try_recv(a), b)), + 1 => right((a, try_recv(b))), + _ => fail ~"select2 return an invalid packet" } } } @@ -586,9 +580,9 @@ fn selecti<T: selectable>(endpoints: &[T]) -> uint { fn select2i<A: selectable, B: selectable>(a: A, b: B) -> either<(), ()> { alt wait_many([a.header(), b.header()]/_) { - 0 { left(()) } - 1 { right(()) } - _ { fail ~"wait returned unexpected index" } + 0 => left(()), + 1 => right(()), + _ => fail ~"wait returned unexpected index" } } @@ -655,15 +649,13 @@ struct send_packet_buffered<T: send, Tbuffer: send> { pure fn header() -> *packet_header { alt self.p { - some(packet) { - unsafe { - let packet = &*packet; - let header = ptr::addr_of(packet.header); - //forget(packet); - header - } + some(packet) => unsafe { + let packet = &*packet; + let header = ptr::addr_of(packet.header); + //forget(packet); + header } - none { fail ~"packet already consumed" } + none => fail ~"packet already consumed" } } @@ -718,15 +710,13 @@ struct recv_packet_buffered<T: send, Tbuffer: send> : selectable { pure fn header() -> *packet_header { alt self.p { - some(packet) { - unsafe { - let packet = &*packet; - let header = ptr::addr_of(packet.header); - //forget(packet); - header - } + some(packet) => unsafe { + let packet = &*packet; + let header = ptr::addr_of(packet.header); + //forget(packet); + header } - none { fail ~"packet already consumed" } + none => fail ~"packet already consumed" } } @@ -847,11 +837,11 @@ impl port<T: send> of recv<T> for port<T> { let mut endp = none; endp <-> self.endp; alt move pipes::try_recv(unwrap(endp)) { - some(streamp::data(x, endp)) { + some(streamp::data(x, endp)) => { self.endp = some(move_it!{endp}); some(move_it!{x}) } - none { none } + none => none } } @@ -859,10 +849,8 @@ impl port<T: send> of recv<T> for port<T> { let mut endp = none; endp <-> self.endp; let peek = alt endp { - some(endp) { - pipes::peek(endp) - } - none { fail ~"peeking empty stream" } + some(endp) => pipes::peek(endp), + none => fail ~"peeking empty stream" }; self.endp <-> endp; peek @@ -894,10 +882,10 @@ struct port_set<T: send> : recv<T> { while result == none && ports.len() > 0 { let i = wait_many(ports.map(|p| p.header())); alt move ports[i].try_recv() { - some(copy m) { + some(copy m) => { result = some(move m); } - none { + none => { // Remove this port. let mut ports_ = ~[]; ports <-> ports_; @@ -914,8 +902,8 @@ struct port_set<T: send> : recv<T> { fn recv() -> T { match move self.try_recv() { - some(copy x) { move x } - none { fail ~"port_set: endpoints closed" } + some(copy x) => move x, + none => fail ~"port_set: endpoints closed" } } @@ -932,10 +920,8 @@ struct port_set<T: send> : recv<T> { impl<T: send> of selectable for port<T> { pure fn header() -> *packet_header unchecked { alt self.endp { - some(endp) { - endp.header() - } - none { fail ~"peeking empty stream" } + some(endp) => endp.header(), + none => fail ~"peeking empty stream" } } } @@ -968,22 +954,18 @@ impl<T: send, U: send, Left: selectable recv<T>, Right: selectable recv<U>> fn select() -> either<T, U> { alt self { - (lp, rp) { - alt select2i(lp, rp) { - left(()) { left (lp.recv()) } - right(()) { right(rp.recv()) } - } + (lp, rp) => alt select2i(lp, rp) { + left(()) => left (lp.recv()), + right(()) => right(rp.recv()) } } } fn try_select() -> either<option<T>, option<U>> { alt self { - (lp, rp) { - alt select2i(lp, rp) { - left(()) { left (lp.try_recv()) } - right(()) { right(rp.try_recv()) } - } + (lp, rp) => alt select2i(lp, rp) { + left(()) => left (lp.try_recv()), + right(()) => right(rp.try_recv()) } } } @@ -999,8 +981,8 @@ mod test { c1.send(~"abc"); alt (p1, p2).select() { - right(_) { fail } - _ { } + right(_) => fail, + _ => () } c2.send(123); diff --git a/src/libcore/priv.rs b/src/libcore/priv.rs index 00bbe3d032a..5d7123f1bba 100644 --- a/src/libcore/priv.rs +++ b/src/libcore/priv.rs @@ -50,8 +50,8 @@ unsafe fn chan_from_global_ptr<T: send>( // Wait to hear if we are the official instance of // this global task alt comm::recv::<msg>(setup_po) { - proceed { f(po); } - abort { } + proceed => f(po), + abort => () } }; diff --git a/src/libcore/result.rs b/src/libcore/result.rs index 58a4c558050..a74ac589b93 100644 --- a/src/libcore/result.rs +++ b/src/libcore/result.rs @@ -19,9 +19,9 @@ enum result<T, U> { */ pure fn get<T: copy, U>(res: result<T, U>) -> T { alt res { - ok(t) { t } - err(the_err) { - unchecked{ fail fmt!{"get called on error result: %?", the_err}; } + ok(t) => t, + err(the_err) => unchecked { + fail fmt!{"get called on error result: %?", the_err} } } } @@ -35,18 +35,16 @@ pure fn get<T: copy, U>(res: result<T, U>) -> T { */ pure fn get_err<T, U: copy>(res: result<T, U>) -> U { alt res { - err(u) { u } - ok(_) { - fail ~"get_error called on ok result"; - } + err(u) => u, + ok(_) => fail ~"get_error called on ok result" } } /// Returns true if the result is `ok` pure fn is_ok<T, U>(res: result<T, U>) -> bool { alt res { - ok(_) { true } - err(_) { false } + ok(_) => true, + err(_) => false } } @@ -63,8 +61,8 @@ pure fn is_err<T, U>(res: result<T, U>) -> bool { */ pure fn to_either<T: copy, U: copy>(res: result<U, T>) -> either<T, U> { alt res { - ok(res) { either::right(res) } - err(fail_) { either::left(fail_) } + ok(res) => either::right(res), + err(fail_) => either::left(fail_) } } @@ -85,8 +83,8 @@ pure fn to_either<T: copy, U: copy>(res: result<U, T>) -> either<T, U> { fn chain<T, U: copy, V: copy>(res: result<T, V>, op: fn(T) -> result<U, V>) -> result<U, V> { alt res { - ok(t) { op(t) } - err(e) { err(e) } + ok(t) => op(t), + err(e) => err(e) } } @@ -103,8 +101,8 @@ fn chain_err<T: copy, U: copy, V: copy>( op: fn(V) -> result<T, U>) -> result<T, U> { alt res { - ok(t) { ok(t) } - err(v) { op(v) } + ok(t) => ok(t), + err(v) => op(v) } } @@ -124,8 +122,8 @@ fn chain_err<T: copy, U: copy, V: copy>( */ fn iter<T, E>(res: result<T, E>, f: fn(T)) { alt res { - ok(t) { f(t) } - err(_) { } + ok(t) => f(t), + err(_) => () } } @@ -139,8 +137,8 @@ fn iter<T, E>(res: result<T, E>, f: fn(T)) { */ fn iter_err<T, E>(res: result<T, E>, f: fn(E)) { alt res { - ok(_) { } - err(e) { f(e) } + ok(_) => (), + err(e) => f(e) } } @@ -161,8 +159,8 @@ fn iter_err<T, E>(res: result<T, E>, f: fn(E)) { fn map<T, E: copy, U: copy>(res: result<T, E>, op: fn(T) -> U) -> result<U, E> { alt res { - ok(t) { ok(op(t)) } - err(e) { err(e) } + ok(t) => ok(op(t)), + err(e) => err(e) } } @@ -177,8 +175,8 @@ fn map<T, E: copy, U: copy>(res: result<T, E>, op: fn(T) -> U) fn map_err<T: copy, E, F: copy>(res: result<T, E>, op: fn(E) -> F) -> result<T, F> { alt res { - ok(t) { ok(t) } - err(e) { err(op(e)) } + ok(t) => ok(t), + err(e) => err(op(e)) } } @@ -189,15 +187,15 @@ impl extensions<T, E> for result<T, E> { fn iter(f: fn(T)) { alt self { - ok(t) { f(t) } - err(_) { } + ok(t) => f(t), + err(_) => () } } fn iter_err(f: fn(E)) { alt self { - ok(_) { } - err(e) { f(e) } + ok(_) => (), + err(e) => f(e) } } } @@ -207,8 +205,8 @@ impl extensions<T:copy, E> for result<T, E> { fn map_err<F:copy>(op: fn(E) -> F) -> result<T,F> { alt self { - ok(t) { ok(t) } - err(e) { err(op(e)) } + ok(t) => ok(t), + err(e) => err(op(e)) } } } @@ -218,8 +216,8 @@ impl extensions<T, E:copy> for result<T, E> { fn map<U:copy>(op: fn(T) -> U) -> result<U,E> { alt self { - ok(t) { ok(op(t)) } - err(e) { err(e) } + ok(t) => ok(op(t)), + err(e) => err(e) } } } @@ -258,8 +256,8 @@ fn map_vec<T,U:copy,V:copy>( vec::reserve(vs, vec::len(ts)); for vec::each(ts) |t| { alt op(t) { - ok(v) { vec::push(vs, v); } - err(u) { return err(u); } + ok(v) => vec::push(vs, v), + err(u) => return err(u) } } return ok(vs); @@ -269,12 +267,10 @@ fn map_opt<T,U:copy,V:copy>( o_t: option<T>, op: fn(T) -> result<V,U>) -> result<option<V>,U> { alt o_t { - none { ok(none) } - some(t) { - alt op(t) { - ok(v) { ok(some(v)) } - err(e) { err(e) } - } + none => ok(none), + some(t) => alt op(t) { + ok(v) => ok(some(v)), + err(e) => err(e) } } } @@ -298,8 +294,8 @@ fn map_vec2<S,T,U:copy,V:copy>(ss: ~[S], ts: ~[T], let mut i = 0u; while i < n { alt op(ss[i],ts[i]) { - ok(v) { vec::push(vs, v); } - err(u) { return err(u); } + ok(v) => vec::push(vs, v), + err(u) => return err(u) } i += 1u; } @@ -319,8 +315,8 @@ fn iter_vec2<S,T,U:copy>(ss: ~[S], ts: ~[T], let mut i = 0u; while i < n { alt op(ss[i],ts[i]) { - ok(()) { } - err(u) { return err(u); } + ok(()) => (), + err(u) => return err(u) } i += 1u; } @@ -331,8 +327,8 @@ fn iter_vec2<S,T,U:copy>(ss: ~[S], ts: ~[T], fn unwrap<T, U>(-res: result<T, U>) -> T { unsafe { let addr = alt res { - ok(x) { ptr::addr_of(x) } - err(_) { fail ~"error result" } + ok(x) => ptr::addr_of(x), + err(_) => fail ~"error result" }; let liberated_value = unsafe::reinterpret_cast(*addr); unsafe::forget(res); diff --git a/src/libcore/run.rs b/src/libcore/run.rs index bb604d7748a..60527e786bd 100644 --- a/src/libcore/run.rs +++ b/src/libcore/run.rs @@ -97,7 +97,7 @@ fn with_envp<T>(env: option<~[(~str,~str)]>, // 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) { + some(es) if !vec::is_empty(es) => { let mut tmps = ~[]; let mut ptrs = ~[]; @@ -112,9 +112,7 @@ fn with_envp<T>(env: option<~[(~str,~str)]>, unsafe { cb(::unsafe::reinterpret_cast(p)) } ) } - _ { - cb(ptr::null()) - } + _ => cb(ptr::null()) } } @@ -126,7 +124,7 @@ fn with_envp<T>(env: option<~[(~str,~str)]>, // \0 to terminate. unsafe { alt env { - some(es) if !vec::is_empty(es) { + some(es) if !vec::is_empty(es) => { let mut blk : ~[u8] = ~[]; for vec::each(es) |e| { let (k,v) = e; @@ -138,9 +136,7 @@ fn with_envp<T>(env: option<~[(~str,~str)]>, blk += ~[0_u8]; vec::as_buf(blk, |p, _len| cb(::unsafe::reinterpret_cast(p))) } - _ { - cb(ptr::null()) - } + _ => cb(ptr::null()) } } } @@ -148,8 +144,8 @@ fn with_envp<T>(env: option<~[(~str,~str)]>, fn with_dirp<T>(d: option<~str>, cb: fn(*libc::c_char) -> T) -> T { alt d { - some(dir) { str::as_c_str(dir, cb) } - none { cb(ptr::null()) } + some(dir) => str::as_c_str(dir, cb), + none => cb(ptr::null()) } } @@ -314,10 +310,10 @@ fn program_output(prog: ~str, args: ~[~str]) -> while count > 0 { let stream = comm::recv(p); alt check stream { - (1, s) { + (1, s) => { outs = s; } - (2, s) { + (2, s) => { errs = s; } }; diff --git a/src/libcore/send_map.rs b/src/libcore/send_map.rs index f2976e67eeb..a242587a21c 100644 --- a/src/libcore/send_map.rs +++ b/src/libcore/send_map.rs @@ -116,14 +116,10 @@ mod linear { let _ = for self.bucket_sequence(hash) |i| { alt buckets[i] { - some(bkt) { - if bkt.hash == hash && self.eqfn(k, &bkt.key) { - return found_entry(i); - } - } - none => { - return found_hole(i); + some(bkt) => if bkt.hash == hash && self.eqfn(k, &bkt.key) { + return found_entry(i); } + none => return found_hole(i) } }; return table_full; @@ -162,7 +158,7 @@ mod linear { alt self.bucket_for_key_with_hash(self.buckets, hash, unsafe{borrow(k)}) { table_full => {fail ~"Internal logic error";} - found_hole(idx) { + found_hole(idx) => { debug!{"insert fresh (%?->%?) at idx %?, hash %?", k, v, idx, hash}; self.buckets[idx] = some({hash: hash, key: k, value: v}); diff --git a/src/libcore/str.rs b/src/libcore/str.rs index 0c58f425d7d..cec8ec52ee4 100644 --- a/src/libcore/str.rs +++ b/src/libcore/str.rs @@ -342,18 +342,16 @@ fn unshift_char(&s: ~str, ch: char) { s = from_char(ch) + s; } /// Returns a string with leading whitespace removed pure fn trim_left(s: &str) -> ~str { alt find(s, |c| !char::is_whitespace(c)) { - none { ~"" } - some(first) { - unsafe { unsafe::slice_bytes(s, first, len(s)) } - } + none => ~"", + some(first) => unsafe { unsafe::slice_bytes(s, first, len(s)) } } } /// Returns a string with trailing whitespace removed pure fn trim_right(s: &str) -> ~str { alt rfind(s, |c| !char::is_whitespace(c)) { - none { ~"" } - some(last) { + none => ~"", + some(last) => { let {next, _} = char_range_at(s, last); unsafe { unsafe::slice_bytes(s, 0u, next) } } @@ -2779,9 +2777,9 @@ mod tests { let mut i = 0; do chars_iter(~"x\u03c0y") |ch| { alt check i { - 0 { assert ch == 'x'; } - 1 { assert ch == '\u03c0'; } - 2 { assert ch == 'y'; } + 0 => assert ch == 'x', + 1 => assert ch == '\u03c0', + 2 => assert ch == 'y' } i += 1; } @@ -2795,9 +2793,9 @@ mod tests { do bytes_iter(~"xyz") |bb| { alt check i { - 0 { assert bb == 'x' as u8; } - 1 { assert bb == 'y' as u8; } - 2 { assert bb == 'z' as u8; } + 0 => assert bb == 'x' as u8, + 1 => assert bb == 'y' as u8, + 2 => assert bb == 'z' as u8 } i += 1; } @@ -2813,11 +2811,11 @@ mod tests { do split_char_iter(data, ' ') |xx| { alt ii { - 0 { assert ~"\nMary" == xx; } - 1 { assert ~"had" == xx; } - 2 { assert ~"a" == xx; } - 3 { assert ~"little" == xx; } - _ { () } + 0 => assert ~"\nMary" == xx, + 1 => assert ~"had" == xx, + 2 => assert ~"a" == xx, + 3 => assert ~"little" == xx, + _ => () } ii += 1; } @@ -2831,10 +2829,10 @@ mod tests { do splitn_char_iter(data, ' ', 2u) |xx| { alt ii { - 0 { assert ~"\nMary" == xx; } - 1 { assert ~"had" == xx; } - 2 { assert ~"a little lamb\nLittle lamb\n" == xx; } - _ { () } + 0 => assert ~"\nMary" == xx, + 1 => assert ~"had" == xx, + 2 => assert ~"a little lamb\nLittle lamb\n" == xx, + _ => () } ii += 1; } @@ -2848,11 +2846,11 @@ mod tests { do words_iter(data) |ww| { alt ii { - 0 { assert ~"Mary" == ww; } - 1 { assert ~"had" == ww; } - 2 { assert ~"a" == ww; } - 3 { assert ~"little" == ww; } - _ { () } + 0 => assert ~"Mary" == ww, + 1 => assert ~"had" == ww, + 2 => assert ~"a" == ww, + 3 => assert ~"little" == ww, + _ => () } ii += 1; } @@ -2868,11 +2866,11 @@ mod tests { do lines_iter(lf) |x| { alt ii { - 0 { assert ~"" == x; } - 1 { assert ~"Mary had a little lamb" == x; } - 2 { assert ~"Little lamb" == x; } - 3 { assert ~"" == x; } - _ { () } + 0 => assert ~"" == x, + 1 => assert ~"Mary had a little lamb" == x, + 2 => assert ~"Little lamb" == x, + 3 => assert ~"" == x, + _ => () } ii += 1; } diff --git a/src/libcore/task.rs b/src/libcore/task.rs index 576e7244b69..da25eb308ab 100644 --- a/src/libcore/task.rs +++ b/src/libcore/task.rs @@ -280,7 +280,7 @@ impl task_builder for task_builder { blk(do future::from_fn { alt comm::recv(po) { - exit(_, result) { result } + exit(_, result) => result } }); @@ -503,8 +503,8 @@ fn try<T:send>(+f: fn~() -> T) -> result<T,()> { comm::send(ch, f()); } alt future::get(option::unwrap(result)) { - success { result::ok(comm::recv(po)) } - failure { result::err(()) } + success => result::ok(comm::recv(po)), + failure => result::err(()) } } @@ -992,7 +992,7 @@ fn gen_child_taskgroup(linked: bool, supervised: bool) * Step 1. Get spawner's taskgroup info. *######################################################################*/ let spawner_group = alt unsafe { local_get(spawner, taskgroup_key()) } { - none { + none => { // Main task, doing first spawn ever. Lazily initialise here. let mut members = new_taskset(); taskset_insert(&mut members, spawner); @@ -1005,7 +1005,7 @@ fn gen_child_taskgroup(linked: bool, supervised: bool) unsafe { local_set(spawner, taskgroup_key(), group); } group } - some(group) { group } + some(group) => group }; /*######################################################################* * Step 2. Process spawn options for child. @@ -1029,8 +1029,8 @@ fn gen_child_taskgroup(linked: bool, supervised: bool) // it should be enabled only in debug builds. let new_generation = alt *old_ancestors { - some(arc) { access_ancestors(arc, |a| a.generation+1) } - none { 0 } // the actual value doesn't really matter. + some(arc) => access_ancestors(arc, |a| a.generation+1), + none => 0 // the actual value doesn't really matter. }; assert new_generation < uint::max_value; // Build a new node in the ancestor list. @@ -1074,8 +1074,8 @@ fn spawn_raw(opts: task_opts, +f: fn~()) { let (child_tg, ancestors, f) = option::swap_unwrap(child_data); // Create child task. let new_task = alt opts.sched { - none { rustrt::new_task() } - some(sched_opts) { new_task_in_new_sched(sched_opts) } + none => rustrt::new_task(), + some(sched_opts) => new_task_in_new_sched(sched_opts) }; assert !new_task.is_null(); // Getting killed after here would leak the task. @@ -1163,20 +1163,20 @@ fn spawn_raw(opts: task_opts, +f: fn~()) { } let num_threads = alt opts.mode { - single_threaded { 1u } - thread_per_core { + single_threaded => 1u, + thread_per_core => { fail ~"thread_per_core scheduling mode unimplemented" } - thread_per_task { + thread_per_task => { fail ~"thread_per_task scheduling mode unimplemented" } - manual_threads(threads) { + manual_threads(threads) => { if threads == 0u { fail ~"can not create a scheduler with no threads"; } threads } - osmain { 0u /* Won't be used */ } + osmain => 0u /* Won't be used */ }; let sched_id = if opts.mode != osmain { @@ -1273,7 +1273,10 @@ unsafe fn local_data_lookup<T: owned>( let key_value = key_to_key_value(key); let map_pos = (*map).position(|entry| - alt entry { some((k,_,_)) { k == key_value } none { false } } + alt entry { + some((k,_,_)) => k == key_value, + none => false + } ); do map_pos.map |index| { // .get() is guaranteed because of "none { false }" above. @@ -1334,20 +1337,16 @@ unsafe fn local_set<T: owned>( let new_entry = some((keyval, data_ptr, data_box)); // Find a place to put it. alt local_data_lookup(map, key) { - some((index, _old_data_ptr)) { + some((index, _old_data_ptr)) => { // Key already had a value set, _old_data_ptr, whose reference // will get dropped when the local_data box is overwritten. (*map).set_elt(index, new_entry); } - none { + none => { // Find an empty slot. If not, grow the vector. alt (*map).position(|x| x == none) { - some(empty_index) { - (*map).set_elt(empty_index, new_entry); - } - none { - (*map).push(new_entry); - } + some(empty_index) => (*map).set_elt(empty_index, new_entry), + none => (*map).push(new_entry) } } } @@ -1698,8 +1697,8 @@ fn test_try_success() { alt do try { ~"Success!" } { - result::ok(~"Success!") { } - _ { fail; } + result::ok(~"Success!") => (), + _ => fail } } @@ -1709,8 +1708,8 @@ fn test_try_fail() { alt do try { fail } { - result::err(()) { } - result::ok(()) { fail; } + result::err(()) => (), + result::ok(()) => fail } } @@ -2054,15 +2053,15 @@ fn test_tls_modify() unsafe { fn my_key(+_x: @~str) { } local_data_modify(my_key, |data| { alt data { - some(@val) { fail ~"unwelcome value: " + val } - none { some(@~"first data") } + some(@val) => fail ~"unwelcome value: " + val, + none => some(@~"first data") } }); local_data_modify(my_key, |data| { alt data { - some(@~"first data") { some(@~"next data") } - some(@val) { fail ~"wrong value: " + val } - none { fail ~"missing value" } + some(@~"first data") => some(@~"next data"), + some(@val) => fail ~"wrong value: " + val, + none => fail ~"missing value" } }); assert *(local_data_pop(my_key).get()) == ~"next data"; diff --git a/src/libcore/uint-template.rs b/src/libcore/uint-template.rs index d3e1fb41ca2..d3b0e8cea24 100644 --- a/src/libcore/uint-template.rs +++ b/src/libcore/uint-template.rs @@ -128,8 +128,8 @@ fn parse_buf(buf: ~[u8], radix: uint) -> option<T> { let mut n = 0u as T; loop { alt char::to_digit(buf[i] as char, radix) { - some(d) { n += d as T * power; } - none { return none; } + some(d) => n += d as T * power, + none => return none } power *= radix as T; if i == 0u { return some(n); } @@ -147,8 +147,8 @@ fn from_str_radix(buf: ~str, radix: u64) -> option<u64> { let mut power = 1u64, n = 0u64; loop { alt char::to_digit(buf[i] as char, radix as uint) { - some(d) { n += d as u64 * power; } - none { return none; } + some(d) => n += d as u64 * power, + none => return none } power *= radix; if i == 0u { return some(n); } diff --git a/src/libcore/unicode.rs b/src/libcore/unicode.rs index 61fd8d40f23..343bf7954e6 100644 --- a/src/libcore/unicode.rs +++ b/src/libcore/unicode.rs @@ -2,9 +2,8 @@ mod general_category { pure fn Cc(c: char) -> bool { return alt c { '\x00' to '\x1f' - | '\x7f' to '\x9f' - { true } - _ { false } + | '\x7f' to '\x9f' => true, + _ => false }; } @@ -22,25 +21,22 @@ mod general_category { | '\ufff9' to '\ufffb' | '\U000110bd' | '\U0001d173' to '\U0001d17a' - | '\U000e0001' to '\U000e007f' - { true } - _ { false } + | '\U000e0001' to '\U000e007f' => true, + _ => false }; } pure fn Co(c: char) -> bool { return alt c { - '\ue000' to '\uf8ff' - { true } - _ { false } + '\ue000' to '\uf8ff' => true, + _ => false }; } pure fn Cs(c: char) -> bool { return alt c { - '\ud800' to '\udfff' - { true } - _ { false } + '\ud800' to '\udfff' => true, + _ => false }; } @@ -644,8 +640,8 @@ mod general_category { | '\U0001d7aa' to '\U0001d7c2' | '\U0001d7c4' to '\U0001d7c9' | '\U0001d7cb' - { true } - _ { false } + => true, + _ => false }; } @@ -700,8 +696,8 @@ mod general_category { | '\uaadd' | '\uff70' | '\uff9e' to '\uff9f' - { true } - _ { false } + => true, + _ => false }; } @@ -886,8 +882,8 @@ mod general_category { | '\U00012000' to '\U0001236e' | '\U00013000' to '\U0001b001' | '\U00020000' to '\U0002fa1d' - { true } - _ { false } + => true, + _ => false }; } @@ -903,8 +899,8 @@ mod general_category { | '\u1fbc' | '\u1fcc' | '\u1ffc' - { true } - _ { false } + => true, + _ => false }; } @@ -1495,8 +1491,8 @@ mod general_category { | '\U0001d756' to '\U0001d76e' | '\U0001d790' to '\U0001d7a8' | '\U0001d7ca' - { true } - _ { false } + => true, + _ => false }; } @@ -1606,8 +1602,8 @@ mod general_category { | '\U000110b7' to '\U000110b8' | '\U0001d165' to '\U0001d166' | '\U0001d16d' to '\U0001d172' - { true } - _ { false } + => true, + _ => false }; } @@ -1617,8 +1613,8 @@ mod general_category { | '\u20dd' to '\u20e0' | '\u20e2' to '\u20e4' | '\ua670' to '\ua672' - { true } - _ { false } + => true, + _ => false }; } @@ -1810,8 +1806,8 @@ mod general_category { | '\U0001d1aa' to '\U0001d1ad' | '\U0001d242' to '\U0001d244' | '\U000e0100' to '\U000e01ef' - { true } - _ { false } + => true, + _ => false }; } @@ -1854,8 +1850,8 @@ mod general_category { | '\U000104a0' to '\U000104a9' | '\U00011066' to '\U0001106f' | '\U0001d7ce' to '\U0001d7ff' - { true } - _ { false } + => true, + _ => false }; } @@ -1873,8 +1869,8 @@ mod general_category { | '\U0001034a' | '\U000103d1' to '\U000103d5' | '\U00012400' to '\U00012462' - { true } - _ { false } + => true, + _ => false }; } @@ -1921,8 +1917,8 @@ mod general_category { | '\U00011052' to '\U00011065' | '\U0001d360' to '\U0001d371' | '\U0001f100' to '\U0001f10a' - { true } - _ { false } + => true, + _ => false }; } @@ -1934,8 +1930,8 @@ mod general_category { | '\ufe33' to '\ufe34' | '\ufe4d' to '\ufe4f' | '\uff3f' - { true } - _ { false } + => true, + _ => false }; } @@ -1956,8 +1952,8 @@ mod general_category { | '\ufe58' | '\ufe63' | '\uff0d' - { true } - _ { false } + => true, + _ => false }; } @@ -2033,8 +2029,8 @@ mod general_category { | '\uff5d' | '\uff60' | '\uff63' - { true } - _ { false } + => true, + _ => false }; } @@ -2050,8 +2046,8 @@ mod general_category { | '\u2e0d' | '\u2e1d' | '\u2e21' - { true } - _ { false } + => true, + _ => false }; } @@ -2068,8 +2064,8 @@ mod general_category { | '\u2e0c' | '\u2e1c' | '\u2e20' - { true } - _ { false } + => true, + _ => false }; } @@ -2201,8 +2197,8 @@ mod general_category { | '\U000110bb' to '\U000110bc' | '\U000110be' to '\U000110c1' | '\U00012470' to '\U00012473' - { true } - _ { false } + => true, + _ => false }; } @@ -2280,8 +2276,8 @@ mod general_category { | '\uff5b' | '\uff5f' | '\uff62' - { true } - _ { false } + => true, + _ => false }; } @@ -2303,8 +2299,8 @@ mod general_category { | '\uff04' | '\uffe0' to '\uffe1' | '\uffe5' to '\uffe6' - { true } - _ { false } + => true, + _ => false }; } @@ -2337,8 +2333,8 @@ mod general_category { | '\uff3e' | '\uff40' | '\uffe3' - { true } - _ { false } + => true, + _ => false }; } @@ -2408,8 +2404,8 @@ mod general_category { | '\U0001d789' | '\U0001d7a9' | '\U0001d7c3' - { true } - _ { false } + => true, + _ => false }; } @@ -2527,24 +2523,22 @@ mod general_category { | '\U0001d245' to '\U0001d356' | '\U0001f000' to '\U0001f0df' | '\U0001f110' to '\U0001f773' - { true } - _ { false } + => true, + _ => false }; } pure fn Zl(c: char) -> bool { return alt c { - '\u2028' - { true } - _ { false } + '\u2028' => true, + _ => false }; } pure fn Zp(c: char) -> bool { return alt c { - '\u2029' - { true } - _ { false } + '\u2029' => true, + _ => false }; } @@ -2558,8 +2552,8 @@ mod general_category { | '\u202f' | '\u205f' | '\u3000' - { true } - _ { false } + => true, + _ => false }; } @@ -3299,8 +3293,8 @@ mod derived_property { | '\U0002a700' to '\U0002b734' | '\U0002b740' to '\U0002b81d' | '\U0002f800' to '\U0002fa1d' - { true } - _ { false } + => true, + _ => false }; } @@ -4170,8 +4164,8 @@ mod derived_property { | '\U0002b740' to '\U0002b81d' | '\U0002f800' to '\U0002fa1d' | '\U000e0100' to '\U000e01ef' - { true } - _ { false } + => true, + _ => false }; } @@ -4676,8 +4670,8 @@ mod derived_property { | '\U0002a700' to '\U0002b734' | '\U0002b740' to '\U0002b81d' | '\U0002f800' to '\U0002fa1d' - { true } - _ { false } + => true, + _ => false }; } diff --git a/src/libcore/vec.rs b/src/libcore/vec.rs index 2606bdf72f8..93bdd53d90d 100644 --- a/src/libcore/vec.rs +++ b/src/libcore/vec.rs @@ -357,8 +357,8 @@ fn split<T: copy>(v: &[T], f: fn(T) -> bool) -> ~[~[T]] { let mut result = ~[]; while start < ln { alt position_between(v, start, ln, f) { - none { break } - some(i) { + none => break, + some(i) => { push(result, slice(v, start, i)); start = i + 1u; } @@ -381,8 +381,8 @@ fn splitn<T: copy>(v: &[T], n: uint, f: fn(T) -> bool) -> ~[~[T]] { let mut result = ~[]; while start < ln && count > 0u { alt position_between(v, start, ln, f) { - none { break } - some(i) { + none => break, + some(i) => { push(result, slice(v, start, i)); // Make sure to skip the separator. start = i + 1u; @@ -406,8 +406,8 @@ fn rsplit<T: copy>(v: &[T], f: fn(T) -> bool) -> ~[~[T]] { let mut result = ~[]; while end > 0u { alt rposition_between(v, 0u, end, f) { - none { break } - some(i) { + none => break, + some(i) => { push(result, slice(v, i + 1u, end)); end = i; } @@ -430,8 +430,8 @@ fn rsplitn<T: copy>(v: &[T], n: uint, f: fn(T) -> bool) -> ~[~[T]] { let mut result = ~[]; while end > 0u && count > 0u { alt rposition_between(v, 0u, end, f) { - none { break } - some(i) { + none => break, + some(i) => { push(result, slice(v, i + 1u, end)); // Make sure to skip the separator. end = i; @@ -714,8 +714,8 @@ pure fn filter_map<T, U: copy>(v: &[T], f: fn(T) -> option<U>) let mut result = ~[]; for each(v) |elem| { alt f(elem) { - none {/* no-op */ } - some(result_elem) { unsafe { push(result, result_elem); } } + none => {/* no-op */ } + some(result_elem) => unsafe { push(result, result_elem); } } } return result; |
