]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/tests/ui/single_match_else.rs
Merge branch 'master' into hooks
[rust.git] / src / tools / clippy / tests / ui / single_match_else.rs
1 #![warn(clippy::single_match_else)]
2 #![allow(clippy::needless_return)]
3 #![allow(clippy::no_effect)]
4
5 enum ExprNode {
6     ExprAddrOf,
7     Butterflies,
8     Unicorns,
9 }
10
11 static NODE: ExprNode = ExprNode::Unicorns;
12
13 fn unwrap_addr() -> Option<&'static ExprNode> {
14     match ExprNode::Butterflies {
15         ExprNode::ExprAddrOf => Some(&NODE),
16         _ => {
17             let x = 5;
18             None
19         },
20     }
21 }
22
23 macro_rules! unwrap_addr {
24     ($expression:expr) => {
25         match $expression {
26             ExprNode::ExprAddrOf => Some(&NODE),
27             _ => {
28                 let x = 5;
29                 None
30             },
31         }
32     };
33 }
34
35 #[rustfmt::skip]
36 fn main() {
37     unwrap_addr!(ExprNode::Unicorns);
38
39     //
40     // don't lint single exprs/statements
41     //
42
43     // don't lint here
44     match Some(1) {
45         Some(a) => println!("${:?}", a),
46         None => return,
47     }
48
49     // don't lint here
50     match Some(1) {
51         Some(a) => println!("${:?}", a),
52         None => {
53             return
54         },
55     }
56
57     // don't lint here
58     match Some(1) {
59         Some(a) => println!("${:?}", a),
60         None => {
61             return;
62         },
63     }
64
65     //
66     // lint multiple exprs/statements "else" blocks
67     //
68
69     // lint here
70     match Some(1) {
71         Some(a) => println!("${:?}", a),
72         None => {
73             println!("else block");
74             return
75         },
76     }
77
78     // lint here
79     match Some(1) {
80         Some(a) => println!("${:?}", a),
81         None => {
82             println!("else block");
83             return;
84         },
85     }
86 }