RS.CLIPPY.CASE_SENSITIVE_FILE_EXTENSION_COMPARISONS
Checks for calls to ends_with with case-sensitive file extensions
This checker is a Clippy lint created by The Rust Project Contributors. The documentation shown here is a copy of the original documentation for: case_sensitive_file_extension_comparisons. Copyright ©2025 The Rust Team. All rights reserved.
What it does
Checks for calls to ends_with with possible file extensions
and suggests to use a case-insensitive approach instead.
Why is this bad?
ends_with is case-sensitive and may not detect files with a valid extension.
Example
fn is_rust_file(filename: &str) -> bool {
filename.ends_with(".rs")
}
Use instead:
fn is_rust_file(filename: &str) -> bool {
let filename = std::path::Path::new(filename);
filename.extension()
.map_or(false, |ext| ext.eq_ignore_ascii_case("rs"))
}