Skip to content

Commit 51d98d9

Browse files
committed
Expunge match checks
1 parent b0f2893 commit 51d98d9

File tree

9 files changed

+54
-28
lines changed

9 files changed

+54
-28
lines changed

src/libcore/comm.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -412,9 +412,10 @@ fn test_select2_stress() {
412412
let mut as = 0;
413413
let mut bs = 0;
414414
for iter::repeat(msgs * times * 2u) {
415-
match check select2(po_a, po_b) {
415+
match select2(po_a, po_b) {
416416
either::left(~"a") => as += 1,
417-
either::right(~"b") => bs += 1
417+
either::right(~"b") => bs += 1,
418+
_ => fail ~"test_select_2_stress failed"
418419
}
419420
}
420421

src/libcore/run.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,13 +312,17 @@ fn program_output(prog: &str, args: &[~str]) ->
312312
let mut count = 2;
313313
while count > 0 {
314314
let stream = comm::recv(p);
315-
match check stream {
315+
match stream {
316316
(1, s) => {
317317
outs = s;
318318
}
319319
(2, s) => {
320320
errs = s;
321321
}
322+
(n, _) => {
323+
fail(#fmt("program_output received an unexpected file \
324+
number: %u", n));
325+
}
322326
};
323327
count -= 1;
324328
};

src/libcore/str.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2771,10 +2771,11 @@ mod tests {
27712771
fn test_chars_iter() {
27722772
let mut i = 0;
27732773
do chars_iter(~"x\u03c0y") |ch| {
2774-
match check i {
2774+
match i {
27752775
0 => assert ch == 'x',
27762776
1 => assert ch == '\u03c0',
2777-
2 => assert ch == 'y'
2777+
2 => assert ch == 'y',
2778+
_ => fail ~"test_chars_iter failed"
27782779
}
27792780
i += 1;
27802781
}
@@ -2787,10 +2788,11 @@ mod tests {
27872788
let mut i = 0;
27882789
27892790
do bytes_iter(~"xyz") |bb| {
2790-
match check i {
2791+
match i {
27912792
0 => assert bb == 'x' as u8,
27922793
1 => assert bb == 'y' as u8,
2793-
2 => assert bb == 'z' as u8
2794+
2 => assert bb == 'z' as u8,
2795+
_ => fail ~"test_bytes_iter failed"
27942796
}
27952797
i += 1;
27962798
}

src/libstd/base64.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,22 +30,25 @@ impl ~[u8]: to_base64 {
3030
i += 3u;
3131
}
3232

33-
match check len % 3u {
34-
0u => (),
35-
1u => {
33+
// Heh, would be cool if we knew this was exhaustive
34+
// (the dream of bounded integer types)
35+
match len % 3 {
36+
0 => (),
37+
1 => {
3638
let n = (self[i] as uint) << 16u;
3739
str::push_char(s, chars[(n >> 18u) & 63u]);
3840
str::push_char(s, chars[(n >> 12u) & 63u]);
3941
str::push_char(s, '=');
4042
str::push_char(s, '=');
4143
}
42-
2u => {
44+
2 => {
4345
let n = (self[i] as uint) << 16u | (self[i + 1u] as uint) << 8u;
4446
str::push_char(s, chars[(n >> 18u) & 63u]);
4547
str::push_char(s, chars[(n >> 12u) & 63u]);
4648
str::push_char(s, chars[(n >> 6u) & 63u]);
4749
str::push_char(s, '=');
4850
}
51+
_ => fail ~"Algebra is broken, please alert the math police"
4952
}
5053

5154
s

src/libstd/ebml.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -602,14 +602,17 @@ fn test_option_int() {
602602
fn deserialize_0<S: serialization::deserializer>(s: S) -> option<int> {
603603
do s.read_enum(~"core::option::t") {
604604
do s.read_enum_variant |i| {
605-
match check i {
606-
0u => none,
607-
1u => {
605+
match i {
606+
0 => none,
607+
1 => {
608608
let v0 = do s.read_enum_variant_arg(0u) {
609609
deserialize_1(s)
610610
};
611611
some(v0)
612612
}
613+
_ => {
614+
fail #fmt("deserialize_0: unexpected variant %u", i);
615+
}
613616
}
614617
}
615618
}

src/libstd/getopts.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,11 +431,12 @@ mod tests {
431431
let args = ~[~"--test=20"];
432432
let opts = ~[reqopt(~"test")];
433433
let rs = getopts(args, opts);
434-
match check rs {
434+
match rs {
435435
ok(m) => {
436436
assert (opt_present(m, ~"test"));
437437
assert (opt_str(m, ~"test") == ~"20");
438438
}
439+
_ => { fail ~"test_reqopt_long failed"; }
439440
}
440441
}
441442

src/libstd/list.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,11 @@ pure fn tail<T: copy>(ls: @list<T>) -> @list<T> {
9191

9292
/// Returns the first element of a list
9393
pure fn head<T: copy>(ls: @list<T>) -> T {
94-
match check *ls { cons(hd, _) => hd }
94+
match *ls {
95+
cons(hd, _) => hd,
96+
// makes me sad
97+
_ => fail ~"head invoked on empty list"
98+
}
9599
}
96100

97101
/// Appends one list to another

src/libstd/serialization.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -260,9 +260,10 @@ fn deserialize_option<D: deserializer,T: copy>(d: D, st: fn() -> T)
260260
-> option<T> {
261261
do d.read_enum(~"option") {
262262
do d.read_enum_variant |i| {
263-
match check i {
264-
0u => none,
265-
1u => some(d.read_enum_variant_arg(0u, || st() ))
263+
match i {
264+
0 => none,
265+
1 => some(d.read_enum_variant_arg(0u, || st() )),
266+
_ => fail(#fmt("Bad variant for option: %u", i))
266267
}
267268
}
268269
}

src/libstd/time.rs

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -572,26 +572,30 @@ fn strptime(s: ~str, format: ~str) -> result<tm, ~str> {
572572
fn strftime(format: ~str, tm: tm) -> ~str {
573573
fn parse_type(ch: char, tm: tm) -> ~str {
574574
//FIXME (#2350): Implement missing types.
575-
match check ch {
576-
'A' => match check tm.tm_wday as int {
575+
let die = || #fmt("strftime: can't understand this format %c ",
576+
ch);
577+
match ch {
578+
'A' => match tm.tm_wday as int {
577579
0 => ~"Sunday",
578580
1 => ~"Monday",
579581
2 => ~"Tuesday",
580582
3 => ~"Wednesday",
581583
4 => ~"Thursday",
582584
5 => ~"Friday",
583-
6 => ~"Saturday"
585+
6 => ~"Saturday",
586+
_ => die()
584587
},
585-
'a' => match check tm.tm_wday as int {
588+
'a' => match tm.tm_wday as int {
586589
0 => ~"Sun",
587590
1 => ~"Mon",
588591
2 => ~"Tue",
589592
3 => ~"Wed",
590593
4 => ~"Thu",
591594
5 => ~"Fri",
592-
6 => ~"Sat"
595+
6 => ~"Sat",
596+
_ => die()
593597
},
594-
'B' => match check tm.tm_mon as int {
598+
'B' => match tm.tm_mon as int {
595599
0 => ~"January",
596600
1 => ~"February",
597601
2 => ~"March",
@@ -603,9 +607,10 @@ fn strftime(format: ~str, tm: tm) -> ~str {
603607
8 => ~"September",
604608
9 => ~"October",
605609
10 => ~"November",
606-
11 => ~"December"
610+
11 => ~"December",
611+
_ => die()
607612
},
608-
'b' | 'h' => match check tm.tm_mon as int {
613+
'b' | 'h' => match tm.tm_mon as int {
609614
0 => ~"Jan",
610615
1 => ~"Feb",
611616
2 => ~"Mar",
@@ -618,6 +623,7 @@ fn strftime(format: ~str, tm: tm) -> ~str {
618623
9 => ~"Oct",
619624
10 => ~"Nov",
620625
11 => ~"Dec",
626+
_ => die()
621627
},
622628
'C' => fmt!{"%02d", (tm.tm_year as int + 1900) / 100},
623629
'c' => {
@@ -712,7 +718,8 @@ fn strftime(format: ~str, tm: tm) -> ~str {
712718
fmt!{"%c%02d%02d", sign, h as int, m as int}
713719
}
714720
//'+' {}
715-
'%' => ~"%"
721+
'%' => ~"%",
722+
_ => die()
716723
}
717724
}
718725

0 commit comments

Comments
 (0)