aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_ty/src/lib.rs
diff options
context:
space:
mode:
authorFlorian Diebold <[email protected]>2021-03-13 16:55:50 +0000
committerFlorian Diebold <[email protected]>2021-03-13 16:56:48 +0000
commit9719ce9fc731a400c9744ba1a6569e978c1a97e7 (patch)
treea9c674c83723e2ed145793f72450c873da62a6fc /crates/hir_ty/src/lib.rs
parent19664e276aba21a42cad5351a2c91995d1ce5d52 (diff)
Use chalk_ir::FnDefId
Diffstat (limited to 'crates/hir_ty/src/lib.rs')
-rw-r--r--crates/hir_ty/src/lib.rs24
1 files changed, 18 insertions, 6 deletions
diff --git a/crates/hir_ty/src/lib.rs b/crates/hir_ty/src/lib.rs
index 5752ddc4e..6b3485264 100644
--- a/crates/hir_ty/src/lib.rs
+++ b/crates/hir_ty/src/lib.rs
@@ -53,6 +53,7 @@ pub use crate::traits::chalk::Interner;
53 53
54pub type ForeignDefId = chalk_ir::ForeignDefId<Interner>; 54pub type ForeignDefId = chalk_ir::ForeignDefId<Interner>;
55pub type AssocTypeId = chalk_ir::AssocTypeId<Interner>; 55pub type AssocTypeId = chalk_ir::AssocTypeId<Interner>;
56pub(crate) type FnDefId = chalk_ir::FnDefId<Interner>;
56 57
57#[derive(Clone, PartialEq, Eq, Debug, Hash)] 58#[derive(Clone, PartialEq, Eq, Debug, Hash)]
58pub enum Lifetime { 59pub enum Lifetime {
@@ -182,7 +183,7 @@ pub enum TyKind {
182 /// fn foo() -> i32 { 1 } 183 /// fn foo() -> i32 { 1 }
183 /// let bar = foo; // bar: fn() -> i32 {foo} 184 /// let bar = foo; // bar: fn() -> i32 {foo}
184 /// ``` 185 /// ```
185 FnDef(CallableDefId, Substs), 186 FnDef(FnDefId, Substs),
186 187
187 /// The pointee of a string slice. Written as `str`. 188 /// The pointee of a string slice. Written as `str`.
188 Str, 189 Str,
@@ -703,10 +704,12 @@ impl Ty {
703 } 704 }
704 } 705 }
705 706
706 pub fn as_generic_def(&self) -> Option<GenericDefId> { 707 pub fn as_generic_def(&self, db: &dyn HirDatabase) -> Option<GenericDefId> {
707 match *self.interned(&Interner) { 708 match *self.interned(&Interner) {
708 TyKind::Adt(AdtId(adt), ..) => Some(adt.into()), 709 TyKind::Adt(AdtId(adt), ..) => Some(adt.into()),
709 TyKind::FnDef(callable, ..) => Some(callable.into()), 710 TyKind::FnDef(callable, ..) => {
711 Some(db.lookup_intern_callable_def(callable.into()).into())
712 }
710 TyKind::AssociatedType(type_alias, ..) => Some(from_assoc_type_id(type_alias).into()), 713 TyKind::AssociatedType(type_alias, ..) => Some(from_assoc_type_id(type_alias).into()),
711 TyKind::ForeignType(type_alias, ..) => Some(from_foreign_def_id(type_alias).into()), 714 TyKind::ForeignType(type_alias, ..) => Some(from_foreign_def_id(type_alias).into()),
712 _ => None, 715 _ => None,
@@ -775,18 +778,27 @@ impl Ty {
775 } 778 }
776 } 779 }
777 780
778 pub fn as_fn_def(&self) -> Option<FunctionId> { 781 pub fn callable_def(&self, db: &dyn HirDatabase) -> Option<CallableDefId> {
779 match self.interned(&Interner) { 782 match self.interned(&Interner) {
780 &TyKind::FnDef(CallableDefId::FunctionId(func), ..) => Some(func), 783 &TyKind::FnDef(def, ..) => Some(db.lookup_intern_callable_def(def.into())),
781 _ => None, 784 _ => None,
782 } 785 }
783 } 786 }
784 787
788 pub fn as_fn_def(&self, db: &dyn HirDatabase) -> Option<FunctionId> {
789 if let Some(CallableDefId::FunctionId(func)) = self.callable_def(db) {
790 Some(func)
791 } else {
792 None
793 }
794 }
795
785 pub fn callable_sig(&self, db: &dyn HirDatabase) -> Option<CallableSig> { 796 pub fn callable_sig(&self, db: &dyn HirDatabase) -> Option<CallableSig> {
786 match self.interned(&Interner) { 797 match self.interned(&Interner) {
787 TyKind::Function(fn_ptr) => Some(CallableSig::from_fn_ptr(fn_ptr)), 798 TyKind::Function(fn_ptr) => Some(CallableSig::from_fn_ptr(fn_ptr)),
788 TyKind::FnDef(def, parameters) => { 799 TyKind::FnDef(def, parameters) => {
789 let sig = db.callable_item_signature(*def); 800 let callable_def = db.lookup_intern_callable_def((*def).into());
801 let sig = db.callable_item_signature(callable_def);
790 Some(sig.subst(&parameters)) 802 Some(sig.subst(&parameters))
791 } 803 }
792 TyKind::Closure(.., substs) => { 804 TyKind::Closure(.., substs) => {