From d7be1a437239770552199028259639e6dfa8a664 Mon Sep 17 00:00:00 2001 From: Edwin Cheng Date: Sun, 12 Jan 2020 18:08:53 +0800 Subject: Use attr location for builtin macro goto-imp --- crates/ra_hir/src/code_model.rs | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'crates/ra_hir') 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::{ }; use ra_db::{CrateId, Edition, FileId}; use ra_prof::profile; -use ra_syntax::ast; +use ra_syntax::ast::{self, AttrsOwner}; use crate::{ db::{DefDatabase, HirDatabase}, + has_source::HasSource, CallableDef, HirDisplay, InFile, Name, }; @@ -805,6 +806,27 @@ impl ImplBlock { pub fn krate(&self, db: &impl DefDatabase) -> Crate { Crate { id: self.module(db).id.krate } } + + pub fn is_builtin_derive(&self, db: &impl DefDatabase) -> Option> { + let src = self.source(db); + let item = src.file_id.is_builtin_derive(db)?; + let hygenic = hir_expand::hygiene::Hygiene::new(db, item.file_id); + + let attr = item + .value + .attrs() + .filter_map(|it| { + let path = hir_def::path::ModPath::from_src(it.path()?, &hygenic)?; + if path.as_ident()?.to_string() == "derive" { + Some(it) + } else { + None + } + }) + .last()?; + + Some(item.with_value(attr)) + } } #[derive(Clone, PartialEq, Eq, Debug)] -- cgit v1.2.3