summaryrefslogtreecommitdiffstats
path: root/src/tools/clippy/tests/ui/format_collect.rs
blob: 26ebdc6c0cb6182e81392ad12aefd55e4228a29a (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
#![allow(unused, dead_code)]
#![warn(clippy::format_collect)]

fn hex_encode(bytes: &[u8]) -> String {
    bytes.iter().map(|b| format!("{b:02X}")).collect()
    //~^ ERROR: use of `format!` to build up a string from an iterator
}

#[rustfmt::skip]
fn hex_encode_deep(bytes: &[u8]) -> String {
    bytes.iter().map(|b| {{{{{ format!("{b:02X}") }}}}}).collect()
    //~^ ERROR: use of `format!` to build up a string from an iterator
}

macro_rules! fmt {
    ($x:ident) => {
        format!("{x:02X}", x = $x)
    };
}

fn from_macro(bytes: &[u8]) -> String {
    bytes.iter().map(|x| fmt!(x)).collect()
}

fn with_block() -> String {
    (1..10)
        //~^ ERROR: use of `format!` to build up a string from an iterator
        .map(|s| {
            let y = 1;
            format!("{s} {y}")
        })
        .collect()
}
fn main() {}