]> git.proxmox.com Git - rustc.git/blame - src/tools/clippy/src/docs/case_sensitive_file_extension_comparisons.txt
New upstream version 1.66.0+dfsg1
[rustc.git] / src / tools / clippy / src / docs / case_sensitive_file_extension_comparisons.txt
CommitLineData
f2b60f7d
FG
1### What it does
2Checks for calls to `ends_with` with possible file extensions
3and suggests to use a case-insensitive approach instead.
4
5### Why is this bad?
6`ends_with` is case-sensitive and may not detect files with a valid extension.
7
8### Example
9```
10fn is_rust_file(filename: &str) -> bool {
11 filename.ends_with(".rs")
12}
13```
14Use instead:
15```
16fn is_rust_file(filename: &str) -> bool {
17 let filename = std::path::Path::new(filename);
18 filename.extension()
19 .map_or(false, |ext| ext.eq_ignore_ascii_case("rs"))
20}
21```