Skip to content
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

useless_format does not play well with format arg capture #8290

Closed
matthiaskrgr opened this issue Jan 15, 2022 · 0 comments · Fixed by #8295
Closed

useless_format does not play well with format arg capture #8290

matthiaskrgr opened this issue Jan 15, 2022 · 0 comments · Fixed by #8295
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 P-high Priority: High

Comments

@matthiaskrgr
Copy link
Member

Summary

Clippy does not yet understand fully understand format!("{x}"); yet.
This probably needs to be a msrvlint.

Reproducer

I tried this code:

fn main() {
    let x = "hello";
    let _string = format!("{x}");
}

I expected to see this happen:
Clippy should suggest something like x.to_string() but instead suggests {x}.to_string()

Instead, this happened:

warning: useless use of `format!`
 --> src/main.rs:3:19
  |
3 |     let _string = format!("{x}");
  |                   ^^^^^^^^^^^^^^ help: consider using `.to_string()`: `{x}.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

Version

`clippy 0.1.60 (38c22af 2022-01-15)`

Additional Labels

No response

@matthiaskrgr matthiaskrgr added 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 P-high Priority: High I-nominated Issue: Nominated to be discussed at the next Clippy meeting labels Jan 15, 2022
@bors bors closed this as completed in 0d27bd8 Jan 16, 2022
@flip1995 flip1995 removed the I-nominated Issue: Nominated to be discussed at the next Clippy meeting label Feb 8, 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 P-high Priority: High
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants