Skip to content

Commit 55de777

Browse files
Make connection between Placeholder and Bound a bit more clear in the type abstraction
1 parent c6d6358 commit 55de777

File tree

4 files changed

+42
-23
lines changed

4 files changed

+42
-23
lines changed

compiler/rustc_middle/src/ty/mod.rs

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -933,7 +933,9 @@ impl Placeholder<BoundVar> {
933933

934934
pub type PlaceholderRegion = Placeholder<BoundRegion>;
935935

936-
impl rustc_type_ir::inherent::PlaceholderLike for PlaceholderRegion {
936+
impl<'tcx> rustc_type_ir::inherent::PlaceholderLike<TyCtxt<'tcx>> for PlaceholderRegion {
937+
type Bound = BoundRegion;
938+
937939
fn universe(self) -> UniverseIndex {
938940
self.universe
939941
}
@@ -946,14 +948,20 @@ impl rustc_type_ir::inherent::PlaceholderLike for PlaceholderRegion {
946948
Placeholder { universe: ui, ..self }
947949
}
948950

949-
fn new(ui: UniverseIndex, var: BoundVar) -> Self {
951+
fn new(ui: UniverseIndex, bound: BoundRegion) -> Self {
952+
Placeholder { universe: ui, bound }
953+
}
954+
955+
fn new_anon(ui: UniverseIndex, var: BoundVar) -> Self {
950956
Placeholder { universe: ui, bound: BoundRegion { var, kind: BoundRegionKind::Anon } }
951957
}
952958
}
953959

954960
pub type PlaceholderType = Placeholder<BoundTy>;
955961

956-
impl rustc_type_ir::inherent::PlaceholderLike for PlaceholderType {
962+
impl<'tcx> rustc_type_ir::inherent::PlaceholderLike<TyCtxt<'tcx>> for PlaceholderType {
963+
type Bound = BoundTy;
964+
957965
fn universe(self) -> UniverseIndex {
958966
self.universe
959967
}
@@ -966,7 +974,11 @@ impl rustc_type_ir::inherent::PlaceholderLike for PlaceholderType {
966974
Placeholder { universe: ui, ..self }
967975
}
968976

969-
fn new(ui: UniverseIndex, var: BoundVar) -> Self {
977+
fn new(ui: UniverseIndex, bound: BoundTy) -> Self {
978+
Placeholder { universe: ui, bound }
979+
}
980+
981+
fn new_anon(ui: UniverseIndex, var: BoundVar) -> Self {
970982
Placeholder { universe: ui, bound: BoundTy { var, kind: BoundTyKind::Anon } }
971983
}
972984
}
@@ -980,7 +992,9 @@ pub struct BoundConst<'tcx> {
980992

981993
pub type PlaceholderConst = Placeholder<BoundVar>;
982994

983-
impl rustc_type_ir::inherent::PlaceholderLike for PlaceholderConst {
995+
impl<'tcx> rustc_type_ir::inherent::PlaceholderLike<TyCtxt<'tcx>> for PlaceholderConst {
996+
type Bound = BoundVar;
997+
984998
fn universe(self) -> UniverseIndex {
985999
self.universe
9861000
}
@@ -993,7 +1007,11 @@ impl rustc_type_ir::inherent::PlaceholderLike for PlaceholderConst {
9931007
Placeholder { universe: ui, ..self }
9941008
}
9951009

996-
fn new(ui: UniverseIndex, var: BoundVar) -> Self {
1010+
fn new(ui: UniverseIndex, bound: BoundVar) -> Self {
1011+
Placeholder { universe: ui, bound }
1012+
}
1013+
1014+
fn new_anon(ui: UniverseIndex, var: BoundVar) -> Self {
9971015
Placeholder { universe: ui, bound: var }
9981016
}
9991017
}

compiler/rustc_next_trait_solver/src/canonicalizer.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -435,13 +435,13 @@ impl<'a, D: SolverDelegate<Interner = I>, I: Interner> Canonicalizer<'a, D, I> {
435435
},
436436
ty::Placeholder(placeholder) => match self.canonicalize_mode {
437437
CanonicalizeMode::Input { .. } => CanonicalVarKind::PlaceholderTy(
438-
PlaceholderLike::new(placeholder.universe(), self.variables.len().into()),
438+
PlaceholderLike::new_anon(placeholder.universe(), self.variables.len().into()),
439439
),
440440
CanonicalizeMode::Response { .. } => CanonicalVarKind::PlaceholderTy(placeholder),
441441
},
442442
ty::Param(_) => match self.canonicalize_mode {
443443
CanonicalizeMode::Input { .. } => CanonicalVarKind::PlaceholderTy(
444-
PlaceholderLike::new(ty::UniverseIndex::ROOT, self.variables.len().into()),
444+
PlaceholderLike::new_anon(ty::UniverseIndex::ROOT, self.variables.len().into()),
445445
),
446446
CanonicalizeMode::Response { .. } => panic!("param ty in response: {t:?}"),
447447
},
@@ -594,15 +594,15 @@ impl<D: SolverDelegate<Interner = I>, I: Interner> TypeFolder<I> for Canonicaliz
594594
},
595595
ty::ConstKind::Placeholder(placeholder) => match self.canonicalize_mode {
596596
CanonicalizeMode::Input { .. } => CanonicalVarKind::PlaceholderConst(
597-
PlaceholderLike::new(placeholder.universe(), self.variables.len().into()),
597+
PlaceholderLike::new_anon(placeholder.universe(), self.variables.len().into()),
598598
),
599599
CanonicalizeMode::Response { .. } => {
600600
CanonicalVarKind::PlaceholderConst(placeholder)
601601
}
602602
},
603603
ty::ConstKind::Param(_) => match self.canonicalize_mode {
604604
CanonicalizeMode::Input { .. } => CanonicalVarKind::PlaceholderConst(
605-
PlaceholderLike::new(ty::UniverseIndex::ROOT, self.variables.len().into()),
605+
PlaceholderLike::new_anon(ty::UniverseIndex::ROOT, self.variables.len().into()),
606606
),
607607
CanonicalizeMode::Response { .. } => panic!("param ty in response: {c:?}"),
608608
},

compiler/rustc_type_ir/src/inherent.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -524,13 +524,14 @@ pub trait Clauses<I: Interner<Clauses = Self>>:
524524
}
525525

526526
/// Common capabilities of placeholder kinds
527-
pub trait PlaceholderLike: Copy + Debug + Hash + Eq {
527+
pub trait PlaceholderLike<I: Interner>: Copy + Debug + Hash + Eq {
528528
fn universe(self) -> ty::UniverseIndex;
529529
fn var(self) -> ty::BoundVar;
530530

531+
type Bound: BoundVarLike<I>;
532+
fn new(ui: ty::UniverseIndex, bound: Self::Bound) -> Self;
533+
fn new_anon(ui: ty::UniverseIndex, var: ty::BoundVar) -> Self;
531534
fn with_updated_universe(self, ui: ty::UniverseIndex) -> Self;
532-
533-
fn new(ui: ty::UniverseIndex, var: ty::BoundVar) -> Self;
534535
}
535536

536537
pub trait IntoKind {
@@ -539,13 +540,13 @@ pub trait IntoKind {
539540
fn kind(self) -> Self::Kind;
540541
}
541542

542-
pub trait BoundVarLike<I: Interner> {
543+
pub trait BoundVarLike<I: Interner>: Copy + Debug + Hash + Eq {
543544
fn var(self) -> ty::BoundVar;
544545

545546
fn assert_eq(self, var: I::BoundVarKind);
546547
}
547548

548-
pub trait ParamLike {
549+
pub trait ParamLike: Copy + Debug + Hash + Eq {
549550
fn index(self) -> u32;
550551
}
551552

compiler/rustc_type_ir/src/interner.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,9 @@ pub trait Interner:
103103
type Ty: Ty<Self>;
104104
type Tys: Tys<Self>;
105105
type FnInputTys: Copy + Debug + Hash + Eq + SliceLike<Item = Self::Ty> + TypeVisitable<Self>;
106-
type ParamTy: Copy + Debug + Hash + Eq + ParamLike;
107-
type BoundTy: Copy + Debug + Hash + Eq + BoundVarLike<Self>;
108-
type PlaceholderTy: PlaceholderLike;
106+
type ParamTy: ParamLike;
107+
type BoundTy: BoundVarLike<Self>;
108+
type PlaceholderTy: PlaceholderLike<Self, Bound = Self::BoundTy>;
109109

110110
// Things stored inside of tys
111111
type ErrorGuaranteed: Copy + Debug + Hash + Eq;
@@ -131,19 +131,19 @@ pub trait Interner:
131131

132132
// Kinds of consts
133133
type Const: Const<Self>;
134-
type PlaceholderConst: PlaceholderLike;
135134
type ParamConst: Copy + Debug + Hash + Eq + ParamLike;
136-
type BoundConst: Copy + Debug + Hash + Eq + BoundVarLike<Self>;
135+
type BoundConst: BoundVarLike<Self>;
136+
type PlaceholderConst: PlaceholderLike<Self, Bound = Self::BoundConst>;
137137
type ValueConst: ValueConst<Self>;
138138
type ExprConst: ExprConst<Self>;
139139
type ValTree: Copy + Debug + Hash + Eq;
140140

141141
// Kinds of regions
142142
type Region: Region<Self>;
143-
type EarlyParamRegion: Copy + Debug + Hash + Eq + ParamLike;
143+
type EarlyParamRegion: ParamLike;
144144
type LateParamRegion: Copy + Debug + Hash + Eq;
145-
type BoundRegion: Copy + Debug + Hash + Eq + BoundVarLike<Self>;
146-
type PlaceholderRegion: PlaceholderLike;
145+
type BoundRegion: BoundVarLike<Self>;
146+
type PlaceholderRegion: PlaceholderLike<Self, Bound = Self::BoundRegion>;
147147

148148
// Predicates
149149
type ParamEnv: ParamEnv<Self>;

0 commit comments

Comments
 (0)