Skip to content

Commit aed3bd6

Browse files
compiler-errorslcnr
authored andcommitted
Require T: TypeFoldable in Binder<T> visit
1 parent 881e0d8 commit aed3bd6

File tree

11 files changed

+23
-25
lines changed

11 files changed

+23
-25
lines changed

compiler/rustc_hir_analysis/src/hir_ty_lowering/bounds.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ use rustc_hir::def_id::{DefId, LocalDefId};
99
use rustc_hir::{AmbigArg, HirId};
1010
use rustc_middle::bug;
1111
use rustc_middle::ty::{
12-
self as ty, IsSuggestable, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable, TypeVisitableExt,
13-
TypeVisitor, Upcast,
12+
self as ty, IsSuggestable, Ty, TyCtxt, TypeFoldable, TypeSuperVisitable, TypeVisitable,
13+
TypeVisitableExt, TypeVisitor, Upcast,
1414
};
1515
use rustc_span::{ErrorGuaranteed, Ident, Span, Symbol, kw, sym};
1616
use rustc_trait_selection::traits;
@@ -996,7 +996,7 @@ struct GenericParamAndBoundVarCollector<'a, 'tcx> {
996996
impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for GenericParamAndBoundVarCollector<'_, 'tcx> {
997997
type Result = ControlFlow<ErrorGuaranteed>;
998998

999-
fn visit_binder<T: TypeVisitable<TyCtxt<'tcx>>>(
999+
fn visit_binder<T: TypeFoldable<TyCtxt<'tcx>>>(
10001000
&mut self,
10011001
binder: &ty::Binder<'tcx, T>,
10021002
) -> Self::Result {

compiler/rustc_infer/src/infer/outlives/for_liveness.rs

-4
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,6 @@ impl<'tcx, OP> TypeVisitor<TyCtxt<'tcx>> for FreeRegionsVisitor<'tcx, OP>
2424
where
2525
OP: FnMut(ty::Region<'tcx>),
2626
{
27-
fn visit_binder<T: TypeVisitable<TyCtxt<'tcx>>>(&mut self, t: &ty::Binder<'tcx, T>) {
28-
t.super_visit_with(self);
29-
}
30-
3127
fn visit_region(&mut self, r: ty::Region<'tcx>) {
3228
match r.kind() {
3329
// ignore bound regions, keep visiting

compiler/rustc_lint/src/impl_trait_overcaptures.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ use rustc_middle::ty::relate::{
1515
Relate, RelateResult, TypeRelation, structurally_relate_consts, structurally_relate_tys,
1616
};
1717
use rustc_middle::ty::{
18-
self, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable, TypeVisitableExt, TypeVisitor,
18+
self, Ty, TyCtxt, TypeFoldable, TypeSuperVisitable, TypeVisitable, TypeVisitableExt,
19+
TypeVisitor,
1920
};
2021
use rustc_middle::{bug, span_bug};
2122
use rustc_session::lint::FutureIncompatibilityReason;
@@ -209,7 +210,7 @@ where
209210
VarFn: FnOnce() -> FxHashMap<DefId, ty::Variance>,
210211
OutlivesFn: FnOnce() -> OutlivesEnvironment<'tcx>,
211212
{
212-
fn visit_binder<T: TypeVisitable<TyCtxt<'tcx>>>(&mut self, t: &ty::Binder<'tcx, T>) {
213+
fn visit_binder<T: TypeFoldable<TyCtxt<'tcx>>>(&mut self, t: &ty::Binder<'tcx, T>) {
213214
// When we get into a binder, we need to add its own bound vars to the scope.
214215
let mut added = vec![];
215216
for arg in t.bound_vars() {

compiler/rustc_middle/src/ty/print/pretty.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2934,7 +2934,7 @@ impl<'tcx> FmtPrinter<'_, 'tcx> {
29342934

29352935
fn prepare_region_info<T>(&mut self, value: &ty::Binder<'tcx, T>)
29362936
where
2937-
T: TypeVisitable<TyCtxt<'tcx>>,
2937+
T: TypeFoldable<TyCtxt<'tcx>>,
29382938
{
29392939
struct RegionNameCollector<'tcx> {
29402940
used_region_names: FxHashSet<Symbol>,

compiler/rustc_middle/src/ty/visit.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ impl<'tcx> TyCtxt<'tcx> {
6666
{
6767
type Result = ControlFlow<()>;
6868

69-
fn visit_binder<T: TypeVisitable<TyCtxt<'tcx>>>(
69+
fn visit_binder<T: TypeFoldable<TyCtxt<'tcx>>>(
7070
&mut self,
7171
t: &Binder<'tcx, T>,
7272
) -> Self::Result {
@@ -168,7 +168,7 @@ impl LateBoundRegionsCollector {
168168
}
169169

170170
impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for LateBoundRegionsCollector {
171-
fn visit_binder<T: TypeVisitable<TyCtxt<'tcx>>>(&mut self, t: &Binder<'tcx, T>) {
171+
fn visit_binder<T: TypeFoldable<TyCtxt<'tcx>>>(&mut self, t: &Binder<'tcx, T>) {
172172
self.current_index.shift_in(1);
173173
t.super_visit_with(self);
174174
self.current_index.shift_out(1);

compiler/rustc_trait_selection/src/traits/query/normalize.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use rustc_macros::extension;
99
pub use rustc_middle::traits::query::NormalizationResult;
1010
use rustc_middle::ty::{
1111
self, FallibleTypeFolder, Ty, TyCtxt, TypeFoldable, TypeSuperFoldable, TypeSuperVisitable,
12-
TypeVisitable, TypeVisitableExt, TypeVisitor, TypingMode,
12+
TypeVisitableExt, TypeVisitor, TypingMode,
1313
};
1414
use rustc_span::DUMMY_SP;
1515
use tracing::{debug, info, instrument};
@@ -127,7 +127,7 @@ struct MaxEscapingBoundVarVisitor {
127127
}
128128

129129
impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for MaxEscapingBoundVarVisitor {
130-
fn visit_binder<T: TypeVisitable<TyCtxt<'tcx>>>(&mut self, t: &ty::Binder<'tcx, T>) {
130+
fn visit_binder<T: TypeFoldable<TyCtxt<'tcx>>>(&mut self, t: &ty::Binder<'tcx, T>) {
131131
self.outer_index.shift_in(1);
132132
t.super_visit_with(self);
133133
self.outer_index.shift_out(1);

compiler/rustc_ty_utils/src/ty.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ use rustc_infer::infer::TyCtxtInferExt;
77
use rustc_middle::bug;
88
use rustc_middle::query::Providers;
99
use rustc_middle::ty::{
10-
self, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable, TypeVisitor, Upcast, fold_regions,
10+
self, Ty, TyCtxt, TypeFoldable, TypeSuperVisitable, TypeVisitable, TypeVisitor, Upcast,
11+
fold_regions,
1112
};
1213
use rustc_span::DUMMY_SP;
1314
use rustc_span::def_id::{CRATE_DEF_ID, DefId, LocalDefId};
@@ -185,7 +186,7 @@ struct ImplTraitInTraitFinder<'a, 'tcx> {
185186
}
186187

187188
impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for ImplTraitInTraitFinder<'_, 'tcx> {
188-
fn visit_binder<T: TypeVisitable<TyCtxt<'tcx>>>(&mut self, binder: &ty::Binder<'tcx, T>) {
189+
fn visit_binder<T: TypeFoldable<TyCtxt<'tcx>>>(&mut self, binder: &ty::Binder<'tcx, T>) {
189190
self.depth.shift_in(1);
190191
binder.super_visit_with(self);
191192
self.depth.shift_out(1);

compiler/rustc_type_ir/src/binder.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ impl<I: Interner, T: TypeFoldable<I>> TypeFoldable<I> for Binder<I, T> {
128128
}
129129
}
130130

131-
impl<I: Interner, T: TypeVisitable<I>> TypeVisitable<I> for Binder<I, T> {
131+
impl<I: Interner, T: TypeFoldable<I>> TypeVisitable<I> for Binder<I, T> {
132132
fn visit_with<V: TypeVisitor<I>>(&self, visitor: &mut V) -> V::Result {
133133
visitor.visit_binder(self)
134134
}
@@ -147,7 +147,7 @@ impl<I: Interner, T: TypeFoldable<I>> TypeSuperFoldable<I> for Binder<I, T> {
147147
}
148148
}
149149

150-
impl<I: Interner, T: TypeVisitable<I>> TypeSuperVisitable<I> for Binder<I, T> {
150+
impl<I: Interner, T: TypeFoldable<I>> TypeSuperVisitable<I> for Binder<I, T> {
151151
fn super_visit_with<V: TypeVisitor<I>>(&self, visitor: &mut V) -> V::Result {
152152
self.as_ref().skip_binder().visit_with(visitor)
153153
}
@@ -292,7 +292,7 @@ impl<I: Interner> ValidateBoundVars<I> {
292292
impl<I: Interner> TypeVisitor<I> for ValidateBoundVars<I> {
293293
type Result = ControlFlow<()>;
294294

295-
fn visit_binder<T: TypeVisitable<I>>(&mut self, t: &Binder<I, T>) -> Self::Result {
295+
fn visit_binder<T: TypeFoldable<I>>(&mut self, t: &Binder<I, T>) -> Self::Result {
296296
self.binder_index.shift_in(1);
297297
let result = t.super_visit_with(self);
298298
self.binder_index.shift_out(1);

compiler/rustc_type_ir/src/ty_kind/closure.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ struct HasRegionsBoundAt {
342342
// FIXME: Could be optimized to not walk into components with no escaping bound vars.
343343
impl<I: Interner> TypeVisitor<I> for HasRegionsBoundAt {
344344
type Result = ControlFlow<()>;
345-
fn visit_binder<T: TypeVisitable<I>>(&mut self, t: &ty::Binder<I, T>) -> Self::Result {
345+
fn visit_binder<T: TypeFoldable<I>>(&mut self, t: &ty::Binder<I, T>) -> Self::Result {
346346
self.binder.shift_in(1);
347347
t.super_visit_with(self)?;
348348
self.binder.shift_out(1);

compiler/rustc_type_ir/src/visit.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ use smallvec::SmallVec;
5252
use thin_vec::ThinVec;
5353

5454
use crate::inherent::*;
55-
use crate::{self as ty, Interner, TypeFlags};
55+
use crate::{self as ty, Interner, TypeFlags, TypeFoldable};
5656

5757
/// This trait is implemented for every type that can be visited,
5858
/// providing the skeleton of the traversal.
@@ -94,7 +94,7 @@ pub trait TypeVisitor<I: Interner>: Sized {
9494
#[cfg(not(feature = "nightly"))]
9595
type Result: VisitorResult;
9696

97-
fn visit_binder<T: TypeVisitable<I>>(&mut self, t: &ty::Binder<I, T>) -> Self::Result {
97+
fn visit_binder<T: TypeFoldable<I>>(&mut self, t: &ty::Binder<I, T>) -> Self::Result {
9898
t.super_visit_with(self)
9999
}
100100

@@ -401,7 +401,7 @@ impl std::fmt::Debug for HasTypeFlagsVisitor {
401401
impl<I: Interner> TypeVisitor<I> for HasTypeFlagsVisitor {
402402
type Result = ControlFlow<FoundFlags>;
403403

404-
fn visit_binder<T: TypeVisitable<I>>(&mut self, t: &ty::Binder<I, T>) -> Self::Result {
404+
fn visit_binder<T: TypeFoldable<I>>(&mut self, t: &ty::Binder<I, T>) -> Self::Result {
405405
// If we're looking for the HAS_BINDER_VARS flag, check if the
406406
// binder has vars. This won't be present in the binder's bound
407407
// value, so we need to check here too.
@@ -510,7 +510,7 @@ struct HasEscapingVarsVisitor {
510510
impl<I: Interner> TypeVisitor<I> for HasEscapingVarsVisitor {
511511
type Result = ControlFlow<FoundEscapingVars>;
512512

513-
fn visit_binder<T: TypeVisitable<I>>(&mut self, t: &ty::Binder<I, T>) -> Self::Result {
513+
fn visit_binder<T: TypeFoldable<I>>(&mut self, t: &ty::Binder<I, T>) -> Self::Result {
514514
self.outer_index.shift_in(1);
515515
let result = t.super_visit_with(self);
516516
self.outer_index.shift_out(1);

src/tools/clippy/clippy_utils/src/ty/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -915,7 +915,7 @@ pub fn for_each_top_level_late_bound_region<B>(
915915
ControlFlow::Continue(())
916916
}
917917
}
918-
fn visit_binder<T: TypeVisitable<TyCtxt<'tcx>>>(&mut self, t: &Binder<'tcx, T>) -> Self::Result {
918+
fn visit_binder<T: TypeFoldable<TyCtxt<'tcx>>>(&mut self, t: &Binder<'tcx, T>) -> Self::Result {
919919
self.index += 1;
920920
let res = t.super_visit_with(self);
921921
self.index -= 1;

0 commit comments

Comments
 (0)