1 use rustc_hir
::{self as hir, intravisit}
;
2 use rustc_lint
::LateContext
;
4 use rustc_target
::spec
::abi
::Abi
;
6 use clippy_utils
::diagnostics
::span_lint
;
7 use clippy_utils
::is_trait_impl_item
;
9 use super::TOO_MANY_ARGUMENTS
;
11 pub(super) fn check_fn(
12 cx
: &LateContext
<'tcx
>,
13 kind
: intravisit
::FnKind
<'tcx
>,
14 decl
: &'tcx hir
::FnDecl
<'_
>,
17 too_many_arguments_threshold
: u64,
19 // don't warn for implementations, it's not their fault
20 if !is_trait_impl_item(cx
, hir_id
) {
21 // don't lint extern functions decls, it's not their fault either
23 intravisit
::FnKind
::Method(
26 header
: hir
::FnHeader { abi: Abi::Rust, .. }
,
31 | intravisit
::FnKind
::ItemFn(_
, _
, hir
::FnHeader { abi: Abi::Rust, .. }
, _
) => check_arg_number(
34 span
.with_hi(decl
.output
.span().hi()),
35 too_many_arguments_threshold
,
42 pub(super) fn check_trait_item(
43 cx
: &LateContext
<'tcx
>,
44 item
: &'tcx hir
::TraitItem
<'_
>,
45 too_many_arguments_threshold
: u64,
47 if let hir
::TraitItemKind
::Fn(ref sig
, _
) = item
.kind
{
48 // don't lint extern functions decls, it's not their fault
49 if sig
.header
.abi
== Abi
::Rust
{
53 item
.span
.with_hi(sig
.decl
.output
.span().hi()),
54 too_many_arguments_threshold
,
60 fn check_arg_number(cx
: &LateContext
<'_
>, decl
: &hir
::FnDecl
<'_
>, fn_span
: Span
, too_many_arguments_threshold
: u64) {
61 let args
= decl
.inputs
.len() as u64;
62 if args
> too_many_arguments_threshold
{
68 "this function has too many arguments ({}/{})",
69 args
, too_many_arguments_threshold