Skip to content

single_char_pattern suggests using char instead of str for starts_with #11675

@david-monroe

Description

@david-monroe

Summary

warning: single-character string constant used as pattern
   --> src/core/data/mod.rs:314:31
    |
314 |         if string.starts_with("[") {
    |                               ^^^ help: try using a `char` instead: `'['`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#single_char_pattern
    = note: `#[warn(clippy::single_char_pattern)]` on by default

and then

Why is this bad?

Performing these methods using a char is faster than using a str.

But the opposite is true for starts_with.

Lint Name

single_char_pattern

Reproducer

No response

Version

rustc 1.73.0 (cc66ad468 2023-10-03)
binary: rustc
commit-hash: cc66ad468955717ab92600c770da8c1601a4ff33
commit-date: 2023-10-03
host: x86_64-unknown-linux-gnu
release: 1.73.0
LLVM version: 17.0.2

Additional Labels

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't have

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions