Remove parameter names from function item tree

This commit is contained in:
Lukas Wirth 2023-04-07 09:57:19 +02:00
parent 513d4a9c9a
commit 79c4c4fb48
5 changed files with 15 additions and 33 deletions

View File

@ -100,7 +100,7 @@ impl FunctionData {
params: enabled_params
.clone()
.filter_map(|id| match &item_tree[id] {
Param::Normal(_, ty) => Some(ty.clone()),
Param::Normal(ty) => Some(ty.clone()),
Param::Varargs => None,
})
.collect(),

View File

@ -606,7 +606,7 @@ pub struct Function {
#[derive(Debug, Clone, Eq, PartialEq)]
pub enum Param {
Normal(Option<Name>, Interned<TypeRef>),
Normal(Interned<TypeRef>),
Varargs,
}

View File

@ -293,7 +293,7 @@ impl<'a> Ctx<'a> {
}
};
let ty = Interned::new(self_type);
let idx = self.data().params.alloc(Param::Normal(None, ty));
let idx = self.data().params.alloc(Param::Normal(ty));
self.add_attrs(
idx.into(),
RawAttrs::new(self.db.upcast(), &self_param, self.hygiene()),
@ -306,19 +306,7 @@ impl<'a> Ctx<'a> {
None => {
let type_ref = TypeRef::from_ast_opt(&self.body_ctx, param.ty());
let ty = Interned::new(type_ref);
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 = 'name: loop {
match pat {
Some(ast::Pat::RefPat(ref_pat)) => pat = ref_pat.pat(),
Some(ast::Pat::IdentPat(ident)) => {
break 'name ident.name().map(|it| it.as_name())
}
_ => break 'name None,
}
};
self.data().params.alloc(Param::Normal(name, ty))
self.data().params.alloc(Param::Normal(ty))
}
};
self.add_attrs(idx.into(), RawAttrs::new(self.db.upcast(), &param, self.hygiene()));

View File

@ -257,21 +257,15 @@ impl<'a> Printer<'a> {
w!(self, "(");
if !params.is_empty() {
self.indented(|this| {
for (i, param) in params.clone().enumerate() {
for param in params.clone() {
this.print_attrs_of(param);
match &this.tree[param] {
Param::Normal(name, ty) => {
match name {
Some(name) => w!(this, "{}: ", name),
None => w!(this, "_: "),
Param::Normal(ty) => {
if flags.contains(FnFlags::HAS_SELF_PARAM) {
w!(this, "self: ");
}
this.print_type_ref(ty);
w!(this, ",");
if flags.contains(FnFlags::HAS_SELF_PARAM) && i == 0 {
wln!(this, " // self");
} else {
wln!(this);
}
wln!(this, ",");
}
Param::Varargs => {
wln!(this, "...");

View File

@ -165,7 +165,7 @@ trait Tr: SuperTrait + 'lifetime {
fn method(&self);
}
"#,
expect![[r##"
expect![[r#"
pub static mut ST: () = _;
pub(self) const _: Anon = _;
@ -174,8 +174,8 @@ trait Tr: SuperTrait + 'lifetime {
#[inner_attr_in_fn]
pub(self) fn f(
#[attr]
arg: u8,
_: (),
u8,
(),
) -> () { ... }
pub(self) trait Tr<Self>
@ -186,10 +186,10 @@ trait Tr: SuperTrait + 'lifetime {
pub(self) type Assoc: AssocBound = Default;
pub(self) fn method(
_: &Self, // self
self: &Self,
) -> ();
}
"##]],
"#]],
);
}
@ -336,7 +336,7 @@ trait Tr<'a, T: 'a>: Super where Self: for<'a> Tr<'a, T> {}
T: 'b
{
pub(self) fn f<G>(
arg: impl Copy,
impl Copy,
) -> impl Copy
where
G: 'a { ... }