diff options
| author | bors <bors@rust-lang.org> | 2021-04-16 06:44:26 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2021-04-16 06:44:26 +0000 |
| commit | ddc2598230e4bb67d8a30d3a5cd8431c1cecb63e (patch) | |
| tree | dc8b89c9200e990c9f8d1508044323dcad9abeec /clippy_lints/src | |
| parent | faa97568a0ed3804339bec3becc2dda54ccdcafc (diff) | |
| parent | 9a55c0c1763cc5894ce1dbf1c40d03119e3de5f3 (diff) | |
| download | rust-ddc2598230e4bb67d8a30d3a5cd8431c1cecb63e.tar.gz rust-ddc2598230e4bb67d8a30d3a5cd8431c1cecb63e.zip | |
Auto merge of #7093 - Jarcho:single_match_fp, r=llogiq
Fix `single_match` fixes: #7038 changelog: Don't suggest an equality check for types which don't implement `PartialEq` in `single_match`
Diffstat (limited to 'clippy_lints/src')
| -rw-r--r-- | clippy_lints/src/matches.rs | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/clippy_lints/src/matches.rs b/clippy_lints/src/matches.rs index 8f1112cff7b..e4d1451b369 100644 --- a/clippy_lints/src/matches.rs +++ b/clippy_lints/src/matches.rs @@ -738,8 +738,11 @@ fn report_single_match_single_pattern( let (msg, sugg) = if_chain! { if let PatKind::Path(_) | PatKind::Lit(_) = pat.kind; let (ty, ty_ref_count) = peel_mid_ty_refs(cx.typeck_results().expr_ty(ex)); - if let Some(trait_id) = cx.tcx.lang_items().structural_peq_trait(); - if ty.is_integral() || ty.is_char() || ty.is_str() || implements_trait(cx, ty, trait_id, &[]); + if let Some(spe_trait_id) = cx.tcx.lang_items().structural_peq_trait(); + if let Some(pe_trait_id) = cx.tcx.lang_items().eq_trait(); + if ty.is_integral() || ty.is_char() || ty.is_str() + || (implements_trait(cx, ty, spe_trait_id, &[]) + && implements_trait(cx, ty, pe_trait_id, &[ty.into()])); then { // scrutinee derives PartialEq and the pattern is a constant. let pat_ref_count = match pat.kind { |
