diff options
Diffstat (limited to 'crates/ra_hir')
-rw-r--r-- | crates/ra_hir/src/code_model.rs | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs index df9c151e5..a177cebca 100644 --- a/crates/ra_hir/src/code_model.rs +++ b/crates/ra_hir/src/code_model.rs | |||
@@ -26,10 +26,11 @@ use hir_ty::{ | |||
26 | }; | 26 | }; |
27 | use ra_db::{CrateId, Edition, FileId}; | 27 | use ra_db::{CrateId, Edition, FileId}; |
28 | use ra_prof::profile; | 28 | use ra_prof::profile; |
29 | use ra_syntax::ast; | 29 | use ra_syntax::ast::{self, AttrsOwner}; |
30 | 30 | ||
31 | use crate::{ | 31 | use crate::{ |
32 | db::{DefDatabase, HirDatabase}, | 32 | db::{DefDatabase, HirDatabase}, |
33 | has_source::HasSource, | ||
33 | CallableDef, HirDisplay, InFile, Name, | 34 | CallableDef, HirDisplay, InFile, Name, |
34 | }; | 35 | }; |
35 | 36 | ||
@@ -805,6 +806,27 @@ impl ImplBlock { | |||
805 | pub fn krate(&self, db: &impl DefDatabase) -> Crate { | 806 | pub fn krate(&self, db: &impl DefDatabase) -> Crate { |
806 | Crate { id: self.module(db).id.krate } | 807 | Crate { id: self.module(db).id.krate } |
807 | } | 808 | } |
809 | |||
810 | pub fn is_builtin_derive(&self, db: &impl DefDatabase) -> Option<InFile<ast::Attr>> { | ||
811 | let src = self.source(db); | ||
812 | let item = src.file_id.is_builtin_derive(db)?; | ||
813 | let hygenic = hir_expand::hygiene::Hygiene::new(db, item.file_id); | ||
814 | |||
815 | let attr = item | ||
816 | .value | ||
817 | .attrs() | ||
818 | .filter_map(|it| { | ||
819 | let path = hir_def::path::ModPath::from_src(it.path()?, &hygenic)?; | ||
820 | if path.as_ident()?.to_string() == "derive" { | ||
821 | Some(it) | ||
822 | } else { | ||
823 | None | ||
824 | } | ||
825 | }) | ||
826 | .last()?; | ||
827 | |||
828 | Some(item.with_value(attr)) | ||
829 | } | ||
808 | } | 830 | } |
809 | 831 | ||
810 | #[derive(Clone, PartialEq, Eq, Debug)] | 832 | #[derive(Clone, PartialEq, Eq, Debug)] |