diff options
| author | bors <bors@rust-lang.org> | 2024-02-14 18:20:49 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2024-02-14 18:20:49 +0000 |
| commit | eb300fdad40e4761ad061e4bca5c61f25356ba4b (patch) | |
| tree | b74ea44b328b89684a2cd89505c4231f1b55f0ae | |
| parent | 2c3213f5c5c3ecce5712d7aded3020fe61791179 (diff) | |
| parent | 9492de509fbf0793019dfe5ff8583b9a2c88dd83 (diff) | |
| download | rust-eb300fdad40e4761ad061e4bca5c61f25356ba4b.tar.gz rust-eb300fdad40e4761ad061e4bca5c61f25356ba4b.zip | |
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
3 files changed, 11 insertions, 0 deletions
diff --git a/clippy_lints/src/methods/case_sensitive_file_extension_comparisons.rs b/clippy_lints/src/methods/case_sensitive_file_extension_comparisons.rs index a37087d0abf..a5df863d800 100644 --- a/clippy_lints/src/methods/case_sensitive_file_extension_comparisons.rs +++ b/clippy_lints/src/methods/case_sensitive_file_extension_comparisons.rs @@ -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)) { diff --git a/tests/ui/case_sensitive_file_extension_comparisons.fixed b/tests/ui/case_sensitive_file_extension_comparisons.fixed index a816224c91c..8b4a165a97c 100644 --- a/tests/ui/case_sensitive_file_extension_comparisons.fixed +++ b/tests/ui/case_sensitive_file_extension_comparisons.fixed @@ -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"); } diff --git a/tests/ui/case_sensitive_file_extension_comparisons.rs b/tests/ui/case_sensitive_file_extension_comparisons.rs index 994de2805f7..e4b8178110b 100644 --- a/tests/ui/case_sensitive_file_extension_comparisons.rs +++ b/tests/ui/case_sensitive_file_extension_comparisons.rs @@ -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"); } |
