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