Skip to content

simplify too_many_args #15462

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion clippy_lints/src/functions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ impl<'tcx> LateLintPass<'tcx> for Functions {
def_id: LocalDefId,
) {
let hir_id = cx.tcx.local_def_id_to_hir_id(def_id);
too_many_arguments::check_fn(cx, kind, decl, span, hir_id, self.too_many_arguments_threshold);
too_many_arguments::check_fn(cx, kind, decl, hir_id, def_id, self.too_many_arguments_threshold);
too_many_lines::check_fn(cx, kind, span, body, self.too_many_lines_threshold);
not_unsafe_ptr_arg_deref::check_fn(cx, kind, decl, body, def_id);
misnamed_getters::check_fn(cx, kind, decl, body, span);
Expand Down
37 changes: 9 additions & 28 deletions clippy_lints/src/functions/too_many_arguments.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use rustc_abi::ExternAbi;
use rustc_hir::{self as hir, intravisit};
use rustc_hir as hir;
use rustc_hir::def_id::LocalDefId;
use rustc_hir::intravisit::FnKind;
use rustc_lint::LateContext;
use rustc_span::Span;

Expand All @@ -10,39 +12,18 @@ use super::TOO_MANY_ARGUMENTS;

pub(super) fn check_fn(
cx: &LateContext<'_>,
kind: intravisit::FnKind<'_>,
kind: FnKind<'_>,
decl: &hir::FnDecl<'_>,
span: Span,
hir_id: hir::HirId,
def_id: LocalDefId,
too_many_arguments_threshold: u64,
) {
// don't warn for implementations, it's not their fault
if !is_trait_impl_item(cx, hir_id) {
if !is_trait_impl_item(cx, hir_id)
// don't lint extern functions decls, it's not their fault either
match kind {
intravisit::FnKind::Method(
_,
&hir::FnSig {
header: hir::FnHeader {
abi: ExternAbi::Rust, ..
},
..
},
)
| intravisit::FnKind::ItemFn(
_,
_,
hir::FnHeader {
abi: ExternAbi::Rust, ..
},
) => check_arg_number(
cx,
decl,
span.with_hi(decl.output.span().hi()),
too_many_arguments_threshold,
),
_ => {},
}
&& kind.header().is_some_and(|header| header.abi == ExternAbi::Rust)
{
check_arg_number(cx, decl, cx.tcx.def_span(def_id), too_many_arguments_threshold);
}
}

Expand Down