mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-02 22:54:58 +00:00
internal: Store function param names in ItemTree
This commit is contained in:
parent
f609efff87
commit
cd9d76e0ca
11 changed files with 60 additions and 91 deletions
|
@ -20,7 +20,7 @@ use crate::{
|
|||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct FunctionData {
|
||||
pub name: Name,
|
||||
pub params: Vec<Interned<TypeRef>>,
|
||||
pub params: Vec<(Option<Name>, Interned<TypeRef>)>,
|
||||
pub ret_type: Interned<TypeRef>,
|
||||
pub async_ret_type: Option<Interned<TypeRef>>,
|
||||
pub attrs: Attrs,
|
||||
|
@ -72,7 +72,7 @@ impl FunctionData {
|
|||
params: enabled_params
|
||||
.clone()
|
||||
.filter_map(|id| match &item_tree[id] {
|
||||
Param::Normal(ty) => Some(ty.clone()),
|
||||
Param::Normal(name, ty) => Some((name.clone(), ty.clone())),
|
||||
Param::Varargs => None,
|
||||
})
|
||||
.collect(),
|
||||
|
|
|
@ -113,7 +113,7 @@ impl GenericParams {
|
|||
// Don't create an `Expander` nor call `loc.source(db)` if not needed since this
|
||||
// causes a reparse after the `ItemTree` has been created.
|
||||
let mut expander = Lazy::new(|| Expander::new(db, loc.source(db).file_id, module));
|
||||
for param in &func_data.params {
|
||||
for (_, param) in &func_data.params {
|
||||
generic_params.fill_implicit_impl_trait_args(db, &mut expander, param);
|
||||
}
|
||||
|
||||
|
|
|
@ -598,7 +598,7 @@ pub struct Function {
|
|||
|
||||
#[derive(Debug, Clone, Eq, PartialEq)]
|
||||
pub enum Param {
|
||||
Normal(Interned<TypeRef>),
|
||||
Normal(Option<Name>, Interned<TypeRef>),
|
||||
Varargs,
|
||||
}
|
||||
|
||||
|
|
|
@ -269,7 +269,7 @@ impl<'a> Ctx<'a> {
|
|||
}
|
||||
};
|
||||
let ty = Interned::new(self_type);
|
||||
let idx = self.data().params.alloc(Param::Normal(ty));
|
||||
let idx = self.data().params.alloc(Param::Normal(None, ty));
|
||||
self.add_attrs(idx.into(), RawAttrs::new(self.db, &self_param, &self.hygiene));
|
||||
has_self_param = true;
|
||||
}
|
||||
|
@ -279,7 +279,19 @@ impl<'a> Ctx<'a> {
|
|||
None => {
|
||||
let type_ref = TypeRef::from_ast_opt(&self.body_ctx, param.ty());
|
||||
let ty = Interned::new(type_ref);
|
||||
self.data().params.alloc(Param::Normal(ty))
|
||||
let mut pat = param.pat();
|
||||
// FIXME: This really shouldn't be here, in fact FunctionData/ItemTree's function shouldn't know about
|
||||
// pattern names at all
|
||||
let name = loop {
|
||||
match pat {
|
||||
Some(ast::Pat::RefPat(ref_pat)) => pat = ref_pat.pat(),
|
||||
Some(ast::Pat::IdentPat(ident)) => {
|
||||
break ident.name().map(|it| it.as_name())
|
||||
}
|
||||
_ => break None,
|
||||
}
|
||||
};
|
||||
self.data().params.alloc(Param::Normal(name, ty))
|
||||
}
|
||||
};
|
||||
self.add_attrs(idx.into(), RawAttrs::new(self.db, ¶m, &self.hygiene));
|
||||
|
|
|
@ -257,8 +257,11 @@ impl<'a> Printer<'a> {
|
|||
for param in params.clone() {
|
||||
this.print_attrs_of(param);
|
||||
match &this.tree[param] {
|
||||
Param::Normal(ty) => {
|
||||
w!(this, "_: ");
|
||||
Param::Normal(name, ty) => {
|
||||
match name {
|
||||
Some(name) => w!(this, "{}: ", name),
|
||||
None => w!(this, "_: "),
|
||||
}
|
||||
this.print_type_ref(ty);
|
||||
wln!(this, ",");
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue