This commit is contained in:
Matthias Krüger 2020-04-14 12:25:45 +02:00
parent 74e92566d5
commit c1f2da40ab
4 changed files with 8 additions and 8 deletions

View file

@ -121,7 +121,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LenZero {
fn check_trait_items(cx: &LateContext<'_, '_>, visited_trait: &Item<'_>, trait_items: &[TraitItemRef]) {
fn is_named_self(cx: &LateContext<'_, '_>, item: &TraitItemRef, name: &str) -> bool {
item.ident.name.as_str() == name
&& if let AssocItemKind::Method { has_self } = item.kind {
&& if let AssocItemKind::Fn { has_self } = item.kind {
has_self && {
let did = cx.tcx.hir().local_def_id(item.id.hir_id);
cx.tcx.fn_sig(did).inputs().skip_binder().len() == 1
@ -149,8 +149,8 @@ fn check_trait_items(cx: &LateContext<'_, '_>, visited_trait: &Item<'_>, trait_i
.iter()
.flat_map(|&i| cx.tcx.associated_items(i).in_definition_order())
.any(|i| {
i.kind == ty::AssocKind::Method
&& i.method_has_self_argument
i.kind == ty::AssocKind::Fn
&& i.fn_has_self_parameter
&& i.ident.name == sym!(is_empty)
&& cx.tcx.fn_sig(i.def_id).inputs().skip_binder().len() == 1
});
@ -172,7 +172,7 @@ fn check_trait_items(cx: &LateContext<'_, '_>, visited_trait: &Item<'_>, trait_i
fn check_impl_items(cx: &LateContext<'_, '_>, item: &Item<'_>, impl_items: &[ImplItemRef<'_>]) {
fn is_named_self(cx: &LateContext<'_, '_>, item: &ImplItemRef<'_>, name: &str) -> bool {
item.ident.name.as_str() == name
&& if let AssocItemKind::Method { has_self } = item.kind {
&& if let AssocItemKind::Fn { has_self } = item.kind {
has_self && {
let did = cx.tcx.hir().local_def_id(item.id.hir_id);
cx.tcx.fn_sig(did).inputs().skip_binder().len() == 1
@ -261,7 +261,7 @@ fn check_len(
fn has_is_empty(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> bool {
/// Gets an `AssocItem` and return true if it matches `is_empty(self)`.
fn is_is_empty(cx: &LateContext<'_, '_>, item: &ty::AssocItem) -> bool {
if let ty::AssocKind::Method = item.kind {
if let ty::AssocKind::Fn = item.kind {
if item.ident.name.as_str() == "is_empty" {
let sig = cx.tcx.fn_sig(item.def_id);
let ty = sig.skip_binder();

View file

@ -100,7 +100,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NewWithoutDefault {
} = item.kind
{
for assoc_item in items {
if let hir::AssocItemKind::Method { has_self: false } = assoc_item.kind {
if let hir::AssocItemKind::Fn { has_self: false } = assoc_item.kind {
let impl_item = cx.tcx.hir().impl_item(assoc_item.id);
if in_external_macro(cx.sess(), impl_item.span) {
return;

View file

@ -50,7 +50,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedSelf {
let assoc_item = cx.tcx.associated_item(def_id);
if_chain! {
if let ItemKind::Impl { of_trait: None, .. } = parent_item.kind;
if assoc_item.method_has_self_argument;
if assoc_item.fn_has_self_parameter;
if let ImplItemKind::Fn(.., body_id) = &impl_item.kind;
let body = cx.tcx.hir().body(*body_id);
if !body.params.is_empty();

View file

@ -119,7 +119,7 @@ fn check_trait_method_impl_decl<'a, 'tcx>(
let trait_method = cx
.tcx
.associated_items(impl_trait_ref.def_id)
.find_by_name_and_kind(cx.tcx, impl_item.ident, ty::AssocKind::Method, impl_trait_ref.def_id)
.find_by_name_and_kind(cx.tcx, impl_item.ident, ty::AssocKind::Fn, impl_trait_ref.def_id)
.expect("impl method matches a trait method");
let trait_method_sig = cx.tcx.fn_sig(trait_method.def_id);