about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2024-06-03 12:16:29 +0000
committerbors <bors@rust-lang.org>2024-06-03 12:16:29 +0000
commitfa41f196b5231be57a31868414621586f7b9a2ba (patch)
treeae25af00402f4dd2ec0f810283773a9f676e1887
parentfcde6c9b356538f814f4bb6b7a8c4d4115a9f5b6 (diff)
parent88f125ebc97b291e56fae77cdb5a1c2938418e8f (diff)
downloadrust-fa41f196b5231be57a31868414621586f7b9a2ba.tar.gz
rust-fa41f196b5231be57a31868414621586f7b9a2ba.zip
Auto merge of #17312 - regexident:function-fn-ptr-type, r=Veykril
Add `Function::fn_ptr_type(…)` for obtaining name-erased function type

The use case of this function if being able to group functions by their function ptr type.

cc `@flodiebold`
-rw-r--r--src/tools/rust-analyzer/crates/hir/src/lib.rs8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/tools/rust-analyzer/crates/hir/src/lib.rs b/src/tools/rust-analyzer/crates/hir/src/lib.rs
index 777be711a5e..963ad6ca993 100644
--- a/src/tools/rust-analyzer/crates/hir/src/lib.rs
+++ b/src/tools/rust-analyzer/crates/hir/src/lib.rs
@@ -1884,6 +1884,14 @@ impl Function {
         Type::from_value_def(db, self.id)
     }
 
+    pub fn fn_ptr_type(self, db: &dyn HirDatabase) -> Type {
+        let resolver = self.id.resolver(db.upcast());
+        let substs = TyBuilder::placeholder_subst(db, self.id);
+        let callable_sig = db.callable_item_signature(self.id.into()).substitute(Interner, &substs);
+        let ty = TyKind::Function(callable_sig.to_fn_ptr()).intern(Interner);
+        Type::new_with_resolver_inner(db, &resolver, ty)
+    }
+
     /// Get this function's return type
     pub fn ret_type(self, db: &dyn HirDatabase) -> Type {
         let resolver = self.id.resolver(db.upcast());