RS.CLIPPY.CHARS_NEXT_CMP

Using `.chars().next()` to check if a string starts with a char

This checker is a Clippy lint created by The Rust Project Contributors. The documentation shown here is a copy of the original documentation for: chars_next_cmp. Copyright ©2025 The Rust Team. All rights reserved.

What it does

Checks for usage of .chars().next() on a str to check if it starts with a given char.

Why is this bad?

Readability, this can be written more concisely as _.starts_with(_).

Example

let name = "foo";
if name.chars().next() == Some(\'_\') {};

Use instead:

let name = "foo";
if name.starts_with(\'_\') {};