From 51d98d9c7bcdfad2daec697739b25193adc09ced Mon Sep 17 00:00:00 2001 From: Tim Chevalier Date: Wed, 15 Aug 2012 11:55:17 -0700 Subject: Expunge match checks --- src/libstd/base64.rs | 11 +++++++---- src/libstd/ebml.rs | 9 ++++++--- src/libstd/getopts.rs | 3 ++- src/libstd/list.rs | 6 +++++- src/libstd/serialization.rs | 7 ++++--- src/libstd/time.rs | 25 ++++++++++++++++--------- 6 files changed, 40 insertions(+), 21 deletions(-) (limited to 'src/libstd') diff --git a/src/libstd/base64.rs b/src/libstd/base64.rs index b22fe2b9582..99e83d11e52 100644 --- a/src/libstd/base64.rs +++ b/src/libstd/base64.rs @@ -30,22 +30,25 @@ impl ~[u8]: to_base64 { i += 3u; } - match check len % 3u { - 0u => (), - 1u => { + // Heh, would be cool if we knew this was exhaustive + // (the dream of bounded integer types) + match len % 3 { + 0 => (), + 1 => { let n = (self[i] as uint) << 16u; str::push_char(s, chars[(n >> 18u) & 63u]); str::push_char(s, chars[(n >> 12u) & 63u]); str::push_char(s, '='); str::push_char(s, '='); } - 2u => { + 2 => { let n = (self[i] as uint) << 16u | (self[i + 1u] as uint) << 8u; str::push_char(s, chars[(n >> 18u) & 63u]); str::push_char(s, chars[(n >> 12u) & 63u]); str::push_char(s, chars[(n >> 6u) & 63u]); str::push_char(s, '='); } + _ => fail ~"Algebra is broken, please alert the math police" } s diff --git a/src/libstd/ebml.rs b/src/libstd/ebml.rs index 5a587752093..b3222f7ab24 100644 --- a/src/libstd/ebml.rs +++ b/src/libstd/ebml.rs @@ -602,14 +602,17 @@ fn test_option_int() { fn deserialize_0(s: S) -> option { do s.read_enum(~"core::option::t") { do s.read_enum_variant |i| { - match check i { - 0u => none, - 1u => { + match i { + 0 => none, + 1 => { let v0 = do s.read_enum_variant_arg(0u) { deserialize_1(s) }; some(v0) } + _ => { + fail #fmt("deserialize_0: unexpected variant %u", i); + } } } } diff --git a/src/libstd/getopts.rs b/src/libstd/getopts.rs index 04a04691077..1c92fd4ce0d 100644 --- a/src/libstd/getopts.rs +++ b/src/libstd/getopts.rs @@ -431,11 +431,12 @@ mod tests { let args = ~[~"--test=20"]; let opts = ~[reqopt(~"test")]; let rs = getopts(args, opts); - match check rs { + match rs { ok(m) => { assert (opt_present(m, ~"test")); assert (opt_str(m, ~"test") == ~"20"); } + _ => { fail ~"test_reqopt_long failed"; } } } diff --git a/src/libstd/list.rs b/src/libstd/list.rs index 4b8b75d3d66..0eb01aa5b66 100644 --- a/src/libstd/list.rs +++ b/src/libstd/list.rs @@ -91,7 +91,11 @@ pure fn tail(ls: @list) -> @list { /// Returns the first element of a list pure fn head(ls: @list) -> T { - match check *ls { cons(hd, _) => hd } + match *ls { + cons(hd, _) => hd, + // makes me sad + _ => fail ~"head invoked on empty list" + } } /// Appends one list to another diff --git a/src/libstd/serialization.rs b/src/libstd/serialization.rs index c27081a457b..15eb565dc84 100644 --- a/src/libstd/serialization.rs +++ b/src/libstd/serialization.rs @@ -260,9 +260,10 @@ fn deserialize_option(d: D, st: fn() -> T) -> option { do d.read_enum(~"option") { do d.read_enum_variant |i| { - match check i { - 0u => none, - 1u => some(d.read_enum_variant_arg(0u, || st() )) + match i { + 0 => none, + 1 => some(d.read_enum_variant_arg(0u, || st() )), + _ => fail(#fmt("Bad variant for option: %u", i)) } } } diff --git a/src/libstd/time.rs b/src/libstd/time.rs index 47dbff2ccb1..1aa6c4d74da 100644 --- a/src/libstd/time.rs +++ b/src/libstd/time.rs @@ -572,26 +572,30 @@ fn strptime(s: ~str, format: ~str) -> result { fn strftime(format: ~str, tm: tm) -> ~str { fn parse_type(ch: char, tm: tm) -> ~str { //FIXME (#2350): Implement missing types. - match check ch { - 'A' => match check tm.tm_wday as int { + let die = || #fmt("strftime: can't understand this format %c ", + ch); + match ch { + 'A' => match tm.tm_wday as int { 0 => ~"Sunday", 1 => ~"Monday", 2 => ~"Tuesday", 3 => ~"Wednesday", 4 => ~"Thursday", 5 => ~"Friday", - 6 => ~"Saturday" + 6 => ~"Saturday", + _ => die() }, - 'a' => match check tm.tm_wday as int { + 'a' => match tm.tm_wday as int { 0 => ~"Sun", 1 => ~"Mon", 2 => ~"Tue", 3 => ~"Wed", 4 => ~"Thu", 5 => ~"Fri", - 6 => ~"Sat" + 6 => ~"Sat", + _ => die() }, - 'B' => match check tm.tm_mon as int { + 'B' => match tm.tm_mon as int { 0 => ~"January", 1 => ~"February", 2 => ~"March", @@ -603,9 +607,10 @@ fn strftime(format: ~str, tm: tm) -> ~str { 8 => ~"September", 9 => ~"October", 10 => ~"November", - 11 => ~"December" + 11 => ~"December", + _ => die() }, - 'b' | 'h' => match check tm.tm_mon as int { + 'b' | 'h' => match tm.tm_mon as int { 0 => ~"Jan", 1 => ~"Feb", 2 => ~"Mar", @@ -618,6 +623,7 @@ fn strftime(format: ~str, tm: tm) -> ~str { 9 => ~"Oct", 10 => ~"Nov", 11 => ~"Dec", + _ => die() }, 'C' => fmt!{"%02d", (tm.tm_year as int + 1900) / 100}, 'c' => { @@ -712,7 +718,8 @@ fn strftime(format: ~str, tm: tm) -> ~str { fmt!{"%c%02d%02d", sign, h as int, m as int} } //'+' {} - '%' => ~"%" + '%' => ~"%", + _ => die() } } -- cgit 1.4.1-3-g733a5