Skip to content

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

@jakubdabek

Description

@jakubdabek

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

Metadata

Metadata

Assignees

Labels

A-lintArea: New lintsC-enhancementCategory: Enhancement of lints, like adding more cases or adding help messagesgood first issueThese issues are a good way to get started with Clippy

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions