rust/tests/ui/match/guards.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

21 lines
491 B
Rust
Raw Normal View History

//@ run-pass
#![allow(non_shorthand_field_patterns)]
2015-03-30 13:38:27 +00:00
#[derive(Copy, Clone)]
struct Pair { x: isize, y: isize }
pub fn main() {
let a: isize =
2015-01-25 21:05:03 +00:00
match 10 { x if x < 7 => { 1 } x if x < 11 => { 2 } 10 => { 3 } _ => { 4 } };
assert_eq!(a, 2);
let b: isize =
match (Pair {x: 10, y: 20}) {
2015-01-25 21:05:03 +00:00
x if x.x < 5 && x.y < 5 => { 1 }
Pair {x: x, y: y} if x == 10 && y == 20 => { 2 }
Pair {x: _x, y: _y} => { 3 }
2011-09-02 22:34:58 +00:00
};
assert_eq!(b, 2);
}