diff options
author | Jonas Schievink <[email protected]> | 2021-04-09 12:38:01 +0100 |
---|---|---|
committer | Jonas Schievink <[email protected]> | 2021-04-09 12:38:01 +0100 |
commit | c0dd36fd425416f5465abf7f12f5d3a14b35751d (patch) | |
tree | 3fc19fa9306afd69bf5702919237753c94337007 /crates/hir_def/src | |
parent | 546da15972312f62be8a64a409d39a8d96ed53a6 (diff) |
Store `#[derive]` attribute ID along macro invoc
Diffstat (limited to 'crates/hir_def/src')
-rw-r--r-- | crates/hir_def/src/lib.rs | 4 | ||||
-rw-r--r-- | crates/hir_def/src/nameres.rs | 2 | ||||
-rw-r--r-- | crates/hir_def/src/nameres/collector.rs | 18 |
3 files changed, 15 insertions, 9 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 | }; |
67 | use la_arena::Idx; | 67 | use la_arena::Idx; |
68 | use nameres::DefMap; | 68 | use nameres::DefMap; |
@@ -699,6 +699,7 @@ fn macro_call_as_call_id( | |||
699 | 699 | ||
700 | fn derive_macro_as_call_id( | 700 | fn 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 | }; |
18 | use hir_expand::{InFile, MacroCallLoc}; | 18 | use hir_expand::{InFile, MacroCallLoc}; |
19 | use rustc_hash::{FxHashMap, FxHashSet}; | 19 | use rustc_hash::{FxHashMap, FxHashSet}; |
@@ -216,7 +216,7 @@ struct MacroDirective { | |||
216 | #[derive(Clone, Debug, Eq, PartialEq)] | 216 | #[derive(Clone, Debug, Eq, PartialEq)] |
217 | enum MacroDirectiveKind { | 217 | enum 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 | ||
222 | struct DefData<'a> { | 222 | struct 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 | } |