From 2d8618e95cf46f9d975f38eee06a1a94d5d4cd7e Mon Sep 17 00:00:00 2001 From: flip1995 Date: Fri, 15 Mar 2019 23:44:42 +0100 Subject: [PATCH] Remove ty::TyKind from eta_reduction and replace it with ty::Ty --- clippy_lints/src/eta_reduction.rs | 28 ++++++++++++++-------------- clippy_lints/src/transmute.rs | 2 +- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/clippy_lints/src/eta_reduction.rs b/clippy_lints/src/eta_reduction.rs index 7998a266285b..2b68277ac366 100644 --- a/clippy_lints/src/eta_reduction.rs +++ b/clippy_lints/src/eta_reduction.rs @@ -129,27 +129,27 @@ fn get_ufcs_type_name( method_def_id: def_id::DefId, self_arg: &Expr, ) -> std::option::Option { - let expected_type_of_self = &cx.tcx.fn_sig(method_def_id).inputs_and_output().skip_binder()[0].sty; - let actual_type_of_self = &cx.tables.node_type(self_arg.hir_id).sty; + let expected_type_of_self = &cx.tcx.fn_sig(method_def_id).inputs_and_output().skip_binder()[0]; + let actual_type_of_self = &cx.tables.node_type(self_arg.hir_id); if let Some(trait_id) = cx.tcx.trait_of_item(method_def_id) { - if match_borrow_depth(expected_type_of_self, actual_type_of_self) { + if match_borrow_depth(expected_type_of_self, &actual_type_of_self) { return Some(cx.tcx.def_path_str(trait_id)); } } cx.tcx.impl_of_method(method_def_id).and_then(|_| { //a type may implicitly implement other type's methods (e.g. Deref) - if match_types(expected_type_of_self, actual_type_of_self) { + if match_types(expected_type_of_self, &actual_type_of_self) { return Some(get_type_name(cx, &actual_type_of_self)); } None }) } -fn match_borrow_depth(lhs: &ty::TyKind<'_>, rhs: &ty::TyKind<'_>) -> bool { - match (lhs, rhs) { - (ty::Ref(_, t1, _), ty::Ref(_, t2, _)) => match_borrow_depth(&t1.sty, &t2.sty), +fn match_borrow_depth(lhs: &ty::Ty<'_>, rhs: &ty::Ty<'_>) -> bool { + match (&lhs.sty, &rhs.sty) { + (ty::Ref(_, t1, _), ty::Ref(_, t2, _)) => match_borrow_depth(&t1, &t2), (l, r) => match (l, r) { (ty::Ref(_, _, _), _) | (_, ty::Ref(_, _, _)) => false, (_, _) => true, @@ -157,8 +157,8 @@ fn match_borrow_depth(lhs: &ty::TyKind<'_>, rhs: &ty::TyKind<'_>) -> bool { } } -fn match_types(lhs: &ty::TyKind<'_>, rhs: &ty::TyKind<'_>) -> bool { - match (lhs, rhs) { +fn match_types(lhs: &ty::Ty<'_>, rhs: &ty::Ty<'_>) -> bool { + match (&lhs.sty, &rhs.sty) { (ty::Bool, ty::Bool) | (ty::Char, ty::Char) | (ty::Int(_), ty::Int(_)) @@ -166,17 +166,17 @@ fn match_types(lhs: &ty::TyKind<'_>, rhs: &ty::TyKind<'_>) -> bool { | (ty::Str, ty::Str) => true, (ty::Ref(_, t1, _), ty::Ref(_, t2, _)) | (ty::Array(t1, _), ty::Array(t2, _)) - | (ty::Slice(t1), ty::Slice(t2)) => match_types(&t1.sty, &t2.sty), + | (ty::Slice(t1), ty::Slice(t2)) => match_types(&t1, &t2), (ty::Adt(def1, _), ty::Adt(def2, _)) => def1 == def2, (_, _) => false, } } -fn get_type_name(cx: &LateContext<'_, '_>, kind: &ty::TyKind<'_>) -> String { - match kind { +fn get_type_name(cx: &LateContext<'_, '_>, ty: &ty::Ty<'_>) -> String { + match ty.sty { ty::Adt(t, _) => cx.tcx.def_path_str(t.did), - ty::Ref(_, r, _) => get_type_name(cx, &r.sty), - _ => kind.to_string(), + ty::Ref(_, r, _) => get_type_name(cx, &r), + _ => ty.to_string(), } } diff --git a/clippy_lints/src/transmute.rs b/clippy_lints/src/transmute.rs index 2c4bfe7358d6..e4eb1bb0b740 100644 --- a/clippy_lints/src/transmute.rs +++ b/clippy_lints/src/transmute.rs @@ -347,7 +347,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Transmute { |db| { let arg = sugg::Sugg::hir(cx, &args[0], ".."); let arg = if let ty::Int(_) = from_ty.sty { - arg.as_ty(ty::Uint(ast::UintTy::U32)) + arg.as_ty(ast::UintTy::U32) } else { arg };