From c648884397bfdb779c447fa31964dc1fce94bd95 Mon Sep 17 00:00:00 2001 From: Zac Pullar-Strecker Date: Thu, 3 Sep 2020 19:55:24 +1200 Subject: Differentiate method/tymethod by determining 'defaultness' Currently a method only has defaultness if it is a provided trait method, but this will change when specialisation is available and may need to become a concept known to hir. I opted to go for a 'fewest changes' approach given specialisation is still under development. --- crates/hir_def/src/data.rs | 2 ++ crates/hir_def/src/item_tree.rs | 1 + crates/hir_def/src/item_tree/lower.rs | 3 +++ 3 files changed, 6 insertions(+) (limited to 'crates/hir_def') diff --git a/crates/hir_def/src/data.rs b/crates/hir_def/src/data.rs index 6190906da..ff1ef0df6 100644 --- a/crates/hir_def/src/data.rs +++ b/crates/hir_def/src/data.rs @@ -25,6 +25,7 @@ pub struct FunctionData { /// True if the first param is `self`. This is relevant to decide whether this /// can be called as a method. pub has_self_param: bool, + pub has_body: bool, pub is_unsafe: bool, pub is_varargs: bool, pub visibility: RawVisibility, @@ -42,6 +43,7 @@ impl FunctionData { ret_type: func.ret_type.clone(), attrs: item_tree.attrs(ModItem::from(loc.id.value).into()).clone(), has_self_param: func.has_self_param, + has_body: func.has_body, is_unsafe: func.is_unsafe, is_varargs: func.is_varargs, visibility: item_tree[func.visibility].clone(), diff --git a/crates/hir_def/src/item_tree.rs b/crates/hir_def/src/item_tree.rs index 0fd91b9d0..8a1121bbd 100644 --- a/crates/hir_def/src/item_tree.rs +++ b/crates/hir_def/src/item_tree.rs @@ -505,6 +505,7 @@ pub struct Function { pub visibility: RawVisibilityId, pub generic_params: GenericParamsId, pub has_self_param: bool, + pub has_body: bool, pub is_unsafe: bool, pub params: Box<[TypeRef]>, pub is_varargs: bool, diff --git a/crates/hir_def/src/item_tree/lower.rs b/crates/hir_def/src/item_tree/lower.rs index 54814f141..3328639cf 100644 --- a/crates/hir_def/src/item_tree/lower.rs +++ b/crates/hir_def/src/item_tree/lower.rs @@ -330,12 +330,15 @@ impl Ctx { ret_type }; + let has_body = func.body().is_some(); + let ast_id = self.source_ast_id_map.ast_id(func); let mut res = Function { name, visibility, generic_params: GenericParamsId::EMPTY, has_self_param, + has_body, is_unsafe: func.unsafe_token().is_some(), params: params.into_boxed_slice(), is_varargs, -- cgit v1.2.3