Skip to content

clippy::useless_format ignores format!("") #7796

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
klensy opened this issue Oct 9, 2021 · 3 comments · Fixed by #7801
Closed

clippy::useless_format ignores format!("") #7796

klensy opened this issue Oct 9, 2021 · 3 comments · Fixed by #7801
Assignees
Labels
C-bug Category: Clippy is not doing the correct thing I-false-negative Issue: The lint should have been triggered on code, but wasn't

Comments

@klensy
Copy link
Contributor

klensy commented Oct 9, 2021

Lint name: clippy::useless_format

I tried this code:

pub fn foo()->String{
    format!("")
}

I expected to see this happen:
Warning from clippy about useless format! call, similar to:

warning: useless use of `format!`
 --> src/main.rs:6:5
  |
6 |     format!("")
  |     ^^^^^^^^^^^ help: consider using `.to_string()`: `"".to_string()`

Instead, this happened:
No warning.

Meta

Rust version (rustc -Vv):

rustc 1.57.0-nightly (54bb4fec6 2021-10-08)
binary: rustc
commit-hash: 54bb4fec68cb592e23077896baea072919721573
commit-date: 2021-10-08
host: x86_64-pc-windows-msvc
release: 1.57.0-nightly
LLVM version: 13.0.0
@klensy klensy added C-bug Category: Clippy is not doing the correct thing I-false-negative Issue: The lint should have been triggered on code, but wasn't labels Oct 9, 2021
@Kixunil
Copy link

Kixunil commented Oct 9, 2021

Maybe String::new() is even nicer?

@klensy
Copy link
Contributor Author

klensy commented Oct 9, 2021

Example shows how warning looks now, so it's simpler(?) to fix. Bonus points to String::new() :-)

@aDotInTheVoid
Copy link
Member

@rustbot claim

aDotInTheVoid added a commit to aDotInTheVoid/rust-clippy that referenced this issue Oct 11, 2021
aDotInTheVoid added a commit to aDotInTheVoid/rust-clippy that referenced this issue Oct 11, 2021
aDotInTheVoid added a commit to aDotInTheVoid/rust-clippy that referenced this issue Oct 21, 2021
aDotInTheVoid added a commit to aDotInTheVoid/rust-clippy that referenced this issue Oct 21, 2021
bors added a commit that referenced this issue Oct 21, 2021
Make useless_format recognize format!("")

Closes #7796

changelog: [`useless_format`] Fix for false negitive for `format!("")`
@bors bors closed this as completed in 081d0f8 Oct 21, 2021
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-false-negative Issue: The lint should have been triggered on code, but wasn't
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants