aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_def
diff options
context:
space:
mode:
authorPaul Daniel Faria <[email protected]>2020-06-27 22:11:43 +0100
committerPaul Daniel Faria <[email protected]>2020-08-10 13:44:54 +0100
commitd5f11e530dbf6edbdd0ca32d6cd5fafe634c8c4a (patch)
treeb348ea6d5552be08913ac3a451836cad5ac75c1a /crates/ra_hir_def
parent38440d53d8329ac9f3f2013c6e32b3f69b069c72 (diff)
Unsafe borrow of packed fields: account for borrow through ref binding, auto ref function calls
Diffstat (limited to 'crates/ra_hir_def')
-rw-r--r--crates/ra_hir_def/src/data.rs6
-rw-r--r--crates/ra_hir_def/src/item_tree.rs8
-rw-r--r--crates/ra_hir_def/src/item_tree/lower.rs9
3 files changed, 16 insertions, 7 deletions
diff --git a/crates/ra_hir_def/src/data.rs b/crates/ra_hir_def/src/data.rs
index 88a8ef9bf..2a26b0183 100644
--- a/crates/ra_hir_def/src/data.rs
+++ b/crates/ra_hir_def/src/data.rs
@@ -10,7 +10,7 @@ use crate::{
10 attr::Attrs, 10 attr::Attrs,
11 body::Expander, 11 body::Expander,
12 db::DefDatabase, 12 db::DefDatabase,
13 item_tree::{AssocItem, ItemTreeId, ModItem}, 13 item_tree::{AssocItem, ItemTreeId, ModItem, SelfParam},
14 type_ref::{TypeBound, TypeRef}, 14 type_ref::{TypeBound, TypeRef},
15 visibility::RawVisibility, 15 visibility::RawVisibility,
16 AssocContainerId, AssocItemId, ConstId, ConstLoc, FunctionId, FunctionLoc, HasModule, ImplId, 16 AssocContainerId, AssocItemId, ConstId, ConstLoc, FunctionId, FunctionLoc, HasModule, ImplId,
@@ -25,7 +25,7 @@ pub struct FunctionData {
25 pub attrs: Attrs, 25 pub attrs: Attrs,
26 /// True if the first param is `self`. This is relevant to decide whether this 26 /// True if the first param is `self`. This is relevant to decide whether this
27 /// can be called as a method. 27 /// can be called as a method.
28 pub has_self_param: bool, 28 pub self_param: Option<SelfParam>,
29 pub is_unsafe: bool, 29 pub is_unsafe: bool,
30 pub is_varargs: bool, 30 pub is_varargs: bool,
31 pub visibility: RawVisibility, 31 pub visibility: RawVisibility,
@@ -42,7 +42,7 @@ impl FunctionData {
42 params: func.params.to_vec(), 42 params: func.params.to_vec(),
43 ret_type: func.ret_type.clone(), 43 ret_type: func.ret_type.clone(),
44 attrs: item_tree.attrs(ModItem::from(loc.id.value).into()).clone(), 44 attrs: item_tree.attrs(ModItem::from(loc.id.value).into()).clone(),
45 has_self_param: func.has_self_param, 45 self_param: func.self_param,
46 is_unsafe: func.is_unsafe, 46 is_unsafe: func.is_unsafe,
47 is_varargs: func.is_varargs, 47 is_varargs: func.is_varargs,
48 visibility: item_tree[func.visibility].clone(), 48 visibility: item_tree[func.visibility].clone(),
diff --git a/crates/ra_hir_def/src/item_tree.rs b/crates/ra_hir_def/src/item_tree.rs
index a67e75dac..1eaea66e4 100644
--- a/crates/ra_hir_def/src/item_tree.rs
+++ b/crates/ra_hir_def/src/item_tree.rs
@@ -500,7 +500,7 @@ pub struct Function {
500 pub name: Name, 500 pub name: Name,
501 pub visibility: RawVisibilityId, 501 pub visibility: RawVisibilityId,
502 pub generic_params: GenericParamsId, 502 pub generic_params: GenericParamsId,
503 pub has_self_param: bool, 503 pub self_param: Option<SelfParam>,
504 pub is_unsafe: bool, 504 pub is_unsafe: bool,
505 pub params: Box<[TypeRef]>, 505 pub params: Box<[TypeRef]>,
506 pub is_varargs: bool, 506 pub is_varargs: bool,
@@ -508,6 +508,12 @@ pub struct Function {
508 pub ast_id: FileAstId<ast::Fn>, 508 pub ast_id: FileAstId<ast::Fn>,
509} 509}
510 510
511#[derive(Debug, Copy, Clone, Eq, PartialEq)]
512pub struct SelfParam {
513 pub is_ref: bool,
514 pub is_mut: bool,
515}
516
511#[derive(Debug, Clone, Eq, PartialEq)] 517#[derive(Debug, Clone, Eq, PartialEq)]
512pub struct Struct { 518pub struct Struct {
513 pub name: Name, 519 pub name: Name,
diff --git a/crates/ra_hir_def/src/item_tree/lower.rs b/crates/ra_hir_def/src/item_tree/lower.rs
index 450ef8798..89ad91d37 100644
--- a/crates/ra_hir_def/src/item_tree/lower.rs
+++ b/crates/ra_hir_def/src/item_tree/lower.rs
@@ -283,7 +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 has_self_param = false; 286 let mut func_self_param = None;
287 if let Some(param_list) = func.param_list() { 287 if let Some(param_list) = func.param_list() {
288 if let Some(self_param) = param_list.self_param() { 288 if let Some(self_param) = param_list.self_param() {
289 let self_type = match self_param.ty() { 289 let self_type = match self_param.ty() {
@@ -302,7 +302,10 @@ impl Ctx {
302 } 302 }
303 }; 303 };
304 params.push(self_type); 304 params.push(self_type);
305 has_self_param = true; 305 func_self_param = Some(SelfParam {
306 is_ref: self_param.amp_token().is_some(),
307 is_mut: self_param.mut_token().is_some(),
308 });
306 } 309 }
307 for param in param_list.params() { 310 for param in param_list.params() {
308 let type_ref = TypeRef::from_ast_opt(&self.body_ctx, param.ty()); 311 let type_ref = TypeRef::from_ast_opt(&self.body_ctx, param.ty());
@@ -335,7 +338,7 @@ impl Ctx {
335 name, 338 name,
336 visibility, 339 visibility,
337 generic_params: GenericParamsId::EMPTY, 340 generic_params: GenericParamsId::EMPTY,
338 has_self_param, 341 self_param: func_self_param,
339 is_unsafe: func.unsafe_token().is_some(), 342 is_unsafe: func.unsafe_token().is_some(),
340 params: params.into_boxed_slice(), 343 params: params.into_boxed_slice(),
341 is_varargs, 344 is_varargs,