mirror of
https://github.com/rust-lang/rust.git
synced 2025-01-26 14:43:24 +00:00
Remove ty::TyKind from eta_reduction and replace it with ty::Ty
This commit is contained in:
parent
8eadbfd35b
commit
2d8618e95c
@ -129,27 +129,27 @@ fn get_ufcs_type_name(
|
||||
method_def_id: def_id::DefId,
|
||||
self_arg: &Expr,
|
||||
) -> std::option::Option<String> {
|
||||
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(),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user