aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_ty/src/types.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/hir_ty/src/types.rs')
-rw-r--r--crates/hir_ty/src/types.rs15
1 files changed, 15 insertions, 0 deletions
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)]