Skip to content

Commit 3e5a02b

Browse files
committed
Auto merge of rust-lang#12921 - flip1995:rustup, r=flip1995
Rustup r? `@ghost` changelog: none
2 parents aaade2d + 89658ef commit 3e5a02b

Some content is hidden

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

48 files changed

+172
-209
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.80"
3+
version = "0.1.81"
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.80"
3+
version = "0.1.81"
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.80"
3+
version = "0.1.81"
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/default_numeric_fallback.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ declare_clippy_lint! {
4848
declare_lint_pass!(DefaultNumericFallback => [DEFAULT_NUMERIC_FALLBACK]);
4949

5050
impl<'tcx> LateLintPass<'tcx> for DefaultNumericFallback {
51-
fn check_body(&mut self, cx: &LateContext<'tcx>, body: &'tcx Body<'_>) {
51+
fn check_body(&mut self, cx: &LateContext<'tcx>, body: &Body<'tcx>) {
5252
let hir = cx.tcx.hir();
5353
let is_parent_const = matches!(
5454
hir.body_const_context(hir.body_owner_def_id(body.id())),

clippy_lints/src/dereference.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -643,7 +643,7 @@ impl<'tcx> LateLintPass<'tcx> for Dereferencing<'tcx> {
643643
}
644644
}
645645

646-
fn check_body_post(&mut self, cx: &LateContext<'tcx>, body: &'tcx Body<'_>) {
646+
fn check_body_post(&mut self, cx: &LateContext<'tcx>, body: &Body<'_>) {
647647
if Some(body.id()) == self.current_body {
648648
for pat in self.ref_locals.drain(..).filter_map(|(_, x)| x) {
649649
let replacements = pat.replacements;

clippy_lints/src/doc/needless_doctest_main.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use rustc_data_structures::sync::Lrc;
88
use rustc_errors::emitter::HumanEmitter;
99
use rustc_errors::{Diag, DiagCtxt};
1010
use rustc_lint::LateContext;
11-
use rustc_parse::maybe_new_parser_from_source_str;
11+
use rustc_parse::new_parser_from_source_str;
1212
use rustc_parse::parser::ForceCollect;
1313
use rustc_session::parse::ParseSess;
1414
use rustc_span::edition::Edition;
@@ -50,7 +50,7 @@ pub fn check(
5050
let sm = Lrc::new(SourceMap::new(FilePathMapping::empty()));
5151
let psess = ParseSess::with_dcx(dcx, sm);
5252

53-
let mut parser = match maybe_new_parser_from_source_str(&psess, filename, code) {
53+
let mut parser = match new_parser_from_source_str(&psess, filename, code) {
5454
Ok(p) => p,
5555
Err(errs) => {
5656
errs.into_iter().for_each(Diag::cancel);

clippy_lints/src/eta_reduction.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use rustc_hir::{BindingMode, Expr, ExprKind, FnRetTy, Param, PatKind, QPath, Saf
99
use rustc_infer::infer::TyCtxtInferExt;
1010
use rustc_lint::{LateContext, LateLintPass};
1111
use rustc_middle::ty::{
12-
self, Binder, ClosureArgs, ClosureKind, FnSig, GenericArg, GenericArgKind, List, Region, RegionKind, Ty,
12+
self, Binder, ClosureArgs, ClosureKind, FnSig, GenericArg, GenericArgKind, List, Region, RegionKind, Ty, TyCtxt,
1313
TypeVisitableExt, TypeckResults,
1414
};
1515
use rustc_session::declare_lint_pass;
@@ -251,7 +251,7 @@ fn check_inputs(
251251
})
252252
}
253253

254-
fn check_sig<'tcx>(cx: &LateContext<'tcx>, closure: ClosureArgs<'tcx>, call_sig: FnSig<'_>) -> bool {
254+
fn check_sig<'tcx>(cx: &LateContext<'tcx>, closure: ClosureArgs<TyCtxt<'tcx>>, call_sig: FnSig<'_>) -> bool {
255255
call_sig.safety == Safety::Safe
256256
&& !has_late_bound_to_non_late_bound_regions(
257257
cx.tcx.signature_unclosure(closure.sig(), Safety::Safe).skip_binder(),

clippy_lints/src/future_not_send.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ impl<'tcx> LateLintPass<'tcx> for FutureNotSend {
7979
let send_trait = cx.tcx.get_diagnostic_item(sym::Send).unwrap();
8080
let span = decl.output.span();
8181
let infcx = cx.tcx.infer_ctxt().build();
82-
let ocx = ObligationCtxt::new(&infcx);
82+
let ocx = ObligationCtxt::new_with_diagnostics(&infcx);
8383
let cause = traits::ObligationCause::misc(span, fn_def_id);
8484
ocx.register_bound(cause, cx.param_env, ret_ty, send_trait);
8585
let send_errors = ocx.select_all_or_error();

clippy_lints/src/implicit_hasher.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ impl<'a, 'b, 'tcx> ImplicitHasherConstructorVisitor<'a, 'b, 'tcx> {
328328
impl<'a, 'b, 'tcx> Visitor<'tcx> for ImplicitHasherConstructorVisitor<'a, 'b, 'tcx> {
329329
type NestedFilter = nested_filter::OnlyBodies;
330330

331-
fn visit_body(&mut self, body: &'tcx Body<'_>) {
331+
fn visit_body(&mut self, body: &Body<'tcx>) {
332332
let old_maybe_typeck_results = self.maybe_typeck_results.replace(self.cx.tcx.typeck_body(body.id()));
333333
walk_body(self, body);
334334
self.maybe_typeck_results = old_maybe_typeck_results;

clippy_lints/src/implied_bounds_in_impls.rs

+29-29
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-
GenericArg, GenericBound, GenericBounds, ItemKind, PredicateOrigin, TraitBoundModifier, TyKind, TypeBinding,
7-
WherePredicate,
6+
AssocItemConstraint, GenericArg, GenericBound, GenericBounds, ItemKind, PredicateOrigin, TraitBoundModifier,
7+
TyKind, WherePredicate,
88
};
99
use rustc_hir_analysis::lower_ty;
1010
use rustc_lint::{LateContext, LateLintPass};
@@ -54,9 +54,9 @@ fn emit_lint(
5454
poly_trait: &rustc_hir::PolyTraitRef<'_>,
5555
bounds: GenericBounds<'_>,
5656
index: usize,
57-
// The bindings that were implied, used for suggestion purposes since removing a bound with associated types
58-
// means we might need to then move it to a different bound
59-
implied_bindings: &[TypeBinding<'_>],
57+
// The constraints that were implied, used for suggestion purposes since removing a bound with
58+
// associated types means we might need to then move it to a different bound.
59+
implied_constraints: &[AssocItemConstraint<'_>],
6060
bound: &ImplTraitBound<'_>,
6161
) {
6262
let implied_by = snippet(cx, bound.span, "..");
@@ -83,46 +83,46 @@ fn emit_lint(
8383

8484
let mut sugg = vec![(implied_span_extended, String::new())];
8585

86-
// We also might need to include associated type binding that were specified in the implied bound,
87-
// but omitted in the implied-by bound:
86+
// We also might need to include associated item constraints that were specified in the implied
87+
// bound, but omitted in the implied-by bound:
8888
// `fn f() -> impl Deref<Target = u8> + DerefMut`
8989
// If we're going to suggest removing `Deref<..>`, we'll need to put `<Target = u8>` on `DerefMut`
90-
let omitted_assoc_tys: Vec<_> = implied_bindings
90+
let omitted_constraints: Vec<_> = implied_constraints
9191
.iter()
92-
.filter(|binding| !bound.bindings.iter().any(|b| b.ident == binding.ident))
92+
.filter(|constraint| !bound.constraints.iter().any(|c| c.ident == constraint.ident))
9393
.collect();
9494

95-
if !omitted_assoc_tys.is_empty() {
96-
// `<>` needs to be added if there aren't yet any generic arguments or bindings
97-
let needs_angle_brackets = bound.args.is_empty() && bound.bindings.is_empty();
98-
let insert_span = match (bound.args, bound.bindings) {
99-
([.., arg], [.., binding]) => arg.span().max(binding.span).shrink_to_hi(),
95+
if !omitted_constraints.is_empty() {
96+
// `<>` needs to be added if there aren't yet any generic arguments or constraints
97+
let needs_angle_brackets = bound.args.is_empty() && bound.constraints.is_empty();
98+
let insert_span = match (bound.args, bound.constraints) {
99+
([.., arg], [.., constraint]) => arg.span().max(constraint.span).shrink_to_hi(),
100100
([.., arg], []) => arg.span().shrink_to_hi(),
101-
([], [.., binding]) => binding.span.shrink_to_hi(),
101+
([], [.., constraint]) => constraint.span.shrink_to_hi(),
102102
([], []) => bound.span.shrink_to_hi(),
103103
};
104104

105-
let mut associated_tys_sugg = if needs_angle_brackets {
105+
let mut constraints_sugg = if needs_angle_brackets {
106106
"<".to_owned()
107107
} else {
108-
// If angle brackets aren't needed (i.e., there are already generic arguments or bindings),
108+
// If angle brackets aren't needed (i.e., there are already generic arguments or constraints),
109109
// we need to add a comma:
110110
// `impl A<B, C >`
111111
// ^ if we insert `Assoc=i32` without a comma here, that'd be invalid syntax:
112112
// `impl A<B, C Assoc=i32>`
113113
", ".to_owned()
114114
};
115115

116-
for (index, binding) in omitted_assoc_tys.into_iter().enumerate() {
116+
for (index, constraint) in omitted_constraints.into_iter().enumerate() {
117117
if index > 0 {
118-
associated_tys_sugg += ", ";
118+
constraints_sugg += ", ";
119119
}
120-
associated_tys_sugg += &snippet(cx, binding.span, "..");
120+
constraints_sugg += &snippet(cx, constraint.span, "..");
121121
}
122122
if needs_angle_brackets {
123-
associated_tys_sugg += ">";
123+
constraints_sugg += ">";
124124
}
125-
sugg.push((insert_span, associated_tys_sugg));
125+
sugg.push((insert_span, constraints_sugg));
126126
}
127127

128128
diag.multipart_suggestion_with_style(
@@ -229,8 +229,8 @@ struct ImplTraitBound<'tcx> {
229229
trait_def_id: DefId,
230230
/// The generic arguments on the `impl Trait` bound
231231
args: &'tcx [GenericArg<'tcx>],
232-
/// The associated types on this bound
233-
bindings: &'tcx [TypeBinding<'tcx>],
232+
/// The associated item constraints of this bound
233+
constraints: &'tcx [AssocItemConstraint<'tcx>],
234234
}
235235

236236
/// Given an `impl Trait` type, gets all the supertraits from each bound ("implied bounds").
@@ -253,7 +253,7 @@ fn collect_supertrait_bounds<'tcx>(cx: &LateContext<'tcx>, bounds: GenericBounds
253253
Some(ImplTraitBound {
254254
predicates,
255255
args: path.args.map_or([].as_slice(), |p| p.args),
256-
bindings: path.args.map_or([].as_slice(), |p| p.bindings),
256+
constraints: path.args.map_or([].as_slice(), |p| p.constraints),
257257
trait_def_id,
258258
span: bound.span(),
259259
})
@@ -310,20 +310,20 @@ fn check<'tcx>(cx: &LateContext<'tcx>, bounds: GenericBounds<'tcx>) {
310310
if let GenericBound::Trait(poly_trait, TraitBoundModifier::None) = bound
311311
&& let [.., path] = poly_trait.trait_ref.path.segments
312312
&& let implied_args = path.args.map_or([].as_slice(), |a| a.args)
313-
&& let implied_bindings = path.args.map_or([].as_slice(), |a| a.bindings)
313+
&& let implied_constraints = path.args.map_or([].as_slice(), |a| a.constraints)
314314
&& let Some(def_id) = poly_trait.trait_ref.path.res.opt_def_id()
315315
&& let Some(bound) = find_bound_in_supertraits(cx, def_id, implied_args, &supertraits)
316316
// If the implied bound has a type binding that also exists in the implied-by trait,
317317
// then we shouldn't lint. See #11880 for an example.
318318
&& let assocs = cx.tcx.associated_items(bound.trait_def_id)
319-
&& !implied_bindings.iter().any(|binding| {
319+
&& !implied_constraints.iter().any(|constraint| {
320320
assocs
321-
.filter_by_name_unhygienic(binding.ident.name)
321+
.filter_by_name_unhygienic(constraint.ident.name)
322322
.next()
323323
.is_some_and(|assoc| assoc.kind == ty::AssocKind::Type)
324324
})
325325
{
326-
emit_lint(cx, poly_trait, bounds, index, implied_bindings, bound);
326+
emit_lint(cx, poly_trait, bounds, index, implied_constraints, bound);
327327
}
328328
}
329329
}

clippy_lints/src/large_const_arrays.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ impl<'tcx> LateLintPass<'tcx> for LargeConstArrays {
5454
&& generics.params.is_empty() && !generics.has_where_clause_predicates
5555
&& let ty = cx.tcx.type_of(item.owner_id).instantiate_identity()
5656
&& let ty::Array(element_type, cst) = ty.kind()
57-
&& let ConstKind::Value(ty::ValTree::Leaf(element_count)) = cst.kind()
58-
&& let Ok(element_count) = element_count.try_to_target_usize(cx.tcx)
57+
&& let ConstKind::Value(_, ty::ValTree::Leaf(element_count)) = cst.kind()
58+
&& let element_count = element_count.to_target_usize(cx.tcx)
5959
&& let Ok(element_size) = cx.layout_of(*element_type).map(|l| l.size.bytes())
6060
&& self.maximum_allowed_size < u128::from(element_count) * u128::from(element_size)
6161
{

clippy_lints/src/large_stack_arrays.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ impl<'tcx> LateLintPass<'tcx> for LargeStackArrays {
6464
if let ExprKind::Repeat(_, _) | ExprKind::Array(_) = expr.kind
6565
&& !self.is_from_vec_macro(cx, expr.span)
6666
&& let ty::Array(element_type, cst) = cx.typeck_results().expr_ty(expr).kind()
67-
&& let ConstKind::Value(ty::ValTree::Leaf(element_count)) = cst.kind()
68-
&& let Ok(element_count) = element_count.try_to_target_usize(cx.tcx)
67+
&& let ConstKind::Value(_, ty::ValTree::Leaf(element_count)) = cst.kind()
68+
&& let element_count = element_count.to_target_usize(cx.tcx)
6969
&& let Ok(element_size) = cx.layout_of(*element_type).map(|l| l.size.bytes())
7070
&& !cx.tcx.hir().parent_iter(expr.hir_id).any(|(_, node)| {
7171
matches!(

clippy_lints/src/len_zero.rs

+7-12
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use rustc_hir::def_id::{DefId, DefIdSet};
99
use rustc_hir::{
1010
AssocItemKind, BinOpKind, Expr, ExprKind, FnRetTy, GenericArg, GenericBound, ImplItem, ImplItemKind,
1111
ImplicitSelfKind, Item, ItemKind, Mutability, Node, OpaqueTyOrigin, PatKind, PathSegment, PrimTy, QPath,
12-
TraitItemRef, TyKind, TypeBindingKind,
12+
TraitItemRef, TyKind,
1313
};
1414
use rustc_lint::{LateContext, LateLintPass};
1515
use rustc_middle::ty::{self, AssocKind, FnSig, Ty};
@@ -253,7 +253,7 @@ fn check_trait_items(cx: &LateContext<'_>, visited_trait: &Item<'_>, trait_items
253253
// fill the set with current and super traits
254254
fn fill_trait_set(traitt: DefId, set: &mut DefIdSet, cx: &LateContext<'_>) {
255255
if set.insert(traitt) {
256-
for supertrait in rustc_trait_selection::traits::supertrait_def_ids(cx.tcx, traitt) {
256+
for supertrait in cx.tcx.supertrait_def_ids(traitt) {
257257
fill_trait_set(supertrait, set, cx);
258258
}
259259
}
@@ -307,17 +307,12 @@ fn extract_future_output<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> Option<&
307307
&& let [GenericBound::Trait(trait_ref, _)] = &opaque.bounds
308308
&& let Some(segment) = trait_ref.trait_ref.path.segments.last()
309309
&& let Some(generic_args) = segment.args
310-
&& generic_args.bindings.len() == 1
311-
&& let TypeBindingKind::Equality {
312-
term:
313-
rustc_hir::Term::Ty(rustc_hir::Ty {
314-
kind: TyKind::Path(QPath::Resolved(_, path)),
315-
..
316-
}),
317-
} = &generic_args.bindings[0].kind
318-
&& path.segments.len() == 1
310+
&& let [constraint] = generic_args.constraints
311+
&& let Some(ty) = constraint.ty()
312+
&& let TyKind::Path(QPath::Resolved(_, path)) = ty.kind
313+
&& let [segment] = path.segments
319314
{
320-
return Some(&path.segments[0]);
315+
return Some(segment);
321316
}
322317

323318
None

clippy_lints/src/macro_metavars_in_unsafe.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ impl<'a, 'tcx> Visitor<'tcx> for BodyVisitor<'a, 'tcx> {
186186
}
187187

188188
impl<'tcx> LateLintPass<'tcx> for ExprMetavarsInUnsafe {
189-
fn check_body(&mut self, cx: &LateContext<'tcx>, body: &'tcx rustc_hir::Body<'tcx>) {
189+
fn check_body(&mut self, cx: &LateContext<'tcx>, body: &rustc_hir::Body<'tcx>) {
190190
if is_lint_allowed(cx, MACRO_METAVARS_IN_UNSAFE, body.value.hir_id) {
191191
return;
192192
}

clippy_lints/src/manual_async_fn.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ use rustc_errors::Applicability;
44
use rustc_hir::intravisit::FnKind;
55
use rustc_hir::{
66
Block, Body, Closure, ClosureKind, CoroutineDesugaring, CoroutineKind, CoroutineSource, Expr, ExprKind, FnDecl,
7-
FnRetTy, GenericArg, GenericBound, ImplItem, Item, ItemKind, LifetimeName, Node, Term, TraitRef, Ty, TyKind,
8-
TypeBindingKind,
7+
FnRetTy, GenericArg, GenericBound, ImplItem, Item, ItemKind, LifetimeName, Node, TraitRef, Ty, TyKind,
98
};
109
use rustc_lint::{LateContext, LateLintPass};
1110
use rustc_session::declare_lint_pass;
@@ -138,10 +137,9 @@ fn future_trait_ref<'tcx>(
138137
fn future_output_ty<'tcx>(trait_ref: &'tcx TraitRef<'tcx>) -> Option<&'tcx Ty<'tcx>> {
139138
if let Some(segment) = trait_ref.path.segments.last()
140139
&& let Some(args) = segment.args
141-
&& args.bindings.len() == 1
142-
&& let binding = &args.bindings[0]
143-
&& binding.ident.name == sym::Output
144-
&& let TypeBindingKind::Equality { term: Term::Ty(output) } = binding.kind
140+
&& let [constraint] = args.constraints
141+
&& constraint.ident.name == sym::Output
142+
&& let Some(output) = constraint.ty()
145143
{
146144
return Some(output);
147145
}

clippy_lints/src/matches/overlapping_arms.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,14 @@ fn all_ranges<'tcx>(cx: &LateContext<'tcx>, arms: &'tcx [Arm<'_>], ty: Ty<'tcx>)
3737
Some(lhs) => constant(cx, cx.typeck_results(), lhs)?,
3838
None => {
3939
let min_val_const = ty.numeric_min_val(cx.tcx)?;
40-
mir_to_const(cx, mir::Const::from_ty_const(min_val_const, cx.tcx))?
40+
mir_to_const(cx, mir::Const::from_ty_const(min_val_const, ty, cx.tcx))?
4141
},
4242
};
4343
let rhs_const = match rhs {
4444
Some(rhs) => constant(cx, cx.typeck_results(), rhs)?,
4545
None => {
4646
let max_val_const = ty.numeric_max_val(cx.tcx)?;
47-
mir_to_const(cx, mir::Const::from_ty_const(max_val_const, cx.tcx))?
47+
mir_to_const(cx, mir::Const::from_ty_const(max_val_const, ty, cx.tcx))?
4848
},
4949
};
5050
let lhs_val = lhs_const.int_value(cx, ty)?;

clippy_lints/src/methods/iter_on_single_or_empty_collections.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ fn is_arg_ty_unified_in_fn<'tcx>(
4242
cx.tcx.predicates_of(fn_id).predicates.iter().any(|(clause, _)| {
4343
clause
4444
.as_projection_clause()
45-
.and_then(|p| p.map_bound(|p| p.term.ty()).transpose())
45+
.and_then(|p| p.map_bound(|p| p.term.as_type()).transpose())
4646
.is_some_and(|ty| ty.skip_binder() == arg_ty_in_args)
4747
}) || fn_sig
4848
.inputs()

clippy_lints/src/methods/option_map_unwrap_or.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ pub(super) fn check<'tcx>(
5959
};
6060

6161
let map = cx.tcx.hir();
62-
let body = map.body(map.body_owned_by(map.enclosing_body_owner(expr.hir_id)));
62+
let body = map.body_owned_by(map.enclosing_body_owner(expr.hir_id));
6363
reference_visitor.visit_body(body);
6464

6565
if reference_visitor.found_reference {

0 commit comments

Comments
 (0)