From 88f125ebc97b291e56fae77cdb5a1c2938418e8f Mon Sep 17 00:00:00 2001 From: Vincent Esche Date: Wed, 29 May 2024 19:41:55 +0200 Subject: [PATCH] =?UTF-8?q?Add=20`Function::fn=5Fptr=5Ftype(=E2=80=A6)`=20?= =?UTF-8?q?for=20obtaining=20name-erased=20function=20type?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/tools/rust-analyzer/crates/hir/src/lib.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/tools/rust-analyzer/crates/hir/src/lib.rs b/src/tools/rust-analyzer/crates/hir/src/lib.rs index 777be711a5e6..963ad6ca993c 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());