Skip to content

Commit a109190

Browse files
committed
Auto merge of #13561 - flip1995:rustup, r=flip1995
Rustup r? `@ghost` changelog: none
2 parents dae1be9 + 4b5d189 commit a109190

Some content is hidden

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

53 files changed

+138
-156
lines changed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "clippy"
3-
version = "0.1.83"
3+
version = "0.1.84"
44
description = "A bunch of helpful lints to avoid common pitfalls in Rust"
55
repository = "https://github.com/rust-lang/rust-clippy"
66
readme = "README.md"

clippy_config/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "clippy_config"
3-
version = "0.1.83"
3+
version = "0.1.84"
44
edition = "2021"
55

66
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

clippy_lints/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "clippy_lints"
3-
version = "0.1.83"
3+
version = "0.1.84"
44
description = "A bunch of helpful lints to avoid common pitfalls in Rust"
55
repository = "https://github.com/rust-lang/rust-clippy"
66
readme = "README.md"

clippy_lints/src/attrs/allow_attributes_without_reason.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
use super::{ALLOW_ATTRIBUTES_WITHOUT_REASON, Attribute};
22
use clippy_utils::diagnostics::span_lint_and_then;
33
use clippy_utils::is_from_proc_macro;
4-
use rustc_ast::{MetaItemKind, NestedMetaItem};
4+
use rustc_ast::{MetaItemInner, MetaItemKind};
55
use rustc_lint::{LateContext, LintContext};
66
use rustc_middle::lint::in_external_macro;
77
use rustc_span::sym;
88
use rustc_span::symbol::Symbol;
99

10-
pub(super) fn check<'cx>(cx: &LateContext<'cx>, name: Symbol, items: &[NestedMetaItem], attr: &'cx Attribute) {
10+
pub(super) fn check<'cx>(cx: &LateContext<'cx>, name: Symbol, items: &[MetaItemInner], attr: &'cx Attribute) {
1111
// Check if the reason is present
12-
if let Some(item) = items.last().and_then(NestedMetaItem::meta_item)
12+
if let Some(item) = items.last().and_then(MetaItemInner::meta_item)
1313
&& let MetaItemKind::NameValue(_) = &item.kind
1414
&& item.path == sym::reason
1515
{

clippy_lints/src/attrs/blanket_clippy_restriction_lints.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
use super::BLANKET_CLIPPY_RESTRICTION_LINTS;
22
use super::utils::extract_clippy_lint;
33
use clippy_utils::diagnostics::{span_lint_and_help, span_lint_and_then};
4-
use rustc_ast::NestedMetaItem;
4+
use rustc_ast::MetaItemInner;
55
use rustc_lint::{LateContext, Level, LintContext};
66
use rustc_span::symbol::Symbol;
77
use rustc_span::{DUMMY_SP, sym};
88

9-
pub(super) fn check(cx: &LateContext<'_>, name: Symbol, items: &[NestedMetaItem]) {
9+
pub(super) fn check(cx: &LateContext<'_>, name: Symbol, items: &[MetaItemInner]) {
1010
for lint in items {
1111
if let Some(lint_name) = extract_clippy_lint(lint) {
1212
if lint_name.as_str() == "restriction" && name != sym::allow {

clippy_lints/src/attrs/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ mod utils;
1414

1515
use clippy_config::Conf;
1616
use clippy_config::msrvs::{self, Msrv};
17-
use rustc_ast::{Attribute, MetaItemKind, NestedMetaItem};
17+
use rustc_ast::{Attribute, MetaItemInner, MetaItemKind};
1818
use rustc_hir::{ImplItem, Item, ItemKind, TraitItem};
1919
use rustc_lint::{EarlyContext, EarlyLintPass, LateContext, LateLintPass};
2020
use rustc_session::impl_lint_pass;
@@ -456,7 +456,7 @@ impl<'tcx> LateLintPass<'tcx> for Attributes {
456456
return;
457457
}
458458
for item in items {
459-
if let NestedMetaItem::MetaItem(mi) = &item
459+
if let MetaItemInner::MetaItem(mi) = &item
460460
&& let MetaItemKind::NameValue(lit) = &mi.kind
461461
&& mi.has_name(sym::since)
462462
{

clippy_lints/src/attrs/non_minimal_cfg.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use super::{Attribute, NON_MINIMAL_CFG};
22
use clippy_utils::diagnostics::span_lint_and_then;
33
use clippy_utils::source::SpanRangeExt;
4-
use rustc_ast::{MetaItemKind, NestedMetaItem};
4+
use rustc_ast::{MetaItemInner, MetaItemKind};
55
use rustc_errors::Applicability;
66
use rustc_lint::EarlyContext;
77
use rustc_span::sym;
@@ -14,9 +14,9 @@ pub(super) fn check(cx: &EarlyContext<'_>, attr: &Attribute) {
1414
}
1515
}
1616

17-
fn check_nested_cfg(cx: &EarlyContext<'_>, items: &[NestedMetaItem]) {
17+
fn check_nested_cfg(cx: &EarlyContext<'_>, items: &[MetaItemInner]) {
1818
for item in items {
19-
if let NestedMetaItem::MetaItem(meta) = item {
19+
if let MetaItemInner::MetaItem(meta) = item {
2020
if !meta.has_name(sym::any) && !meta.has_name(sym::all) {
2121
continue;
2222
}

clippy_lints/src/attrs/useless_attribute.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use super::utils::{extract_clippy_lint, is_lint_level, is_word};
22
use super::{Attribute, USELESS_ATTRIBUTE};
33
use clippy_utils::diagnostics::span_lint_and_then;
44
use clippy_utils::source::{SpanRangeExt, first_line_of_span};
5-
use rustc_ast::NestedMetaItem;
5+
use rustc_ast::MetaItemInner;
66
use rustc_errors::Applicability;
77
use rustc_hir::{Item, ItemKind};
88
use rustc_lint::{LateContext, LintContext};
@@ -21,7 +21,7 @@ pub(super) fn check(cx: &LateContext<'_>, item: &Item<'_>, attrs: &[Attribute])
2121
for lint in lint_list {
2222
match item.kind {
2323
ItemKind::Use(..) => {
24-
if let NestedMetaItem::MetaItem(meta_item) = lint
24+
if let MetaItemInner::MetaItem(meta_item) = lint
2525
&& meta_item.is_word()
2626
&& let Some(ident) = meta_item.ident()
2727
&& matches!(

clippy_lints/src/attrs/utils.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use clippy_utils::macros::{is_panic, macro_backtrace};
2-
use rustc_ast::{AttrId, NestedMetaItem};
2+
use rustc_ast::{AttrId, MetaItemInner};
33
use rustc_hir::{
44
Block, Expr, ExprKind, ImplItem, ImplItemKind, Item, ItemKind, StmtKind, TraitFn, TraitItem, TraitItemKind,
55
};
@@ -8,8 +8,8 @@ use rustc_middle::ty;
88
use rustc_span::sym;
99
use rustc_span::symbol::Symbol;
1010

11-
pub(super) fn is_word(nmi: &NestedMetaItem, expected: Symbol) -> bool {
12-
if let NestedMetaItem::MetaItem(mi) = &nmi {
11+
pub(super) fn is_word(nmi: &MetaItemInner, expected: Symbol) -> bool {
12+
if let MetaItemInner::MetaItem(mi) = &nmi {
1313
mi.is_word() && mi.has_name(expected)
1414
} else {
1515
false
@@ -74,7 +74,7 @@ fn is_relevant_expr(cx: &LateContext<'_>, typeck_results: &ty::TypeckResults<'_>
7474
}
7575

7676
/// Returns the lint name if it is clippy lint.
77-
pub(super) fn extract_clippy_lint(lint: &NestedMetaItem) -> Option<Symbol> {
77+
pub(super) fn extract_clippy_lint(lint: &MetaItemInner) -> Option<Symbol> {
7878
if let Some(meta_item) = lint.meta_item()
7979
&& meta_item.path.segments.len() > 1
8080
&& let tool_name = meta_item.path.segments[0].ident

clippy_lints/src/cfg_not_test.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use clippy_utils::diagnostics::span_lint_and_then;
2-
use rustc_ast::NestedMetaItem;
2+
use rustc_ast::MetaItemInner;
33
use rustc_lint::{EarlyContext, EarlyLintPass};
44
use rustc_session::declare_lint_pass;
55

@@ -47,7 +47,7 @@ impl EarlyLintPass for CfgNotTest {
4747
}
4848
}
4949

50-
fn contains_not_test(list: Option<&[NestedMetaItem]>, not: bool) -> bool {
50+
fn contains_not_test(list: Option<&[MetaItemInner]>, not: bool) -> bool {
5151
list.is_some_and(|list| {
5252
list.iter().any(|item| {
5353
item.ident().is_some_and(|ident| match ident.name {

clippy_lints/src/extra_unused_type_parameters.rs

+1-7
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use rustc_errors::Applicability;
66
use rustc_hir::intravisit::{Visitor, walk_impl_item, walk_item, walk_param_bound, walk_ty};
77
use rustc_hir::{
88
BodyId, ExprKind, GenericBound, GenericParam, GenericParamKind, Generics, ImplItem, ImplItemKind, Item, ItemKind,
9-
PredicateOrigin, Ty, TyKind, WherePredicate,
9+
PredicateOrigin, Ty, WherePredicate,
1010
};
1111
use rustc_lint::{LateContext, LateLintPass, LintContext};
1212
use rustc_middle::hir::nested_filter;
@@ -199,12 +199,6 @@ impl<'tcx> Visitor<'tcx> for TypeWalker<'_, 'tcx> {
199199
fn visit_ty(&mut self, t: &'tcx Ty<'tcx>) {
200200
if let Some((def_id, _)) = t.peel_refs().as_generic_param() {
201201
self.ty_params.remove(&def_id);
202-
} else if let TyKind::OpaqueDef(id, _, _) = t.kind {
203-
// Explicitly walk OpaqueDef. Normally `walk_ty` would do the job, but it calls
204-
// `visit_nested_item`, which checks that `Self::NestedFilter::INTER` is set. We're
205-
// using `OnlyBodies`, so the check ends up failing and the type isn't fully walked.
206-
let item = self.nested_visit_map().item(id);
207-
walk_item(self, item);
208202
} else {
209203
walk_ty(self, t);
210204
}

clippy_lints/src/implied_bounds_in_impls.rs

+8-9
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ use clippy_utils::source::snippet;
33
use rustc_errors::{Applicability, SuggestionStyle};
44
use rustc_hir::def_id::DefId;
55
use rustc_hir::{
6-
AssocItemConstraint, GenericArg, GenericBound, GenericBounds, ItemKind, PredicateOrigin, TraitBoundModifier,
7-
TyKind, WherePredicate,
6+
AssocItemConstraint, GenericArg, GenericBound, GenericBounds, PredicateOrigin, TraitBoundModifier, TyKind,
7+
WherePredicate,
88
};
99
use rustc_hir_analysis::lower_ty;
1010
use rustc_lint::{LateContext, LateLintPass};
@@ -242,7 +242,8 @@ fn collect_supertrait_bounds<'tcx>(cx: &LateContext<'tcx>, bounds: GenericBounds
242242
bounds
243243
.iter()
244244
.filter_map(|bound| {
245-
if let GenericBound::Trait(poly_trait, TraitBoundModifier::None) = bound
245+
if let GenericBound::Trait(poly_trait) = bound
246+
&& let TraitBoundModifier::None = poly_trait.modifiers
246247
&& let [.., path] = poly_trait.trait_ref.path.segments
247248
&& poly_trait.bound_generic_params.is_empty()
248249
&& let Some(trait_def_id) = path.res.opt_def_id()
@@ -307,7 +308,8 @@ fn check<'tcx>(cx: &LateContext<'tcx>, bounds: GenericBounds<'tcx>) {
307308
// This involves some extra logic when generic arguments are present, since
308309
// simply comparing trait `DefId`s won't be enough. We also need to compare the generics.
309310
for (index, bound) in bounds.iter().enumerate() {
310-
if let GenericBound::Trait(poly_trait, TraitBoundModifier::None) = bound
311+
if let GenericBound::Trait(poly_trait) = bound
312+
&& let TraitBoundModifier::None = poly_trait.modifiers
311313
&& let [.., path] = poly_trait.trait_ref.path.segments
312314
&& let implied_args = path.args.map_or([].as_slice(), |a| a.args)
313315
&& let implied_constraints = path.args.map_or([].as_slice(), |a| a.constraints)
@@ -342,11 +344,8 @@ impl<'tcx> LateLintPass<'tcx> for ImpliedBoundsInImpls {
342344
}
343345
}
344346

345-
fn check_ty(&mut self, cx: &LateContext<'_>, ty: &rustc_hir::Ty<'_>) {
346-
if let TyKind::OpaqueDef(item_id, ..) = ty.kind
347-
&& let item = cx.tcx.hir().item(item_id)
348-
&& let ItemKind::OpaqueTy(opaque_ty) = item.kind
349-
{
347+
fn check_ty(&mut self, cx: &LateContext<'tcx>, ty: &rustc_hir::Ty<'tcx>) {
348+
if let TyKind::OpaqueDef(opaque_ty, ..) = ty.kind {
350349
check(cx, opaque_ty.bounds);
351350
}
352351
}

clippy_lints/src/index_refutable_slice.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use clippy_utils::diagnostics::span_lint_and_then;
55
use clippy_utils::higher::IfLet;
66
use clippy_utils::ty::is_copy;
77
use clippy_utils::{is_expn_of, is_lint_allowed, path_to_local};
8-
use rustc_data_structures::fx::{FxHashSet, FxIndexMap};
8+
use rustc_data_structures::fx::{FxHashSet, FxIndexMap, FxIndexSet};
99
use rustc_errors::Applicability;
1010
use rustc_hir as hir;
1111
use rustc_hir::HirId;
@@ -133,7 +133,7 @@ fn lint_slice(cx: &LateContext<'_>, slice: &SliceLintInformation) {
133133
.index_use
134134
.iter()
135135
.map(|(index, _)| *index)
136-
.collect::<FxHashSet<_>>();
136+
.collect::<FxIndexSet<_>>();
137137

138138
let value_name = |index| format!("{}_{index}", slice.ident.name);
139139

clippy_lints/src/len_zero.rs

+3-7
Original file line numberDiff line numberDiff line change
@@ -308,13 +308,9 @@ enum LenOutput {
308308

309309
fn extract_future_output<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> Option<&'tcx PathSegment<'tcx>> {
310310
if let ty::Alias(_, alias_ty) = ty.kind()
311-
&& let Some(Node::Item(item)) = cx.tcx.hir().get_if_local(alias_ty.def_id)
312-
&& let Item {
313-
kind: ItemKind::OpaqueTy(opaque),
314-
..
315-
} = item
316-
&& let OpaqueTyOrigin::AsyncFn(_) = opaque.origin
317-
&& let [GenericBound::Trait(trait_ref, _)] = &opaque.bounds
311+
&& let Some(Node::OpaqueTy(opaque)) = cx.tcx.hir().get_if_local(alias_ty.def_id)
312+
&& let OpaqueTyOrigin::AsyncFn { .. } = opaque.origin
313+
&& let [GenericBound::Trait(trait_ref)] = &opaque.bounds
318314
&& let Some(segment) = trait_ref.trait_ref.path.segments.last()
319315
&& let Some(generic_args) = segment.args
320316
&& let [constraint] = generic_args.constraints

clippy_lints/src/lib.rs

-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
#![feature(binary_heap_into_iter_sorted)]
33
#![feature(box_patterns)]
44
#![feature(macro_metavar_expr_concat)]
5-
#![feature(control_flow_enum)]
65
#![feature(f128)]
76
#![feature(f16)]
87
#![feature(if_let_guard)]
@@ -28,8 +27,6 @@
2827
unused_qualifications,
2928
rustc::internal
3029
)]
31-
// Disable this rustc lint for now, as it was also done in rustc
32-
#![allow(rustc::potential_query_instability)]
3330

3431
// FIXME: switch to something more ergonomic here, once available.
3532
// (Currently there is no way to opt into sysroot crates without `extern crate`.)

clippy_lints/src/lifetimes.rs

+10-12
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
use clippy_utils::diagnostics::{span_lint, span_lint_and_then};
22
use clippy_utils::trait_ref_of_method;
33
use itertools::Itertools;
4-
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
4+
use rustc_data_structures::fx::{FxHashSet, FxIndexMap, FxIndexSet};
55
use rustc_errors::Applicability;
66
use rustc_hir::FnRetTy::Return;
77
use rustc_hir::intravisit::nested_filter::{self as hir_nested_filter, NestedFilter};
88
use rustc_hir::intravisit::{
9-
Visitor, walk_fn_decl, walk_generic_args, walk_generics, walk_impl_item_ref, walk_item, walk_param_bound,
10-
walk_poly_trait_ref, walk_trait_ref, walk_ty, walk_where_predicate,
9+
Visitor, walk_fn_decl, walk_generic_args, walk_generics, walk_impl_item_ref, walk_param_bound, walk_poly_trait_ref,
10+
walk_trait_ref, walk_ty, walk_where_predicate,
1111
};
1212
use rustc_hir::{
1313
BareFnTy, BodyId, FnDecl, FnSig, GenericArg, GenericArgs, GenericBound, GenericParam, GenericParamKind, Generics,
@@ -163,7 +163,7 @@ fn check_fn_inner<'tcx>(
163163
if visitor.lts.iter().any(|lt| matches!(lt.res, LifetimeName::Param(_))) {
164164
return;
165165
}
166-
if let GenericBound::Trait(ref trait_ref, _) = *bound {
166+
if let GenericBound::Trait(ref trait_ref) = *bound {
167167
let params = &trait_ref
168168
.trait_ref
169169
.path
@@ -311,7 +311,7 @@ fn could_use_elision<'tcx>(
311311
Some((elidable_lts, usages))
312312
}
313313

314-
fn allowed_lts_from(named_generics: &[GenericParam<'_>]) -> FxHashSet<LocalDefId> {
314+
fn allowed_lts_from(named_generics: &[GenericParam<'_>]) -> FxIndexSet<LocalDefId> {
315315
named_generics
316316
.iter()
317317
.filter_map(|par| {
@@ -420,11 +420,9 @@ impl<'tcx> Visitor<'tcx> for RefVisitor<'_, 'tcx> {
420420

421421
fn visit_ty(&mut self, ty: &'tcx Ty<'_>) {
422422
match ty.kind {
423-
TyKind::OpaqueDef(item, bounds, _) => {
424-
let map = self.cx.tcx.hir();
425-
let item = map.item(item);
423+
TyKind::OpaqueDef(opaque, bounds) => {
426424
let len = self.lts.len();
427-
walk_item(self, item);
425+
self.visit_opaque_ty(opaque);
428426
self.lts.truncate(len);
429427
self.lts.extend(bounds.iter().filter_map(|bound| match bound {
430428
GenericArg::Lifetime(&l) => Some(l),
@@ -440,7 +438,7 @@ impl<'tcx> Visitor<'tcx> for RefVisitor<'_, 'tcx> {
440438
if !lt.is_elided() {
441439
self.unelided_trait_object_lifetime = true;
442440
}
443-
for (bound, _) in bounds {
441+
for bound in bounds {
444442
self.visit_poly_trait_ref(bound);
445443
}
446444
},
@@ -499,7 +497,7 @@ struct Usage {
499497

500498
struct LifetimeChecker<'cx, 'tcx, F> {
501499
cx: &'cx LateContext<'tcx>,
502-
map: FxHashMap<LocalDefId, Vec<Usage>>,
500+
map: FxIndexMap<LocalDefId, Vec<Usage>>,
503501
where_predicate_depth: usize,
504502
generic_args_depth: usize,
505503
phantom: std::marker::PhantomData<F>,
@@ -621,7 +619,7 @@ fn report_extra_impl_lifetimes<'tcx>(cx: &LateContext<'tcx>, impl_: &'tcx Impl<'
621619
fn report_elidable_impl_lifetimes<'tcx>(
622620
cx: &LateContext<'tcx>,
623621
impl_: &'tcx Impl<'_>,
624-
map: &FxHashMap<LocalDefId, Vec<Usage>>,
622+
map: &FxIndexMap<LocalDefId, Vec<Usage>>,
625623
) {
626624
let single_usages = map
627625
.iter()

clippy_lints/src/loops/needless_range_loop.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use clippy_utils::ty::has_iter_method;
55
use clippy_utils::visitors::is_local_used;
66
use clippy_utils::{SpanlessEq, contains_name, higher, is_integer_const, sugg};
77
use rustc_ast::ast;
8-
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
8+
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap};
99
use rustc_errors::Applicability;
1010
use rustc_hir::def::{DefKind, Res};
1111
use rustc_hir::intravisit::{Visitor, walk_expr};
@@ -39,7 +39,7 @@ pub(super) fn check<'tcx>(
3939
var: canonical_id,
4040
indexed_mut: FxHashSet::default(),
4141
indexed_indirectly: FxHashMap::default(),
42-
indexed_directly: FxHashMap::default(),
42+
indexed_directly: FxIndexMap::default(),
4343
referenced: FxHashSet::default(),
4444
nonindex: false,
4545
prefer_mutable: false,
@@ -229,7 +229,7 @@ struct VarVisitor<'a, 'tcx> {
229229
indexed_indirectly: FxHashMap<Symbol, Option<region::Scope>>,
230230
/// subset of `indexed` of vars that are indexed directly: `v[i]`
231231
/// this will not contain cases like `v[calc_index(i)]` or `v[(i + 4) % N]`
232-
indexed_directly: FxHashMap<Symbol, (Option<region::Scope>, Ty<'tcx>)>,
232+
indexed_directly: FxIndexMap<Symbol, (Option<region::Scope>, Ty<'tcx>)>,
233233
/// Any names that are used outside an index operation.
234234
/// Used to detect things like `&mut vec` used together with `vec[i]`
235235
referenced: FxHashSet<Symbol>,

0 commit comments

Comments
 (0)