Closed
Description
Summary
Fun with off-by-ones.
cc @compiler-errors didn't you just fix something similar to this in rustc or am I imagining things
Reproducer
I tried this code:
fn main() {
let variable = "string";
let _ = format!("{variable}");
let abc = "abc";
let _ = format!("{abc}");
let x = "x";
let _ = format!("{x}");
let xx = "xx";
let _ = format!("{xx}");
}
I expected to see this happen:
warning: useless use of `format!`
--> src\main.rs:3:13
|
3 | let _ = format!("{variable}");
| ^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `variable.to_string()`
|
= note: `#[warn(clippy::useless_format)]` on by default
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#useless_format
warning: useless use of `format!`
--> src\main.rs:6:13
|
6 | let _ = format!("{abc}");
| ^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `abc.to_string()`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#useless_format
warning: useless use of `format!`
--> src\main.rs:9:13
|
9 | let _ = format!("{x}");
| ^^^^^^^^^^^^^^ help: consider using `.to_string()`: `x.to_string()`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#useless_format
warning: useless use of `format!`
--> src\main.rs:9:13
|
12 | let _ = format!("{xx}");
| ^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `xx.to_string()`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#useless_format
Instead, this happened:
warning: useless use of `format!`
--> src\main.rs:3:13
|
3 | let _ = format!("{variable}");
| ^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `ariabl.to_string()`
|
= note: `#[warn(clippy::useless_format)]` on by default
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#useless_format
warning: useless use of `format!`
--> src\main.rs:6:13
|
6 | let _ = format!("{abc}");
| ^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `b.to_string()`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#useless_format
warning: useless use of `format!`
--> src\main.rs:9:13
|
9 | let _ = format!("{x}");
| ^^^^^^^^^^^^^^ help: consider using `.to_string()`: `x.to_string()`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#useless_format
warning: useless use of `format!`
--> src\main.rs:9:13
|
12 | let _ = format!("{xx}");
| ^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `.to_string()`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#useless_format
Note the suggestions: they've mangled the name of the bindings by slicing off the first and last character.
Version
rustc 1.64.0-nightly (f8588549c 2022-07-18)
binary: rustc
commit-hash: f8588549c3c3d45c32b404210cada01e2a45def3
commit-date: 2022-07-18
host: x86_64-pc-windows-msvc
release: 1.64.0-nightly
LLVM version: 14.0.6
Additional Labels
@rustbot label +I-suggestion-causes-error