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