Skip to content

Commit f4a88f2

Browse files
committed
Auto merge of rust-lang#92805 - BoxyUwU:revert-lazy-anon-const-substs, r=lcnr
partially revertish `lazily "compute" anon const default substs` reverts rust-lang#87280 except for some of the changes around `ty::Unevaluated` having a visitor and a generic for promoted why revert: <rust-lang#92805 (comment)> r? `@lcnr`
2 parents 938b4c3 + fb86f84 commit f4a88f2

16 files changed

+41
-39
lines changed

clippy_lints/src/escape.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,7 @@ impl<'a, 'tcx> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> {
175175
// skip if there is a `self` parameter binding to a type
176176
// that contains `Self` (i.e.: `self: Box<Self>`), see #4804
177177
if let Some(trait_self_ty) = self.trait_self_ty {
178-
if map.name(cmt.hir_id) == kw::SelfLower && contains_ty(self.cx.tcx, cmt.place.ty(), trait_self_ty)
179-
{
178+
if map.name(cmt.hir_id) == kw::SelfLower && contains_ty(cmt.place.ty(), trait_self_ty) {
180179
return;
181180
}
182181
}

clippy_lints/src/let_underscore.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ impl<'tcx> LateLintPass<'tcx> for LetUnderscore {
124124
if let Some(init) = local.init;
125125
then {
126126
let init_ty = cx.typeck_results().expr_ty(init);
127-
let contains_sync_guard = init_ty.walk(cx.tcx).any(|inner| match inner.unpack() {
127+
let contains_sync_guard = init_ty.walk().any(|inner| match inner.unpack() {
128128
GenericArgKind::Type(inner_ty) => {
129129
SYNC_GUARD_PATHS.iter().any(|path| match_type(cx, inner_ty, path))
130130
},

clippy_lints/src/loops/same_item_push.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ pub(super) fn check<'tcx>(
4949
if same_item_push_visitor.should_lint();
5050
if let Some((vec, pushed_item)) = same_item_push_visitor.vec_push;
5151
let vec_ty = cx.typeck_results().expr_ty(vec);
52-
let ty = vec_ty.walk(cx.tcx).nth(1).unwrap().expect_ty();
52+
let ty = vec_ty.walk().nth(1).unwrap().expect_ty();
5353
if cx
5454
.tcx
5555
.lang_items()

clippy_lints/src/methods/mod.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -2129,10 +2129,10 @@ impl<'tcx> LateLintPass<'tcx> for Methods {
21292129

21302130
// walk the return type and check for Self (this does not check associated types)
21312131
if let Some(self_adt) = self_ty.ty_adt_def() {
2132-
if contains_adt_constructor(cx.tcx, ret_ty, self_adt) {
2132+
if contains_adt_constructor(ret_ty, self_adt) {
21332133
return;
21342134
}
2135-
} else if contains_ty(cx.tcx, ret_ty, self_ty) {
2135+
} else if contains_ty(ret_ty, self_ty) {
21362136
return;
21372137
}
21382138

@@ -2143,10 +2143,10 @@ impl<'tcx> LateLintPass<'tcx> for Methods {
21432143
if let ty::PredicateKind::Projection(projection_predicate) = predicate.kind().skip_binder() {
21442144
// walk the associated type and check for Self
21452145
if let Some(self_adt) = self_ty.ty_adt_def() {
2146-
if contains_adt_constructor(cx.tcx, projection_predicate.ty, self_adt) {
2146+
if contains_adt_constructor(projection_predicate.ty, self_adt) {
21472147
return;
21482148
}
2149-
} else if contains_ty(cx.tcx, projection_predicate.ty, self_ty) {
2149+
} else if contains_ty(projection_predicate.ty, self_ty) {
21502150
return;
21512151
}
21522152
}
@@ -2195,7 +2195,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods {
21952195
if let TraitItemKind::Fn(_, _) = item.kind;
21962196
let ret_ty = return_ty(cx, item.hir_id());
21972197
let self_ty = TraitRef::identity(cx.tcx, item.def_id.to_def_id()).self_ty().skip_binder();
2198-
if !contains_ty(cx.tcx, ret_ty, self_ty);
2198+
if !contains_ty(ret_ty, self_ty);
21992199

22002200
then {
22012201
span_lint(

clippy_lints/src/needless_pass_by_value.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue {
118118
let fn_def_id = cx.tcx.hir().local_def_id(hir_id);
119119

120120
let preds = traits::elaborate_predicates(cx.tcx, cx.param_env.caller_bounds().iter())
121-
.filter(|p| !p.is_global(cx.tcx))
121+
.filter(|p| !p.is_global())
122122
.filter_map(|obligation| {
123123
// Note that we do not want to deal with qualified predicates here.
124124
match obligation.predicate.kind().no_bound_vars() {

clippy_lints/src/non_copy_const.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,10 @@ fn is_value_unfrozen_expr<'tcx>(cx: &LateContext<'tcx>, hir_id: HirId, def_id: D
188188

189189
let result = cx.tcx.const_eval_resolve(
190190
cx.param_env,
191-
ty::Unevaluated::new(ty::WithOptConstParam::unknown(def_id), substs),
191+
ty::Unevaluated::new(
192+
ty::WithOptConstParam::unknown(def_id),
193+
substs,
194+
),
192195
None,
193196
);
194197
is_value_unfrozen_raw(cx, result, ty)

clippy_lints/src/non_send_fields_in_send_ty.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ impl<'tcx> LateLintPass<'tcx> for NonSendFieldInSendTy {
111111
non_send_fields.push(NonSendField {
112112
def: field_def,
113113
ty: field_ty,
114-
generic_params: collect_generic_params(cx, field_ty),
114+
generic_params: collect_generic_params(field_ty),
115115
})
116116
}
117117
}
@@ -171,8 +171,8 @@ impl<'tcx> NonSendField<'tcx> {
171171

172172
/// Given a type, collect all of its generic parameters.
173173
/// Example: `MyStruct<P, Box<Q, R>>` => `vec![P, Q, R]`
174-
fn collect_generic_params<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> Vec<Ty<'tcx>> {
175-
ty.walk(cx.tcx)
174+
fn collect_generic_params(ty: Ty<'_>) -> Vec<Ty<'_>> {
175+
ty.walk()
176176
.filter_map(|inner| match inner.unpack() {
177177
GenericArgKind::Type(inner_ty) => Some(inner_ty),
178178
_ => None,
@@ -226,7 +226,7 @@ fn ty_allowed_with_raw_pointer_heuristic<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'t
226226

227227
/// Checks if the type contains any pointer-like types in substs (including nested ones)
228228
fn contains_pointer_like<'tcx>(cx: &LateContext<'tcx>, target_ty: Ty<'tcx>) -> bool {
229-
for ty_node in target_ty.walk(cx.tcx) {
229+
for ty_node in target_ty.walk() {
230230
if let GenericArgKind::Type(inner_ty) = ty_node.unpack() {
231231
match inner_ty.kind() {
232232
ty::RawPtr(_) => {

clippy_lints/src/redundant_clone.rs

+6-9
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use rustc_middle::mir::{
1414
visit::{MutatingUseContext, NonMutatingUseContext, PlaceContext, Visitor as _},
1515
Mutability,
1616
};
17-
use rustc_middle::ty::{self, fold::TypeVisitor, Ty, TyCtxt};
17+
use rustc_middle::ty::{self, fold::TypeVisitor, Ty};
1818
use rustc_mir_dataflow::{Analysis, AnalysisDomain, CallReturnPlaces, GenKill, GenKillAnalysis, ResultsCursor};
1919
use rustc_session::{declare_lint_pass, declare_tool_lint};
2020
use rustc_span::source_map::{BytePos, Span};
@@ -575,7 +575,7 @@ impl<'a, 'tcx> mir::visit::Visitor<'tcx> for PossibleBorrowerVisitor<'a, 'tcx> {
575575
self.possible_borrower.add(borrowed.local, lhs);
576576
},
577577
other => {
578-
if ContainsRegion(self.cx.tcx)
578+
if ContainsRegion
579579
.visit_ty(place.ty(&self.body.local_decls, self.cx.tcx).ty)
580580
.is_continue()
581581
{
@@ -624,7 +624,7 @@ impl<'a, 'tcx> mir::visit::Visitor<'tcx> for PossibleBorrowerVisitor<'a, 'tcx> {
624624
.flat_map(HybridBitSet::iter)
625625
.collect();
626626

627-
if ContainsRegion(self.cx.tcx)
627+
if ContainsRegion
628628
.visit_ty(self.body.local_decls[*dest].ty)
629629
.is_break()
630630
{
@@ -703,15 +703,12 @@ impl<'a, 'tcx> mir::visit::Visitor<'tcx> for PossibleOriginVisitor<'a, 'tcx> {
703703
}
704704
}
705705

706-
struct ContainsRegion<'tcx>(TyCtxt<'tcx>);
706+
struct ContainsRegion;
707707

708-
impl<'tcx> TypeVisitor<'tcx> for ContainsRegion<'tcx> {
708+
impl TypeVisitor<'_> for ContainsRegion {
709709
type BreakTy = ();
710-
fn tcx_for_anon_const_substs(&self) -> Option<TyCtxt<'tcx>> {
711-
Some(self.0)
712-
}
713710

714-
fn visit_region(&mut self, _: ty::Region<'tcx>) -> ControlFlow<Self::BreakTy> {
711+
fn visit_region(&mut self, _: ty::Region<'_>) -> ControlFlow<Self::BreakTy> {
715712
ControlFlow::BREAK
716713
}
717714
}

clippy_lints/src/returns.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ impl<'tcx> Visitor<'tcx> for BorrowVisitor<'_, 'tcx> {
301301
.fn_sig(def_id)
302302
.output()
303303
.skip_binder()
304-
.walk(self.cx.tcx)
304+
.walk()
305305
.any(|arg| matches!(arg.unpack(), GenericArgKind::Lifetime(_)));
306306
}
307307

clippy_lints/src/self_named_constructors.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,10 @@ impl<'tcx> LateLintPass<'tcx> for SelfNamedConstructors {
6363

6464
// Ensure method is constructor-like
6565
if let Some(self_adt) = self_ty.ty_adt_def() {
66-
if !contains_adt_constructor(cx.tcx, ret_ty, self_adt) {
66+
if !contains_adt_constructor(ret_ty, self_adt) {
6767
return;
6868
}
69-
} else if !contains_ty(cx.tcx, ret_ty, self_ty) {
69+
} else if !contains_ty(ret_ty, self_ty) {
7070
return;
7171
}
7272

clippy_lints/src/unnecessary_sort_by.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ fn expr_borrows(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
226226
let ty = cx.typeck_results().expr_ty(expr);
227227
matches!(ty.kind(), ty::Ref(..))
228228
|| ty
229-
.walk(cx.tcx)
229+
.walk()
230230
.any(|arg| matches!(arg.unpack(), GenericArgKind::Lifetime(_)))
231231
}
232232

clippy_lints/src/use_self.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ impl<'tcx> LateLintPass<'tcx> for UseSelf {
170170
//
171171
// See also https://github.com/rust-lang/rust-clippy/issues/2894.
172172
for (impl_hir_ty, trait_sem_ty) in impl_inputs_outputs.zip(trait_method_sig.inputs_and_output) {
173-
if trait_sem_ty.walk(cx.tcx).any(|inner| inner == self_ty.into()) {
173+
if trait_sem_ty.walk().any(|inner| inner == self_ty.into()) {
174174
let mut visitor = SkipTyCollector::default();
175175
visitor.visit_ty(impl_hir_ty);
176176
types_to_skip.extend(visitor.types_to_skip);

clippy_utils/src/consts.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,10 @@ impl<'a, 'tcx> ConstEvalLateContext<'a, 'tcx> {
413413
.tcx
414414
.const_eval_resolve(
415415
self.param_env,
416-
ty::Unevaluated::new(ty::WithOptConstParam::unknown(def_id), substs),
416+
ty::Unevaluated::new(
417+
ty::WithOptConstParam::unknown(def_id),
418+
substs,
419+
),
417420
None,
418421
)
419422
.ok()

clippy_utils/src/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1955,7 +1955,7 @@ pub fn fn_has_unsatisfiable_preds(cx: &LateContext<'_>, did: DefId) -> bool {
19551955
.predicates_of(did)
19561956
.predicates
19571957
.iter()
1958-
.filter_map(|(p, _)| if p.is_global(cx.tcx) { Some(*p) } else { None });
1958+
.filter_map(|(p, _)| if p.is_global() { Some(*p) } else { None });
19591959
traits::impossible_predicates(
19601960
cx.tcx,
19611961
traits::elaborate_predicates(cx.tcx, predicates)
@@ -2001,15 +2001,15 @@ pub fn is_slice_of_primitives(cx: &LateContext<'_>, expr: &Expr<'_>) -> Option<S
20012001
if is_primitive {
20022002
// if we have wrappers like Array, Slice or Tuple, print these
20032003
// and get the type enclosed in the slice ref
2004-
match expr_type.peel_refs().walk(cx.tcx).nth(1).unwrap().expect_ty().kind() {
2004+
match expr_type.peel_refs().walk().nth(1).unwrap().expect_ty().kind() {
20052005
rustc_ty::Slice(..) => return Some("slice".into()),
20062006
rustc_ty::Array(..) => return Some("array".into()),
20072007
rustc_ty::Tuple(..) => return Some("tuple".into()),
20082008
_ => {
20092009
// is_recursively_primitive_type() should have taken care
20102010
// of the rest and we can rely on the type that is found
20112011
let refs_peeled = expr_type.peel_refs();
2012-
return Some(refs_peeled.walk(cx.tcx).last().unwrap().to_string());
2012+
return Some(refs_peeled.walk().last().unwrap().to_string());
20132013
},
20142014
}
20152015
}

clippy_utils/src/qualify_min_const_fn.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ pub fn is_min_const_fn<'a, 'tcx>(tcx: TyCtxt<'tcx>, body: &'a Body<'tcx>, msrv:
8686
}
8787

8888
fn check_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, span: Span) -> McfResult {
89-
for arg in ty.walk(tcx) {
89+
for arg in ty.walk() {
9090
let ty = match arg.unpack() {
9191
GenericArgKind::Type(ty) => ty,
9292

clippy_utils/src/ty.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,17 @@ pub fn can_partially_move_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool
3737
}
3838

3939
/// Walks into `ty` and returns `true` if any inner type is the same as `other_ty`
40-
pub fn contains_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, other_ty: Ty<'tcx>) -> bool {
41-
ty.walk(tcx).any(|inner| match inner.unpack() {
40+
pub fn contains_ty(ty: Ty<'_>, other_ty: Ty<'_>) -> bool {
41+
ty.walk().any(|inner| match inner.unpack() {
4242
GenericArgKind::Type(inner_ty) => ty::TyS::same_type(other_ty, inner_ty),
4343
GenericArgKind::Lifetime(_) | GenericArgKind::Const(_) => false,
4444
})
4545
}
4646

4747
/// Walks into `ty` and returns `true` if any inner type is an instance of the given adt
4848
/// constructor.
49-
pub fn contains_adt_constructor<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, adt: &'tcx AdtDef) -> bool {
50-
ty.walk(tcx).any(|inner| match inner.unpack() {
49+
pub fn contains_adt_constructor(ty: Ty<'_>, adt: &AdtDef) -> bool {
50+
ty.walk().any(|inner| match inner.unpack() {
5151
GenericArgKind::Type(inner_ty) => inner_ty.ty_adt_def() == Some(adt),
5252
GenericArgKind::Lifetime(_) | GenericArgKind::Const(_) => false,
5353
})
@@ -221,7 +221,7 @@ fn is_normalizable_helper<'tcx>(
221221
.iter()
222222
.all(|field| is_normalizable_helper(cx, param_env, field.ty(cx.tcx, substs), cache))
223223
}),
224-
_ => ty.walk(cx.tcx).all(|generic_arg| match generic_arg.unpack() {
224+
_ => ty.walk().all(|generic_arg| match generic_arg.unpack() {
225225
GenericArgKind::Type(inner_ty) if inner_ty != ty => {
226226
is_normalizable_helper(cx, param_env, inner_ty, cache)
227227
},

0 commit comments

Comments
 (0)