aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_ty
diff options
context:
space:
mode:
Diffstat (limited to 'crates/hir_ty')
-rw-r--r--crates/hir_ty/src/lib.rs29
-rw-r--r--crates/hir_ty/src/types.rs15
2 files changed, 15 insertions, 29 deletions
diff --git a/crates/hir_ty/src/lib.rs b/crates/hir_ty/src/lib.rs
index 61f5adbc4..2c70c4277 100644
--- a/crates/hir_ty/src/lib.rs
+++ b/crates/hir_ty/src/lib.rs
@@ -99,15 +99,6 @@ where
99 Binders::empty(&Interner, value.shifted_in_from(DebruijnIndex::ONE)) 99 Binders::empty(&Interner, value.shifted_in_from(DebruijnIndex::ONE))
100} 100}
101 101
102impl<T: TypeWalk> Binders<T> {
103 /// Substitutes all variables.
104 pub fn substitute(self, interner: &Interner, subst: &Substitution) -> T {
105 let (value, binders) = self.into_value_and_skipped_binders();
106 assert_eq!(subst.len(interner), binders.len(interner));
107 value.subst_bound_vars(subst)
108 }
109}
110
111pub fn make_only_type_binders<T>(num_vars: usize, value: T) -> Binders<T> { 102pub fn make_only_type_binders<T>(num_vars: usize, value: T) -> Binders<T> {
112 Binders::new( 103 Binders::new(
113 VariableKinds::from_iter( 104 VariableKinds::from_iter(
@@ -120,31 +111,11 @@ pub fn make_only_type_binders<T>(num_vars: usize, value: T) -> Binders<T> {
120} 111}
121 112
122impl TraitRef { 113impl TraitRef {
123 pub fn self_type_parameter(&self, interner: &Interner) -> &Ty {
124 &self.substitution.at(interner, 0).assert_ty_ref(interner)
125 }
126
127 pub fn hir_trait_id(&self) -> TraitId { 114 pub fn hir_trait_id(&self) -> TraitId {
128 from_chalk_trait_id(self.trait_id) 115 from_chalk_trait_id(self.trait_id)
129 } 116 }
130} 117}
131 118
132impl WhereClause {
133 pub fn is_implemented(&self) -> bool {
134 matches!(self, WhereClause::Implemented(_))
135 }
136
137 pub fn trait_ref(&self, db: &dyn HirDatabase) -> Option<TraitRef> {
138 match self {
139 WhereClause::Implemented(tr) => Some(tr.clone()),
140 WhereClause::AliasEq(AliasEq { alias: AliasTy::Projection(proj), .. }) => {
141 Some(proj.trait_ref(db))
142 }
143 WhereClause::AliasEq(_) => None,
144 }
145 }
146}
147
148impl<T> Canonical<T> { 119impl<T> Canonical<T> {
149 pub fn new(value: T, kinds: impl IntoIterator<Item = TyVariableKind>) -> Self { 120 pub fn new(value: T, kinds: impl IntoIterator<Item = TyVariableKind>) -> Self {
150 let kinds = kinds.into_iter().map(|tk| { 121 let kinds = kinds.into_iter().map(|tk| {
diff --git a/crates/hir_ty/src/types.rs b/crates/hir_ty/src/types.rs
index 6dffda1ca..4a626d5e7 100644
--- a/crates/hir_ty/src/types.rs
+++ b/crates/hir_ty/src/types.rs
@@ -360,6 +360,15 @@ impl<T: Clone> Binders<&T> {
360 } 360 }
361} 361}
362 362
363impl<T: TypeWalk> Binders<T> {
364 /// Substitutes all variables.
365 pub fn substitute(self, interner: &Interner, subst: &Substitution) -> T {
366 let (value, binders) = self.into_value_and_skipped_binders();
367 assert_eq!(subst.len(interner), binders.len(interner));
368 value.subst_bound_vars(subst)
369 }
370}
371
363impl<T: std::fmt::Debug> std::fmt::Debug for Binders<T> { 372impl<T: std::fmt::Debug> std::fmt::Debug for Binders<T> {
364 fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> { 373 fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> {
365 let Binders { ref binders, ref value } = *self; 374 let Binders { ref binders, ref value } = *self;
@@ -375,6 +384,12 @@ pub struct TraitRef {
375 pub substitution: Substitution, 384 pub substitution: Substitution,
376} 385}
377 386
387impl TraitRef {
388 pub fn self_type_parameter(&self, interner: &Interner) -> &Ty {
389 &self.substitution.at(interner, 0).assert_ty_ref(interner)
390 }
391}
392
378/// Like `generics::WherePredicate`, but with resolved types: A condition on the 393/// Like `generics::WherePredicate`, but with resolved types: A condition on the
379/// parameters of a generic item. 394/// parameters of a generic item.
380#[derive(Debug, Clone, PartialEq, Eq, Hash)] 395#[derive(Debug, Clone, PartialEq, Eq, Hash)]