RS.CLIPPY.MANUAL_PATTERN_CHAR_COMPARISON

Manual char comparison in string patterns

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

What it does

Checks for manual char comparison in string patterns

Why is this bad?

This can be written more concisely using a char or an array of char. This is more readable and more optimized when comparing to only one char.

Example

"Hello World!".trim_end_matches(|c| c == \'.\' || c == \',\' || c == \'!\' || c == \'?\');

Use instead:

"Hello World!".trim_end_matches([\'.\', \',\', \'!\', \'?\']);

Configuration

  • msrv: The minimum rust version that the project supports. Defaults to the rust-version field in Cargo.toml

    (default: current version)