Skip to content

Commit bca364c

Browse files
committed
Auto merge of rust-lang#14525 - Veykril:hir-pretty, r=Veykril
internal: Remove parameter names from function item tree
2 parents d73161b + 79c4c4f commit bca364c

File tree

5 files changed

+15
-33
lines changed

5 files changed

+15
-33
lines changed

crates/hir-def/src/data.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ impl FunctionData {
100100
params: enabled_params
101101
.clone()
102102
.filter_map(|id| match &item_tree[id] {
103-
Param::Normal(_, ty) => Some(ty.clone()),
103+
Param::Normal(ty) => Some(ty.clone()),
104104
Param::Varargs => None,
105105
})
106106
.collect(),

crates/hir-def/src/item_tree.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,7 @@ pub struct Function {
606606

607607
#[derive(Debug, Clone, Eq, PartialEq)]
608608
pub enum Param {
609-
Normal(Option<Name>, Interned<TypeRef>),
609+
Normal(Interned<TypeRef>),
610610
Varargs,
611611
}
612612

crates/hir-def/src/item_tree/lower.rs

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ impl<'a> Ctx<'a> {
293293
}
294294
};
295295
let ty = Interned::new(self_type);
296-
let idx = self.data().params.alloc(Param::Normal(None, ty));
296+
let idx = self.data().params.alloc(Param::Normal(ty));
297297
self.add_attrs(
298298
idx.into(),
299299
RawAttrs::new(self.db.upcast(), &self_param, self.hygiene()),
@@ -306,19 +306,7 @@ impl<'a> Ctx<'a> {
306306
None => {
307307
let type_ref = TypeRef::from_ast_opt(&self.body_ctx, param.ty());
308308
let ty = Interned::new(type_ref);
309-
let mut pat = param.pat();
310-
// FIXME: This really shouldn't be here, in fact FunctionData/ItemTree's function shouldn't know about
311-
// pattern names at all
312-
let name = 'name: loop {
313-
match pat {
314-
Some(ast::Pat::RefPat(ref_pat)) => pat = ref_pat.pat(),
315-
Some(ast::Pat::IdentPat(ident)) => {
316-
break 'name ident.name().map(|it| it.as_name())
317-
}
318-
_ => break 'name None,
319-
}
320-
};
321-
self.data().params.alloc(Param::Normal(name, ty))
309+
self.data().params.alloc(Param::Normal(ty))
322310
}
323311
};
324312
self.add_attrs(idx.into(), RawAttrs::new(self.db.upcast(), &param, self.hygiene()));

crates/hir-def/src/item_tree/pretty.rs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -257,21 +257,15 @@ impl<'a> Printer<'a> {
257257
w!(self, "(");
258258
if !params.is_empty() {
259259
self.indented(|this| {
260-
for (i, param) in params.clone().enumerate() {
260+
for param in params.clone() {
261261
this.print_attrs_of(param);
262262
match &this.tree[param] {
263-
Param::Normal(name, ty) => {
264-
match name {
265-
Some(name) => w!(this, "{}: ", name),
266-
None => w!(this, "_: "),
263+
Param::Normal(ty) => {
264+
if flags.contains(FnFlags::HAS_SELF_PARAM) {
265+
w!(this, "self: ");
267266
}
268267
this.print_type_ref(ty);
269-
w!(this, ",");
270-
if flags.contains(FnFlags::HAS_SELF_PARAM) && i == 0 {
271-
wln!(this, " // self");
272-
} else {
273-
wln!(this);
274-
}
268+
wln!(this, ",");
275269
}
276270
Param::Varargs => {
277271
wln!(this, "...");

crates/hir-def/src/item_tree/tests.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ trait Tr: SuperTrait + 'lifetime {
165165
fn method(&self);
166166
}
167167
"#,
168-
expect![[r##"
168+
expect![[r#"
169169
pub static mut ST: () = _;
170170
171171
pub(self) const _: Anon = _;
@@ -174,8 +174,8 @@ trait Tr: SuperTrait + 'lifetime {
174174
#[inner_attr_in_fn]
175175
pub(self) fn f(
176176
#[attr]
177-
arg: u8,
178-
_: (),
177+
u8,
178+
(),
179179
) -> () { ... }
180180
181181
pub(self) trait Tr<Self>
@@ -186,10 +186,10 @@ trait Tr: SuperTrait + 'lifetime {
186186
pub(self) type Assoc: AssocBound = Default;
187187
188188
pub(self) fn method(
189-
_: &Self, // self
189+
self: &Self,
190190
) -> ();
191191
}
192-
"##]],
192+
"#]],
193193
);
194194
}
195195

@@ -336,7 +336,7 @@ trait Tr<'a, T: 'a>: Super where Self: for<'a> Tr<'a, T> {}
336336
T: 'b
337337
{
338338
pub(self) fn f<G>(
339-
arg: impl Copy,
339+
impl Copy,
340340
) -> impl Copy
341341
where
342342
G: 'a { ... }

0 commit comments

Comments
 (0)