Skip to content

Commit

Permalink
Change MSRV check for manual_pattern_char_comparison only for pattern…
Browse files Browse the repository at this point in the history
… arrays
  • Loading branch information
AurelienFT committed Jun 15, 2024
1 parent 63388cb commit 51c6630
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
11 changes: 6 additions & 5 deletions clippy_lints/src/string_patterns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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);
}
}

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/manual_pattern_char_comparison.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,4 @@ fn msrv_1_57() {
fn msrv_1_58() {
let sentence = "Hello, world!";
sentence.trim_end_matches(['.', ',', '!', '?']);
}
}

0 comments on commit 51c6630

Please sign in to comment.