From 79c4c4fb48ee7ce32f26597123f4f2a90b786297 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Fri, 7 Apr 2023 09:57:19 +0200 Subject: [PATCH] Remove parameter names from function item tree --- crates/hir-def/src/data.rs | 2 +- crates/hir-def/src/item_tree.rs | 2 +- crates/hir-def/src/item_tree/lower.rs | 16 ++-------------- crates/hir-def/src/item_tree/pretty.rs | 16 +++++----------- crates/hir-def/src/item_tree/tests.rs | 12 ++++++------ 5 files changed, 15 insertions(+), 33 deletions(-) diff --git a/crates/hir-def/src/data.rs b/crates/hir-def/src/data.rs index de1e10ae2b0..98cf69c1689 100644 --- a/crates/hir-def/src/data.rs +++ b/crates/hir-def/src/data.rs @@ -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(), diff --git a/crates/hir-def/src/item_tree.rs b/crates/hir-def/src/item_tree.rs index d445e063f5f..8546d36d798 100644 --- a/crates/hir-def/src/item_tree.rs +++ b/crates/hir-def/src/item_tree.rs @@ -606,7 +606,7 @@ pub struct Function { #[derive(Debug, Clone, Eq, PartialEq)] pub enum Param { - Normal(Option, Interned), + Normal(Interned), Varargs, } diff --git a/crates/hir-def/src/item_tree/lower.rs b/crates/hir-def/src/item_tree/lower.rs index 0488bad3f98..c67c8bb4401 100644 --- a/crates/hir-def/src/item_tree/lower.rs +++ b/crates/hir-def/src/item_tree/lower.rs @@ -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(), ¶m, self.hygiene())); diff --git a/crates/hir-def/src/item_tree/pretty.rs b/crates/hir-def/src/item_tree/pretty.rs index edd5c3b1151..94c5157386e 100644 --- a/crates/hir-def/src/item_tree/pretty.rs +++ b/crates/hir-def/src/item_tree/pretty.rs @@ -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, "..."); diff --git a/crates/hir-def/src/item_tree/tests.rs b/crates/hir-def/src/item_tree/tests.rs index e30d9652bb5..1b7564f7a99 100644 --- a/crates/hir-def/src/item_tree/tests.rs +++ b/crates/hir-def/src/item_tree/tests.rs @@ -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 @@ -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( - arg: impl Copy, + impl Copy, ) -> impl Copy where G: 'a { ... }