Skip to content

Commit eb300fd

Browse files
committed
Auto merge of #12293 - Ethiraric:fix-12252, r=y21
[`case_sensitive_file_extension_comparisons`]: Don't trigger on digits-only extensions If we find a file extension check with only digits (`.123`), do not trigger `case_sensitive_file_extension_comparisons`. Fixes #12252 --- *Please write a short comment explaining your change (or "none" for internal only changes)* changelog: [`case_sensitive_file_extension_comparisons`]: Don't trigger on digits-only extensions
2 parents 2c3213f + 9492de5 commit eb300fd

3 files changed

+11
-0
lines changed

clippy_lints/src/methods/case_sensitive_file_extension_comparisons.rs

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ pub(super) fn check<'tcx>(
3838
&& ext_str.starts_with('.')
3939
&& (ext_str.chars().skip(1).all(|c| c.is_uppercase() || c.is_ascii_digit())
4040
|| ext_str.chars().skip(1).all(|c| c.is_lowercase() || c.is_ascii_digit()))
41+
&& !ext_str.chars().skip(1).all(|c| c.is_ascii_digit())
4142
&& let recv_ty = cx.typeck_results().expr_ty(recv).peel_refs()
4243
&& (recv_ty.is_str() || is_type_lang_item(cx, recv_ty, LangItem::String))
4344
{

tests/ui/case_sensitive_file_extension_comparisons.fixed

+5
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,9 @@ fn main() {
6363
let _ = String::new().ends_with("a.ext");
6464
let _ = "str".ends_with("a.extA");
6565
TestStruct {}.ends_with("a.ext");
66+
67+
// Shouldn't fail if the extension has no ascii letter
68+
let _ = String::new().ends_with(".123");
69+
let _ = "str".ends_with(".123");
70+
TestStruct {}.ends_with(".123");
6671
}

tests/ui/case_sensitive_file_extension_comparisons.rs

+5
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,9 @@ fn main() {
5151
let _ = String::new().ends_with("a.ext");
5252
let _ = "str".ends_with("a.extA");
5353
TestStruct {}.ends_with("a.ext");
54+
55+
// Shouldn't fail if the extension has no ascii letter
56+
let _ = String::new().ends_with(".123");
57+
let _ = "str".ends_with(".123");
58+
TestStruct {}.ends_with(".123");
5459
}

0 commit comments

Comments
 (0)