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

New lint: adding a char to a String through to_string() #12775

Open
jakubdabek opened this issue May 7, 2024 · 2 comments
Open

New lint: adding a char to a String through to_string() #12775

jakubdabek opened this issue May 7, 2024 · 2 comments
Assignees
Labels
A-lint Area: New lints C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages good-first-issue These issues are a good way to get started with Clippy

Comments

@jakubdabek
Copy link

jakubdabek commented May 7, 2024

What it does

Warns when turning a char into a String before pushing it to another String.

Advantage

  • It's more clear that we're pushing only a single char
  • It doesn't allocate a new String

Drawbacks

No response

Example

let mut s = String::from("...");
let c = 'a';
// or: let c = &'a';
s.push_str(&c.to_string());
// or: s = s + &c.to_string();
// or: s += &c.to_string();

Could be written as:

let mut s = String::from("...");
let c = 'a';
s.push(c);
// or: s.push(*c); for the reference case
@jakubdabek jakubdabek added the A-lint Area: New lints label May 7, 2024
@J-ZhengLi
Copy link
Member

could be an extension of clippy::single_char_add_str, which is a lot easier

@J-ZhengLi J-ZhengLi added good-first-issue These issues are a good way to get started with Clippy C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages labels May 11, 2024
@belyakov-am
Copy link

@rustbot claim

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: New lints C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages good-first-issue These issues are a good way to get started with Clippy
Projects
None yet
Development

No branches or pull requests

3 participants