]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/mir_build_match_comparisons.rs
Changed issue number to 36105
[rust.git] / src / test / run-pass / mir_build_match_comparisons.rs
1 // Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 #![feature(rustc_attrs)]
12
13 #[rustc_mir]
14 fn test1(x: i8) -> i32 {
15   match x {
16     1...10 => 0,
17     _ => 1,
18   }
19 }
20
21 const U: Option<i8> = Some(10);
22 const S: &'static str = "hello";
23
24 #[rustc_mir]
25 fn test2(x: i8) -> i32 {
26   match Some(x) {
27     U => 0,
28     _ => 1,
29   }
30 }
31
32 #[rustc_mir]
33 fn test3(x: &'static str) -> i32 {
34   match x {
35     S => 0,
36     _ => 1,
37   }
38 }
39
40 enum Opt<T> {
41     Some { v: T },
42     None
43 }
44
45 #[rustc_mir]
46 fn test4(x: u64) -> i32 {
47   let opt = Opt::Some{ v: x };
48   match opt {
49     Opt::Some { v: 10 } => 0,
50     _ => 1,
51   }
52 }
53
54
55 fn main() {
56   assert_eq!(test1(0), 1);
57   assert_eq!(test1(1), 0);
58   assert_eq!(test1(2), 0);
59   assert_eq!(test1(5), 0);
60   assert_eq!(test1(9), 0);
61   assert_eq!(test1(10), 0);
62   assert_eq!(test1(11), 1);
63   assert_eq!(test1(20), 1);
64   assert_eq!(test2(10), 0);
65   assert_eq!(test2(0), 1);
66   assert_eq!(test2(20), 1);
67   assert_eq!(test3("hello"), 0);
68   assert_eq!(test3(""), 1);
69   assert_eq!(test3("world"), 1);
70   assert_eq!(test4(10), 0);
71   assert_eq!(test4(0), 1);
72   assert_eq!(test4(20), 1);
73 }