about summary refs log tree commit diff
path: root/src/tools/clippy/tests/ui/format_collect.rs
blob: c7f2b7b695074f4be38ddce6b6ab09ec5a5c26e3 (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
#![allow(unused, dead_code)]
#![warn(clippy::format_collect)]

fn hex_encode(bytes: &[u8]) -> String {
    bytes.iter().map(|b| format!("{b:02X}")).collect()
}

#[rustfmt::skip]
fn hex_encode_deep(bytes: &[u8]) -> String {
    bytes.iter().map(|b| {{{{{ format!("{b:02X}") }}}}}).collect()
}

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)
        .map(|s| {
            let y = 1;
            format!("{s} {y}")
        })
        .collect()
}
fn main() {}