aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/hir_def/src/lib.rs4
-rw-r--r--crates/hir_def/src/nameres.rs2
-rw-r--r--crates/hir_def/src/nameres/collector.rs18
-rw-r--r--crates/hir_expand/src/builtin_derive.rs8
-rw-r--r--crates/hir_expand/src/lib.rs2
5 files changed, 22 insertions, 12 deletions
diff --git a/crates/hir_def/src/lib.rs b/crates/hir_def/src/lib.rs
index b72884925..d69116d51 100644
--- a/crates/hir_def/src/lib.rs
+++ b/crates/hir_def/src/lib.rs
@@ -62,7 +62,7 @@ use hir_expand::{
62 ast_id_map::FileAstId, 62 ast_id_map::FileAstId,
63 eager::{expand_eager_macro, ErrorEmitted, ErrorSink}, 63 eager::{expand_eager_macro, ErrorEmitted, ErrorSink},
64 hygiene::Hygiene, 64 hygiene::Hygiene,
65 AstId, HirFileId, InFile, MacroCallId, MacroCallKind, MacroDefId, MacroDefKind, 65 AstId, AttrId, HirFileId, InFile, MacroCallId, MacroCallKind, MacroDefId, MacroDefKind,
66}; 66};
67use la_arena::Idx; 67use la_arena::Idx;
68use nameres::DefMap; 68use nameres::DefMap;
@@ -699,6 +699,7 @@ fn macro_call_as_call_id(
699 699
700fn derive_macro_as_call_id( 700fn derive_macro_as_call_id(
701 item_attr: &AstIdWithPath<ast::Item>, 701 item_attr: &AstIdWithPath<ast::Item>,
702 derive_attr: AttrId,
702 db: &dyn db::DefDatabase, 703 db: &dyn db::DefDatabase,
703 krate: CrateId, 704 krate: CrateId,
704 resolver: impl Fn(path::ModPath) -> Option<MacroDefId>, 705 resolver: impl Fn(path::ModPath) -> Option<MacroDefId>,
@@ -712,6 +713,7 @@ fn derive_macro_as_call_id(
712 MacroCallKind::Derive { 713 MacroCallKind::Derive {
713 ast_id: item_attr.ast_id, 714 ast_id: item_attr.ast_id,
714 derive_name: last_segment.to_string(), 715 derive_name: last_segment.to_string(),
716 derive_attr,
715 }, 717 },
716 ) 718 )
717 .into(); 719 .into();
diff --git a/crates/hir_def/src/nameres.rs b/crates/hir_def/src/nameres.rs
index d966fc239..9e181751c 100644
--- a/crates/hir_def/src/nameres.rs
+++ b/crates/hir_def/src/nameres.rs
@@ -617,7 +617,7 @@ mod diagnostics {
617 let node = ast_id.to_node(db.upcast()); 617 let node = ast_id.to_node(db.upcast());
618 (ast_id.file_id, SyntaxNodePtr::from(AstPtr::new(&node)), None) 618 (ast_id.file_id, SyntaxNodePtr::from(AstPtr::new(&node)), None)
619 } 619 }
620 MacroCallKind::Derive { ast_id, derive_name } => { 620 MacroCallKind::Derive { ast_id, derive_name, .. } => {
621 let node = ast_id.to_node(db.upcast()); 621 let node = ast_id.to_node(db.upcast());
622 622
623 // Compute the precise location of the macro name's token in the derive 623 // Compute the precise location of the macro name's token in the derive
diff --git a/crates/hir_def/src/nameres/collector.rs b/crates/hir_def/src/nameres/collector.rs
index f431da3f2..d13d7be27 100644
--- a/crates/hir_def/src/nameres/collector.rs
+++ b/crates/hir_def/src/nameres/collector.rs
@@ -13,7 +13,7 @@ use hir_expand::{
13 builtin_macro::find_builtin_macro, 13 builtin_macro::find_builtin_macro,
14 name::{AsName, Name}, 14 name::{AsName, Name},
15 proc_macro::ProcMacroExpander, 15 proc_macro::ProcMacroExpander,
16 HirFileId, MacroCallId, MacroCallKind, MacroDefId, MacroDefKind, 16 AttrId, HirFileId, MacroCallId, MacroCallKind, MacroDefId, MacroDefKind,
17}; 17};
18use hir_expand::{InFile, MacroCallLoc}; 18use hir_expand::{InFile, MacroCallLoc};
19use rustc_hash::{FxHashMap, FxHashSet}; 19use rustc_hash::{FxHashMap, FxHashSet};
@@ -216,7 +216,7 @@ struct MacroDirective {
216#[derive(Clone, Debug, Eq, PartialEq)] 216#[derive(Clone, Debug, Eq, PartialEq)]
217enum MacroDirectiveKind { 217enum MacroDirectiveKind {
218 FnLike { ast_id: AstIdWithPath<ast::MacroCall> }, 218 FnLike { ast_id: AstIdWithPath<ast::MacroCall> },
219 Derive { ast_id: AstIdWithPath<ast::Item> }, 219 Derive { ast_id: AstIdWithPath<ast::Item>, derive_attr: AttrId },
220} 220}
221 221
222struct DefData<'a> { 222struct DefData<'a> {
@@ -831,10 +831,14 @@ impl DefCollector<'_> {
831 Err(UnresolvedMacro) | Ok(Err(_)) => {} 831 Err(UnresolvedMacro) | Ok(Err(_)) => {}
832 } 832 }
833 } 833 }
834 MacroDirectiveKind::Derive { ast_id } => { 834 MacroDirectiveKind::Derive { ast_id, derive_attr } => {
835 match derive_macro_as_call_id(ast_id, self.db, self.def_map.krate, |path| { 835 match derive_macro_as_call_id(
836 self.resolve_derive_macro(directive.module_id, &path) 836 ast_id,
837 }) { 837 *derive_attr,
838 self.db,
839 self.def_map.krate,
840 |path| self.resolve_derive_macro(directive.module_id, &path),
841 ) {
838 Ok(call_id) => { 842 Ok(call_id) => {
839 resolved.push((directive.module_id, call_id, directive.depth)); 843 resolved.push((directive.module_id, call_id, directive.depth));
840 res = ReachedFixedPoint::No; 844 res = ReachedFixedPoint::No;
@@ -1368,7 +1372,7 @@ impl ModCollector<'_, '_> {
1368 self.def_collector.unexpanded_macros.push(MacroDirective { 1372 self.def_collector.unexpanded_macros.push(MacroDirective {
1369 module_id: self.module_id, 1373 module_id: self.module_id,
1370 depth: self.macro_depth + 1, 1374 depth: self.macro_depth + 1,
1371 kind: MacroDirectiveKind::Derive { ast_id }, 1375 kind: MacroDirectiveKind::Derive { ast_id, derive_attr: derive.id },
1372 }); 1376 });
1373 } 1377 }
1374 } 1378 }
diff --git a/crates/hir_expand/src/builtin_derive.rs b/crates/hir_expand/src/builtin_derive.rs
index 392079ed4..537c03028 100644
--- a/crates/hir_expand/src/builtin_derive.rs
+++ b/crates/hir_expand/src/builtin_derive.rs
@@ -269,7 +269,7 @@ mod tests {
269 use expect_test::{expect, Expect}; 269 use expect_test::{expect, Expect};
270 use name::AsName; 270 use name::AsName;
271 271
272 use crate::{test_db::TestDB, AstId, MacroCallId, MacroCallKind, MacroCallLoc}; 272 use crate::{test_db::TestDB, AstId, AttrId, MacroCallId, MacroCallKind, MacroCallLoc};
273 273
274 use super::*; 274 use super::*;
275 275
@@ -317,7 +317,11 @@ $0
317 local_inner: false, 317 local_inner: false,
318 }, 318 },
319 krate: CrateId(0), 319 krate: CrateId(0),
320 kind: MacroCallKind::Derive { ast_id, derive_name: name.to_string() }, 320 kind: MacroCallKind::Derive {
321 ast_id,
322 derive_name: name.to_string(),
323 derive_attr: AttrId(0),
324 },
321 }; 325 };
322 326
323 let id: MacroCallId = db.intern_macro(loc).into(); 327 let id: MacroCallId = db.intern_macro(loc).into();
diff --git a/crates/hir_expand/src/lib.rs b/crates/hir_expand/src/lib.rs
index 8637abc6a..a0e6aec62 100644
--- a/crates/hir_expand/src/lib.rs
+++ b/crates/hir_expand/src/lib.rs
@@ -291,7 +291,7 @@ pub struct MacroCallLoc {
291#[derive(Debug, Clone, PartialEq, Eq, Hash)] 291#[derive(Debug, Clone, PartialEq, Eq, Hash)]
292pub enum MacroCallKind { 292pub enum MacroCallKind {
293 FnLike { ast_id: AstId<ast::MacroCall> }, 293 FnLike { ast_id: AstId<ast::MacroCall> },
294 Derive { ast_id: AstId<ast::Item>, derive_name: String }, 294 Derive { ast_id: AstId<ast::Item>, derive_name: String, derive_attr: AttrId },
295} 295}
296 296
297#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 297#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]