summary refs log tree commit diff
path: root/src/tools/clippy/tests/ui/match_single_binding2.fixed
blob: e73a85b73d7c67b3a74882b04a1cc66d32c88848 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// run-rustfix

#![warn(clippy::match_single_binding)]
#![allow(unused_variables)]

fn main() {
    // Lint (additional curly braces needed, see #6572)
    struct AppendIter<I>
    where
        I: Iterator,
    {
        inner: Option<(I, <I as Iterator>::Item)>,
    }

    #[allow(dead_code)]
    fn size_hint<I: Iterator>(iter: &AppendIter<I>) -> (usize, Option<usize>) {
        match &iter.inner {
            Some((iter, _item)) => {
                let (min, max) = iter.size_hint();
                (min.saturating_add(1), max.and_then(|max| max.checked_add(1)))
            },
            None => (0, Some(0)),
        }
    }

    // Lint (no additional curly braces needed)
    let opt = Some((5, 2));
    let get_tup = || -> (i32, i32) { (1, 2) };
    match opt {
        #[rustfmt::skip]
        Some((first, _second)) => {
            let (a, b) = get_tup();
            println!("a {:?} and b {:?}", a, b);
        },
        None => println!("nothing"),
    }
}