Skip to content

Commit ac3492a

Browse files
committed
simplify too_many_args
import `FnKind` completely save `header` as an intermediate variable match on `header.abi` directly use `FnKind::header` nest `if`s use `cx.tcx.def_span`, as recommended in #15461 (comment)
1 parent 36ef395 commit ac3492a

File tree

2 files changed

+10
-29
lines changed

2 files changed

+10
-29
lines changed

clippy_lints/src/functions/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ impl<'tcx> LateLintPass<'tcx> for Functions {
535535
def_id: LocalDefId,
536536
) {
537537
let hir_id = cx.tcx.local_def_id_to_hir_id(def_id);
538-
too_many_arguments::check_fn(cx, kind, decl, span, hir_id, self.too_many_arguments_threshold);
538+
too_many_arguments::check_fn(cx, kind, decl, hir_id, def_id, self.too_many_arguments_threshold);
539539
too_many_lines::check_fn(cx, kind, body, span, def_id, self.too_many_lines_threshold);
540540
not_unsafe_ptr_arg_deref::check_fn(cx, kind, decl, body, def_id);
541541
misnamed_getters::check_fn(cx, kind, decl, body, span);

clippy_lints/src/functions/too_many_arguments.rs

Lines changed: 9 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
use rustc_abi::ExternAbi;
2-
use rustc_hir::{self as hir, intravisit};
2+
use rustc_hir as hir;
3+
use rustc_hir::def_id::LocalDefId;
4+
use rustc_hir::intravisit::FnKind;
35
use rustc_lint::LateContext;
46
use rustc_span::Span;
57

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

1113
pub(super) fn check_fn(
1214
cx: &LateContext<'_>,
13-
kind: intravisit::FnKind<'_>,
15+
kind: FnKind<'_>,
1416
decl: &hir::FnDecl<'_>,
15-
span: Span,
1617
hir_id: hir::HirId,
18+
def_id: LocalDefId,
1719
too_many_arguments_threshold: u64,
1820
) {
1921
// don't warn for implementations, it's not their fault
20-
if !is_trait_impl_item(cx, hir_id) {
22+
if !is_trait_impl_item(cx, hir_id)
2123
// don't lint extern functions decls, it's not their fault either
22-
match kind {
23-
intravisit::FnKind::Method(
24-
_,
25-
&hir::FnSig {
26-
header: hir::FnHeader {
27-
abi: ExternAbi::Rust, ..
28-
},
29-
..
30-
},
31-
)
32-
| intravisit::FnKind::ItemFn(
33-
_,
34-
_,
35-
hir::FnHeader {
36-
abi: ExternAbi::Rust, ..
37-
},
38-
) => check_arg_number(
39-
cx,
40-
decl,
41-
span.with_hi(decl.output.span().hi()),
42-
too_many_arguments_threshold,
43-
),
44-
_ => {},
45-
}
24+
&& kind.header().is_some_and(|header| header.abi == ExternAbi::Rust)
25+
{
26+
check_arg_number(cx, decl, cx.tcx.def_span(def_id), too_many_arguments_threshold);
4627
}
4728
}
4829

0 commit comments

Comments
 (0)