]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/src/docs/unnecessary_join.txt
Auto merge of #104673 - matthiaskrgr:rollup-85f65ov, r=matthiaskrgr
[rust.git] / src / tools / clippy / src / docs / unnecessary_join.txt
1 ### What it does
2 Checks for use of `.collect::<Vec<String>>().join("")` on iterators.
3
4 ### Why is this bad?
5 `.collect::<String>()` is more concise and might be more performant
6
7 ### Example
8 ```
9 let vector = vec!["hello",  "world"];
10 let output = vector.iter().map(|item| item.to_uppercase()).collect::<Vec<String>>().join("");
11 println!("{}", output);
12 ```
13 The correct use would be:
14 ```
15 let vector = vec!["hello",  "world"];
16 let output = vector.iter().map(|item| item.to_uppercase()).collect::<String>();
17 println!("{}", output);
18 ```
19 ### Known problems
20 While `.collect::<String>()` is sometimes more performant, there are cases where
21 using `.collect::<String>()` over `.collect::<Vec<String>>().join("")`
22 will prevent loop unrolling and will result in a negative performance impact.
23
24 Additionally, differences have been observed between aarch64 and x86_64 assembly output,
25 with aarch64 tending to producing faster assembly in more cases when using `.collect::<String>()`