From 51c6630d4f70d3c371cbda470358f85e9e2c3918 Mon Sep 17 00:00:00 2001 From: AurelienFT Date: Sat, 15 Jun 2024 21:52:42 +0200 Subject: [PATCH] Change MSRV check for manual_pattern_char_comparison only for pattern arrays --- clippy_lints/src/string_patterns.rs | 11 ++++++----- tests/ui/manual_pattern_char_comparison.fixed | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/clippy_lints/src/string_patterns.rs b/clippy_lints/src/string_patterns.rs index 084a4b597322..7ba58942a175 100644 --- a/clippy_lints/src/string_patterns.rs +++ b/clippy_lints/src/string_patterns.rs @@ -134,7 +134,7 @@ fn get_char_span<'tcx>(cx: &'_ LateContext<'tcx>, expr: &'tcx Expr<'_>) -> Optio } } -fn check_manual_pattern_char_comparison(cx: &LateContext<'_>, method_arg: &Expr<'_>) { +fn check_manual_pattern_char_comparison(cx: &LateContext<'_>, method_arg: &Expr<'_>, msrv: &Msrv) { if let ExprKind::Closure(closure) = method_arg.kind && let body = cx.tcx.hir().body(closure.body) && let Some(PatKind::Binding(_, binding, ..)) = body.params.first().map(|p| p.pat.kind) @@ -190,6 +190,9 @@ fn check_manual_pattern_char_comparison(cx: &LateContext<'_>, method_arg: &Expr< { return; } + if set_char_spans.len() > 1 && !msrv.meets(msrvs::PATTERN_TRAIT_CHAR_ARRAY) { + return; + } span_lint_and_then( cx, MANUAL_PATTERN_CHAR_COMPARISON, @@ -232,10 +235,8 @@ impl<'tcx> LateLintPass<'tcx> for StringPatterns { && let Some(arg) = args.get(pos) { check_single_char_pattern_lint(cx, arg); - if !self.msrv.meets(msrvs::PATTERN_TRAIT_CHAR_ARRAY) { - return; - } - check_manual_pattern_char_comparison(cx, arg); + + check_manual_pattern_char_comparison(cx, arg, &self.msrv); } } diff --git a/tests/ui/manual_pattern_char_comparison.fixed b/tests/ui/manual_pattern_char_comparison.fixed index 6020d7071bdf..03e621d95ba1 100644 --- a/tests/ui/manual_pattern_char_comparison.fixed +++ b/tests/ui/manual_pattern_char_comparison.fixed @@ -58,4 +58,4 @@ fn msrv_1_57() { fn msrv_1_58() { let sentence = "Hello, world!"; sentence.trim_end_matches(['.', ',', '!', '?']); -} \ No newline at end of file +}