Skip to content

clippy::useless_format slices {name} to am.to_string() #9234

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
CAD97 opened this issue Jul 24, 2022 · 0 comments · Fixed by #9237
Closed

clippy::useless_format slices {name} to am.to_string() #9234

CAD97 opened this issue Jul 24, 2022 · 0 comments · Fixed by #9237
Assignees
Labels
C-bug Category: Clippy is not doing the correct thing I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied

Comments

@CAD97
Copy link
Contributor

CAD97 commented Jul 24, 2022

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

@CAD97 CAD97 added the C-bug Category: Clippy is not doing the correct thing label Jul 24, 2022
@rustbot rustbot added the I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied label Jul 24, 2022
@Alexendoo Alexendoo self-assigned this Jul 24, 2022
@bors bors closed this as completed in 20e4204 Jul 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants