mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-02 07:22:42 +00:00
Show impl Trait
in argument positon in completion details
`hir`: Use `db.callable_item_signature` query more.
This commit is contained in:
parent
c53412046f
commit
d26deb5b9f
@ -1389,15 +1389,15 @@ impl Function {
|
||||
}
|
||||
|
||||
pub fn assoc_fn_params(self, db: &dyn HirDatabase) -> Vec<Param> {
|
||||
let resolver = self.id.resolver(db.upcast());
|
||||
let ctx = hir_ty::TyLoweringContext::new(db, &resolver);
|
||||
let environment = db.trait_environment(self.id.into());
|
||||
db.function_data(self.id)
|
||||
.params
|
||||
let substs = TyBuilder::placeholder_subst(db, self.id);
|
||||
let callable_sig = db.callable_item_signature(self.id.into()).substitute(Interner, &substs);
|
||||
callable_sig
|
||||
.params()
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|(idx, (_, type_ref))| {
|
||||
let ty = Type { env: environment.clone(), ty: ctx.lower_ty(type_ref) };
|
||||
.map(|(idx, ty)| {
|
||||
let ty = Type { env: environment.clone(), ty: ty.clone() };
|
||||
Param { func: self, ty, idx }
|
||||
})
|
||||
.collect()
|
||||
@ -1411,17 +1411,17 @@ impl Function {
|
||||
}
|
||||
|
||||
pub fn params_without_self(self, db: &dyn HirDatabase) -> Vec<Param> {
|
||||
let resolver = self.id.resolver(db.upcast());
|
||||
let ctx = hir_ty::TyLoweringContext::new(db, &resolver);
|
||||
let environment = db.trait_environment(self.id.into());
|
||||
let substs = TyBuilder::placeholder_subst(db, self.id);
|
||||
let callable_sig = db.callable_item_signature(self.id.into()).substitute(Interner, &substs);
|
||||
let skip = if db.function_data(self.id).has_self_param() { 1 } else { 0 };
|
||||
db.function_data(self.id)
|
||||
.params
|
||||
callable_sig
|
||||
.params()
|
||||
.iter()
|
||||
.enumerate()
|
||||
.skip(skip)
|
||||
.map(|(idx, (_, type_ref))| {
|
||||
let ty = Type { env: environment.clone(), ty: ctx.lower_ty(type_ref) };
|
||||
.map(|(idx, ty)| {
|
||||
let ty = Type { env: environment.clone(), ty: ty.clone() };
|
||||
Param { func: self, ty, idx }
|
||||
})
|
||||
.collect()
|
||||
@ -1573,11 +1573,12 @@ impl SelfParam {
|
||||
}
|
||||
|
||||
pub fn ty(&self, db: &dyn HirDatabase) -> Type {
|
||||
let resolver = self.func.resolver(db.upcast());
|
||||
let ctx = hir_ty::TyLoweringContext::new(db, &resolver);
|
||||
let substs = TyBuilder::placeholder_subst(db, self.func);
|
||||
let callable_sig =
|
||||
db.callable_item_signature(self.func.into()).substitute(Interner, &substs);
|
||||
let environment = db.trait_environment(self.func.into());
|
||||
|
||||
Type { env: environment, ty: ctx.lower_ty(&db.function_data(self.func).params[0].1) }
|
||||
let ty = callable_sig.params()[0].clone();
|
||||
Type { env: environment, ty }
|
||||
}
|
||||
}
|
||||
|
||||
@ -2576,10 +2577,9 @@ impl Impl {
|
||||
}
|
||||
|
||||
pub fn self_ty(self, db: &dyn HirDatabase) -> Type {
|
||||
let impl_data = db.impl_data(self.id);
|
||||
let resolver = self.id.resolver(db.upcast());
|
||||
let ctx = hir_ty::TyLoweringContext::new(db, &resolver);
|
||||
let ty = ctx.lower_ty(&impl_data.self_ty);
|
||||
let substs = TyBuilder::placeholder_subst(db, self.id);
|
||||
let ty = db.impl_self_ty(self.id).substitute(Interner, &substs);
|
||||
Type::new_with_resolver_inner(db, &resolver, ty)
|
||||
}
|
||||
|
||||
|
@ -642,3 +642,23 @@ fn main() {
|
||||
"]],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn detail_impl_trait_in_argument_position() {
|
||||
check_empty(
|
||||
r"
|
||||
//- minicore: sized
|
||||
trait Trait<T> {}
|
||||
struct Foo;
|
||||
impl Foo {
|
||||
fn bar<U>(_: impl Trait<U>) {}
|
||||
}
|
||||
fn main() {
|
||||
Foo::$0
|
||||
}
|
||||
",
|
||||
expect![[r"
|
||||
fn bar(…) fn(impl Trait<U>)
|
||||
"]],
|
||||
);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user