Auto merge of #14525 - Veykril:hir-pretty, r=Veykril
internal: Remove parameter names from function item tree
This commit is contained in:
commit
bca364c3fe
@ -100,7 +100,7 @@ impl FunctionData {
|
|||||||
params: enabled_params
|
params: enabled_params
|
||||||
.clone()
|
.clone()
|
||||||
.filter_map(|id| match &item_tree[id] {
|
.filter_map(|id| match &item_tree[id] {
|
||||||
Param::Normal(_, ty) => Some(ty.clone()),
|
Param::Normal(ty) => Some(ty.clone()),
|
||||||
Param::Varargs => None,
|
Param::Varargs => None,
|
||||||
})
|
})
|
||||||
.collect(),
|
.collect(),
|
||||||
|
@ -606,7 +606,7 @@ pub struct Function {
|
|||||||
|
|
||||||
#[derive(Debug, Clone, Eq, PartialEq)]
|
#[derive(Debug, Clone, Eq, PartialEq)]
|
||||||
pub enum Param {
|
pub enum Param {
|
||||||
Normal(Option<Name>, Interned<TypeRef>),
|
Normal(Interned<TypeRef>),
|
||||||
Varargs,
|
Varargs,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -293,7 +293,7 @@ impl<'a> Ctx<'a> {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
let ty = Interned::new(self_type);
|
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(
|
self.add_attrs(
|
||||||
idx.into(),
|
idx.into(),
|
||||||
RawAttrs::new(self.db.upcast(), &self_param, self.hygiene()),
|
RawAttrs::new(self.db.upcast(), &self_param, self.hygiene()),
|
||||||
@ -306,19 +306,7 @@ impl<'a> Ctx<'a> {
|
|||||||
None => {
|
None => {
|
||||||
let type_ref = TypeRef::from_ast_opt(&self.body_ctx, param.ty());
|
let type_ref = TypeRef::from_ast_opt(&self.body_ctx, param.ty());
|
||||||
let ty = Interned::new(type_ref);
|
let ty = Interned::new(type_ref);
|
||||||
let mut pat = param.pat();
|
self.data().params.alloc(Param::Normal(ty))
|
||||||
// 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.add_attrs(idx.into(), RawAttrs::new(self.db.upcast(), ¶m, self.hygiene()));
|
self.add_attrs(idx.into(), RawAttrs::new(self.db.upcast(), ¶m, self.hygiene()));
|
||||||
|
@ -257,21 +257,15 @@ impl<'a> Printer<'a> {
|
|||||||
w!(self, "(");
|
w!(self, "(");
|
||||||
if !params.is_empty() {
|
if !params.is_empty() {
|
||||||
self.indented(|this| {
|
self.indented(|this| {
|
||||||
for (i, param) in params.clone().enumerate() {
|
for param in params.clone() {
|
||||||
this.print_attrs_of(param);
|
this.print_attrs_of(param);
|
||||||
match &this.tree[param] {
|
match &this.tree[param] {
|
||||||
Param::Normal(name, ty) => {
|
Param::Normal(ty) => {
|
||||||
match name {
|
if flags.contains(FnFlags::HAS_SELF_PARAM) {
|
||||||
Some(name) => w!(this, "{}: ", name),
|
w!(this, "self: ");
|
||||||
None => w!(this, "_: "),
|
|
||||||
}
|
}
|
||||||
this.print_type_ref(ty);
|
this.print_type_ref(ty);
|
||||||
w!(this, ",");
|
wln!(this, ",");
|
||||||
if flags.contains(FnFlags::HAS_SELF_PARAM) && i == 0 {
|
|
||||||
wln!(this, " // self");
|
|
||||||
} else {
|
|
||||||
wln!(this);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Param::Varargs => {
|
Param::Varargs => {
|
||||||
wln!(this, "...");
|
wln!(this, "...");
|
||||||
|
@ -165,7 +165,7 @@ trait Tr: SuperTrait + 'lifetime {
|
|||||||
fn method(&self);
|
fn method(&self);
|
||||||
}
|
}
|
||||||
"#,
|
"#,
|
||||||
expect![[r##"
|
expect![[r#"
|
||||||
pub static mut ST: () = _;
|
pub static mut ST: () = _;
|
||||||
|
|
||||||
pub(self) const _: Anon = _;
|
pub(self) const _: Anon = _;
|
||||||
@ -174,8 +174,8 @@ trait Tr: SuperTrait + 'lifetime {
|
|||||||
#[inner_attr_in_fn]
|
#[inner_attr_in_fn]
|
||||||
pub(self) fn f(
|
pub(self) fn f(
|
||||||
#[attr]
|
#[attr]
|
||||||
arg: u8,
|
u8,
|
||||||
_: (),
|
(),
|
||||||
) -> () { ... }
|
) -> () { ... }
|
||||||
|
|
||||||
pub(self) trait Tr<Self>
|
pub(self) trait Tr<Self>
|
||||||
@ -186,10 +186,10 @@ trait Tr: SuperTrait + 'lifetime {
|
|||||||
pub(self) type Assoc: AssocBound = Default;
|
pub(self) type Assoc: AssocBound = Default;
|
||||||
|
|
||||||
pub(self) fn method(
|
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
|
T: 'b
|
||||||
{
|
{
|
||||||
pub(self) fn f<G>(
|
pub(self) fn f<G>(
|
||||||
arg: impl Copy,
|
impl Copy,
|
||||||
) -> impl Copy
|
) -> impl Copy
|
||||||
where
|
where
|
||||||
G: 'a { ... }
|
G: 'a { ... }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user