RS.CLIPPY.SINGLE_CHAR_PATTERN

Using a single-character str where a char could be used, e.g., `_.split(\"x\")`

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

What it does

Checks for string methods that receive a single-character str as an argument, e.g., _.split("x").

Why is this bad?

While this can make a perf difference on some systems, benchmarks have proven inconclusive. But at least using a char literal makes it clear that we are looking at a single character.

Known problems

Does not catch multi-byte unicode characters. This is by design, on many machines, splitting by a non-ascii char is actually slower. Please do your own measurements instead of relying solely on the results of this lint.

Example

_.split("x");

Use instead:

_.split(\'x\');