]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/src/docs/uninlined_format_args.txt
Rollup merge of #102072 - scottmcm:ptr-alignment-type, r=thomcc
[rust.git] / src / tools / clippy / src / docs / uninlined_format_args.txt
1 ### What it does
2 Detect when a variable is not inlined in a format string,
3 and suggests to inline it.
4
5 ### Why is this bad?
6 Non-inlined code is slightly more difficult to read and understand,
7 as it requires arguments to be matched against the format string.
8 The inlined syntax, where allowed, is simpler.
9
10 ### Example
11 ```
12 format!("{}", var);
13 format!("{v:?}", v = var);
14 format!("{0} {0}", var);
15 format!("{0:1$}", var, width);
16 format!("{:.*}", prec, var);
17 ```
18 Use instead:
19 ```
20 format!("{var}");
21 format!("{var:?}");
22 format!("{var} {var}");
23 format!("{var:width$}");
24 format!("{var:.prec$}");
25 ```
26
27 ### Known Problems
28
29 There may be a false positive if the format string is expanded from certain proc macros:
30
31 ```
32 println!(indoc!("{}"), var);
33 ```
34
35 If a format string contains a numbered argument that cannot be inlined
36 nothing will be suggested, e.g. `println!("{0}={1}", var, 1+2)`.