Skip to content

Commit 225ebff

Browse files
committed
better docs
1 parent c4b4b27 commit 225ebff

4 files changed

+20
-6
lines changed

clippy_lints/src/format_args.rs

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,14 +103,20 @@ declare_clippy_lint! {
103103
/// format!("{var:.prec$}");
104104
/// ```
105105
///
106-
/// ### Known Problems
107-
///
108-
/// There may be a false positive if the format string is expanded from certain proc macros:
109-
///
110-
/// ```ignore
111-
/// println!(indoc!("{}"), var);
106+
/// If allow-mixed-uninlined-format-args is set to false in clippy.toml,
107+
/// the following code will also trigger the lint:
108+
/// ```rust
109+
/// # let var = 42;
110+
/// format!("{} {}", var, 1+2);
111+
/// ```
112+
/// Use instead:
113+
/// ```rust
114+
/// # let var = 42;
115+
/// format!("{var} {}", 1+2);
112116
/// ```
113117
///
118+
/// ### Known Problems
119+
///
114120
/// If a format string contains a numbered argument that cannot be inlined
115121
/// nothing will be suggested, e.g. `println!("{0}={1}", var, 1+2)`.
116122
#[clippy::version = "1.65.0"]
@@ -308,6 +314,11 @@ fn check_uninlined_args(
308314
"variables can be used directly in the `format!` string",
309315
|diag| {
310316
diag.multipart_suggestion("change this to", fixes, Applicability::MachineApplicable);
317+
if ignore_mixed {
318+
// Improve lint config discoverability
319+
diag.note_once("this lint can also fix mixed format arg inlining if \
320+
`allow-mixed-uninlined-format-args = false` is set in the `clippy.toml` file");
321+
}
311322
},
312323
);
313324
}

tests/ui/uninlined_format_args.stderr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ error: variables can be used directly in the `format!` string
44
LL | println!("val='{}'", local_i32);
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
66
|
7+
= note: this lint can also fix mixed format arg inlining if `allow-mixed-uninlined-format-args = false` is set in the `clippy.toml` file
78
= note: `-D clippy::uninlined-format-args` implied by `-D warnings`
89
help: change this to
910
|

tests/ui/uninlined_format_args_panic.edition2018.stderr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ error: variables can be used directly in the `format!` string
44
LL | println!("val='{}'", var);
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^
66
|
7+
= note: this lint can also fix mixed format arg inlining if `allow-mixed-uninlined-format-args = false` is set in the `clippy.toml` file
78
= note: `-D clippy::uninlined-format-args` implied by `-D warnings`
89
help: change this to
910
|

tests/ui/uninlined_format_args_panic.edition2021.stderr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ error: variables can be used directly in the `format!` string
44
LL | println!("val='{}'", var);
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^
66
|
7+
= note: this lint can also fix mixed format arg inlining if `allow-mixed-uninlined-format-args = false` is set in the `clippy.toml` file
78
= note: `-D clippy::uninlined-format-args` implied by `-D warnings`
89
help: change this to
910
|

0 commit comments

Comments
 (0)