about summary refs log tree commit diff
path: root/src/docs/uninlined_format_args.txt
diff options
context:
space:
mode:
authorPhilipp Krones <hello@philkrones.com>2022-10-06 09:44:38 +0200
committerPhilipp Krones <hello@philkrones.com>2022-10-06 09:44:38 +0200
commitd75b25faabdcf0a22fe37928917c4ab1761fa265 (patch)
treee8c46d2dae51a0a61a6d28de138ca9add8276d8d /src/docs/uninlined_format_args.txt
parentda16cc1da9814710e637ff242b71768a4d3724b7 (diff)
downloadrust-d75b25faabdcf0a22fe37928917c4ab1761fa265.tar.gz
rust-d75b25faabdcf0a22fe37928917c4ab1761fa265.zip
Merge commit 'ac0e10aa68325235069a842f47499852b2dee79e' into clippyup
Diffstat (limited to 'src/docs/uninlined_format_args.txt')
-rw-r--r--src/docs/uninlined_format_args.txt36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/docs/uninlined_format_args.txt b/src/docs/uninlined_format_args.txt
new file mode 100644
index 00000000000..3d2966c84db
--- /dev/null
+++ b/src/docs/uninlined_format_args.txt
@@ -0,0 +1,36 @@
+### What it does
+Detect when a variable is not inlined in a format string,
+and suggests to inline it.
+
+### Why is this bad?
+Non-inlined code is slightly more difficult to read and understand,
+as it requires arguments to be matched against the format string.
+The inlined syntax, where allowed, is simpler.
+
+### Example
+```
+format!("{}", var);
+format!("{v:?}", v = var);
+format!("{0} {0}", var);
+format!("{0:1$}", var, width);
+format!("{:.*}", prec, var);
+```
+Use instead:
+```
+format!("{var}");
+format!("{var:?}");
+format!("{var} {var}");
+format!("{var:width$}");
+format!("{var:.prec$}");
+```
+
+### Known Problems
+
+There may be a false positive if the format string is expanded from certain proc macros:
+
+```
+println!(indoc!("{}"), var);
+```
+
+If a format string contains a numbered argument that cannot be inlined
+nothing will be suggested, e.g. `println!("{0}={1}", var, 1+2)`.
\ No newline at end of file