aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_ty/src/chalk_ext.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/hir_ty/src/chalk_ext.rs')
-rw-r--r--crates/hir_ty/src/chalk_ext.rs28
1 files changed, 27 insertions, 1 deletions
diff --git a/crates/hir_ty/src/chalk_ext.rs b/crates/hir_ty/src/chalk_ext.rs
index b7463366b..0f4cb43e9 100644
--- a/crates/hir_ty/src/chalk_ext.rs
+++ b/crates/hir_ty/src/chalk_ext.rs
@@ -1,6 +1,11 @@
1//! Various extensions traits for Chalk types. 1//! Various extensions traits for Chalk types.
2 2
3use crate::{Interner, Ty, TyKind}; 3use hir_def::{AssocContainerId, Lookup, TraitId};
4
5use crate::{
6 db::HirDatabase, from_assoc_type_id, to_chalk_trait_id, Interner, ProjectionTy, TraitRef, Ty,
7 TyKind,
8};
4 9
5pub trait TyExt { 10pub trait TyExt {
6 fn is_unit(&self) -> bool; 11 fn is_unit(&self) -> bool;
@@ -11,3 +16,24 @@ impl TyExt for Ty {
11 matches!(self.kind(&Interner), TyKind::Tuple(0, _)) 16 matches!(self.kind(&Interner), TyKind::Tuple(0, _))
12 } 17 }
13} 18}
19
20pub trait ProjectionTyExt {
21 fn trait_ref(&self, db: &dyn HirDatabase) -> TraitRef;
22 fn trait_(&self, db: &dyn HirDatabase) -> TraitId;
23}
24
25impl ProjectionTyExt for ProjectionTy {
26 fn trait_ref(&self, db: &dyn HirDatabase) -> TraitRef {
27 TraitRef {
28 trait_id: to_chalk_trait_id(self.trait_(db)),
29 substitution: self.substitution.clone(),
30 }
31 }
32
33 fn trait_(&self, db: &dyn HirDatabase) -> TraitId {
34 match from_assoc_type_id(self.associated_ty_id).lookup(db.upcast()).container {
35 AssocContainerId::TraitId(it) => it,
36 _ => panic!("projection ty without parent trait"),
37 }
38 }
39}