From f972adc2012fc49b35124d080a000a0d44c95452 Mon Sep 17 00:00:00 2001 From: iDawer Date: Tue, 12 Apr 2022 20:40:31 +0500 Subject: [PATCH] fix: comletion detail shows `{unknown}` for `impl Trait` in return position --- crates/hir/src/lib.rs | 6 +-- crates/ide_completion/src/tests/expression.rs | 39 +++++++++++++++++++ 2 files changed, 42 insertions(+), 3 deletions(-) diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs index 06056217fdb..7cda75b3478 100644 --- a/crates/hir/src/lib.rs +++ b/crates/hir/src/lib.rs @@ -1358,9 +1358,9 @@ pub fn name(self, db: &dyn HirDatabase) -> Name { /// Get this function's return type pub fn ret_type(self, db: &dyn HirDatabase) -> Type { let resolver = self.id.resolver(db.upcast()); - let ret_type = &db.function_data(self.id).ret_type; - let ctx = hir_ty::TyLoweringContext::new(db, &resolver); - let ty = ctx.lower_ty(ret_type); + let substs = TyBuilder::placeholder_subst(db, self.id); + let callable_sig = db.callable_item_signature(self.id.into()).substitute(Interner, &substs); + let ty = callable_sig.ret().clone(); Type::new_with_resolver_inner(db, &resolver, ty) } diff --git a/crates/ide_completion/src/tests/expression.rs b/crates/ide_completion/src/tests/expression.rs index f1950235d46..f25e14e0fcd 100644 --- a/crates/ide_completion/src/tests/expression.rs +++ b/crates/ide_completion/src/tests/expression.rs @@ -602,3 +602,42 @@ fn variant fn() -> Enum "#]], ); } + +#[test] +fn detail_impl_trait_in_return_position() { + check_empty( + r" +//- minicore: sized +trait Trait {} +fn foo() -> impl Trait {} +fn main() { + self::$0 +} +", + expect![[r" + tt Trait + fn main() fn() + fn foo() fn() -> impl Trait + "]], + ); +} + +#[test] +fn detail_async_fn() { + // FIXME: #11438 + check_empty( + r#" +//- minicore: future, sized +trait Trait {} +async fn foo() -> u8 {} +fn main() { + self::$0 +} +"#, + expect![[r" + tt Trait + fn main() fn() + fn foo() async fn() -> impl Future + "]], + ); +}