Skip to content

Commit 37f4fbb

Browse files
committed
Auto merge of rust-lang#13157 - flip1995:rustup, r=flip1995
Rustup r? `@ghost` changelog: none
2 parents df0cb6c + 71b0f0f commit 37f4fbb

26 files changed

+112
-76
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.81"
3+
version = "0.1.82"
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.81"
3+
version = "0.1.82"
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.81"
3+
version = "0.1.82"
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/eta_reduction.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use rustc_middle::ty::{
1515
use rustc_session::declare_lint_pass;
1616
use rustc_span::symbol::sym;
1717
use rustc_target::spec::abi::Abi;
18-
use rustc_trait_selection::error_reporting::traits::InferCtxtExt as _;
18+
use rustc_trait_selection::error_reporting::InferCtxtErrorExt as _;
1919

2020
declare_clippy_lint! {
2121
/// ### What it does
@@ -178,7 +178,7 @@ impl<'tcx> LateLintPass<'tcx> for EtaReduction {
178178
// 'cuz currently nothing changes after deleting this check.
179179
local_used_in(cx, l, args) || local_used_after_expr(cx, l, expr)
180180
}) {
181-
match cx.tcx.infer_ctxt().build().type_implements_fn_trait(
181+
match cx.tcx.infer_ctxt().build().err_ctxt().type_implements_fn_trait(
182182
cx.param_env,
183183
Binder::bind_with_vars(callee_ty_adjusted, List::empty()),
184184
ty::PredicatePolarity::Positive,

clippy_lints/src/functions/must_use.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use clippy_utils::source::snippet_opt;
1616
use clippy_utils::ty::is_must_use_ty;
1717
use clippy_utils::visitors::for_each_expr_without_closures;
1818
use clippy_utils::{return_ty, trait_ref_of_method};
19+
use rustc_trait_selection::error_reporting::InferCtxtErrorExt;
1920

2021
use core::ops::ControlFlow;
2122

@@ -117,11 +118,11 @@ fn check_needless_must_use(
117118
// Ignore async functions unless Future::Output type is a must_use type
118119
if sig.header.is_async() {
119120
let infcx = cx.tcx.infer_ctxt().build();
120-
if let Some(future_ty) = infcx.get_impl_future_output_ty(return_ty(cx, item_id))
121+
if let Some(future_ty) = infcx.err_ctxt().get_impl_future_output_ty(return_ty(cx, item_id))
121122
&& !is_must_use_ty(cx, future_ty)
122123
{
123124
return;
124-
}
125+
};
125126
}
126127

127128
span_lint_and_help(

clippy_lints/src/future_not_send.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use rustc_middle::ty::{self, AliasTy, ClauseKind, PredicateKind};
99
use rustc_session::declare_lint_pass;
1010
use rustc_span::def_id::LocalDefId;
1111
use rustc_span::{sym, Span};
12-
use rustc_trait_selection::error_reporting::traits::suggestions::TypeErrCtxtExt;
12+
use rustc_trait_selection::error_reporting::InferCtxtErrorExt;
1313
use rustc_trait_selection::traits::{self, FulfillmentError, ObligationCtxt};
1414

1515
declare_clippy_lint! {

clippy_lints/src/inherent_impl.rs

+7-8
Original file line numberDiff line numberDiff line change
@@ -56,19 +56,18 @@ impl<'tcx> LateLintPass<'tcx> for MultipleInherentImpl {
5656
let Ok(impls) = cx.tcx.crate_inherent_impls(()) else {
5757
return;
5858
};
59-
let inherent_impls = cx
60-
.tcx
61-
.with_stable_hashing_context(|hcx| impls.inherent_impls.to_sorted(&hcx, true));
6259

63-
for (_, impl_ids) in inherent_impls.into_iter().filter(|(&id, impls)| {
64-
impls.len() > 1
60+
for (&id, impl_ids) in &impls.inherent_impls {
61+
if impl_ids.len() < 2
6562
// Check for `#[allow]` on the type definition
66-
&& !is_lint_allowed(
63+
|| is_lint_allowed(
6764
cx,
6865
MULTIPLE_INHERENT_IMPL,
6966
cx.tcx.local_def_id_to_hir_id(id),
70-
)
71-
}) {
67+
) {
68+
continue;
69+
}
70+
7271
for impl_id in impl_ids.iter().map(|id| id.expect_local()) {
7372
let impl_ty = cx.tcx.type_of(impl_id).instantiate_identity();
7473
match type_map.entry(impl_ty) {

clippy_lints/src/large_stack_arrays.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -106,13 +106,12 @@ fn might_be_expanded<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'tcx>) -> bool {
106106
///
107107
/// This is a fail-safe to a case where even the `is_from_proc_macro` is unable to determain the
108108
/// correct result.
109-
fn repeat_expr_might_be_expanded<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'tcx>) -> bool {
110-
let ExprKind::Repeat(_, ArrayLen::Body(anon_const)) = expr.kind else {
109+
fn repeat_expr_might_be_expanded(expr: &Expr<'_>) -> bool {
110+
let ExprKind::Repeat(_, ArrayLen::Body(len_ct)) = expr.kind else {
111111
return false;
112112
};
113-
let len_span = cx.tcx.def_span(anon_const.def_id);
114-
!expr.span.contains(len_span)
113+
!expr.span.contains(len_ct.span())
115114
}
116115

117-
expr.span.from_expansion() || is_from_proc_macro(cx, expr) || repeat_expr_might_be_expanded(cx, expr)
116+
expr.span.from_expansion() || is_from_proc_macro(cx, expr) || repeat_expr_might_be_expanded(expr)
118117
}

clippy_lints/src/min_ident_chars.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -139,11 +139,11 @@ impl Visitor<'_> for IdentVisitor<'_, '_> {
139139
return;
140140
}
141141

142-
// `struct Awa<T>(T)`
143-
// ^
142+
// `struct Array<T, const N: usize>([T; N])`
143+
// ^ ^
144144
if let Node::PathSegment(path) = node {
145145
if let Res::Def(def_kind, ..) = path.res
146-
&& let DefKind::TyParam = def_kind
146+
&& let DefKind::TyParam | DefKind::ConstParam = def_kind
147147
{
148148
return;
149149
}

clippy_lints/src/misc_early/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -364,8 +364,8 @@ declare_lint_pass!(MiscEarlyLints => [
364364
]);
365365

366366
impl EarlyLintPass for MiscEarlyLints {
367-
fn check_generics(&mut self, cx: &EarlyContext<'_>, gen: &Generics) {
368-
for param in &gen.params {
367+
fn check_generics(&mut self, cx: &EarlyContext<'_>, generics: &Generics) {
368+
for param in &generics.params {
369369
builtin_type_shadow::check(cx, param);
370370
}
371371
}

clippy_lints/src/no_effect.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use rustc_lint::{LateContext, LateLintPass, LintContext};
1515
use rustc_middle::lint::in_external_macro;
1616
use rustc_session::impl_lint_pass;
1717
use rustc_span::Span;
18+
use rustc_trait_selection::error_reporting::InferCtxtErrorExt;
1819
use std::ops::Deref;
1920

2021
declare_clippy_lint! {
@@ -159,7 +160,7 @@ impl NoEffect {
159160
// Remove `impl Future<Output = T>` to get `T`
160161
if cx.tcx.ty_is_opaque_future(ret_ty)
161162
&& let Some(true_ret_ty) =
162-
cx.tcx.infer_ctxt().build().get_impl_future_output_ty(ret_ty)
163+
cx.tcx.infer_ctxt().build().err_ctxt().get_impl_future_output_ty(ret_ty)
163164
{
164165
ret_ty = true_ret_ty;
165166
}

clippy_lints/src/non_copy_const.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ impl<'tcx> NonCopyConst<'tcx> {
234234

235235
fn is_value_unfrozen_raw(
236236
cx: &LateContext<'tcx>,
237-
result: Result<Option<ty::ValTree<'tcx>>, ErrorHandled>,
237+
result: Result<Result<ty::ValTree<'tcx>, Ty<'tcx>>, ErrorHandled>,
238238
ty: Ty<'tcx>,
239239
) -> bool {
240240
result.map_or_else(

clippy_lints/src/returns.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -394,8 +394,8 @@ fn check_final_expr<'tcx>(
394394

395395
// Returns may be used to turn an expression into a statement in rustc's AST.
396396
// This allows the addition of attributes, like `#[allow]` (See: clippy#9361)
397-
// `#[expect(clippy::needless_return)]` needs to be handled separately to
398-
// actually fulfill the expectation (clippy::#12998)
397+
// `#[expect(clippy::needless_return)]` needs to be handled separatly to
398+
// actually fullfil the expectation (clippy::#12998)
399399
match cx.tcx.hir().attrs(expr.hir_id) {
400400
[] => {},
401401
[attr] => {

clippy_lints/src/trailing_empty_array.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use clippy_utils::diagnostics::span_lint_and_help;
22
use clippy_utils::has_repr_attr;
33
use rustc_hir::{Item, ItemKind};
44
use rustc_lint::{LateContext, LateLintPass};
5-
use rustc_middle::ty::Const;
5+
use rustc_middle::ty::{Const, FeedConstTy};
66
use rustc_session::declare_lint_pass;
77

88
declare_clippy_lint! {
@@ -53,14 +53,14 @@ impl<'tcx> LateLintPass<'tcx> for TrailingEmptyArray {
5353
}
5454
}
5555

56-
fn is_struct_with_trailing_zero_sized_array(cx: &LateContext<'_>, item: &Item<'_>) -> bool {
56+
fn is_struct_with_trailing_zero_sized_array<'tcx>(cx: &LateContext<'tcx>, item: &Item<'tcx>) -> bool {
5757
if let ItemKind::Struct(data, _) = &item.kind
5858
// First check if last field is an array
5959
&& let Some(last_field) = data.fields().last()
6060
&& let rustc_hir::TyKind::Array(_, rustc_hir::ArrayLen::Body(length)) = last_field.ty.kind
6161

6262
// Then check if that array is zero-sized
63-
&& let length = Const::from_anon_const(cx.tcx, length.def_id)
63+
&& let length = Const::from_const_arg(cx.tcx, length, FeedConstTy::No)
6464
&& let length = length.try_eval_target_usize(cx.tcx, cx.param_env)
6565
&& let Some(length) = length
6666
{

clippy_lints/src/trait_bounds.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,9 @@ impl TraitBounds {
104104
impl_lint_pass!(TraitBounds => [TYPE_REPETITION_IN_BOUNDS, TRAIT_DUPLICATION_IN_BOUNDS]);
105105

106106
impl<'tcx> LateLintPass<'tcx> for TraitBounds {
107-
fn check_generics(&mut self, cx: &LateContext<'tcx>, gen: &'tcx Generics<'_>) {
108-
self.check_type_repetition(cx, gen);
109-
check_trait_bound_duplication(cx, gen);
107+
fn check_generics(&mut self, cx: &LateContext<'tcx>, generics: &'tcx Generics<'_>) {
108+
self.check_type_repetition(cx, generics);
109+
check_trait_bound_duplication(cx, generics);
110110
}
111111

112112
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'tcx>) {
@@ -240,7 +240,7 @@ impl TraitBounds {
240240
}
241241

242242
#[allow(clippy::mutable_key_type)]
243-
fn check_type_repetition<'tcx>(&self, cx: &LateContext<'tcx>, gen: &'tcx Generics<'_>) {
243+
fn check_type_repetition<'tcx>(&self, cx: &LateContext<'tcx>, generics: &'tcx Generics<'_>) {
244244
struct SpanlessTy<'cx, 'tcx> {
245245
ty: &'tcx Ty<'tcx>,
246246
cx: &'cx LateContext<'tcx>,
@@ -260,12 +260,12 @@ impl TraitBounds {
260260
}
261261
impl Eq for SpanlessTy<'_, '_> {}
262262

263-
if gen.span.from_expansion() {
263+
if generics.span.from_expansion() {
264264
return;
265265
}
266266
let mut map: UnhashMap<SpanlessTy<'_, '_>, Vec<&GenericBound<'_>>> = UnhashMap::default();
267267
let mut applicability = Applicability::MaybeIncorrect;
268-
for bound in gen.predicates {
268+
for bound in generics.predicates {
269269
if let WherePredicate::BoundPredicate(ref p) = bound
270270
&& p.origin != PredicateOrigin::ImplTrait
271271
&& p.bounds.len() as u64 <= self.max_trait_bounds
@@ -303,8 +303,8 @@ impl TraitBounds {
303303
}
304304
}
305305

306-
fn check_trait_bound_duplication(cx: &LateContext<'_>, gen: &'_ Generics<'_>) {
307-
if gen.span.from_expansion() {
306+
fn check_trait_bound_duplication(cx: &LateContext<'_>, generics: &'_ Generics<'_>) {
307+
if generics.span.from_expansion() {
308308
return;
309309
}
310310

@@ -315,7 +315,7 @@ fn check_trait_bound_duplication(cx: &LateContext<'_>, gen: &'_ Generics<'_>) {
315315
// |
316316
// collects each of these where clauses into a set keyed by generic name and comparable trait
317317
// eg. (T, Clone)
318-
let where_predicates = gen
318+
let where_predicates = generics
319319
.predicates
320320
.iter()
321321
.filter_map(|pred| {
@@ -344,7 +344,7 @@ fn check_trait_bound_duplication(cx: &LateContext<'_>, gen: &'_ Generics<'_>) {
344344
// |
345345
// compare trait bounds keyed by generic name and comparable trait to collected where
346346
// predicates eg. (T, Clone)
347-
for predicate in gen.predicates.iter().filter(|pred| !pred.in_where_clause()) {
347+
for predicate in generics.predicates.iter().filter(|pred| !pred.in_where_clause()) {
348348
if let WherePredicate::BoundPredicate(bound_predicate) = predicate
349349
&& bound_predicate.origin != PredicateOrigin::ImplTrait
350350
&& !bound_predicate.span.from_expansion()

clippy_lints/src/types/type_complexity.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ impl<'tcx> Visitor<'tcx> for TypeComplexityVisitor {
5757
bound
5858
.bound_generic_params
5959
.iter()
60-
.any(|gen| matches!(gen.kind, GenericParamKind::Lifetime { .. }))
60+
.any(|param| matches!(param.kind, GenericParamKind::Lifetime { .. }))
6161
});
6262
if has_lifetime_parameters {
6363
// complex trait bounds like A<'a, 'b>

clippy_lints/src/unnested_or_patterns.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ fn remove_all_parens(pat: &mut P<Pat>) {
123123
struct Visitor;
124124
impl MutVisitor for Visitor {
125125
fn visit_pat(&mut self, pat: &mut P<Pat>) {
126-
noop_visit_pat(pat, self);
126+
walk_pat(self, pat);
127127
let inner = match &mut pat.kind {
128128
Paren(i) => mem::replace(&mut i.kind, Wild),
129129
_ => return,
@@ -140,7 +140,7 @@ fn insert_necessary_parens(pat: &mut P<Pat>) {
140140
impl MutVisitor for Visitor {
141141
fn visit_pat(&mut self, pat: &mut P<Pat>) {
142142
use ast::BindingMode;
143-
noop_visit_pat(pat, self);
143+
walk_pat(self, pat);
144144
let target = match &mut pat.kind {
145145
// `i @ a | b`, `box a | b`, and `& mut? a | b`.
146146
Ident(.., Some(p)) | Box(p) | Ref(p, _) if matches!(&p.kind, Or(ps) if ps.len() > 1) => p,
@@ -162,7 +162,7 @@ fn unnest_or_patterns(pat: &mut P<Pat>) -> bool {
162162
impl MutVisitor for Visitor {
163163
fn visit_pat(&mut self, p: &mut P<Pat>) {
164164
// This is a bottom up transformation, so recurse first.
165-
noop_visit_pat(p, self);
165+
walk_pat(self, p);
166166

167167
// Don't have an or-pattern? Just quit early on.
168168
let Or(alternatives) = &mut p.kind else { return };
@@ -191,7 +191,7 @@ fn unnest_or_patterns(pat: &mut P<Pat>) -> bool {
191191

192192
// Deal with `Some(Some(0)) | Some(Some(1))`.
193193
if this_level_changed {
194-
noop_visit_pat(p, self);
194+
walk_pat(self, p);
195195
}
196196
}
197197
}

clippy_lints/src/utils/author.rs

+21-7
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@ use clippy_utils::{get_attr, higher};
55
use rustc_ast::ast::{LitFloatType, LitKind};
66
use rustc_ast::LitIntType;
77
use rustc_data_structures::fx::FxHashMap;
8-
use rustc_hir as hir;
98
use rustc_hir::{
10-
ArrayLen, BindingMode, CaptureBy, Closure, ClosureKind, CoroutineKind, ExprKind, FnRetTy, HirId, Lit, PatKind,
11-
QPath, StmtKind, TyKind,
9+
self as hir, ArrayLen, BindingMode, CaptureBy, Closure, ClosureKind, ConstArg, ConstArgKind, CoroutineKind,
10+
ExprKind, FnRetTy, HirId, Lit, PatKind, QPath, StmtKind, TyKind,
1211
};
1312
use rustc_lint::{LateContext, LateLintPass, LintContext};
1413
use rustc_session::declare_lint_pass;
@@ -270,6 +269,21 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> {
270269
}
271270
}
272271

272+
fn const_arg(&self, const_arg: &Binding<&ConstArg<'_>>) {
273+
match const_arg.value.kind {
274+
ConstArgKind::Path(ref qpath) => {
275+
bind!(self, qpath);
276+
chain!(self, "let ConstArgKind::Path(ref {qpath}) = {const_arg}.kind");
277+
self.qpath(qpath);
278+
},
279+
ConstArgKind::Anon(anon_const) => {
280+
bind!(self, anon_const);
281+
chain!(self, "let ConstArgKind::Anon({anon_const}) = {const_arg}.kind");
282+
self.body(field!(anon_const.body));
283+
},
284+
}
285+
}
286+
273287
fn lit(&self, lit: &Binding<&Lit>) {
274288
let kind = |kind| chain!(self, "let LitKind::{kind} = {lit}.node");
275289
macro_rules! kind {
@@ -602,10 +616,10 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> {
602616
self.expr(value);
603617
match length.value {
604618
ArrayLen::Infer(..) => chain!(self, "let ArrayLen::Infer(..) = length"),
605-
ArrayLen::Body(anon_const) => {
606-
bind!(self, anon_const);
607-
chain!(self, "let ArrayLen::Body({anon_const}) = {length}");
608-
self.body(field!(anon_const.body));
619+
ArrayLen::Body(const_arg) => {
620+
bind!(self, const_arg);
621+
chain!(self, "let ArrayLen::Body({const_arg}) = {length}");
622+
self.const_arg(const_arg);
609623
},
610624
}
611625
},

clippy_lints/src/zero_repeat_side_effects.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use clippy_utils::visitors::for_each_expr_without_closures;
55
use rustc_ast::LitKind;
66
use rustc_data_structures::packed::Pu128;
77
use rustc_errors::Applicability;
8-
use rustc_hir::{ArrayLen, ExprKind, Node};
8+
use rustc_hir::{ArrayLen, ConstArgKind, ExprKind, Node};
99
use rustc_lint::{LateContext, LateLintPass};
1010
use rustc_middle::ty::Ty;
1111
use rustc_session::declare_lint_pass;
@@ -61,7 +61,8 @@ impl LateLintPass<'_> for ZeroRepeatSideEffects {
6161
// the const item depends on `#[cfg]s` and has different values in different compilation
6262
// sessions).
6363
else if let ExprKind::Repeat(inner_expr, length) = expr.kind
64-
&& let ArrayLen::Body(anon_const) = length
64+
&& let ArrayLen::Body(const_arg) = length
65+
&& let ConstArgKind::Anon(anon_const) = const_arg.kind
6566
&& let length_expr = hir_map.body(anon_const.body).value
6667
&& !length_expr.span.from_expansion()
6768
&& let ExprKind::Lit(literal) = length_expr.kind

clippy_utils/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "clippy_utils"
3-
version = "0.1.81"
3+
version = "0.1.82"
44
edition = "2021"
55
publish = false
66

0 commit comments

Comments
 (0)