Skip to content

Commit 7bb54d9

Browse files
authored
Rustup (#14539)
r? @ghost changelog: none
2 parents a2251a8 + c97bd74 commit 7bb54d9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+288
-851
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.87"
4+
version = "0.1.88"
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.87"
4+
version = "0.1.88"
55
# end autogenerated version
66
edition = "2024"
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.87"
4+
version = "0.1.88"
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/attrs/duplicated_attributes.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,14 @@ fn check_duplicated_attr(
3636
}
3737
let Some(ident) = attr.ident() else { return };
3838
let name = ident.name;
39-
if name == sym::doc || name == sym::cfg_attr || name == sym::rustc_on_unimplemented || name == sym::reason {
39+
if name == sym::doc || name == sym::cfg_attr_trace || name == sym::rustc_on_unimplemented || name == sym::reason {
4040
// FIXME: Would be nice to handle `cfg_attr` as well. Only problem is to check that cfg
4141
// conditions are the same.
4242
// `#[rustc_on_unimplemented]` contains duplicated subattributes, that's expected.
4343
return;
4444
}
4545
if let Some(direct_parent) = parent.last()
46-
&& ["cfg", "cfg_attr"].contains(&direct_parent.as_str())
46+
&& direct_parent == sym::cfg_trace.as_str()
4747
&& [sym::all, sym::not, sym::any].contains(&name)
4848
{
4949
// FIXME: We don't correctly check `cfg`s for now, so if it's more complex than just a one

clippy_lints/src/casts/unnecessary_cast.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ pub(super) fn check<'tcx>(
143143

144144
if cast_from.kind() == cast_to.kind() && !expr.span.in_external_macro(cx.sess().source_map()) {
145145
if let Some(id) = path_to_local(cast_expr)
146-
&& !cx.tcx.hir().span(id).eq_ctxt(cast_expr.span)
146+
&& !cx.tcx.hir_span(id).eq_ctxt(cast_expr.span)
147147
{
148148
// Binding context is different than the identifiers context.
149149
// Weird macro wizardry could be involved here.

clippy_lints/src/cfg_not_test.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ declare_lint_pass!(CfgNotTest => [CFG_NOT_TEST]);
3232

3333
impl EarlyLintPass for CfgNotTest {
3434
fn check_attribute(&mut self, cx: &EarlyContext<'_>, attr: &rustc_ast::Attribute) {
35-
if attr.has_name(rustc_span::sym::cfg) && contains_not_test(attr.meta_item_list().as_deref(), false) {
35+
if attr.has_name(rustc_span::sym::cfg_trace) && contains_not_test(attr.meta_item_list().as_deref(), false) {
3636
span_lint_and_then(
3737
cx,
3838
CFG_NOT_TEST,

clippy_lints/src/crate_in_macro_def.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ declare_lint_pass!(CrateInMacroDef => [CRATE_IN_MACRO_DEF]);
5353

5454
impl EarlyLintPass for CrateInMacroDef {
5555
fn check_item(&mut self, cx: &EarlyContext<'_>, item: &Item) {
56-
if let ItemKind::MacroDef(macro_def) = &item.kind
56+
if let ItemKind::MacroDef(_, macro_def) = &item.kind
5757
&& item.attrs.iter().any(is_macro_export)
5858
&& let Some(span) = contains_unhygienic_crate_reference(&macro_def.body.tokens)
5959
{

clippy_lints/src/declared_lints.rs

-1
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,6 @@ pub static LINTS: &[&crate::LintInfo] = &[
641641
crate::precedence::PRECEDENCE_INFO,
642642
crate::precedence::PRECEDENCE_BITS_INFO,
643643
crate::ptr::CMP_NULL_INFO,
644-
crate::ptr::INVALID_NULL_PTR_USAGE_INFO,
645644
crate::ptr::MUT_FROM_REF_INFO,
646645
crate::ptr::PTR_ARG_INFO,
647646
crate::ptr::PTR_EQ_INFO,

clippy_lints/src/default.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ impl<'tcx> LateLintPass<'tcx> for Default {
134134
&& let ty::Adt(adt, args) = *binding_type.kind()
135135
&& adt.is_struct()
136136
&& let variant = adt.non_enum_variant()
137-
&& (adt.did().is_local() || !variant.is_field_list_non_exhaustive())
137+
&& !variant.field_list_has_applicable_non_exhaustive()
138138
&& let module_did = cx.tcx.parent_module(stmt.hir_id)
139139
&& variant
140140
.fields

clippy_lints/src/deprecated_lints.rs

+2
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@ declare_with_version! { RENAMED(RENAMED_VERSION): &[(&str, &str)] = &[
131131
("clippy::clone_double_ref", "suspicious_double_ref_op"),
132132
#[clippy::version = ""]
133133
("clippy::cmp_nan", "invalid_nan_comparisons"),
134+
#[clippy::version = "CURRENT_RUSTC_VERSION"]
135+
("clippy::invalid_null_ptr_usage", "invalid_null_arguments"),
134136
#[clippy::version = "1.86.0"]
135137
("clippy::double_neg", "double_negations"),
136138
#[clippy::version = ""]

clippy_lints/src/derive.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ fn check_hash_peq<'tcx>(
254254
|diag| {
255255
if let Some(local_def_id) = impl_id.as_local() {
256256
let hir_id = cx.tcx.local_def_id_to_hir_id(local_def_id);
257-
diag.span_note(cx.tcx.hir().span(hir_id), "`PartialEq` implemented here");
257+
diag.span_note(cx.tcx.hir_span(hir_id), "`PartialEq` implemented here");
258258
}
259259
},
260260
);
@@ -298,7 +298,7 @@ fn check_ord_partial_ord<'tcx>(
298298
span_lint_and_then(cx, DERIVE_ORD_XOR_PARTIAL_ORD, span, mess, |diag| {
299299
if let Some(local_def_id) = impl_id.as_local() {
300300
let hir_id = cx.tcx.local_def_id_to_hir_id(local_def_id);
301-
diag.span_note(cx.tcx.hir().span(hir_id), "`PartialOrd` implemented here");
301+
diag.span_note(cx.tcx.hir_span(hir_id), "`PartialOrd` implemented here");
302302
}
303303
});
304304
}
@@ -324,11 +324,9 @@ fn check_copy_clone<'tcx>(cx: &LateContext<'tcx>, item: &Item<'_>, trait_ref: &h
324324
// there's a Copy impl for any instance of the adt.
325325
if !is_copy(cx, ty) {
326326
if ty_subs.non_erasable_generics().next().is_some() {
327-
let has_copy_impl = cx.tcx.all_local_trait_impls(()).get(&copy_id).is_some_and(|impls| {
328-
impls.iter().any(|&id| {
329-
matches!(cx.tcx.type_of(id).instantiate_identity().kind(), ty::Adt(adt, _)
327+
let has_copy_impl = cx.tcx.local_trait_impls(copy_id).iter().any(|&id| {
328+
matches!(cx.tcx.type_of(id).instantiate_identity().kind(), ty::Adt(adt, _)
330329
if ty_adt.did() == adt.did())
331-
})
332330
});
333331
if !has_copy_impl {
334332
return;

clippy_lints/src/doc/needless_doctest_main.rs

+11-8
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,16 @@ use rustc_parse::parser::ForceCollect;
1313
use rustc_session::parse::ParseSess;
1414
use rustc_span::edition::Edition;
1515
use rustc_span::source_map::{FilePathMapping, SourceMap};
16-
use rustc_span::{FileName, Pos, sym};
16+
use rustc_span::{FileName, Ident, Pos, sym};
1717

1818
use super::Fragments;
1919

20-
fn get_test_spans(item: &Item, test_attr_spans: &mut Vec<Range<usize>>) {
20+
fn get_test_spans(item: &Item, ident: Ident, test_attr_spans: &mut Vec<Range<usize>>) {
2121
test_attr_spans.extend(
2222
item.attrs
2323
.iter()
2424
.find(|attr| attr.has_name(sym::test))
25-
.map(|attr| attr.span.lo().to_usize()..item.ident.span.hi().to_usize()),
25+
.map(|attr| attr.span.lo().to_usize()..ident.span.hi().to_usize()),
2626
);
2727
}
2828

@@ -64,10 +64,13 @@ pub fn check(
6464
match parser.parse_item(ForceCollect::No) {
6565
Ok(Some(item)) => match &item.kind {
6666
ItemKind::Fn(box Fn {
67-
sig, body: Some(block), ..
68-
}) if item.ident.name == sym::main => {
67+
ident,
68+
sig,
69+
body: Some(block),
70+
..
71+
}) if ident.name == sym::main => {
6972
if !ignore {
70-
get_test_spans(&item, &mut test_attr_spans);
73+
get_test_spans(&item, *ident, &mut test_attr_spans);
7174
}
7275
let is_async = matches!(sig.header.coroutine_kind, Some(CoroutineKind::Async { .. }));
7376
let returns_nothing = match &sig.decl.output {
@@ -85,10 +88,10 @@ pub fn check(
8588
}
8689
},
8790
// Another function was found; this case is ignored for needless_doctest_main
88-
ItemKind::Fn(box Fn { .. }) => {
91+
ItemKind::Fn(fn_) => {
8992
eligible = false;
9093
if !ignore {
91-
get_test_spans(&item, &mut test_attr_spans);
94+
get_test_spans(&item, fn_.ident, &mut test_attr_spans);
9295
}
9396
},
9497
// Tests with one of these items are ignored

clippy_lints/src/duplicate_mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ impl_lint_pass!(DuplicateMod => [DUPLICATE_MOD]);
6363

6464
impl EarlyLintPass for DuplicateMod {
6565
fn check_item(&mut self, cx: &EarlyContext<'_>, item: &Item) {
66-
if let ItemKind::Mod(_, ModKind::Loaded(_, Inline::No, mod_spans, _)) = &item.kind
66+
if let ItemKind::Mod(_, _, ModKind::Loaded(_, Inline::No, mod_spans, _)) = &item.kind
6767
&& let FileName::Real(real) = cx.sess().source_map().span_to_filename(mod_spans.inner_span)
6868
&& let Some(local_path) = real.into_local_path()
6969
&& let Ok(absolute_path) = local_path.canonicalize()

clippy_lints/src/empty_line_after.rs

+10-9
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ use rustc_errors::{Applicability, Diag, SuggestionStyle};
88
use rustc_lexer::TokenKind;
99
use rustc_lint::{EarlyContext, EarlyLintPass, LintContext};
1010
use rustc_session::impl_lint_pass;
11-
use rustc_span::symbol::kw;
12-
use rustc_span::{BytePos, ExpnKind, Ident, InnerSpan, Span, SpanData, Symbol};
11+
use rustc_span::{BytePos, ExpnKind, Ident, InnerSpan, Span, SpanData, Symbol, kw};
1312

1413
declare_clippy_lint! {
1514
/// ### What it does
@@ -375,21 +374,23 @@ impl EmptyLineAfter {
375374
&mut self,
376375
cx: &EarlyContext<'_>,
377376
kind: &ItemKind,
378-
ident: &Ident,
377+
ident: Option<Ident>,
379378
span: Span,
380379
attrs: &[Attribute],
381380
id: NodeId,
382381
) {
383382
self.items.push(ItemInfo {
384383
kind: kind.descr(),
385-
name: ident.name,
386-
span: if span.contains(ident.span) {
384+
// FIXME: this `sym::empty` can be leaked, see
385+
// https://github.com/rust-lang/rust/pull/138740#discussion_r2021979899
386+
name: if let Some(ident) = ident { ident.name } else { kw::Empty },
387+
span: if let Some(ident) = ident {
387388
span.with_hi(ident.span.hi())
388389
} else {
389390
span.with_hi(span.lo())
390391
},
391392
mod_items: match kind {
392-
ItemKind::Mod(_, ModKind::Loaded(items, _, _, _)) => items
393+
ItemKind::Mod(_, _, ModKind::Loaded(items, _, _, _)) => items
393394
.iter()
394395
.filter(|i| !matches!(i.span.ctxt().outer_expn_data().kind, ExpnKind::AstPass(_)))
395396
.map(|i| i.id)
@@ -471,7 +472,7 @@ impl EarlyLintPass for EmptyLineAfter {
471472
self.check_item_kind(
472473
cx,
473474
&item.kind.clone().into(),
474-
&item.ident,
475+
item.kind.ident(),
475476
item.span,
476477
&item.attrs,
477478
item.id,
@@ -482,14 +483,14 @@ impl EarlyLintPass for EmptyLineAfter {
482483
self.check_item_kind(
483484
cx,
484485
&item.kind.clone().into(),
485-
&item.ident,
486+
item.kind.ident(),
486487
item.span,
487488
&item.attrs,
488489
item.id,
489490
);
490491
}
491492

492493
fn check_item(&mut self, cx: &EarlyContext<'_>, item: &Item) {
493-
self.check_item_kind(cx, &item.kind, &item.ident, item.span, &item.attrs, item.id);
494+
self.check_item_kind(cx, &item.kind, item.kind.ident(), item.span, &item.attrs, item.id);
494495
}
495496
}

clippy_lints/src/empty_with_brackets.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,9 @@ declare_lint_pass!(EmptyWithBrackets => [EMPTY_STRUCTS_WITH_BRACKETS, EMPTY_ENUM
7474

7575
impl EarlyLintPass for EmptyWithBrackets {
7676
fn check_item(&mut self, cx: &EarlyContext<'_>, item: &Item) {
77-
let span_after_ident = item.span.with_lo(item.ident.span.hi());
78-
79-
if let ItemKind::Struct(var_data, _) = &item.kind
77+
if let ItemKind::Struct(ident, var_data, _) = &item.kind
8078
&& has_brackets(var_data)
79+
&& let span_after_ident = item.span.with_lo(ident.span.hi())
8180
&& has_no_fields(cx, var_data, span_after_ident)
8281
{
8382
span_lint_and_then(

clippy_lints/src/escape.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ impl<'tcx> LateLintPass<'tcx> for BoxedLocal {
119119
cx,
120120
BOXED_LOCAL,
121121
node,
122-
cx.tcx.hir().span(node),
122+
cx.tcx.hir_span(node),
123123
"local variable doesn't need to be boxed here",
124124
);
125125
}

clippy_lints/src/field_scoped_visibility_modifiers.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ declare_lint_pass!(FieldScopedVisibilityModifiers => [FIELD_SCOPED_VISIBILITY_MO
5151

5252
impl EarlyLintPass for FieldScopedVisibilityModifiers {
5353
fn check_item(&mut self, cx: &EarlyContext<'_>, item: &Item) {
54-
let ItemKind::Struct(ref st, _) = item.kind else {
54+
let ItemKind::Struct(_, ref st, _) = item.kind else {
5555
return;
5656
};
5757
for field in st.fields() {

clippy_lints/src/functions/renamed_function_params.rs

+22-21
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use rustc_hir::hir_id::OwnerId;
55
use rustc_hir::{Impl, ImplItem, ImplItemKind, ImplItemRef, ItemKind, Node, TraitRef};
66
use rustc_lint::LateContext;
77
use rustc_span::Span;
8-
use rustc_span::symbol::{Ident, Symbol, kw};
8+
use rustc_span::symbol::{Ident, kw};
99

1010
use super::RENAMED_FUNCTION_PARAMS;
1111

@@ -51,22 +51,31 @@ struct RenamedFnArgs(Vec<(Span, String)>);
5151
impl RenamedFnArgs {
5252
/// Comparing between an iterator of default names and one with current names,
5353
/// then collect the ones that got renamed.
54-
fn new<I, T>(default_names: &mut I, current_names: &mut T) -> Self
54+
fn new<I1, I2>(default_idents: &mut I1, current_idents: &mut I2) -> Self
5555
where
56-
I: Iterator<Item = Ident>,
57-
T: Iterator<Item = Ident>,
56+
I1: Iterator<Item = Option<Ident>>,
57+
I2: Iterator<Item = Option<Ident>>,
5858
{
5959
let mut renamed: Vec<(Span, String)> = vec![];
6060

61-
debug_assert!(default_names.size_hint() == current_names.size_hint());
62-
while let (Some(def_name), Some(cur_name)) = (default_names.next(), current_names.next()) {
63-
let current_name = cur_name.name;
64-
let default_name = def_name.name;
65-
if is_unused_or_empty_symbol(current_name) || is_unused_or_empty_symbol(default_name) {
66-
continue;
67-
}
68-
if current_name != default_name {
69-
renamed.push((cur_name.span, default_name.to_string()));
61+
debug_assert!(default_idents.size_hint() == current_idents.size_hint());
62+
while let (Some(default_ident), Some(current_ident)) = (default_idents.next(), current_idents.next()) {
63+
let has_name_to_check = |ident: Option<Ident>| {
64+
if let Some(ident) = ident
65+
&& ident.name != kw::Underscore
66+
&& !ident.name.as_str().starts_with('_')
67+
{
68+
Some(ident)
69+
} else {
70+
None
71+
}
72+
};
73+
74+
if let Some(default_ident) = has_name_to_check(default_ident)
75+
&& let Some(current_ident) = has_name_to_check(current_ident)
76+
&& default_ident.name != current_ident.name
77+
{
78+
renamed.push((current_ident.span, default_ident.to_string()));
7079
}
7180
}
7281

@@ -83,14 +92,6 @@ impl RenamedFnArgs {
8392
}
8493
}
8594

86-
fn is_unused_or_empty_symbol(symbol: Symbol) -> bool {
87-
// FIXME: `body_param_names` currently returning empty symbols for `wild` as well,
88-
// so we need to check if the symbol is empty first.
89-
// Therefore the check of whether it's equal to [`kw::Underscore`] has no use for now,
90-
// but it would be nice to keep it here just to be future-proof.
91-
symbol.is_empty() || symbol == kw::Underscore || symbol.as_str().starts_with('_')
92-
}
93-
9495
/// Get the [`trait_item_def_id`](ImplItemRef::trait_item_def_id) of a relevant impl item.
9596
fn trait_item_def_id_of_impl(items: &[ImplItemRef], target: OwnerId) -> Option<DefId> {
9697
items.iter().find_map(|item| {

clippy_lints/src/index_refutable_slice.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ impl<'tcx> Visitor<'tcx> for SliceIndexLintingVisitor<'_, 'tcx> {
248248
{
249249
use_info
250250
.index_use
251-
.push((index_value, cx.tcx.hir().span(parent_expr.hir_id)));
251+
.push((index_value, cx.tcx.hir_span(parent_expr.hir_id)));
252252
return;
253253
}
254254

clippy_lints/src/lifetimes.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ fn check_fn_inner<'tcx>(
189189
cx: &LateContext<'tcx>,
190190
sig: &'tcx FnSig<'_>,
191191
body: Option<BodyId>,
192-
trait_sig: Option<&[Ident]>,
192+
trait_sig: Option<&[Option<Ident>]>,
193193
generics: &'tcx Generics<'_>,
194194
span: Span,
195195
report_extra_lifetimes: bool,
@@ -264,7 +264,7 @@ fn could_use_elision<'tcx>(
264264
cx: &LateContext<'tcx>,
265265
func: &'tcx FnDecl<'_>,
266266
body: Option<BodyId>,
267-
trait_sig: Option<&[Ident]>,
267+
trait_sig: Option<&[Option<Ident>]>,
268268
named_generics: &'tcx [GenericParam<'_>],
269269
msrv: Msrv,
270270
) -> Option<(Vec<LocalDefId>, Vec<Lifetime>)> {
@@ -300,8 +300,8 @@ fn could_use_elision<'tcx>(
300300
let input_lts = input_visitor.lts;
301301
let output_lts = output_visitor.lts;
302302

303-
if let Some(trait_sig) = trait_sig
304-
&& non_elidable_self_type(cx, func, trait_sig.first().copied(), msrv)
303+
if let Some(&[trait_sig]) = trait_sig
304+
&& non_elidable_self_type(cx, func, trait_sig, msrv)
305305
{
306306
return None;
307307
}

0 commit comments

Comments
 (0)