2 #![warn(clippy::case_sensitive_file_extension_comparisons)]
4 use std::string::String;
9 fn ends_with(self, _arg: &str) {}
13 fn is_rust_file(filename: &str) -> bool {
14 std::path::Path::new(filename)
16 .map_or(false, |ext| ext.eq_ignore_ascii_case("rs"))
20 // std::string::String and &str should trigger the lint failure with .ext12
21 let _ = std::path::Path::new(&String::new())
23 .map_or(false, |ext| ext.eq_ignore_ascii_case("ext12"));
24 let _ = std::path::Path::new("str")
26 .map_or(false, |ext| ext.eq_ignore_ascii_case("ext12"));
28 // The fixup should preserve the indentation level
30 let _ = std::path::Path::new("str")
32 .map_or(false, |ext| ext.eq_ignore_ascii_case("ext12"));
35 // The test struct should not trigger the lint failure with .ext12
36 TestStruct {}.ends_with(".ext12");
38 // std::string::String and &str should trigger the lint failure with .EXT12
39 let _ = std::path::Path::new(&String::new())
41 .map_or(false, |ext| ext.eq_ignore_ascii_case("EXT12"));
42 let _ = std::path::Path::new("str")
44 .map_or(false, |ext| ext.eq_ignore_ascii_case("EXT12"));
46 // Should not trigger the lint failure because of the calls to to_lowercase and to_uppercase
47 let _ = String::new().to_lowercase().ends_with(".EXT12");
48 let _ = String::new().to_uppercase().ends_with(".EXT12");
50 // The test struct should not trigger the lint failure with .EXT12
51 TestStruct {}.ends_with(".EXT12");
53 // Should not trigger the lint failure with .eXT12
54 let _ = String::new().ends_with(".eXT12");
55 let _ = "str".ends_with(".eXT12");
56 TestStruct {}.ends_with(".eXT12");
58 // Should not trigger the lint failure with .EXT123 (too long)
59 let _ = String::new().ends_with(".EXT123");
60 let _ = "str".ends_with(".EXT123");
61 TestStruct {}.ends_with(".EXT123");
63 // Shouldn't fail if it doesn't start with a dot
64 let _ = String::new().ends_with("a.ext");
65 let _ = "str".ends_with("a.extA");
66 TestStruct {}.ends_with("a.ext");