about summary refs log tree commit diff
path: root/src/test/compile-fail/refutable-pattern-errors.rs
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2014-06-21 02:11:22 +0000
committerbors <bors@rust-lang.org>2014-06-21 02:11:22 +0000
commitb1646cbfd908dc948b251e362669af421100647a (patch)
tree4ee04c45c4e5925fe948aa63f99e7ec3b5b47925 /src/test/compile-fail/refutable-pattern-errors.rs
parent2563481ca93877551116b11cde3cc7e21f1d6048 (diff)
parenta88819adbecabd9f26aec4423415044db4f66279 (diff)
downloadrust-b1646cbfd908dc948b251e362669af421100647a.tar.gz
rust-b1646cbfd908dc948b251e362669af421100647a.zip
auto merge of #14731 : jakub-/rust/pattern-matching-refactor, r=alexcrichton
This PR is changing the error messages for non-exhaustive pattern matching to include a more accurate witness, i.e. a pattern that is not covered by any of the ones provided by the user. Example:

```rust
fn main() {
	match (true, (Some("foo"), [true, true]), Some(42u)) {
		(false, _, _) => (),
		(true, (None, [true, _]), None) => (),
		(true, (None, [false, _]), Some(1u)) => ()
	}
}
```

```sh
/tmp/witness.rs:2:2: 6:3 error: non-exhaustive patterns: (true, (core::option::Some(_), _), _) not covered
/tmp/witness.rs:2 	match (true, (Some("foo"), [true, true]), Some(42u)) {
/tmp/witness.rs:3 		(false, _, _) => (),
/tmp/witness.rs:4 		(true, (None, [true, _]), None) => (),
/tmp/witness.rs:5 		(true, (None, [false, _]), Some(1u)) => ()
/tmp/witness.rs:6 	}
```

As part of that, I refactored some of the relevant code and carried over the changes to fixed vectors from the previous PR.

I'm putting it out there for now but the tests will be red.
Diffstat (limited to 'src/test/compile-fail/refutable-pattern-errors.rs')
-rw-r--r--src/test/compile-fail/refutable-pattern-errors.rs18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/test/compile-fail/refutable-pattern-errors.rs b/src/test/compile-fail/refutable-pattern-errors.rs
new file mode 100644
index 00000000000..9128ee68e26
--- /dev/null
+++ b/src/test/compile-fail/refutable-pattern-errors.rs
@@ -0,0 +1,18 @@
+// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+
+fn func((1, (Some(1), 2..3)): (int, (Option<int>, int))) { }
+//~^ ERROR refutable pattern in function argument: `(_, _)` not covered
+
+fn main() {
+    let (1, (Some(1), 2..3)) = (1, (None, 2));
+    //~^ ERROR refutable pattern in local binding: `(_, _)` not covered
+}