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

Lines changed: 1 addition & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 5 additions & 5 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 4 additions & 1 deletion
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

Lines changed: 4 additions & 4 deletions
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

Lines changed: 6 additions & 9 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 2 deletions
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

0 commit comments

Comments
 (0)