aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_ty/src/lib.rs
diff options
context:
space:
mode:
authorFlorian Diebold <[email protected]>2021-04-05 16:45:18 +0100
committerFlorian Diebold <[email protected]>2021-04-05 18:19:18 +0100
commitad20f00844cec9c794e34869be163673ebbed182 (patch)
tree0f37d26295bc9a8372d09df1612bd08a6d19ff72 /crates/hir_ty/src/lib.rs
parent69714d36e6617800f3edea174f5d6f76c985ad4c (diff)
Use VariableKinds in Binders
Diffstat (limited to 'crates/hir_ty/src/lib.rs')
-rw-r--r--crates/hir_ty/src/lib.rs26
1 files changed, 16 insertions, 10 deletions
diff --git a/crates/hir_ty/src/lib.rs b/crates/hir_ty/src/lib.rs
index 61b5cf269..86973c7ed 100644
--- a/crates/hir_ty/src/lib.rs
+++ b/crates/hir_ty/src/lib.rs
@@ -66,6 +66,8 @@ pub type ClosureId = chalk_ir::ClosureId<Interner>;
66pub type OpaqueTyId = chalk_ir::OpaqueTyId<Interner>; 66pub type OpaqueTyId = chalk_ir::OpaqueTyId<Interner>;
67pub type PlaceholderIndex = chalk_ir::PlaceholderIndex; 67pub type PlaceholderIndex = chalk_ir::PlaceholderIndex;
68 68
69pub type VariableKind = chalk_ir::VariableKind<Interner>;
70pub type VariableKinds = chalk_ir::VariableKinds<Interner>;
69pub type CanonicalVarKinds = chalk_ir::CanonicalVarKinds<Interner>; 71pub type CanonicalVarKinds = chalk_ir::CanonicalVarKinds<Interner>;
70 72
71pub type ChalkTraitId = chalk_ir::TraitId<Interner>; 73pub type ChalkTraitId = chalk_ir::TraitId<Interner>;
@@ -126,22 +128,26 @@ impl<T> Binders<T> {
126 } 128 }
127} 129}
128 130
129impl<T: Clone> Binders<&T> {
130 pub fn cloned(&self) -> Binders<T> {
131 let (value, binders) = self.into_value_and_skipped_binders();
132 Binders::new(binders, value.clone())
133 }
134}
135
136impl<T: TypeWalk> Binders<T> { 131impl<T: TypeWalk> Binders<T> {
137 /// Substitutes all variables. 132 /// Substitutes all variables.
138 pub fn subst(self, subst: &Substitution) -> T { 133 pub fn subst(self, subst: &Substitution) -> T {
139 let (value, binders) = self.into_value_and_skipped_binders(); 134 let (value, binders) = self.into_value_and_skipped_binders();
140 assert_eq!(subst.len(&Interner), binders); 135 assert_eq!(subst.len(&Interner), binders.len(&Interner));
141 value.subst_bound_vars(subst) 136 value.subst_bound_vars(subst)
142 } 137 }
143} 138}
144 139
140pub fn make_only_type_binders<T>(num_vars: usize, value: T) -> Binders<T> {
141 Binders::new(
142 VariableKinds::from_iter(
143 &Interner,
144 std::iter::repeat(chalk_ir::VariableKind::Ty(chalk_ir::TyVariableKind::General))
145 .take(num_vars),
146 ),
147 value,
148 )
149}
150
145impl TraitRef { 151impl TraitRef {
146 pub fn self_type_parameter(&self, interner: &Interner) -> &Ty { 152 pub fn self_type_parameter(&self, interner: &Interner) -> &Ty {
147 &self.substitution.at(interner, 0).assert_ty_ref(interner) 153 &self.substitution.at(interner, 0).assert_ty_ref(interner)
@@ -407,8 +413,8 @@ impl Ty {
407 // This is only used by type walking. 413 // This is only used by type walking.
408 // Parameters will be walked outside, and projection predicate is not used. 414 // Parameters will be walked outside, and projection predicate is not used.
409 // So just provide the Future trait. 415 // So just provide the Future trait.
410 let impl_bound = Binders::new( 416 let impl_bound = Binders::empty(
411 0, 417 &Interner,
412 WhereClause::Implemented(TraitRef { 418 WhereClause::Implemented(TraitRef {
413 trait_id: to_chalk_trait_id(future_trait), 419 trait_id: to_chalk_trait_id(future_trait),
414 substitution: Substitution::empty(&Interner), 420 substitution: Substitution::empty(&Interner),