[case_sensitive_file_extension_comparisons]: Don't trigger on digits-only extensions

This commit is contained in:
Ethiraric 2024-02-14 18:26:06 +01:00
parent 2c3213f5c5
commit 9492de509f
3 changed files with 11 additions and 0 deletions

View file

@ -38,6 +38,7 @@ pub(super) fn check<'tcx>(
&& ext_str.starts_with('.')
&& (ext_str.chars().skip(1).all(|c| c.is_uppercase() || c.is_ascii_digit())
|| ext_str.chars().skip(1).all(|c| c.is_lowercase() || c.is_ascii_digit()))
&& !ext_str.chars().skip(1).all(|c| c.is_ascii_digit())
&& let recv_ty = cx.typeck_results().expr_ty(recv).peel_refs()
&& (recv_ty.is_str() || is_type_lang_item(cx, recv_ty, LangItem::String))
{

View file

@ -63,4 +63,9 @@ fn main() {
let _ = String::new().ends_with("a.ext");
let _ = "str".ends_with("a.extA");
TestStruct {}.ends_with("a.ext");
// Shouldn't fail if the extension has no ascii letter
let _ = String::new().ends_with(".123");
let _ = "str".ends_with(".123");
TestStruct {}.ends_with(".123");
}

View file

@ -51,4 +51,9 @@ fn main() {
let _ = String::new().ends_with("a.ext");
let _ = "str".ends_with("a.extA");
TestStruct {}.ends_with("a.ext");
// Shouldn't fail if the extension has no ascii letter
let _ = String::new().ends_with(".123");
let _ = "str".ends_with(".123");
TestStruct {}.ends_with(".123");
}