about summary refs log tree commit diff
path: root/src/test
diff options
context:
space:
mode:
authorMarijn Haverbeke <marijnh@gmail.com>2012-02-15 09:40:42 +0100
committerMarijn Haverbeke <marijnh@gmail.com>2012-02-15 15:47:42 +0100
commit67cc89f38d2e75cb0dcd6303fbe4bb4f659277a7 (patch)
tree99caacd6c05c72beb28e73a9aa759b5db1d88114 /src/test
parent4b63826050dfc579b9ac65a6b72ad0ca6f6b51fc (diff)
downloadrust-67cc89f38d2e75cb0dcd6303fbe4bb4f659277a7.tar.gz
rust-67cc89f38d2e75cb0dcd6303fbe4bb4f659277a7.zip
Rewrite exhaustiveness checker
Issue #352
Closes #1720

The old checker would happily accept things like 'alt x { @some(a) { a } }'.
It now properly descends into patterns, checks exhaustiveness of booleans,
and complains when number/string patterns aren't exhaustive.
Diffstat (limited to 'src/test')
-rw-r--r--src/test/compile-fail/missing-return2.rs2
-rw-r--r--src/test/compile-fail/non-exhaustive-match-nested.rs2
-rw-r--r--src/test/compile-fail/non-exhaustive-match.rs16
-rw-r--r--src/test/pretty/block-disambig.rs10
-rw-r--r--src/test/pretty/unary-op-disambig.rs4
-rw-r--r--src/test/run-fail/unwind-alt.rs2
-rw-r--r--src/test/run-pass/alt-bot-2.rs2
-rw-r--r--src/test/run-pass/alt-pattern-lit.rs2
-rw-r--r--src/test/run-pass/alt-range.rs2
-rw-r--r--src/test/run-pass/alt-str.rs6
-rw-r--r--src/test/run-pass/binary-minus-without-space.rs2
-rw-r--r--src/test/run-pass/expr-alt-box.rs7
-rw-r--r--src/test/run-pass/expr-alt-generic-box1.rs2
-rw-r--r--src/test/run-pass/expr-alt-generic-box2.rs2
-rw-r--r--src/test/run-pass/expr-alt-generic-unique1.rs2
-rw-r--r--src/test/run-pass/expr-alt-generic-unique2.rs2
-rw-r--r--src/test/run-pass/expr-alt-generic.rs2
-rw-r--r--src/test/run-pass/expr-alt-struct.rs2
-rw-r--r--src/test/run-pass/expr-alt-unique.rs5
-rw-r--r--src/test/run-pass/unreachable-code.rs2
20 files changed, 46 insertions, 30 deletions
diff --git a/src/test/compile-fail/missing-return2.rs b/src/test/compile-fail/missing-return2.rs
index 26a9febd3c7..54d8de63014 100644
--- a/src/test/compile-fail/missing-return2.rs
+++ b/src/test/compile-fail/missing-return2.rs
@@ -3,7 +3,7 @@
 fn f() -> int {
     // Make sure typestate doesn't interpret this alt expression
     // as the function result
-    alt true { true { } };
+    alt check true { true { } };
 }
 
 fn main() { }
diff --git a/src/test/compile-fail/non-exhaustive-match-nested.rs b/src/test/compile-fail/non-exhaustive-match-nested.rs
index b3b854f53e5..a4efbb5684c 100644
--- a/src/test/compile-fail/non-exhaustive-match-nested.rs
+++ b/src/test/compile-fail/non-exhaustive-match-nested.rs
@@ -1,5 +1,5 @@
 // -*- rust -*-
-// error-pattern: Non-exhaustive pattern
+// error-pattern: non-exhaustive patterns
 enum t { a(u), b }
 enum u { c, d }
 
diff --git a/src/test/compile-fail/non-exhaustive-match.rs b/src/test/compile-fail/non-exhaustive-match.rs
index 7beb7f1b17d..b2fec6c0c5d 100644
--- a/src/test/compile-fail/non-exhaustive-match.rs
+++ b/src/test/compile-fail/non-exhaustive-match.rs
@@ -1,5 +1,15 @@
-// -*- rust -*-
-// error-pattern: Non-exhaustive pattern
 enum t { a, b, }
 
-fn main() { let x = a; alt x { b { } } }
+fn main() {
+    let x = a;
+    alt x { b { } } //! ERROR non-exhaustive patterns
+    alt true { //! ERROR non-exhaustive bool patterns
+      true {}
+    }
+    alt @some(10) { //! ERROR non-exhaustive patterns
+      @none {}
+    }
+    alt (2, 3, 4) { //! ERROR non-exhaustive literal patterns
+      (_, _, 4) {}
+    }
+}
diff --git a/src/test/pretty/block-disambig.rs b/src/test/pretty/block-disambig.rs
index d1a7a9b85ac..64752505952 100644
--- a/src/test/pretty/block-disambig.rs
+++ b/src/test/pretty/block-disambig.rs
@@ -8,7 +8,7 @@ fn test2() -> int { let val = @0; { } *val }
 
 fn test3() {
     let regs = @{mutable eax: 0};
-    alt true { true { } }
+    alt check true { true { } }
     (*regs).eax = 1;
 }
 
@@ -20,13 +20,13 @@ fn test6() -> bool { { } (true || false) && true }
 
 fn test7() -> uint {
     let regs = @0;
-    alt true { true { } }
+    alt check true { true { } }
     (*regs < 2) as uint
 }
 
 fn test8() -> int {
     let val = @0;
-    alt true {
+    alt check true {
         true { }
     }
     if *val < 1 {
@@ -36,11 +36,11 @@ fn test8() -> int {
     }
 }
 
-fn test9() { let regs = @mutable 0; alt true { true { } } *regs += 1; }
+fn test9() { let regs = @mutable 0; alt check true { true { } } *regs += 1; }
 
 fn test10() -> int {
     let regs = @mutable [0];
-    alt true { true { } }
+    alt check true { true { } }
     (*regs)[0]
 }
 
diff --git a/src/test/pretty/unary-op-disambig.rs b/src/test/pretty/unary-op-disambig.rs
index 88406813b42..e9fd2c2dc2c 100644
--- a/src/test/pretty/unary-op-disambig.rs
+++ b/src/test/pretty/unary-op-disambig.rs
@@ -10,8 +10,8 @@ fn if_semi() -> int { if true { f() } else { f() }; -1 }
 
 fn if_nosemi() -> int { (if true { 0 } else { 0 }) - 1 }
 
-fn alt_semi() -> int { alt true { true { f() } }; -1 }
+fn alt_semi() -> int { alt check true { true { f() } }; -1 }
 
-fn alt_no_semi() -> int { (alt true { true { 0 } }) - 1 }
+fn alt_no_semi() -> int { (alt check true { true { 0 } }) - 1 }
 
 fn stmt() { { f() }; -1; }
diff --git a/src/test/run-fail/unwind-alt.rs b/src/test/run-fail/unwind-alt.rs
index 741a7eb4975..1cd512cfc41 100644
--- a/src/test/run-fail/unwind-alt.rs
+++ b/src/test/run-fail/unwind-alt.rs
@@ -4,7 +4,7 @@ fn test_box() {
     @0;
 }
 fn test_str() {
-    let res = alt false { true { "happy" } };
+    let res = alt check false { true { "happy" } };
     assert res == "happy";
 }
 fn main() {
diff --git a/src/test/run-pass/alt-bot-2.rs b/src/test/run-pass/alt-bot-2.rs
index 3183b580fc6..e3fd606c2d8 100644
--- a/src/test/run-pass/alt-bot-2.rs
+++ b/src/test/run-pass/alt-bot-2.rs
@@ -1,3 +1,3 @@
 // n.b. This was only ever failing with optimization disabled.
-fn a() -> int { alt ret 1 { 2 { 3 } } }
+fn a() -> int { alt check ret 1 { 2 { 3 } } }
 fn main() { a(); }
diff --git a/src/test/run-pass/alt-pattern-lit.rs b/src/test/run-pass/alt-pattern-lit.rs
index afc72c80afa..d266a63418f 100644
--- a/src/test/run-pass/alt-pattern-lit.rs
+++ b/src/test/run-pass/alt-pattern-lit.rs
@@ -1,7 +1,7 @@
 
 
 fn altlit(f: int) -> int {
-    alt f {
+    alt check f {
       10 { #debug("case 10"); ret 20; }
       11 { #debug("case 11"); ret 22; }
     }
diff --git a/src/test/run-pass/alt-range.rs b/src/test/run-pass/alt-range.rs
index 1cd29cb3517..e85a82a2fd4 100644
--- a/src/test/run-pass/alt-range.rs
+++ b/src/test/run-pass/alt-range.rs
@@ -7,7 +7,7 @@ fn main() {
       6u to 7u { fail "shouldn't match range"; }
       _ {}
     }
-    alt 5u {
+    alt check 5u {
       1u { fail "should match non-first range"; }
       2u to 6u {}
     }
diff --git a/src/test/run-pass/alt-str.rs b/src/test/run-pass/alt-str.rs
index 6b7a3e6c279..c0a096cc2c9 100644
--- a/src/test/run-pass/alt-str.rs
+++ b/src/test/run-pass/alt-str.rs
@@ -1,7 +1,7 @@
 // Issue #53
 
 fn main() {
-    alt "test" { "not-test" { fail; } "test" { } _ { fail; } }
+    alt check "test" { "not-test" { fail; } "test" { } _ { fail; } }
 
     enum t { tag1(str), tag2, }
 
@@ -13,9 +13,9 @@ fn main() {
       _ { fail; }
     }
 
-    let x = alt "a" { "a" { 1 } "b" { 2 } };
+    let x = alt check "a" { "a" { 1 } "b" { 2 } };
     assert (x == 1);
 
-    alt "a" { "a" { } "b" { } }
+    alt check "a" { "a" { } "b" { } }
 
 }
diff --git a/src/test/run-pass/binary-minus-without-space.rs b/src/test/run-pass/binary-minus-without-space.rs
index cb31faacc3c..79627d5501d 100644
--- a/src/test/run-pass/binary-minus-without-space.rs
+++ b/src/test/run-pass/binary-minus-without-space.rs
@@ -1,6 +1,6 @@
 // Check that issue #954 stays fixed
 
 fn main() {
-    alt -1 { -1 {} }
+    alt check -1 { -1 {} }
     assert 1-1 == 0;
 }
diff --git a/src/test/run-pass/expr-alt-box.rs b/src/test/run-pass/expr-alt-box.rs
index 84c9e424f46..93a65d62977 100644
--- a/src/test/run-pass/expr-alt-box.rs
+++ b/src/test/run-pass/expr-alt-box.rs
@@ -4,10 +4,13 @@
 // -*- rust -*-
 
 // Tests for alt as expressions resulting in boxed types
-fn test_box() { let res = alt true { true { @100 } }; assert (*res == 100); }
+fn test_box() {
+    let res = alt check true { true { @100 } };
+    assert (*res == 100);
+}
 
 fn test_str() {
-    let res = alt true { true { "happy" } };
+    let res = alt check true { true { "happy" } };
     assert (res == "happy");
 }
 
diff --git a/src/test/run-pass/expr-alt-generic-box1.rs b/src/test/run-pass/expr-alt-generic-box1.rs
index 98f3b86aec9..bdaa676954b 100644
--- a/src/test/run-pass/expr-alt-generic-box1.rs
+++ b/src/test/run-pass/expr-alt-generic-box1.rs
@@ -5,7 +5,7 @@
 type compare<T> = fn@(@T, @T) -> bool;
 
 fn test_generic<T>(expected: @T, eq: compare<T>) {
-    let actual: @T = alt true { true { expected } };
+    let actual: @T = alt check true { true { expected } };
     assert (eq(expected, actual));
 }
 
diff --git a/src/test/run-pass/expr-alt-generic-box2.rs b/src/test/run-pass/expr-alt-generic-box2.rs
index b4a40c51361..de1143464c8 100644
--- a/src/test/run-pass/expr-alt-generic-box2.rs
+++ b/src/test/run-pass/expr-alt-generic-box2.rs
@@ -5,7 +5,7 @@
 type compare<T> = fn@(T, T) -> bool;
 
 fn test_generic<T: copy>(expected: T, eq: compare<T>) {
-    let actual: T = alt true { true { expected } };
+    let actual: T = alt check true { true { expected } };
     assert (eq(expected, actual));
 }
 
diff --git a/src/test/run-pass/expr-alt-generic-unique1.rs b/src/test/run-pass/expr-alt-generic-unique1.rs
index 2b8b9f53946..55e33263776 100644
--- a/src/test/run-pass/expr-alt-generic-unique1.rs
+++ b/src/test/run-pass/expr-alt-generic-unique1.rs
@@ -4,7 +4,7 @@
 type compare<T> = fn@(~T, ~T) -> bool;
 
 fn test_generic<T: copy>(expected: ~T, eq: compare<T>) {
-    let actual: ~T = alt true { true { expected } };
+    let actual: ~T = alt check true { true { expected } };
     assert (eq(expected, actual));
 }
 
diff --git a/src/test/run-pass/expr-alt-generic-unique2.rs b/src/test/run-pass/expr-alt-generic-unique2.rs
index 0a0dd1dd8d5..9dc580ed3b0 100644
--- a/src/test/run-pass/expr-alt-generic-unique2.rs
+++ b/src/test/run-pass/expr-alt-generic-unique2.rs
@@ -5,7 +5,7 @@
 type compare<T> = fn@(T, T) -> bool;
 
 fn test_generic<T: copy>(expected: T, eq: compare<T>) {
-    let actual: T = alt true { true { expected } };
+    let actual: T = alt check true { true { expected } };
     assert (eq(expected, actual));
 }
 
diff --git a/src/test/run-pass/expr-alt-generic.rs b/src/test/run-pass/expr-alt-generic.rs
index 13da160c73c..84324a00db7 100644
--- a/src/test/run-pass/expr-alt-generic.rs
+++ b/src/test/run-pass/expr-alt-generic.rs
@@ -5,7 +5,7 @@
 type compare<T> = fn@(T, T) -> bool;
 
 fn test_generic<T: copy>(expected: T, eq: compare<T>) {
-    let actual: T = alt true { true { expected } };
+    let actual: T = alt check true { true { expected } };
     assert (eq(expected, actual));
 }
 
diff --git a/src/test/run-pass/expr-alt-struct.rs b/src/test/run-pass/expr-alt-struct.rs
index def9b607afe..52ec91884f6 100644
--- a/src/test/run-pass/expr-alt-struct.rs
+++ b/src/test/run-pass/expr-alt-struct.rs
@@ -5,7 +5,7 @@
 
 // Tests for alt as expressions resulting in structural types
 fn test_rec() {
-    let rs = alt true { true { {i: 100} } };
+    let rs = alt check true { true { {i: 100} } };
     assert (rs == {i: 100});
 }
 
diff --git a/src/test/run-pass/expr-alt-unique.rs b/src/test/run-pass/expr-alt-unique.rs
index f83dae4e9fa..e3a55892955 100644
--- a/src/test/run-pass/expr-alt-unique.rs
+++ b/src/test/run-pass/expr-alt-unique.rs
@@ -4,6 +4,9 @@
 // -*- rust -*-
 
 // Tests for alt as expressions resulting in boxed types
-fn test_box() { let res = alt true { true { ~100 } }; assert (*res == 100); }
+fn test_box() {
+    let res = alt check true { true { ~100 } };
+    assert (*res == 100);
+}
 
 fn main() { test_box(); }
diff --git a/src/test/run-pass/unreachable-code.rs b/src/test/run-pass/unreachable-code.rs
index 2570e598b08..d5f896d36d3 100644
--- a/src/test/run-pass/unreachable-code.rs
+++ b/src/test/run-pass/unreachable-code.rs
@@ -30,7 +30,7 @@ fn log_cont() { do { log(error, cont); } while false }
 fn ret_ret() -> int { ret (ret 2) + 3; }
 
 fn ret_guard() {
-    alt 2 {
+    alt check 2 {
       x if (ret) { x; }
     }
 }