2012-12-10 17:32:48 -08:00
|
|
|
// Copyright 2012 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.
|
|
|
|
|
2015-03-26 18:34:27 -07:00
|
|
|
#![feature(slice_patterns)]
|
|
|
|
|
2012-01-19 18:31:08 -08:00
|
|
|
enum t { a, b, }
|
2010-12-02 14:50:00 -08:00
|
|
|
|
2012-02-15 09:40:42 +01:00
|
|
|
fn main() {
|
2014-11-06 00:05:53 -08:00
|
|
|
let x = t::a;
|
|
|
|
match x { t::b => { } } //~ ERROR non-exhaustive patterns: `a` not covered
|
2014-06-19 20:55:12 +02:00
|
|
|
match true { //~ ERROR non-exhaustive patterns: `false` not covered
|
2012-08-03 19:59:04 -07:00
|
|
|
true => {}
|
2012-02-15 09:40:42 +01:00
|
|
|
}
|
2015-01-31 17:23:42 +01:00
|
|
|
match Some(10) { //~ ERROR non-exhaustive patterns: `Some(_)` not covered
|
2014-01-03 15:08:48 -08:00
|
|
|
None => {}
|
2012-02-15 09:40:42 +01:00
|
|
|
}
|
2015-01-31 17:23:42 +01:00
|
|
|
match (2, 3, 4) { //~ ERROR non-exhaustive patterns: `(_, _, _)` not covered
|
2012-08-03 19:59:04 -07:00
|
|
|
(_, _, 4) => {}
|
2012-02-15 09:40:42 +01:00
|
|
|
}
|
2014-11-06 00:05:53 -08:00
|
|
|
match (t::a, t::a) { //~ ERROR non-exhaustive patterns: `(a, a)` not covered
|
|
|
|
(t::a, t::b) => {}
|
|
|
|
(t::b, t::a) => {}
|
2012-04-24 11:13:25 +02:00
|
|
|
}
|
2014-11-06 00:05:53 -08:00
|
|
|
match t::a { //~ ERROR non-exhaustive patterns: `b` not covered
|
|
|
|
t::a => {}
|
2012-05-03 17:35:12 +02:00
|
|
|
}
|
2012-04-24 11:13:25 +02:00
|
|
|
// This is exhaustive, though the algorithm got it wrong at one point
|
2014-11-06 00:05:53 -08:00
|
|
|
match (t::a, t::b) {
|
|
|
|
(t::a, _) => {}
|
|
|
|
(_, t::a) => {}
|
|
|
|
(t::b, t::b) => {}
|
2012-04-24 11:13:25 +02:00
|
|
|
}
|
2015-01-31 17:23:42 +01:00
|
|
|
let vec = vec!(Some(42), None, Some(21));
|
2015-02-01 21:53:25 -05:00
|
|
|
let vec: &[Option<isize>] = &vec;
|
2016-03-11 12:54:59 +02:00
|
|
|
match *vec { //~ ERROR non-exhaustive patterns: `[]` not covered
|
|
|
|
[Some(..), None, ref tail..] => {}
|
|
|
|
[Some(..), Some(..), ref tail..] => {}
|
2012-12-08 20:22:43 +00:00
|
|
|
[None] => {}
|
|
|
|
}
|
2015-01-31 17:23:42 +01:00
|
|
|
let vec = vec!(1);
|
2015-02-01 21:53:25 -05:00
|
|
|
let vec: &[isize] = &vec;
|
2016-03-11 12:54:59 +02:00
|
|
|
match *vec {
|
|
|
|
[_, ref tail..] => (),
|
2012-12-08 20:22:43 +00:00
|
|
|
[] => ()
|
|
|
|
}
|
2014-06-27 12:30:25 -07:00
|
|
|
let vec = vec!(0.5f32);
|
2015-02-01 21:53:25 -05:00
|
|
|
let vec: &[f32] = &vec;
|
2016-03-11 12:54:59 +02:00
|
|
|
match *vec { //~ ERROR non-exhaustive patterns: `[_, _, _, _]` not covered
|
2012-12-08 20:22:43 +00:00
|
|
|
[0.1, 0.2, 0.3] => (),
|
|
|
|
[0.1, 0.2] => (),
|
|
|
|
[0.1] => (),
|
|
|
|
[] => ()
|
|
|
|
}
|
2015-01-31 17:23:42 +01:00
|
|
|
let vec = vec!(Some(42), None, Some(21));
|
2015-02-01 21:53:25 -05:00
|
|
|
let vec: &[Option<isize>] = &vec;
|
2016-03-11 12:54:59 +02:00
|
|
|
match *vec {
|
|
|
|
[Some(..), None, ref tail..] => {}
|
|
|
|
[Some(..), Some(..), ref tail..] => {}
|
|
|
|
[None, None, ref tail..] => {}
|
|
|
|
[None, Some(..), ref tail..] => {}
|
2012-12-08 20:22:43 +00:00
|
|
|
[Some(_)] => {}
|
|
|
|
[None] => {}
|
|
|
|
[] => {}
|
|
|
|
}
|
2012-02-15 09:40:42 +01:00
|
|
|
}
|