Skip to content

Commit 919a1a4

Browse files
committed
Auto merge of #6957 - camsteffen:eq-ty-kind, r=flip1995
Factor out `SpanlessEq::eq_ty_kind` changelog: none
2 parents b80903b + 9132dbd commit 919a1a4

File tree

2 files changed

+10
-20
lines changed

2 files changed

+10
-20
lines changed

clippy_lints/src/methods/mod.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,11 @@ mod zst_offset;
6262
use bind_instead_of_map::BindInsteadOfMap;
6363
use clippy_utils::diagnostics::{span_lint, span_lint_and_help};
6464
use clippy_utils::ty::{contains_ty, implements_trait, is_copy, is_type_diagnostic_item};
65-
use clippy_utils::{
66-
contains_return, get_trait_def_id, in_macro, iter_input_pats, match_qpath, method_calls, paths, return_ty,
67-
SpanlessEq,
68-
};
65+
use clippy_utils::{contains_return, get_trait_def_id, in_macro, iter_input_pats, method_calls, paths, return_ty};
6966
use if_chain::if_chain;
7067
use rustc_hir as hir;
71-
use rustc_hir::{TraitItem, TraitItemKind};
68+
use rustc_hir::def::Res;
69+
use rustc_hir::{PrimTy, QPath, TraitItem, TraitItemKind};
7270
use rustc_lint::{LateContext, LateLintPass, LintContext};
7371
use rustc_middle::lint::in_external_macro;
7472
use rustc_middle::ty::{self, TraitRef, Ty, TyS};
@@ -1872,7 +1870,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods {
18721870
for method_config in &TRAIT_METHODS {
18731871
if name == method_config.method_name &&
18741872
sig.decl.inputs.len() == method_config.param_count &&
1875-
method_config.output_type.matches(cx, &sig.decl.output) &&
1873+
method_config.output_type.matches(&sig.decl.output) &&
18761874
method_config.self_kind.matches(cx, self_ty, first_arg_ty) &&
18771875
fn_header_equals(method_config.fn_header, sig.header) &&
18781876
method_config.lifetime_param_cond(&impl_item)
@@ -2199,8 +2197,8 @@ enum OutType {
21992197
}
22002198

22012199
impl OutType {
2202-
fn matches(self, cx: &LateContext<'_>, ty: &hir::FnRetTy<'_>) -> bool {
2203-
let is_unit = |ty: &hir::Ty<'_>| SpanlessEq::new(cx).eq_ty_kind(&ty.kind, &hir::TyKind::Tup(&[]));
2200+
fn matches(self, ty: &hir::FnRetTy<'_>) -> bool {
2201+
let is_unit = |ty: &hir::Ty<'_>| matches!(ty.kind, hir::TyKind::Tup(&[]));
22042202
match (self, ty) {
22052203
(Self::Unit, &hir::FnRetTy::DefaultReturn(_)) => true,
22062204
(Self::Unit, &hir::FnRetTy::Return(ref ty)) if is_unit(ty) => true,
@@ -2213,8 +2211,8 @@ impl OutType {
22132211
}
22142212

22152213
fn is_bool(ty: &hir::Ty<'_>) -> bool {
2216-
if let hir::TyKind::Path(ref p) = ty.kind {
2217-
match_qpath(p, &["bool"])
2214+
if let hir::TyKind::Path(QPath::Resolved(_, path)) = ty.kind {
2215+
matches!(path.res, Res::PrimTy(PrimTy::Bool))
22182216
} else {
22192217
false
22202218
}

clippy_utils/src/hir_utils.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,6 @@ impl<'a, 'tcx> SpanlessEq<'a, 'tcx> {
8080
pub fn eq_path_segments(&mut self, left: &[PathSegment<'_>], right: &[PathSegment<'_>]) -> bool {
8181
self.inter_expr().eq_path_segments(left, right)
8282
}
83-
84-
pub fn eq_ty_kind(&mut self, left: &TyKind<'_>, right: &TyKind<'_>) -> bool {
85-
self.inter_expr().eq_ty_kind(left, right)
86-
}
8783
}
8884

8985
struct HirEqInterExpr<'a, 'b, 'tcx> {
@@ -378,13 +374,9 @@ impl HirEqInterExpr<'_, '_, '_> {
378374
left.ident.name == right.ident.name && both(&left.args, &right.args, |l, r| self.eq_path_parameters(l, r))
379375
}
380376

381-
fn eq_ty(&mut self, left: &Ty<'_>, right: &Ty<'_>) -> bool {
382-
self.eq_ty_kind(&left.kind, &right.kind)
383-
}
384-
385377
#[allow(clippy::similar_names)]
386-
fn eq_ty_kind(&mut self, left: &TyKind<'_>, right: &TyKind<'_>) -> bool {
387-
match (left, right) {
378+
fn eq_ty(&mut self, left: &Ty<'_>, right: &Ty<'_>) -> bool {
379+
match (&left.kind, &right.kind) {
388380
(&TyKind::Slice(ref l_vec), &TyKind::Slice(ref r_vec)) => self.eq_ty(l_vec, r_vec),
389381
(&TyKind::Array(ref lt, ref ll_id), &TyKind::Array(ref rt, ref rl_id)) => {
390382
let cx = self.inner.cx;

0 commit comments

Comments
 (0)