]> git.lizzy.rs Git - rust.git/blob - tests/ui/single_match.rs
Split up some single_match UI tests
[rust.git] / tests / ui / single_match.rs
1 #![warn(single_match)]
2
3 fn dummy() {
4 }
5
6 fn single_match(){
7     let x = Some(1u8);
8
9     match x {
10         Some(y) => { println!("{:?}", y); }
11         _ => ()
12     };
13
14     let z = (1u8,1u8);
15     match z {
16         (2...3, 7...9) => dummy(),
17         _ => {}
18     };
19
20     // Not linted (pattern guards used)
21     match x {
22         Some(y) if y == 0 => println!("{:?}", y),
23         _ => ()
24     }
25
26     // Not linted (no block with statements in the single arm)
27     match z {
28         (2...3, 7...9) => println!("{:?}", z),
29         _ => println!("nope"),
30     }
31 }
32
33 enum Foo { Bar, Baz(u8) }
34 use Foo::*;
35 use std::borrow::Cow;
36
37 fn single_match_know_enum() {
38     let x = Some(1u8);
39     let y : Result<_, i8> = Ok(1i8);
40
41     match x {
42         Some(y) => dummy(),
43         None => ()
44     };
45
46     match y {
47         Ok(y) => dummy(),
48         Err(..) => ()
49     };
50
51     let c = Cow::Borrowed("");
52
53     match c {
54         Cow::Borrowed(..) => dummy(),
55         Cow::Owned(..) => (),
56     };
57
58     let z = Foo::Bar;
59     // no warning
60     match z {
61         Bar => println!("42"),
62         Baz(_) => (),
63     }
64
65     match z {
66         Baz(_) => println!("42"),
67         Bar => (),
68     }
69 }
70
71 fn main() { }