]> git.lizzy.rs Git - rust.git/blob - src/docs/case_sensitive_file_extension_comparisons.txt
Auto merge of #9421 - xphoniex:fix-#9420, r=giraffate
[rust.git] / src / docs / case_sensitive_file_extension_comparisons.txt
1 ### What it does
2 Checks for calls to `ends_with` with possible file extensions
3 and 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 ```
10 fn is_rust_file(filename: &str) -> bool {
11     filename.ends_with(".rs")
12 }
13 ```
14 Use instead:
15 ```
16 fn 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 ```