Skip to content

Commit 7e80867

Browse files
Move visitable bounds up into interner
1 parent edc5053 commit 7e80867

File tree

4 files changed

+37
-77
lines changed

4 files changed

+37
-77
lines changed

compiler/rustc_middle/src/ty/context.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use crate::ty::{
2828
self, AdtDef, AdtDefData, AdtKind, Binder, Clause, Const, ConstData, GenericParamDefKind,
2929
ImplPolarity, List, ParamConst, ParamTy, PolyExistentialPredicate, PolyFnSig, Predicate,
3030
PredicateKind, Region, RegionKind, ReprOptions, TraitObjectVisitor, Ty, TyKind, TyVid,
31-
Visibility,
31+
TypeVisitable, Visibility,
3232
};
3333
use crate::ty::{GenericArg, GenericArgs, GenericArgsRef};
3434
use rustc_ast::{self as ast, attr};
@@ -87,7 +87,7 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
8787
type GenericArg = ty::GenericArg<'tcx>;
8888
type Term = ty::Term<'tcx>;
8989

90-
type Binder<T> = Binder<'tcx, T>;
90+
type Binder<T: TypeVisitable<TyCtxt<'tcx>>> = Binder<'tcx, T>;
9191
type BoundVars = &'tcx List<ty::BoundVariableKind>;
9292
type BoundVar = ty::BoundVariableKind;
9393
type CanonicalVars = CanonicalVarInfos<'tcx>;

compiler/rustc_next_trait_solver/src/canonicalizer.rs

+2-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::cmp::Ordering;
22

33
use rustc_type_ir::fold::{TypeFoldable, TypeFolder, TypeSuperFoldable};
4-
use rustc_type_ir::visit::{Flags, TypeVisitableExt};
4+
use rustc_type_ir::visit::TypeVisitableExt;
55
use rustc_type_ir::{
66
self as ty, Canonical, CanonicalTyVarKind, CanonicalVarInfo, CanonicalVarKind, ConstTy,
77
InferCtxtLike, Interner, IntoKind, PlaceholderLike,
@@ -45,13 +45,7 @@ pub struct Canonicalizer<'a, Infcx: InferCtxtLike<Interner = I>, I: Interner> {
4545
binder_index: ty::DebruijnIndex,
4646
}
4747

48-
impl<'a, Infcx: InferCtxtLike<Interner = I>, I: Interner> Canonicalizer<'a, Infcx, I>
49-
where
50-
I::Ty: Flags,
51-
I::Region: Flags,
52-
I::Const: Flags,
53-
I::Predicate: Flags,
54-
{
48+
impl<'a, Infcx: InferCtxtLike<Interner = I>, I: Interner> Canonicalizer<'a, Infcx, I> {
5549
pub fn canonicalize<T: TypeFoldable<I>>(
5650
infcx: &'a Infcx,
5751
canonicalize_mode: CanonicalizeMode,

compiler/rustc_type_ir/src/interner.rs

+11-5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use smallvec::SmallVec;
22
use std::fmt::Debug;
33
use std::hash::Hash;
44

5+
use crate::visit::{Flags, TypeSuperVisitable, TypeVisitable};
56
use crate::{
67
BoundVar, BoundVars, CanonicalVarInfo, ConstKind, DebruijnIndex, DebugWithInfcx, RegionKind,
78
TyKind, UniverseIndex,
@@ -19,7 +20,7 @@ pub trait Interner: Sized {
1920
type GenericArg: Copy + DebugWithInfcx<Self> + Hash + Ord;
2021
type Term: Copy + Debug + Hash + Ord;
2122

22-
type Binder<T>: BoundVars<Self>;
23+
type Binder<T: TypeVisitable<Self>>: BoundVars<Self> + TypeSuperVisitable<Self>;
2324
type BoundVars: IntoIterator<Item = Self::BoundVar>;
2425
type BoundVar;
2526

@@ -31,7 +32,9 @@ pub trait Interner: Sized {
3132
+ Hash
3233
+ Ord
3334
+ Into<Self::GenericArg>
34-
+ IntoKind<Kind = TyKind<Self>>;
35+
+ IntoKind<Kind = TyKind<Self>>
36+
+ TypeSuperVisitable<Self>
37+
+ Flags;
3538
type Tys: Copy + Debug + Hash + Ord + IntoIterator<Item = Self::Ty>;
3639
type AliasTy: Copy + DebugWithInfcx<Self> + Hash + Ord;
3740
type ParamTy: Copy + Debug + Hash + Ord;
@@ -51,7 +54,9 @@ pub trait Interner: Sized {
5154
+ Ord
5255
+ Into<Self::GenericArg>
5356
+ IntoKind<Kind = ConstKind<Self>>
54-
+ ConstTy<Self>;
57+
+ ConstTy<Self>
58+
+ TypeSuperVisitable<Self>
59+
+ Flags;
5560
type AliasConst: Copy + DebugWithInfcx<Self> + Hash + Ord;
5661
type PlaceholderConst: Copy + Debug + Hash + Ord + PlaceholderLike;
5762
type ParamConst: Copy + Debug + Hash + Ord;
@@ -65,15 +70,16 @@ pub trait Interner: Sized {
6570
+ Hash
6671
+ Ord
6772
+ Into<Self::GenericArg>
68-
+ IntoKind<Kind = RegionKind<Self>>;
73+
+ IntoKind<Kind = RegionKind<Self>>
74+
+ Flags;
6975
type EarlyParamRegion: Copy + Debug + Hash + Ord;
7076
type LateParamRegion: Copy + Debug + Hash + Ord;
7177
type BoundRegion: Copy + Debug + Hash + Ord;
7278
type InferRegion: Copy + DebugWithInfcx<Self> + Hash + Ord;
7379
type PlaceholderRegion: Copy + Debug + Hash + Ord + PlaceholderLike;
7480

7581
// Predicates
76-
type Predicate: Copy + Debug + Hash + Eq;
82+
type Predicate: Copy + Debug + Hash + Eq + TypeSuperVisitable<Self> + Flags;
7783
type TraitPredicate: Copy + Debug + Hash + Eq;
7884
type RegionOutlivesPredicate: Copy + Debug + Hash + Eq;
7985
type TypeOutlivesPredicate: Copy + Debug + Hash + Eq;

compiler/rustc_type_ir/src/visit.rs

+22-62
Original file line numberDiff line numberDiff line change
@@ -87,38 +87,28 @@ pub trait TypeVisitor<I: Interner>: Sized {
8787
#[cfg(not(feature = "nightly"))]
8888
type BreakTy;
8989

90-
fn visit_binder<T: TypeVisitable<I>>(&mut self, t: &I::Binder<T>) -> ControlFlow<Self::BreakTy>
91-
where
92-
I::Binder<T>: TypeSuperVisitable<I>,
93-
{
90+
fn visit_binder<T: TypeVisitable<I>>(
91+
&mut self,
92+
t: &I::Binder<T>,
93+
) -> ControlFlow<Self::BreakTy> {
9494
t.super_visit_with(self)
9595
}
9696

97-
fn visit_ty(&mut self, t: I::Ty) -> ControlFlow<Self::BreakTy>
98-
where
99-
I::Ty: TypeSuperVisitable<I>,
100-
{
97+
fn visit_ty(&mut self, t: I::Ty) -> ControlFlow<Self::BreakTy> {
10198
t.super_visit_with(self)
10299
}
103100

104101
// The default region visitor is a no-op because `Region` is non-recursive
105-
// and has no `super_visit_with` method to call. That also explains the
106-
// lack of `I::Region: TypeSuperVisitable<I>` bound.
102+
// and has no `super_visit_with` method to call.
107103
fn visit_region(&mut self, _r: I::Region) -> ControlFlow<Self::BreakTy> {
108104
ControlFlow::Continue(())
109105
}
110106

111-
fn visit_const(&mut self, c: I::Const) -> ControlFlow<Self::BreakTy>
112-
where
113-
I::Const: TypeSuperVisitable<I>,
114-
{
107+
fn visit_const(&mut self, c: I::Const) -> ControlFlow<Self::BreakTy> {
115108
c.super_visit_with(self)
116109
}
117110

118-
fn visit_predicate(&mut self, p: I::Predicate) -> ControlFlow<Self::BreakTy>
119-
where
120-
I::Predicate: TypeSuperVisitable<I>,
121-
{
111+
fn visit_predicate(&mut self, p: I::Predicate) -> ControlFlow<Self::BreakTy> {
122112
p.super_visit_with(self)
123113
}
124114
}
@@ -327,13 +317,7 @@ pub trait TypeVisitableExt<I: Interner>: TypeVisitable<I> {
327317
}
328318
}
329319

330-
impl<I: Interner, T: TypeVisitable<I>> TypeVisitableExt<I> for T
331-
where
332-
I::Ty: Flags,
333-
I::Region: Flags,
334-
I::Const: Flags,
335-
I::Predicate: Flags,
336-
{
320+
impl<I: Interner, T: TypeVisitable<I>> TypeVisitableExt<I> for T {
337321
fn has_type_flags(&self, flags: TypeFlags) -> bool {
338322
let res =
339323
self.visit_with(&mut HasTypeFlagsVisitor { flags }) == ControlFlow::Break(FoundFlags);
@@ -381,19 +365,13 @@ impl std::fmt::Debug for HasTypeFlagsVisitor {
381365
// are present, regardless of whether those bound variables are used. This
382366
// is important for anonymization of binders in `TyCtxt::erase_regions`. We
383367
// specifically detect this case in `visit_binder`.
384-
impl<I: Interner> TypeVisitor<I> for HasTypeFlagsVisitor
385-
where
386-
I::Ty: Flags,
387-
I::Region: Flags,
388-
I::Const: Flags,
389-
I::Predicate: Flags,
390-
{
368+
impl<I: Interner> TypeVisitor<I> for HasTypeFlagsVisitor {
391369
type BreakTy = FoundFlags;
392370

393-
fn visit_binder<T: TypeVisitable<I>>(&mut self, t: &I::Binder<T>) -> ControlFlow<Self::BreakTy>
394-
where
395-
I::Binder<T>: TypeSuperVisitable<I>,
396-
{
371+
fn visit_binder<T: TypeVisitable<I>>(
372+
&mut self,
373+
t: &I::Binder<T>,
374+
) -> ControlFlow<Self::BreakTy> {
397375
// If we're looking for the HAS_BINDER_VARS flag, check if the
398376
// binder has vars. This won't be present in the binder's bound
399377
// value, so we need to check here too.
@@ -480,19 +458,13 @@ struct HasEscapingVarsVisitor {
480458
outer_index: ty::DebruijnIndex,
481459
}
482460

483-
impl<I: Interner> TypeVisitor<I> for HasEscapingVarsVisitor
484-
where
485-
I::Ty: Flags,
486-
I::Region: Flags,
487-
I::Const: Flags,
488-
I::Predicate: Flags,
489-
{
461+
impl<I: Interner> TypeVisitor<I> for HasEscapingVarsVisitor {
490462
type BreakTy = FoundEscapingVars;
491463

492-
fn visit_binder<T: TypeVisitable<I>>(&mut self, t: &I::Binder<T>) -> ControlFlow<Self::BreakTy>
493-
where
494-
I::Binder<T>: TypeSuperVisitable<I>,
495-
{
464+
fn visit_binder<T: TypeVisitable<I>>(
465+
&mut self,
466+
t: &I::Binder<T>,
467+
) -> ControlFlow<Self::BreakTy> {
496468
self.outer_index.shift_in(1);
497469
let result = t.super_visit_with(self);
498470
self.outer_index.shift_out(1);
@@ -550,30 +522,18 @@ where
550522

551523
struct HasErrorVisitor;
552524

553-
impl<I: Interner> TypeVisitor<I> for HasErrorVisitor
554-
where
555-
I::Ty: Flags,
556-
I::Region: Flags,
557-
I::Const: Flags,
558-
I::Predicate: Flags,
559-
{
525+
impl<I: Interner> TypeVisitor<I> for HasErrorVisitor {
560526
type BreakTy = I::ErrorGuaranteed;
561527

562-
fn visit_ty(&mut self, t: <I as Interner>::Ty) -> ControlFlow<Self::BreakTy>
563-
where
564-
<I as Interner>::Ty: TypeSuperVisitable<I>,
565-
{
528+
fn visit_ty(&mut self, t: <I as Interner>::Ty) -> ControlFlow<Self::BreakTy> {
566529
if let ty::Error(guar) = t.kind() {
567530
ControlFlow::Break(guar)
568531
} else {
569532
t.super_visit_with(self)
570533
}
571534
}
572535

573-
fn visit_const(&mut self, c: <I as Interner>::Const) -> ControlFlow<Self::BreakTy>
574-
where
575-
<I as Interner>::Const: TypeSuperVisitable<I>,
576-
{
536+
fn visit_const(&mut self, c: <I as Interner>::Const) -> ControlFlow<Self::BreakTy> {
577537
if let ty::ConstKind::Error(guar) = c.kind() {
578538
ControlFlow::Break(guar)
579539
} else {

0 commit comments

Comments
 (0)