RS.CLIPPY.CHARS_LAST_CMP

Using `.chars().last()` or `.chars().next_back()` to check if a string ends 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_last_cmp. Copyright ©2025 The Rust Team. All rights reserved.

What it does

Checks for usage of _.chars().last() or _.chars().next_back() on a str to check if it ends with a given char.

Why is this bad?

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

Example

name.chars().last() == Some(\'_\') || name.chars().next_back() == Some(\'-\');

Use instead:

name.ends_with(\'_\') || name.ends_with(\'-\');