Skip to content

Commit 53afd2a

Browse files
committed
Auto merge of #12011 - iDawer:completion_detail.impl_trait, r=Veykril
fix: Show `impl Trait` in argument positon in completion details Follow up for #11991 `hir`: Use `db.callable_item_signature` query more.
2 parents dc6aa05 + d26deb5 commit 53afd2a

File tree

2 files changed

+39
-19
lines changed

2 files changed

+39
-19
lines changed

crates/hir/src/lib.rs

+19-19
Original file line numberDiff line numberDiff line change
@@ -1389,15 +1389,15 @@ impl Function {
13891389
}
13901390

13911391
pub fn assoc_fn_params(self, db: &dyn HirDatabase) -> Vec<Param> {
1392-
let resolver = self.id.resolver(db.upcast());
1393-
let ctx = hir_ty::TyLoweringContext::new(db, &resolver);
13941392
let environment = db.trait_environment(self.id.into());
1395-
db.function_data(self.id)
1396-
.params
1393+
let substs = TyBuilder::placeholder_subst(db, self.id);
1394+
let callable_sig = db.callable_item_signature(self.id.into()).substitute(Interner, &substs);
1395+
callable_sig
1396+
.params()
13971397
.iter()
13981398
.enumerate()
1399-
.map(|(idx, (_, type_ref))| {
1400-
let ty = Type { env: environment.clone(), ty: ctx.lower_ty(type_ref) };
1399+
.map(|(idx, ty)| {
1400+
let ty = Type { env: environment.clone(), ty: ty.clone() };
14011401
Param { func: self, ty, idx }
14021402
})
14031403
.collect()
@@ -1411,17 +1411,17 @@ impl Function {
14111411
}
14121412

14131413
pub fn params_without_self(self, db: &dyn HirDatabase) -> Vec<Param> {
1414-
let resolver = self.id.resolver(db.upcast());
1415-
let ctx = hir_ty::TyLoweringContext::new(db, &resolver);
14161414
let environment = db.trait_environment(self.id.into());
1415+
let substs = TyBuilder::placeholder_subst(db, self.id);
1416+
let callable_sig = db.callable_item_signature(self.id.into()).substitute(Interner, &substs);
14171417
let skip = if db.function_data(self.id).has_self_param() { 1 } else { 0 };
1418-
db.function_data(self.id)
1419-
.params
1418+
callable_sig
1419+
.params()
14201420
.iter()
14211421
.enumerate()
14221422
.skip(skip)
1423-
.map(|(idx, (_, type_ref))| {
1424-
let ty = Type { env: environment.clone(), ty: ctx.lower_ty(type_ref) };
1423+
.map(|(idx, ty)| {
1424+
let ty = Type { env: environment.clone(), ty: ty.clone() };
14251425
Param { func: self, ty, idx }
14261426
})
14271427
.collect()
@@ -1573,11 +1573,12 @@ impl SelfParam {
15731573
}
15741574

15751575
pub fn ty(&self, db: &dyn HirDatabase) -> Type {
1576-
let resolver = self.func.resolver(db.upcast());
1577-
let ctx = hir_ty::TyLoweringContext::new(db, &resolver);
1576+
let substs = TyBuilder::placeholder_subst(db, self.func);
1577+
let callable_sig =
1578+
db.callable_item_signature(self.func.into()).substitute(Interner, &substs);
15781579
let environment = db.trait_environment(self.func.into());
1579-
1580-
Type { env: environment, ty: ctx.lower_ty(&db.function_data(self.func).params[0].1) }
1580+
let ty = callable_sig.params()[0].clone();
1581+
Type { env: environment, ty }
15811582
}
15821583
}
15831584

@@ -2576,10 +2577,9 @@ impl Impl {
25762577
}
25772578

25782579
pub fn self_ty(self, db: &dyn HirDatabase) -> Type {
2579-
let impl_data = db.impl_data(self.id);
25802580
let resolver = self.id.resolver(db.upcast());
2581-
let ctx = hir_ty::TyLoweringContext::new(db, &resolver);
2582-
let ty = ctx.lower_ty(&impl_data.self_ty);
2581+
let substs = TyBuilder::placeholder_subst(db, self.id);
2582+
let ty = db.impl_self_ty(self.id).substitute(Interner, &substs);
25832583
Type::new_with_resolver_inner(db, &resolver, ty)
25842584
}
25852585

crates/ide_completion/src/tests/expression.rs

+20
Original file line numberDiff line numberDiff line change
@@ -642,3 +642,23 @@ fn main() {
642642
"]],
643643
);
644644
}
645+
646+
#[test]
647+
fn detail_impl_trait_in_argument_position() {
648+
check_empty(
649+
r"
650+
//- minicore: sized
651+
trait Trait<T> {}
652+
struct Foo;
653+
impl Foo {
654+
fn bar<U>(_: impl Trait<U>) {}
655+
}
656+
fn main() {
657+
Foo::$0
658+
}
659+
",
660+
expect![[r"
661+
fn bar(…) fn(impl Trait<U>)
662+
"]],
663+
);
664+
}

0 commit comments

Comments
 (0)