diff options
author | Zac Pullar-Strecker <[email protected]> | 2020-09-03 08:55:24 +0100 |
---|---|---|
committer | Zac Pullar-Strecker <[email protected]> | 2020-10-08 03:04:21 +0100 |
commit | c648884397bfdb779c447fa31964dc1fce94bd95 (patch) | |
tree | 276467ffe91360d31f285ce04bf16c0753c61a10 /crates/hir | |
parent | 62b76e7004bc215a375e41bd204b2eab5acdf9c2 (diff) |
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.
Diffstat (limited to 'crates/hir')
-rw-r--r-- | crates/hir/src/code_model.rs | 9 | ||||
-rw-r--r-- | crates/hir/src/lib.rs | 4 |
2 files changed, 10 insertions, 3 deletions
diff --git a/crates/hir/src/code_model.rs b/crates/hir/src/code_model.rs index 1dd6d73f3..0b24f247c 100644 --- a/crates/hir/src/code_model.rs +++ b/crates/hir/src/code_model.rs | |||
@@ -772,7 +772,14 @@ impl Function { | |||
772 | hir_ty::diagnostics::validate_body(db, self.id.into(), sink) | 772 | hir_ty::diagnostics::validate_body(db, self.id.into(), sink) |
773 | } | 773 | } |
774 | 774 | ||
775 | pub fn parent_def(self, db: &dyn HirDatabase) -> Option<MethodOwner> { | 775 | /// Whether this function declaration has a definition. |
776 | /// | ||
777 | /// This is false in the case of required (not provided) trait methods. | ||
778 | pub fn has_body(self, db: &dyn HirDatabase) -> bool { | ||
779 | db.function_data(self.id).has_body | ||
780 | } | ||
781 | |||
782 | pub fn method_owner(self, db: &dyn HirDatabase) -> Option<MethodOwner> { | ||
776 | match self.as_assoc_item(db).map(|assoc| assoc.container(db)) { | 783 | match self.as_assoc_item(db).map(|assoc| assoc.container(db)) { |
777 | Some(AssocItemContainer::Trait(t)) => Some(t.into()), | 784 | Some(AssocItemContainer::Trait(t)) => Some(t.into()), |
778 | Some(AssocItemContainer::ImplDef(imp)) => { | 785 | Some(AssocItemContainer::ImplDef(imp)) => { |
diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs index 4094a76cb..687abe6ca 100644 --- a/crates/hir/src/lib.rs +++ b/crates/hir/src/lib.rs | |||
@@ -35,8 +35,8 @@ pub use crate::{ | |||
35 | code_model::{ | 35 | code_model::{ |
36 | Access, Adt, AsAssocItem, AssocItem, AssocItemContainer, Callable, CallableKind, Const, | 36 | Access, Adt, AsAssocItem, AssocItem, AssocItemContainer, Callable, CallableKind, Const, |
37 | Crate, CrateDependency, DefWithBody, Enum, EnumVariant, Field, FieldSource, Function, | 37 | Crate, CrateDependency, DefWithBody, Enum, EnumVariant, Field, FieldSource, Function, |
38 | GenericDef, HasVisibility, ImplDef, Local, MacroDef, Module, ModuleDef, ScopeDef, Static, | 38 | GenericDef, HasVisibility, ImplDef, Local, MacroDef, MethodOwner, Module, ModuleDef, |
39 | Struct, Trait, Type, TypeAlias, TypeParam, Union, VariantDef, Visibility, | 39 | ScopeDef, Static, Struct, Trait, Type, TypeAlias, TypeParam, Union, VariantDef, Visibility, |
40 | }, | 40 | }, |
41 | has_source::HasSource, | 41 | has_source::HasSource, |
42 | semantics::{original_range, PathResolution, Semantics, SemanticsScope}, | 42 | semantics::{original_range, PathResolution, Semantics, SemanticsScope}, |