Skip to content

Warn on push_str with a single-character string literal #5875

Closed
@camelid

Description

@camelid

What it does

Warns when using push_str with a single-character string literal, and push with a char would work fine.

Categories (optional)

  • Kind: clippy::style and clippy::perf (maybe clippy::pedantic?)

What is the advantage of the recommended code over the original code?

  • It's more obvious what's going on; after all, you're not trying to push a string, you're trying to push a character
  • It should be more performant and reduce binary size to push a char, since it's just a number and will be inlined, than to push a &'static str, which must be stored in the binary and accessed via a pointer

Drawbacks

None.

Example

let mut string = String::new();
string.push_str("R");

Could be written as:

let mut string = String::new();
string.push('R');

Metadata

Metadata

Assignees

No one assigned

    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