Skip to content

Commit f416f26

Browse files
committed
turn hir::ItemKind::Fn into a named-field variant
1 parent 1cc5051 commit f416f26

23 files changed

+50
-26
lines changed

clippy_lints/src/arbitrary_source_item_ordering.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ fn convert_module_item_kind(value: &ItemKind<'_>) -> SourceItemOrderingModuleIte
464464
ItemKind::Use(..) => Use,
465465
ItemKind::Static(..) => Static,
466466
ItemKind::Const(..) => Const,
467-
ItemKind::Fn(..) => Fn,
467+
ItemKind::Fn{ .. } => Fn,
468468
ItemKind::Macro(..) => Macro,
469469
ItemKind::Mod(..) => Mod,
470470
ItemKind::ForeignMod { .. } => ForeignMod,

clippy_lints/src/attrs/utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ pub(super) fn is_lint_level(symbol: Symbol, attr_id: AttrId) -> bool {
2121
}
2222

2323
pub(super) fn is_relevant_item(cx: &LateContext<'_>, item: &Item<'_>) -> bool {
24-
if let ItemKind::Fn(_, _, eid) = item.kind {
24+
if let ItemKind::Fn { body: eid, .. } = item.kind {
2525
is_relevant_expr(cx, cx.tcx.typeck_body(eid), cx.tcx.hir().body(eid).value)
2626
} else {
2727
true

clippy_lints/src/doc/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,7 @@ impl<'tcx> LateLintPass<'tcx> for Documentation {
639639
self.check_private_items,
640640
);
641641
match item.kind {
642-
ItemKind::Fn(sig, _, body_id) => {
642+
ItemKind::Fn { sig, body: body_id, .. } => {
643643
if !(is_entrypoint_fn(cx, item.owner_id.to_def_id())
644644
|| in_external_macro(cx.tcx.sess, item.span))
645645
{

clippy_lints/src/doc/too_long_first_doc_paragraph.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ pub(super) fn check(
2525
// page. So associated items or impl blocks are not part of this list.
2626
ItemKind::Static(..)
2727
| ItemKind::Const(..)
28-
| ItemKind::Fn(..)
28+
| ItemKind::Fn{ .. }
2929
| ItemKind::Macro(..)
3030
| ItemKind::Mod(..)
3131
| ItemKind::TyAlias(..)

clippy_lints/src/exit.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ impl<'tcx> LateLintPass<'tcx> for Exit {
4848
&& let Some(def_id) = cx.qpath_res(path, path_expr.hir_id).opt_def_id()
4949
&& cx.tcx.is_diagnostic_item(sym::process_exit, def_id)
5050
&& let parent = cx.tcx.hir().get_parent_item(e.hir_id)
51-
&& let OwnerNode::Item(Item{kind: ItemKind::Fn(..), ..}) = cx.tcx.hir_owner_node(parent)
51+
&& let OwnerNode::Item(Item{kind: ItemKind::Fn{ .. }, ..}) = cx.tcx.hir_owner_node(parent)
5252
// If the next item up is a function we check if it is an entry point
5353
// and only then emit a linter warning
5454
&& !is_entrypoint_fn(cx, parent.to_def_id())

clippy_lints/src/extra_unused_type_parameters.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,11 @@ fn is_empty_body(cx: &LateContext<'_>, body: BodyId) -> bool {
253253

254254
impl<'tcx> LateLintPass<'tcx> for ExtraUnusedTypeParameters {
255255
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'tcx>) {
256-
if let ItemKind::Fn(_, generics, body_id) = item.kind
256+
if let ItemKind::Fn {
257+
generics,
258+
body: body_id,
259+
..
260+
} = item.kind
257261
&& !generics.params.is_empty()
258262
&& !is_empty_body(cx, body_id)
259263
&& (!self.avoid_breaking_exported_api || !cx.effective_visibilities.is_exported(item.owner_id.def_id))

clippy_lints/src/functions/must_use.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,12 @@ use super::{DOUBLE_MUST_USE, MUST_USE_CANDIDATE, MUST_USE_UNIT};
2424
pub(super) fn check_item<'tcx>(cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_>) {
2525
let attrs = cx.tcx.hir().attrs(item.hir_id());
2626
let attr = cx.tcx.get_attr(item.owner_id, sym::must_use);
27-
if let hir::ItemKind::Fn(ref sig, _generics, ref body_id) = item.kind {
27+
if let hir::ItemKind::Fn {
28+
ref sig,
29+
body: ref body_id,
30+
..
31+
} = item.kind
32+
{
2833
let is_public = cx.effective_visibilities.is_exported(item.owner_id.def_id);
2934
let fn_header_span = item.span.with_hi(sig.decl.output.span().hi());
3035
if let Some(attr) = attr {

clippy_lints/src/functions/result.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ fn result_err_ty<'tcx>(
3636
}
3737

3838
pub(super) fn check_item<'tcx>(cx: &LateContext<'tcx>, item: &hir::Item<'tcx>, large_err_threshold: u64, msrv: &Msrv) {
39-
if let hir::ItemKind::Fn(ref sig, _generics, _) = item.kind
39+
if let hir::ItemKind::Fn { ref sig, .. } = item.kind
4040
&& let Some((hir_ty, err_ty)) = result_err_ty(cx, sig.decl, item.owner_id.def_id, item.span)
4141
{
4242
if cx.effective_visibilities.is_exported(item.owner_id.def_id) {

clippy_lints/src/implicit_hasher.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,12 @@ impl<'tcx> LateLintPass<'tcx> for ImplicitHasher {
149149
);
150150
}
151151
},
152-
ItemKind::Fn(ref sig, generics, body_id) => {
152+
ItemKind::Fn {
153+
ref sig,
154+
generics,
155+
body: body_id,
156+
..
157+
} => {
153158
let body = cx.tcx.hir().body(body_id);
154159

155160
for ty in sig.decl.inputs {

clippy_lints/src/lifetimes.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,13 @@ declare_lint_pass!(Lifetimes => [NEEDLESS_LIFETIMES, EXTRA_UNUSED_LIFETIMES]);
9595

9696
impl<'tcx> LateLintPass<'tcx> for Lifetimes {
9797
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) {
98-
if let ItemKind::Fn(ref sig, generics, id) = item.kind {
98+
if let ItemKind::Fn {
99+
ref sig,
100+
generics,
101+
body: id,
102+
..
103+
} = item.kind
104+
{
99105
check_fn_inner(cx, sig, Some(id), None, generics, item.span, true);
100106
} else if let ItemKind::Impl(impl_) = item.kind {
101107
if !item.span.from_expansion() {

clippy_lints/src/loops/infinite_loop.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,11 @@ fn get_parent_fn_ret_ty<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'_>) -> Option
7575
..
7676
}) => (),
7777
Node::Item(hir::Item {
78-
kind: hir::ItemKind::Fn(FnSig { decl, .. }, _, _),
78+
kind:
79+
hir::ItemKind::Fn {
80+
sig: FnSig { decl, .. },
81+
..
82+
},
7983
..
8084
})
8185
| Node::TraitItem(hir::TraitItem {

clippy_lints/src/matches/needless_match.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ fn expr_ty_matches_p_ty(cx: &LateContext<'_>, expr: &Expr<'_>, p_expr: &Expr<'_>
133133
},
134134
// compare match_expr ty with RetTy in `fn foo() -> RetTy`
135135
Node::Item(item) => {
136-
if let ItemKind::Fn(..) = item.kind {
136+
if let ItemKind::Fn{ .. } = item.kind {
137137
let output = cx
138138
.tcx
139139
.fn_sig(item.owner_id)

clippy_lints/src/methods/unnecessary_to_owned.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,7 @@ fn can_change_type<'a>(cx: &LateContext<'a>, mut expr: &'a Expr<'a>, mut ty: Ty<
496496
Node::Stmt(_) => return true,
497497
Node::Block(..) => continue,
498498
Node::Item(item) => {
499-
if let ItemKind::Fn(_, _, body_id) = &item.kind
499+
if let ItemKind::Fn { body: body_id, .. } = &item.kind
500500
&& let output_ty = return_ty(cx, item.owner_id)
501501
&& rustc_hir_typeck::can_coerce(cx.tcx, cx.param_env, item.owner_id.def_id, ty, output_ty)
502502
{

clippy_lints/src/missing_doc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc {
192192

193193
fn check_item(&mut self, cx: &LateContext<'tcx>, it: &'tcx hir::Item<'_>) {
194194
match it.kind {
195-
hir::ItemKind::Fn(..) => {
195+
hir::ItemKind::Fn{ .. } => {
196196
// ignore main()
197197
if it.ident.name == sym::main {
198198
let at_root = cx.tcx.local_parent(it.owner_id.def_id) == CRATE_DEF_ID;

clippy_lints/src/missing_inline.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingInline {
9696
return;
9797
}
9898
match it.kind {
99-
hir::ItemKind::Fn(..) => {
99+
hir::ItemKind::Fn{ .. } => {
100100
let desc = "a function";
101101
let attrs = cx.tcx.hir().attrs(it.hir_id());
102102
check_missing_inline_attrs(cx, attrs, it.span, desc);

clippy_lints/src/mut_key.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ impl_lint_pass!(MutableKeyType<'_> => [ MUTABLE_KEY_TYPE ]);
7676

7777
impl<'tcx> LateLintPass<'tcx> for MutableKeyType<'tcx> {
7878
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::Item<'tcx>) {
79-
if let hir::ItemKind::Fn(ref sig, ..) = item.kind {
79+
if let hir::ItemKind::Fn { ref sig, .. } = item.kind {
8080
self.check_sig(cx, item.owner_id.def_id, sig.decl);
8181
}
8282
}

clippy_lints/src/no_effect.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ impl NoEffect {
144144
|diag| {
145145
for parent in cx.tcx.hir().parent_iter(stmt.hir_id) {
146146
if let Node::Item(item) = parent.1
147-
&& let ItemKind::Fn(..) = item.kind
147+
&& let ItemKind::Fn{ .. } = item.kind
148148
&& let Node::Block(block) = cx.tcx.parent_hir_node(stmt.hir_id)
149149
&& let [.., final_stmt] = block.stmts
150150
&& final_stmt.hir_id == stmt.hir_id

clippy_lints/src/no_mangle_with_rust_abi.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ declare_lint_pass!(NoMangleWithRustAbi => [NO_MANGLE_WITH_RUST_ABI]);
3737

3838
impl<'tcx> LateLintPass<'tcx> for NoMangleWithRustAbi {
3939
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'tcx>) {
40-
if let ItemKind::Fn(fn_sig, _, _) = &item.kind {
40+
if let ItemKind::Fn { sig: fn_sig, .. } = &item.kind {
4141
let attrs = cx.tcx.hir().attrs(item.hir_id());
4242
let mut app = Applicability::MaybeIncorrect;
4343
let fn_snippet = snippet_with_applicability(cx, fn_sig.span.with_hi(item.ident.span.lo()), "..", &mut app);

clippy_lints/src/ptr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ impl<'tcx> LateLintPass<'tcx> for Ptr {
189189
let mut parents = hir.parent_iter(body.value.hir_id);
190190
let (item_id, sig, is_trait_item) = match parents.next() {
191191
Some((_, Node::Item(i))) => {
192-
if let ItemKind::Fn(sig, ..) = &i.kind {
192+
if let ItemKind::Fn { sig, .. } = &i.kind {
193193
(i.owner_id, sig, false)
194194
} else {
195195
return;

clippy_lints/src/returns.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ impl<'tcx> LateLintPass<'tcx> for Return {
204204

205205
// Ensure this is not the final stmt, otherwise removing it would cause a compile error
206206
&& let OwnerNode::Item(item) = cx.tcx.hir_owner_node(cx.tcx.hir().get_parent_item(expr.hir_id))
207-
&& let ItemKind::Fn(_, _, body) = item.kind
207+
&& let ItemKind::Fn { body, .. } = item.kind
208208
&& let block = cx.tcx.hir().body(body).value
209209
&& let ExprKind::Block(block, _) = block.kind
210210
&& !is_inside_let_else(cx.tcx, expr)

clippy_lints/src/unnecessary_box_returns.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,9 @@ impl LateLintPass<'_> for UnnecessaryBoxReturns {
130130
}
131131

132132
fn check_item(&mut self, cx: &LateContext<'_>, item: &Item<'_>) {
133-
let ItemKind::Fn(signature, ..) = &item.kind else {
133+
let ItemKind::Fn { sig, .. } = &item.kind else {
134134
return;
135135
};
136-
self.check_fn_item(cx, signature.decl, item.owner_id.def_id, item.ident.name);
136+
self.check_fn_item(cx, sig.decl, item.owner_id.def_id, item.ident.name);
137137
}
138138
}

clippy_utils/src/check_proc_macro.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ fn item_search_pat(item: &Item<'_>) -> (Pat, Pat) {
245245
ItemKind::ExternCrate(_) => (Pat::Str("extern"), Pat::Str(";")),
246246
ItemKind::Static(..) => (Pat::Str("static"), Pat::Str(";")),
247247
ItemKind::Const(..) => (Pat::Str("const"), Pat::Str(";")),
248-
ItemKind::Fn(sig, ..) => (fn_header_search_pat(sig.header), Pat::Str("")),
248+
ItemKind::Fn { sig, .. } => (fn_header_search_pat(sig.header), Pat::Str("")),
249249
ItemKind::ForeignMod { .. } => (Pat::Str("extern"), Pat::Str("}")),
250250
ItemKind::TyAlias(..) => (Pat::Str("type"), Pat::Str(";")),
251251
ItemKind::Enum(..) => (Pat::Str("enum"), Pat::Str("}")),

clippy_utils/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1397,7 +1397,7 @@ pub fn get_enclosing_block<'tcx>(cx: &LateContext<'tcx>, hir_id: HirId) -> Optio
13971397
enclosing_node.and_then(|node| match node {
13981398
Node::Block(block) => Some(block),
13991399
Node::Item(&Item {
1400-
kind: ItemKind::Fn(_, _, eid),
1400+
kind: ItemKind::Fn { body: eid, .. },
14011401
..
14021402
})
14031403
| Node::ImplItem(&ImplItem {
@@ -2565,7 +2565,7 @@ pub fn is_in_test_function(tcx: TyCtxt<'_>, id: HirId) -> bool {
25652565
// function scope
25662566
.any(|(_id, node)| {
25672567
if let Node::Item(item) = node {
2568-
if let ItemKind::Fn(_, _, _) = item.kind {
2568+
if let ItemKind::Fn { .. } = item.kind {
25692569
// Note that we have sorted the item names in the visitor,
25702570
// so the binary_search gets the same as `contains`, but faster.
25712571
return names.binary_search(&item.ident.name).is_ok();
@@ -2722,7 +2722,7 @@ impl<'tcx> ExprUseCtxt<'tcx> {
27222722
}) => ExprUseNode::ConstStatic(owner_id),
27232723

27242724
Node::Item(&Item {
2725-
kind: ItemKind::Fn(..),
2725+
kind: ItemKind::Fn { .. },
27262726
owner_id,
27272727
..
27282728
})

0 commit comments

Comments
 (0)