From 4039176ec63e5c75d76398f2debe26ac6fa59cbc Mon Sep 17 00:00:00 2001 From: Igor Aleksanov Date: Sat, 3 Oct 2020 12:48:02 +0300 Subject: Create basic support for names case checks and implement function name case check --- crates/hir_def/src/data.rs | 2 ++ crates/hir_def/src/item_tree.rs | 2 ++ crates/hir_def/src/item_tree/lower.rs | 14 ++++++++++++++ 3 files changed, 18 insertions(+) (limited to 'crates/hir_def') diff --git a/crates/hir_def/src/data.rs b/crates/hir_def/src/data.rs index ff1ef0df6..733db2eac 100644 --- a/crates/hir_def/src/data.rs +++ b/crates/hir_def/src/data.rs @@ -19,6 +19,7 @@ use crate::{ #[derive(Debug, Clone, PartialEq, Eq)] pub struct FunctionData { pub name: Name, + pub param_names: Vec>, pub params: Vec, pub ret_type: TypeRef, pub attrs: Attrs, @@ -39,6 +40,7 @@ impl FunctionData { Arc::new(FunctionData { name: func.name.clone(), + param_names: func.param_names.to_vec(), params: func.params.to_vec(), ret_type: func.ret_type.clone(), attrs: item_tree.attrs(ModItem::from(loc.id.value).into()).clone(), diff --git a/crates/hir_def/src/item_tree.rs b/crates/hir_def/src/item_tree.rs index 8a1121bbd..ca502ce2b 100644 --- a/crates/hir_def/src/item_tree.rs +++ b/crates/hir_def/src/item_tree.rs @@ -507,6 +507,8 @@ pub struct Function { pub has_self_param: bool, pub has_body: bool, pub is_unsafe: bool, + /// List of function parameters names. Does not include `self`. + pub param_names: Box<[Option]>, pub params: Box<[TypeRef]>, pub is_varargs: bool, pub ret_type: TypeRef, diff --git a/crates/hir_def/src/item_tree/lower.rs b/crates/hir_def/src/item_tree/lower.rs index 3328639cf..2ffa46ac0 100644 --- a/crates/hir_def/src/item_tree/lower.rs +++ b/crates/hir_def/src/item_tree/lower.rs @@ -283,6 +283,7 @@ impl Ctx { let name = func.name()?.as_name(); let mut params = Vec::new(); + let mut param_names = Vec::new(); let mut has_self_param = false; if let Some(param_list) = func.param_list() { if let Some(self_param) = param_list.self_param() { @@ -305,6 +306,18 @@ impl Ctx { has_self_param = true; } for param in param_list.params() { + let param_name = param + .pat() + .map(|name| { + if let ast::Pat::IdentPat(ident) = name { + Some(ident.name()?.as_name()) + } else { + None + } + }) + .flatten(); + param_names.push(param_name); + let type_ref = TypeRef::from_ast_opt(&self.body_ctx, param.ty()); params.push(type_ref); } @@ -341,6 +354,7 @@ impl Ctx { has_body, is_unsafe: func.unsafe_token().is_some(), params: params.into_boxed_slice(), + param_names: param_names.into_boxed_slice(), is_varargs, ret_type, ast_id, -- cgit v1.2.3 From b42562b5dee4f4ce23094c7bab6406e3b00f90ad Mon Sep 17 00:00:00 2001 From: Igor Aleksanov Date: Sun, 4 Oct 2020 07:39:35 +0300 Subject: Make incorrect case diagnostic work inside of functions --- crates/hir_def/src/item_scope.rs | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'crates/hir_def') diff --git a/crates/hir_def/src/item_scope.rs b/crates/hir_def/src/item_scope.rs index 12c24e1ca..a8b3fe844 100644 --- a/crates/hir_def/src/item_scope.rs +++ b/crates/hir_def/src/item_scope.rs @@ -95,6 +95,12 @@ impl ItemScope { self.impls.iter().copied() } + pub fn values( + &self, + ) -> impl Iterator + ExactSizeIterator + '_ { + self.values.values().copied() + } + pub fn visibility_of(&self, def: ModuleDefId) -> Option { self.name_of(ItemInNs::Types(def)) .or_else(|| self.name_of(ItemInNs::Values(def))) -- cgit v1.2.3 From cfbee8d3a35f81e710b17e48b8018cd6076a8133 Mon Sep 17 00:00:00 2001 From: Igor Aleksanov Date: Sun, 4 Oct 2020 07:42:06 +0300 Subject: Remove previously added parameter names from the function data --- crates/hir_def/src/data.rs | 2 -- crates/hir_def/src/item_tree.rs | 2 -- crates/hir_def/src/item_tree/lower.rs | 14 -------------- 3 files changed, 18 deletions(-) (limited to 'crates/hir_def') diff --git a/crates/hir_def/src/data.rs b/crates/hir_def/src/data.rs index 733db2eac..ff1ef0df6 100644 --- a/crates/hir_def/src/data.rs +++ b/crates/hir_def/src/data.rs @@ -19,7 +19,6 @@ use crate::{ #[derive(Debug, Clone, PartialEq, Eq)] pub struct FunctionData { pub name: Name, - pub param_names: Vec>, pub params: Vec, pub ret_type: TypeRef, pub attrs: Attrs, @@ -40,7 +39,6 @@ impl FunctionData { Arc::new(FunctionData { name: func.name.clone(), - param_names: func.param_names.to_vec(), params: func.params.to_vec(), ret_type: func.ret_type.clone(), attrs: item_tree.attrs(ModItem::from(loc.id.value).into()).clone(), diff --git a/crates/hir_def/src/item_tree.rs b/crates/hir_def/src/item_tree.rs index ca502ce2b..8a1121bbd 100644 --- a/crates/hir_def/src/item_tree.rs +++ b/crates/hir_def/src/item_tree.rs @@ -507,8 +507,6 @@ pub struct Function { pub has_self_param: bool, pub has_body: bool, pub is_unsafe: bool, - /// List of function parameters names. Does not include `self`. - pub param_names: Box<[Option]>, pub params: Box<[TypeRef]>, pub is_varargs: bool, pub ret_type: TypeRef, diff --git a/crates/hir_def/src/item_tree/lower.rs b/crates/hir_def/src/item_tree/lower.rs index 2ffa46ac0..3328639cf 100644 --- a/crates/hir_def/src/item_tree/lower.rs +++ b/crates/hir_def/src/item_tree/lower.rs @@ -283,7 +283,6 @@ impl Ctx { let name = func.name()?.as_name(); let mut params = Vec::new(); - let mut param_names = Vec::new(); let mut has_self_param = false; if let Some(param_list) = func.param_list() { if let Some(self_param) = param_list.self_param() { @@ -306,18 +305,6 @@ impl Ctx { has_self_param = true; } for param in param_list.params() { - let param_name = param - .pat() - .map(|name| { - if let ast::Pat::IdentPat(ident) = name { - Some(ident.name()?.as_name()) - } else { - None - } - }) - .flatten(); - param_names.push(param_name); - let type_ref = TypeRef::from_ast_opt(&self.body_ctx, param.ty()); params.push(type_ref); } @@ -354,7 +341,6 @@ impl Ctx { has_body, is_unsafe: func.unsafe_token().is_some(), params: params.into_boxed_slice(), - param_names: param_names.into_boxed_slice(), is_varargs, ret_type, ast_id, -- cgit v1.2.3