]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/tests/ui/match_single_binding2.fixed
Rollup merge of #102581 - jyn514:src-detection, r=Mark-Simulacrum
[rust.git] / src / tools / clippy / tests / ui / match_single_binding2.fixed
1 // run-rustfix
2 #![warn(clippy::match_single_binding)]
3 #![allow(unused_variables)]
4 #![allow(clippy::uninlined_format_args)]
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)) => {
19                 let (min, max) = iter.size_hint();
20                 (min.saturating_add(1), max.and_then(|max| max.checked_add(1)))
21             },
22             None => (0, Some(0)),
23         }
24     }
25
26     // Lint (no additional curly braces needed)
27     let opt = Some((5, 2));
28     let get_tup = || -> (i32, i32) { (1, 2) };
29     match opt {
30         #[rustfmt::skip]
31         Some((first, _second)) => {
32             let (a, b) = get_tup();
33             println!("a {:?} and b {:?}", a, b);
34         },
35         None => println!("nothing"),
36     }
37
38     fn side_effects() {}
39
40     // Lint (scrutinee has side effects)
41     // issue #7094
42     side_effects();
43     println!("Side effects");
44
45     // Lint (scrutinee has side effects)
46     // issue #7094
47     let x = 1;
48     match x {
49         0 => 1,
50         _ => 2,
51     };
52     println!("Single branch");
53 }