aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_def/src
diff options
context:
space:
mode:
authorIgor Aleksanov <[email protected]>2020-10-03 10:48:02 +0100
committerIgor Aleksanov <[email protected]>2020-10-12 08:59:54 +0100
commit4039176ec63e5c75d76398f2debe26ac6fa59cbc (patch)
tree8f2f2b6d22c57985fc6a8f1b40d84663d40b09f6 /crates/hir_def/src
parent518f6d772482c7c58e59081f340947087a9b4800 (diff)
Create basic support for names case checks and implement function name case check
Diffstat (limited to 'crates/hir_def/src')
-rw-r--r--crates/hir_def/src/data.rs2
-rw-r--r--crates/hir_def/src/item_tree.rs2
-rw-r--r--crates/hir_def/src/item_tree/lower.rs14
3 files changed, 18 insertions, 0 deletions
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::{
19#[derive(Debug, Clone, PartialEq, Eq)] 19#[derive(Debug, Clone, PartialEq, Eq)]
20pub struct FunctionData { 20pub struct FunctionData {
21 pub name: Name, 21 pub name: Name,
22 pub param_names: Vec<Option<Name>>,
22 pub params: Vec<TypeRef>, 23 pub params: Vec<TypeRef>,
23 pub ret_type: TypeRef, 24 pub ret_type: TypeRef,
24 pub attrs: Attrs, 25 pub attrs: Attrs,
@@ -39,6 +40,7 @@ impl FunctionData {
39 40
40 Arc::new(FunctionData { 41 Arc::new(FunctionData {
41 name: func.name.clone(), 42 name: func.name.clone(),
43 param_names: func.param_names.to_vec(),
42 params: func.params.to_vec(), 44 params: func.params.to_vec(),
43 ret_type: func.ret_type.clone(), 45 ret_type: func.ret_type.clone(),
44 attrs: item_tree.attrs(ModItem::from(loc.id.value).into()).clone(), 46 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 {
507 pub has_self_param: bool, 507 pub has_self_param: bool,
508 pub has_body: bool, 508 pub has_body: bool,
509 pub is_unsafe: bool, 509 pub is_unsafe: bool,
510 /// List of function parameters names. Does not include `self`.
511 pub param_names: Box<[Option<Name>]>,
510 pub params: Box<[TypeRef]>, 512 pub params: Box<[TypeRef]>,
511 pub is_varargs: bool, 513 pub is_varargs: bool,
512 pub ret_type: TypeRef, 514 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 {
283 let name = func.name()?.as_name(); 283 let name = func.name()?.as_name();
284 284
285 let mut params = Vec::new(); 285 let mut params = Vec::new();
286 let mut param_names = Vec::new();
286 let mut has_self_param = false; 287 let mut has_self_param = false;
287 if let Some(param_list) = func.param_list() { 288 if let Some(param_list) = func.param_list() {
288 if let Some(self_param) = param_list.self_param() { 289 if let Some(self_param) = param_list.self_param() {
@@ -305,6 +306,18 @@ impl Ctx {
305 has_self_param = true; 306 has_self_param = true;
306 } 307 }
307 for param in param_list.params() { 308 for param in param_list.params() {
309 let param_name = param
310 .pat()
311 .map(|name| {
312 if let ast::Pat::IdentPat(ident) = name {
313 Some(ident.name()?.as_name())
314 } else {
315 None
316 }
317 })
318 .flatten();
319 param_names.push(param_name);
320
308 let type_ref = TypeRef::from_ast_opt(&self.body_ctx, param.ty()); 321 let type_ref = TypeRef::from_ast_opt(&self.body_ctx, param.ty());
309 params.push(type_ref); 322 params.push(type_ref);
310 } 323 }
@@ -341,6 +354,7 @@ impl Ctx {
341 has_body, 354 has_body,
342 is_unsafe: func.unsafe_token().is_some(), 355 is_unsafe: func.unsafe_token().is_some(),
343 params: params.into_boxed_slice(), 356 params: params.into_boxed_slice(),
357 param_names: param_names.into_boxed_slice(),
344 is_varargs, 358 is_varargs,
345 ret_type, 359 ret_type,
346 ast_id, 360 ast_id,