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