mirror of
https://github.com/rust-lang/rust-clippy
synced 2025-01-31 22:33:33 +00:00
This commit is contained in:
parent
74e92566d5
commit
c1f2da40ab
4 changed files with 8 additions and 8 deletions
|
@ -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 check_trait_items(cx: &LateContext<'_, '_>, visited_trait: &Item<'_>, trait_items: &[TraitItemRef]) {
|
||||||
fn is_named_self(cx: &LateContext<'_, '_>, item: &TraitItemRef, name: &str) -> bool {
|
fn is_named_self(cx: &LateContext<'_, '_>, item: &TraitItemRef, name: &str) -> bool {
|
||||||
item.ident.name.as_str() == name
|
item.ident.name.as_str() == name
|
||||||
&& if let AssocItemKind::Method { has_self } = item.kind {
|
&& if let AssocItemKind::Fn { has_self } = item.kind {
|
||||||
has_self && {
|
has_self && {
|
||||||
let did = cx.tcx.hir().local_def_id(item.id.hir_id);
|
let did = cx.tcx.hir().local_def_id(item.id.hir_id);
|
||||||
cx.tcx.fn_sig(did).inputs().skip_binder().len() == 1
|
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()
|
.iter()
|
||||||
.flat_map(|&i| cx.tcx.associated_items(i).in_definition_order())
|
.flat_map(|&i| cx.tcx.associated_items(i).in_definition_order())
|
||||||
.any(|i| {
|
.any(|i| {
|
||||||
i.kind == ty::AssocKind::Method
|
i.kind == ty::AssocKind::Fn
|
||||||
&& i.method_has_self_argument
|
&& i.fn_has_self_parameter
|
||||||
&& i.ident.name == sym!(is_empty)
|
&& i.ident.name == sym!(is_empty)
|
||||||
&& cx.tcx.fn_sig(i.def_id).inputs().skip_binder().len() == 1
|
&& 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 check_impl_items(cx: &LateContext<'_, '_>, item: &Item<'_>, impl_items: &[ImplItemRef<'_>]) {
|
||||||
fn is_named_self(cx: &LateContext<'_, '_>, item: &ImplItemRef<'_>, name: &str) -> bool {
|
fn is_named_self(cx: &LateContext<'_, '_>, item: &ImplItemRef<'_>, name: &str) -> bool {
|
||||||
item.ident.name.as_str() == name
|
item.ident.name.as_str() == name
|
||||||
&& if let AssocItemKind::Method { has_self } = item.kind {
|
&& if let AssocItemKind::Fn { has_self } = item.kind {
|
||||||
has_self && {
|
has_self && {
|
||||||
let did = cx.tcx.hir().local_def_id(item.id.hir_id);
|
let did = cx.tcx.hir().local_def_id(item.id.hir_id);
|
||||||
cx.tcx.fn_sig(did).inputs().skip_binder().len() == 1
|
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 {
|
fn has_is_empty(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> bool {
|
||||||
/// Gets an `AssocItem` and return true if it matches `is_empty(self)`.
|
/// Gets an `AssocItem` and return true if it matches `is_empty(self)`.
|
||||||
fn is_is_empty(cx: &LateContext<'_, '_>, item: &ty::AssocItem) -> bool {
|
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" {
|
if item.ident.name.as_str() == "is_empty" {
|
||||||
let sig = cx.tcx.fn_sig(item.def_id);
|
let sig = cx.tcx.fn_sig(item.def_id);
|
||||||
let ty = sig.skip_binder();
|
let ty = sig.skip_binder();
|
||||||
|
|
|
@ -100,7 +100,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NewWithoutDefault {
|
||||||
} = item.kind
|
} = item.kind
|
||||||
{
|
{
|
||||||
for assoc_item in items {
|
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);
|
let impl_item = cx.tcx.hir().impl_item(assoc_item.id);
|
||||||
if in_external_macro(cx.sess(), impl_item.span) {
|
if in_external_macro(cx.sess(), impl_item.span) {
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -50,7 +50,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedSelf {
|
||||||
let assoc_item = cx.tcx.associated_item(def_id);
|
let assoc_item = cx.tcx.associated_item(def_id);
|
||||||
if_chain! {
|
if_chain! {
|
||||||
if let ItemKind::Impl { of_trait: None, .. } = parent_item.kind;
|
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;
|
if let ImplItemKind::Fn(.., body_id) = &impl_item.kind;
|
||||||
let body = cx.tcx.hir().body(*body_id);
|
let body = cx.tcx.hir().body(*body_id);
|
||||||
if !body.params.is_empty();
|
if !body.params.is_empty();
|
||||||
|
|
|
@ -119,7 +119,7 @@ fn check_trait_method_impl_decl<'a, 'tcx>(
|
||||||
let trait_method = cx
|
let trait_method = cx
|
||||||
.tcx
|
.tcx
|
||||||
.associated_items(impl_trait_ref.def_id)
|
.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");
|
.expect("impl method matches a trait method");
|
||||||
|
|
||||||
let trait_method_sig = cx.tcx.fn_sig(trait_method.def_id);
|
let trait_method_sig = cx.tcx.fn_sig(trait_method.def_id);
|
||||||
|
|
Loading…
Reference in a new issue