diff options
Diffstat (limited to 'crates/hir/src/code_model.rs')
-rw-r--r-- | crates/hir/src/code_model.rs | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/crates/hir/src/code_model.rs b/crates/hir/src/code_model.rs index afb849b4d..d04de053f 100644 --- a/crates/hir/src/code_model.rs +++ b/crates/hir/src/code_model.rs | |||
@@ -41,7 +41,7 @@ use rustc_hash::FxHashSet; | |||
41 | use stdx::impl_from; | 41 | use stdx::impl_from; |
42 | use syntax::{ | 42 | use syntax::{ |
43 | ast::{self, AttrsOwner, NameOwner}, | 43 | ast::{self, AttrsOwner, NameOwner}, |
44 | AstNode, SmolStr, | 44 | AstNode, SmolStr, SyntaxKind, |
45 | }; | 45 | }; |
46 | use tt::{Ident, Leaf, Literal, TokenTree}; | 46 | use tt::{Ident, Leaf, Literal, TokenTree}; |
47 | 47 | ||
@@ -788,8 +788,25 @@ impl Function { | |||
788 | db.function_data(self.id).has_body | 788 | db.function_data(self.id).has_body |
789 | } | 789 | } |
790 | 790 | ||
791 | pub fn source(self, db: &dyn HirDatabase) -> InFile<ast::Fn> { | 791 | /// whether this function is associated with some trait/impl |
792 | self.id.lookup(db.upcast()).source(db.upcast()) | 792 | pub fn is_associated(self, db: &dyn HirDatabase) -> bool { |
793 | if let Some(_) = self.self_param(db) { | ||
794 | return false; | ||
795 | } | ||
796 | |||
797 | let fn_parent_kind = self | ||
798 | .source(db) | ||
799 | .value | ||
800 | .syntax() | ||
801 | .parent() | ||
802 | .and_then(|s| s.parent()) | ||
803 | .and_then(|s| Some(s.kind())); | ||
804 | |||
805 | match fn_parent_kind { | ||
806 | Some(SyntaxKind::IMPL) => true, | ||
807 | Some(SyntaxKind::TRAIT) => true, | ||
808 | _ => false, | ||
809 | } | ||
793 | } | 810 | } |
794 | } | 811 | } |
795 | 812 | ||