RS.CLIPPY.STRING_LIT_CHARS_ANY

Checks for `<string_lit>.chars().any(|i| i == c)`

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

What it does

Checks for <string_lit>.chars().any(|i| i == c).

Why is this bad?

It's significantly slower than using a pattern instead, like matches!(c, \'\\\\\' | \'.\' | \'+\').

Despite this being faster, this is not perf as this is pretty common, and is a rather nice way to check if a char is any in a set. In any case, this restriction lint is available for situations where that additional performance is absolutely necessary.

Example

"\\\\.+*?()|[]{}^$#&-~".chars().any(|x| x == c);

Use instead:

matches!(c, \'\\\\\' | \'.\' | \'+\' | \'*\' | \'(\' | \')\' | \'|\' | \'[\' | \']\' | \'{\' | \'}\' | \'^\' | \'$\' | \'#\' | \'&\' | \'-\' | \'~\');