]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/tests/ui/match_single_binding2.rs
Rollup merge of #99474 - aDotInTheVoid:rustdoc-json-noinline-test-cleanup, r=CraftSpider
[rust.git] / src / tools / clippy / tests / ui / match_single_binding2.rs
1 // run-rustfix
2
3 #![warn(clippy::match_single_binding)]
4 #![allow(unused_variables)]
5
6 fn main() {
7     // Lint (additional curly braces needed, see #6572)
8     struct AppendIter<I>
9     where
10         I: Iterator,
11     {
12         inner: Option<(I, <I as Iterator>::Item)>,
13     }
14
15     #[allow(dead_code)]
16     fn size_hint<I: Iterator>(iter: &AppendIter<I>) -> (usize, Option<usize>) {
17         match &iter.inner {
18             Some((iter, _item)) => match iter.size_hint() {
19                 (min, max) => (min.saturating_add(1), max.and_then(|max| max.checked_add(1))),
20             },
21             None => (0, Some(0)),
22         }
23     }
24
25     // Lint (no additional curly braces needed)
26     let opt = Some((5, 2));
27     let get_tup = || -> (i32, i32) { (1, 2) };
28     match opt {
29         #[rustfmt::skip]
30         Some((first, _second)) => {
31             match get_tup() {
32                 (a, b) => println!("a {:?} and b {:?}", a, b),
33             }
34         },
35         None => println!("nothing"),
36     }
37
38     fn side_effects() {}
39
40     // Lint (scrutinee has side effects)
41     // issue #7094
42     match side_effects() {
43         _ => println!("Side effects"),
44     }
45
46     // Lint (scrutinee has side effects)
47     // issue #7094
48     let x = 1;
49     match match x {
50         0 => 1,
51         _ => 2,
52     } {
53         _ => println!("Single branch"),
54     }
55 }