-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Closed
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't haveIssue: The lint was triggered on code it shouldn't have
Description
Summary
This lint warns me on code which must be in the form of ("{}", x) and can't be in the form of ("{x}") - see code example below
Lint Name
uninlined_format_args
Reproducer
I tried this code:
fn foo() {
let e = "error";
panic!("something bad: {}", e);
}I saw this happen:
error: variables can be used directly in the `format!` string
--> deep/lunar_endpoints/src/bin/TabNine-deep-cloud.rs:101:5
|
101 | panic!("something bad: {}", e);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#uninlined_format_args
= note: `-D clippy::uninlined-format-args` implied by `-D clippy::pedantic`
help: change this to
|
101 - panic!("something bad: {}", e);
101 + panic!("something bad: {e}");
|
I expected to see this happen:
Nothing - the line shouldn't warn on this case, because if the code was as suggested by the lint:
fn foo() {
let e = "error";
panic!("something bad: {e}");
}The panic macro will not refer to it as a format string, but rather as a regular 'static str - and will print "something bad: {e}".
This happens because the panic macro knows to refer to the first argument as a format string only when the macro is being called with 2+ arguments.
Version
rustc 1.66.0-nightly (8b0c05d9a 2022-10-07)
binary: rustc
commit-hash: 8b0c05d9ad7121cdb97600f261bcd5f04c8db20d
commit-date: 2022-10-07
host: x86_64-unknown-linux-gnu
release: 1.66.0-nightly
LLVM version: 15.0.2
Additional Labels
No response
Metadata
Metadata
Assignees
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't haveIssue: The lint was triggered on code it shouldn't have