rust/src/test/compile-fail/non-exhaustive-match.rs

39 lines
1.1 KiB
Rust
Raw Normal View History

// 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.
enum t { a, b, }
fn main() {
let x = a;
2012-08-06 14:34:08 -05:00
match x { b => { } } //~ ERROR non-exhaustive patterns
match true { //~ ERROR non-exhaustive patterns
2012-08-03 21:59:04 -05:00
true => {}
}
2012-08-20 14:23:37 -05:00
match @Some(10) { //~ ERROR non-exhaustive patterns
@None => {}
}
2012-08-06 14:34:08 -05:00
match (2, 3, 4) { //~ ERROR non-exhaustive patterns
2012-08-03 21:59:04 -05:00
(_, _, 4) => {}
}
2012-08-06 14:34:08 -05:00
match (a, a) { //~ ERROR non-exhaustive patterns
2012-08-03 21:59:04 -05:00
(a, b) => {}
(b, a) => {}
}
2012-08-06 14:34:08 -05:00
match a { //~ ERROR b not covered
2012-08-03 21:59:04 -05:00
a => {}
}
// This is exhaustive, though the algorithm got it wrong at one point
2012-08-06 14:34:08 -05:00
match (a, b) {
2012-08-03 21:59:04 -05:00
(a, _) => {}
(_, a) => {}
(b, b) => {}
}
}