Skip to content

Commit ff4a26d

Browse files
authored
r? @ghost changelog: none
2 parents 5dc5842 + 5fb924f commit ff4a26d

Some content is hidden

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

63 files changed

+265
-237
lines changed

Cargo.toml

+2-2
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.84"
4+
version = "0.1.85"
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"
@@ -29,7 +29,7 @@ rustc_tools_util = "0.4.0"
2929
tempfile = { version = "3.3", optional = true }
3030
termize = "0.1"
3131
color-print = "0.3.4"
32-
anstream = "0.6.0"
32+
anstream = "0.6.18"
3333

3434
[dev-dependencies]
3535
cargo_metadata = "0.18.1"

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.84"
4+
version = "0.1.85"
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.84"
4+
version = "0.1.85"
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/assigning_clones.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ impl<'tcx> LateLintPass<'tcx> for AssigningClones {
9696
},
9797
_ => return,
9898
}
99-
&& let Ok(Some(resolved_fn)) = Instance::try_resolve(cx.tcx, cx.param_env, fn_id, fn_gen_args)
99+
&& let Ok(Some(resolved_fn)) = Instance::try_resolve(cx.tcx, cx.typing_env(), fn_id, fn_gen_args)
100100
// TODO: This check currently bails if the local variable has no initializer.
101101
// That is overly conservative - the lint should fire even if there was no initializer,
102102
// but the variable has been initialized before `lhs` was evaluated.

clippy_lints/src/bool_assert_comparison.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ fn is_impl_not_trait_with_bool_out<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -
6262
})
6363
.is_some_and(|assoc_item| {
6464
let proj = Ty::new_projection(cx.tcx, assoc_item.def_id, cx.tcx.mk_args_trait(ty, []));
65-
let nty = cx.tcx.normalize_erasing_regions(cx.param_env, proj);
65+
let nty = cx.tcx.normalize_erasing_regions(cx.typing_env(), proj);
6666

6767
nty.is_bool()
6868
})

clippy_lints/src/casts/ptr_as_ptr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, msrv: &Msrv) {
3939
(Mutability::Not, Mutability::Not) | (Mutability::Mut, Mutability::Mut))
4040
// The `U` in `pointer::cast` have to be `Sized`
4141
// as explained here: https://github.com/rust-lang/rust/issues/60602.
42-
&& to_pointee_ty.is_sized(cx.tcx, cx.param_env)
42+
&& to_pointee_ty.is_sized(cx.tcx, cx.typing_env())
4343
{
4444
let mut app = Applicability::MachineApplicable;
4545
let turbofish = match &cast_to_hir_ty.kind {

clippy_lints/src/dereference.rs

+20-17
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,15 @@ use core::mem;
1010
use rustc_ast::util::parser::{PREC_PREFIX, PREC_UNAMBIGUOUS};
1111
use rustc_data_structures::fx::FxIndexMap;
1212
use rustc_errors::Applicability;
13+
use rustc_hir::def_id::DefId;
1314
use rustc_hir::intravisit::{Visitor, walk_ty};
1415
use rustc_hir::{
1516
self as hir, BindingMode, Body, BodyId, BorrowKind, Expr, ExprKind, HirId, MatchSource, Mutability, Node, Pat,
1617
PatKind, Path, QPath, TyKind, UnOp,
1718
};
1819
use rustc_lint::{LateContext, LateLintPass};
1920
use rustc_middle::ty::adjustment::{Adjust, Adjustment, AutoBorrow, AutoBorrowMutability};
20-
use rustc_middle::ty::{self, ParamEnv, Ty, TyCtxt, TypeVisitableExt, TypeckResults};
21+
use rustc_middle::ty::{self, Ty, TyCtxt, TypeVisitableExt, TypeckResults};
2122
use rustc_session::impl_lint_pass;
2223
use rustc_span::symbol::sym;
2324
use rustc_span::{Span, Symbol};
@@ -753,10 +754,10 @@ impl TyCoercionStability {
753754
fn for_defined_ty<'tcx>(cx: &LateContext<'tcx>, ty: DefinedTy<'tcx>, for_return: bool) -> Self {
754755
match ty {
755756
DefinedTy::Hir(ty) => Self::for_hir_ty(ty),
756-
DefinedTy::Mir(ty) => Self::for_mir_ty(
757+
DefinedTy::Mir { def_site_def_id, ty } => Self::for_mir_ty(
757758
cx.tcx,
758-
ty.param_env,
759-
cx.tcx.instantiate_bound_regions_with_erased(ty.value),
759+
def_site_def_id,
760+
cx.tcx.instantiate_bound_regions_with_erased(ty),
760761
for_return,
761762
),
762763
}
@@ -823,12 +824,15 @@ impl TyCoercionStability {
823824
}
824825
}
825826

826-
fn for_mir_ty<'tcx>(tcx: TyCtxt<'tcx>, param_env: ParamEnv<'tcx>, ty: Ty<'tcx>, for_return: bool) -> Self {
827+
fn for_mir_ty<'tcx>(tcx: TyCtxt<'tcx>, def_site_def_id: Option<DefId>, ty: Ty<'tcx>, for_return: bool) -> Self {
827828
let ty::Ref(_, mut ty, _) = *ty.kind() else {
828829
return Self::None;
829830
};
830831

831-
ty = tcx.try_normalize_erasing_regions(param_env, ty).unwrap_or(ty);
832+
if let Some(def_id) = def_site_def_id {
833+
let typing_env = ty::TypingEnv::non_body_analysis(tcx, def_id);
834+
ty = tcx.try_normalize_erasing_regions(typing_env, ty).unwrap_or(ty);
835+
}
832836
loop {
833837
break match *ty.kind() {
834838
ty::Ref(_, ref_ty, _) => {
@@ -959,7 +963,7 @@ fn report<'tcx>(
959963
// expr_str (the suggestion) is never shown if is_final_ufcs is true, since it's
960964
// `expr.kind == ExprKind::Call`. Therefore, this is, afaik, always unnecessary.
961965
/*
962-
expr_str = if !expr_is_macro_call && is_final_ufcs && expr.precedence().order() < PREC_PREFIX {
966+
expr_str = if !expr_is_macro_call && is_final_ufcs && expr.precedence() < PREC_PREFIX {
963967
Cow::Owned(format!("({expr_str})"))
964968
} else {
965969
expr_str
@@ -999,7 +1003,7 @@ fn report<'tcx>(
9991003
Node::Expr(e) => match e.kind {
10001004
ExprKind::Call(callee, _) if callee.hir_id != data.first_expr.hir_id => (0, false),
10011005
ExprKind::Call(..) => (PREC_UNAMBIGUOUS, matches!(expr.kind, ExprKind::Field(..))),
1002-
_ => (e.precedence().order(), false),
1006+
_ => (e.precedence(), false),
10031007
},
10041008
_ => (0, false),
10051009
};
@@ -1012,7 +1016,7 @@ fn report<'tcx>(
10121016
);
10131017

10141018
let sugg = if !snip_is_macro
1015-
&& (calls_field || expr.precedence().order() < precedence)
1019+
&& (calls_field || expr.precedence() < precedence)
10161020
&& !has_enclosing_paren(&snip)
10171021
&& !is_in_tuple
10181022
{
@@ -1027,7 +1031,7 @@ fn report<'tcx>(
10271031
State::ExplicitDeref { mutability } => {
10281032
if is_block_like(expr)
10291033
&& let ty::Ref(_, ty, _) = data.adjusted_ty.kind()
1030-
&& ty.is_sized(cx.tcx, cx.param_env)
1034+
&& ty.is_sized(cx.tcx, cx.typing_env())
10311035
{
10321036
// Rustc bug: auto deref doesn't work on block expression when targeting sized types.
10331037
return;
@@ -1066,12 +1070,11 @@ fn report<'tcx>(
10661070
let mut app = Applicability::MachineApplicable;
10671071
let (snip, snip_is_macro) =
10681072
snippet_with_context(cx, expr.span, data.first_expr.span.ctxt(), "..", &mut app);
1069-
let sugg =
1070-
if !snip_is_macro && expr.precedence().order() < precedence && !has_enclosing_paren(&snip) {
1071-
format!("{prefix}({snip})")
1072-
} else {
1073-
format!("{prefix}{snip}")
1074-
};
1073+
let sugg = if !snip_is_macro && expr.precedence() < precedence && !has_enclosing_paren(&snip) {
1074+
format!("{prefix}({snip})")
1075+
} else {
1076+
format!("{prefix}{snip}")
1077+
};
10751078
diag.span_suggestion(data.first_expr.span, "try", sugg, app);
10761079
},
10771080
);
@@ -1154,7 +1157,7 @@ impl<'tcx> Dereferencing<'tcx> {
11541157
},
11551158
Some(parent) if !parent.span.from_expansion() => {
11561159
// Double reference might be needed at this point.
1157-
if parent.precedence().order() == PREC_UNAMBIGUOUS {
1160+
if parent.precedence() == PREC_UNAMBIGUOUS {
11581161
// Parentheses would be needed here, don't lint.
11591162
*outer_pat = None;
11601163
} else {

clippy_lints/src/derive.rs

+16-16
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ use rustc_hir::{
1111
};
1212
use rustc_lint::{LateContext, LateLintPass};
1313
use rustc_middle::hir::nested_filter;
14-
use rustc_middle::traits::Reveal;
1514
use rustc_middle::ty::{
1615
self, ClauseKind, GenericArgKind, GenericParamDefKind, ParamEnv, TraitPredicate, Ty, TyCtxt, Upcast,
1716
};
@@ -454,13 +453,13 @@ fn check_partial_eq_without_eq<'tcx>(cx: &LateContext<'tcx>, span: Span, trait_r
454453
&& cx.tcx.is_diagnostic_item(sym::PartialEq, def_id)
455454
&& !has_non_exhaustive_attr(cx.tcx, *adt)
456455
&& !ty_implements_eq_trait(cx.tcx, ty, eq_trait_def_id)
457-
&& let param_env = param_env_for_derived_eq(cx.tcx, adt.did(), eq_trait_def_id)
456+
&& let typing_env = typing_env_env_for_derived_eq(cx.tcx, adt.did(), eq_trait_def_id)
458457
&& let Some(local_def_id) = adt.did().as_local()
459458
// If all of our fields implement `Eq`, we can implement `Eq` too
460459
&& adt
461460
.all_fields()
462461
.map(|f| f.ty(cx.tcx, args))
463-
.all(|ty| implements_trait_with_env(cx.tcx, param_env, ty, eq_trait_def_id, None, &[]))
462+
.all(|ty| implements_trait_with_env(cx.tcx, typing_env, ty, eq_trait_def_id, None, &[]))
464463
{
465464
span_lint_hir_and_then(
466465
cx,
@@ -485,7 +484,7 @@ fn ty_implements_eq_trait<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, eq_trait_id: De
485484
}
486485

487486
/// Creates the `ParamEnv` used for the give type's derived `Eq` impl.
488-
fn param_env_for_derived_eq(tcx: TyCtxt<'_>, did: DefId, eq_trait_id: DefId) -> ParamEnv<'_> {
487+
fn typing_env_env_for_derived_eq(tcx: TyCtxt<'_>, did: DefId, eq_trait_id: DefId) -> ty::TypingEnv<'_> {
489488
// Initial map from generic index to param def.
490489
// Vec<(param_def, needs_eq)>
491490
let mut params = tcx
@@ -506,16 +505,17 @@ fn param_env_for_derived_eq(tcx: TyCtxt<'_>, did: DefId, eq_trait_id: DefId) ->
506505
}
507506
}
508507

509-
ParamEnv::new(
510-
tcx.mk_clauses_from_iter(ty_predicates.iter().map(|&(p, _)| p).chain(
511-
params.iter().filter(|&&(_, needs_eq)| needs_eq).map(|&(param, _)| {
512-
ClauseKind::Trait(TraitPredicate {
513-
trait_ref: ty::TraitRef::new(tcx, eq_trait_id, [tcx.mk_param_from_def(param)]),
514-
polarity: ty::PredicatePolarity::Positive,
515-
})
516-
.upcast(tcx)
517-
}),
518-
)),
519-
Reveal::UserFacing,
520-
)
508+
let param_env = ParamEnv::new(tcx.mk_clauses_from_iter(ty_predicates.iter().map(|&(p, _)| p).chain(
509+
params.iter().filter(|&&(_, needs_eq)| needs_eq).map(|&(param, _)| {
510+
ClauseKind::Trait(TraitPredicate {
511+
trait_ref: ty::TraitRef::new(tcx, eq_trait_id, [tcx.mk_param_from_def(param)]),
512+
polarity: ty::PredicatePolarity::Positive,
513+
})
514+
.upcast(tcx)
515+
}),
516+
)));
517+
ty::TypingEnv {
518+
typing_mode: ty::TypingMode::non_body_analysis(),
519+
param_env,
520+
}
521521
}

clippy_lints/src/drop_forget_ref.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -99,15 +99,15 @@ impl<'tcx> LateLintPass<'tcx> for DropForgetRef {
9999
sym::mem_forget if is_copy => return,
100100
sym::mem_drop if is_type_lang_item(cx, arg_ty, LangItem::ManuallyDrop) => return,
101101
sym::mem_drop
102-
if !(arg_ty.needs_drop(cx.tcx, cx.param_env)
102+
if !(arg_ty.needs_drop(cx.tcx, cx.typing_env())
103103
|| is_must_use_func_call(cx, arg)
104104
|| is_must_use_ty(cx, arg_ty)
105105
|| drop_is_single_call_in_arm) =>
106106
{
107107
(DROP_NON_DROP, DROP_NON_DROP_SUMMARY.into(), Some(arg.span))
108108
},
109109
sym::mem_forget => {
110-
if arg_ty.needs_drop(cx.tcx, cx.param_env) {
110+
if arg_ty.needs_drop(cx.tcx, cx.typing_env()) {
111111
(
112112
MEM_FORGET,
113113
Cow::Owned(format!(

clippy_lints/src/extra_unused_type_parameters.rs

+4-3
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, WherePredicate,
9+
PredicateOrigin, Ty, WherePredicate, WherePredicateKind,
1010
};
1111
use rustc_lint::{LateContext, LateLintPass, LintContext};
1212
use rustc_middle::hir::nested_filter;
@@ -205,12 +205,13 @@ impl<'tcx> Visitor<'tcx> for TypeWalker<'_, 'tcx> {
205205
}
206206

207207
fn visit_where_predicate(&mut self, predicate: &'tcx WherePredicate<'tcx>) {
208-
if let WherePredicate::BoundPredicate(predicate) = predicate {
208+
let span = predicate.span;
209+
if let WherePredicateKind::BoundPredicate(predicate) = predicate.kind {
209210
// Collect spans for any bounds on type parameters.
210211
if let Some((def_id, _)) = predicate.bounded_ty.peel_refs().as_generic_param() {
211212
match predicate.origin {
212213
PredicateOrigin::GenericParam => {
213-
self.inline_bounds.insert(def_id, predicate.span);
214+
self.inline_bounds.insert(def_id, span);
214215
},
215216
PredicateOrigin::WhereClause => {
216217
self.where_bounds.insert(def_id);

clippy_lints/src/functions/must_use.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ fn is_mutable_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>, tys: &mut DefIdSet)
198198
// primitive types are never mutable
199199
ty::Bool | ty::Char | ty::Int(_) | ty::Uint(_) | ty::Float(_) | ty::Str => false,
200200
ty::Adt(adt, args) => {
201-
tys.insert(adt.did()) && !ty.is_freeze(cx.tcx, cx.param_env)
201+
tys.insert(adt.did()) && !ty.is_freeze(cx.tcx, cx.typing_env())
202202
|| matches!(cx.tcx.get_diagnostic_name(adt.did()), Some(sym::Rc | sym::Arc))
203203
&& args.types().any(|ty| is_mutable_ty(cx, ty, tys))
204204
},

clippy_lints/src/implied_bounds_in_impls.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use rustc_errors::{Applicability, SuggestionStyle};
44
use rustc_hir::def_id::DefId;
55
use rustc_hir::{
66
AssocItemConstraint, GenericArg, GenericBound, GenericBounds, PredicateOrigin, TraitBoundModifiers, TyKind,
7-
WherePredicate,
7+
WherePredicateKind,
88
};
99
use rustc_hir_analysis::lower_ty;
1010
use rustc_lint::{LateContext, LateLintPass};
@@ -324,7 +324,7 @@ fn check<'tcx>(cx: &LateContext<'tcx>, bounds: GenericBounds<'tcx>) {
324324
impl<'tcx> LateLintPass<'tcx> for ImpliedBoundsInImpls {
325325
fn check_generics(&mut self, cx: &LateContext<'tcx>, generics: &rustc_hir::Generics<'tcx>) {
326326
for predicate in generics.predicates {
327-
if let WherePredicate::BoundPredicate(predicate) = predicate
327+
if let WherePredicateKind::BoundPredicate(predicate) = predicate.kind
328328
// In theory, the origin doesn't really matter,
329329
// we *could* also lint on explicit where clauses written out by the user,
330330
// not just impl trait desugared ones, but that contradicts with the lint name...

clippy_lints/src/iter_not_returning_iterator.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ fn check_sig(cx: &LateContext<'_>, name: Symbol, sig: &FnSig<'_>, fn_id: LocalDe
7070
.instantiate_bound_regions_with_erased(cx.tcx.fn_sig(fn_id).instantiate_identity().output());
7171
let ret_ty = cx
7272
.tcx
73-
.try_normalize_erasing_regions(cx.param_env, ret_ty)
73+
.try_normalize_erasing_regions(cx.typing_env(), ret_ty)
7474
.unwrap_or(ret_ty);
7575
if cx
7676
.tcx

clippy_lints/src/iter_without_into_iter.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ impl {self_ty_without_ref} {{
215215
&& implements_trait(cx, ret_ty, iterator_did, &[])
216216
&& let Some(iter_ty) = make_normalized_projection(
217217
cx.tcx,
218-
cx.param_env,
218+
cx.typing_env(),
219219
iterator_did,
220220
sym::Item,
221221
[ret_ty],

clippy_lints/src/large_const_arrays.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ use clippy_utils::diagnostics::span_lint_and_then;
33
use rustc_errors::Applicability;
44
use rustc_hir::{Item, ItemKind};
55
use rustc_lint::{LateContext, LateLintPass};
6+
use rustc_middle::ty;
67
use rustc_middle::ty::layout::LayoutOf;
7-
use rustc_middle::ty::{self, ParamEnv};
88
use rustc_session::impl_lint_pass;
99
use rustc_span::{BytePos, Pos, Span};
1010

@@ -57,7 +57,7 @@ impl<'tcx> LateLintPass<'tcx> for LargeConstArrays {
5757
&& let ty = cx.tcx.type_of(item.owner_id).instantiate_identity()
5858
&& let ty::Array(element_type, cst) = ty.kind()
5959
&& let Some((ty::ValTree::Leaf(element_count), _)) = cx.tcx
60-
.try_normalize_erasing_regions(ParamEnv::empty(), *cst).unwrap_or(*cst).try_to_valtree()
60+
.try_normalize_erasing_regions(cx.typing_env(), *cst).unwrap_or(*cst).try_to_valtree()
6161
&& let element_count = element_count.to_target_usize(cx.tcx)
6262
&& let Ok(element_size) = cx.layout_of(*element_type).map(|l| l.size.bytes())
6363
&& u128::from(self.maximum_allowed_size) < u128::from(element_count) * u128::from(element_size)

clippy_lints/src/large_futures.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ impl<'tcx> LateLintPass<'tcx> for LargeFuture {
6363
&& let ty = cx.typeck_results().expr_ty(arg)
6464
&& let Some(future_trait_def_id) = cx.tcx.lang_items().future_trait()
6565
&& implements_trait(cx, ty, future_trait_def_id, &[])
66-
&& let Ok(layout) = cx.tcx.layout_of(cx.param_env.and(ty))
66+
&& let Ok(layout) = cx.tcx.layout_of(cx.typing_env().as_query_input(ty))
6767
&& let size = layout.layout.size()
6868
&& size >= Size::from_bytes(self.future_size_threshold)
6969
{

clippy_lints/src/large_stack_frames.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,11 @@ impl<'tcx> LateLintPass<'tcx> for LargeStackFrames {
150150
}
151151

152152
let mir = cx.tcx.optimized_mir(def_id);
153-
let param_env = cx.tcx.param_env(def_id);
153+
let typing_env = mir.typing_env(cx.tcx);
154154

155155
let sizes_of_locals = || {
156156
mir.local_decls.iter().filter_map(|local| {
157-
let layout = cx.tcx.layout_of(param_env.and(local.ty)).ok()?;
157+
let layout = cx.tcx.layout_of(typing_env.as_query_input(local.ty)).ok()?;
158158
Some((local, layout.size.bytes()))
159159
})
160160
};

clippy_lints/src/let_if_seq.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ impl<'tcx> LateLintPass<'tcx> for LetIfSeq {
8080
let has_interior_mutability = !cx
8181
.typeck_results()
8282
.node_type(canonical_id)
83-
.is_freeze(cx.tcx, cx.param_env);
83+
.is_freeze(cx.tcx, cx.typing_env());
8484
if has_interior_mutability {
8585
return;
8686
}

0 commit comments

Comments
 (0)