Skip to content

Commit 19e305b

Browse files
authored
r? @ghost changelog: none
2 parents 894e87c + 663892b commit 19e305b

36 files changed

+86
-46
lines changed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "clippy"
33
# begin autogenerated version
4-
version = "0.1.85"
4+
version = "0.1.86"
55
# end autogenerated version
66
description = "A bunch of helpful lints to avoid common pitfalls in Rust"
77
repository = "https://github.com/rust-lang/rust-clippy"

clippy_config/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "clippy_config"
33
# begin autogenerated version
4-
version = "0.1.85"
4+
version = "0.1.86"
55
# end autogenerated version
66
edition = "2021"
77
publish = false

clippy_lints/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "clippy_lints"
33
# begin autogenerated version
4-
version = "0.1.85"
4+
version = "0.1.86"
55
# end autogenerated version
66
description = "A bunch of helpful lints to avoid common pitfalls in Rust"
77
repository = "https://github.com/rust-lang/rust-clippy"

clippy_lints/src/arbitrary_source_item_ordering.rs

+1-1
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

+1-1
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

+1-1
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

+1-1
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/equatable_if_let.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ fn unary_pattern(pat: &Pat<'_>) -> bool {
5555
| PatKind::Err(_) => false,
5656
PatKind::Struct(_, a, etc) => !etc && a.iter().all(|x| unary_pattern(x.pat)),
5757
PatKind::Tuple(a, etc) | PatKind::TupleStruct(_, a, etc) => etc.as_opt_usize().is_none() && array_rec(a),
58-
PatKind::Ref(x, _) | PatKind::Box(x) | PatKind::Deref(x) => unary_pattern(x),
58+
PatKind::Ref(x, _) | PatKind::Box(x) | PatKind::Deref(x) | PatKind::Guard(x, _) => unary_pattern(x),
5959
PatKind::Path(_) | PatKind::Lit(_) => true,
6060
}
6161
}

clippy_lints/src/exit.rs

+1-1
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

+5-1
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

+6-1
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

+1-1
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

+6-1
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

+7-1
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

+5-1
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/match_same_arms.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -254,9 +254,11 @@ impl<'a> NormalizedPat<'a> {
254254
fn from_pat(cx: &LateContext<'_>, arena: &'a DroplessArena, pat: &'a Pat<'_>) -> Self {
255255
match pat.kind {
256256
PatKind::Wild | PatKind::Binding(.., None) => Self::Wild,
257-
PatKind::Binding(.., Some(pat)) | PatKind::Box(pat) | PatKind::Deref(pat) | PatKind::Ref(pat, _) => {
258-
Self::from_pat(cx, arena, pat)
259-
},
257+
PatKind::Binding(.., Some(pat))
258+
| PatKind::Box(pat)
259+
| PatKind::Deref(pat)
260+
| PatKind::Ref(pat, _)
261+
| PatKind::Guard(pat, _) => Self::from_pat(cx, arena, pat),
260262
PatKind::Never => Self::Never,
261263
PatKind::Struct(ref path, fields, _) => {
262264
let fields =

clippy_lints/src/matches/needless_match.rs

+1-1
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/matches/single_match.rs

+4
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,10 @@ impl<'a> PatState<'a> {
343343
matches!(self, Self::Wild)
344344
},
345345

346+
PatKind::Guard(..) => {
347+
matches!(self, Self::Wild)
348+
},
349+
346350
// Patterns for things which can only contain a single sub-pattern.
347351
PatKind::Binding(_, _, _, Some(pat)) | PatKind::Ref(pat, _) | PatKind::Box(pat) | PatKind::Deref(pat) => {
348352
self.add_pat(cx, pat)

clippy_lints/src/methods/unnecessary_to_owned.rs

+1-1
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(..) => {},
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

+1-1
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

+1-1
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

+1-1
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

+1-1
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

+1-1
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

+1-1
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

+1-1
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

+2-2
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_lints/src/utils/author.rs

+6
Original file line numberDiff line numberDiff line change
@@ -712,6 +712,12 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> {
712712
kind!("Ref({pat}, Mutability::{muta:?})");
713713
self.pat(pat);
714714
},
715+
PatKind::Guard(pat, cond) => {
716+
bind!(self, pat, cond);
717+
kind!("Guard({pat}, {cond})");
718+
self.pat(pat);
719+
self.expr(cond);
720+
},
715721
PatKind::Lit(lit_expr) => {
716722
bind!(self, lit_expr);
717723
kind!("Lit({lit_expr})");

clippy_utils/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "clippy_utils"
33
# begin autogenerated version
4-
version = "0.1.85"
4+
version = "0.1.86"
55
# end autogenerated version
66
edition = "2021"
77
description = "Helpful tools for writing lints, provided as they are used in Clippy"

clippy_utils/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ This crate is only guaranteed to build with this `nightly` toolchain:
88

99
<!-- begin autogenerated nightly -->
1010
```
11-
nightly-2024-12-26
11+
nightly-2025-01-09
1212
```
1313
<!-- end autogenerated nightly -->
1414

clippy_utils/src/check_proc_macro.rs

+1-1
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/hir_utils.rs

+4
Original file line numberDiff line numberDiff line change
@@ -1104,6 +1104,10 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> {
11041104
self.hash_pat(pat);
11051105
std::mem::discriminant(&mu).hash(&mut self.s);
11061106
},
1107+
PatKind::Guard(pat, guard) => {
1108+
self.hash_pat(pat);
1109+
self.hash_expr(guard);
1110+
},
11071111
PatKind::Slice(l, m, r) => {
11081112
for pat in l {
11091113
self.hash_pat(pat);

clippy_utils/src/lib.rs

+4-4
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 {
@@ -1776,7 +1776,7 @@ pub fn is_refutable(cx: &LateContext<'_>, pat: &Pat<'_>) -> bool {
17761776
},
17771777
}
17781778
},
1779-
PatKind::Lit(..) | PatKind::Range(..) | PatKind::Err(_) | PatKind::Deref(_) => true,
1779+
PatKind::Lit(..) | PatKind::Range(..) | PatKind::Err(_) | PatKind::Deref(_) | PatKind::Guard(..) => true,
17801780
}
17811781
}
17821782

@@ -2564,7 +2564,7 @@ pub fn is_in_test_function(tcx: TyCtxt<'_>, id: HirId) -> bool {
25642564
// function scope
25652565
.any(|(_id, node)| {
25662566
if let Node::Item(item) = node {
2567-
if let ItemKind::Fn(_, _, _) = item.kind {
2567+
if let ItemKind::Fn { .. } = item.kind {
25682568
// Note that we have sorted the item names in the visitor,
25692569
// so the binary_search gets the same as `contains`, but faster.
25702570
return names.binary_search(&item.ident.name).is_ok();
@@ -2721,7 +2721,7 @@ impl<'tcx> ExprUseCtxt<'tcx> {
27212721
}) => ExprUseNode::ConstStatic(owner_id),
27222722

27232723
Node::Item(&Item {
2724-
kind: ItemKind::Fn(..),
2724+
kind: ItemKind::Fn { .. },
27252725
owner_id,
27262726
..
27272727
})

rust-toolchain

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[toolchain]
22
# begin autogenerated nightly
3-
channel = "nightly-2024-12-26"
3+
channel = "nightly-2025-01-09"
44
# end autogenerated nightly
55
components = ["cargo", "llvm-tools", "rust-src", "rust-std", "rustc", "rustc-dev", "rustfmt"]
66
profile = "minimal"

tests/ui-internal/custom_ice_message.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
thread '<unnamed>' panicked at clippy_lints/src/utils/internal_lints/produce_ice.rs:
23
Would you like some help with that?
34
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

0 commit comments

Comments
 (0)