Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/hir-def/src/nameres/collector.rs')
-rw-r--r--crates/hir-def/src/nameres/collector.rs28
1 files changed, 22 insertions, 6 deletions
diff --git a/crates/hir-def/src/nameres/collector.rs b/crates/hir-def/src/nameres/collector.rs
index 3cfbf6c89c..ef10b3d2da 100644
--- a/crates/hir-def/src/nameres/collector.rs
+++ b/crates/hir-def/src/nameres/collector.rs
@@ -237,6 +237,8 @@ enum MacroDirectiveKind {
derive_attr: AttrId,
derive_pos: usize,
ctxt: SyntaxContextId,
+ /// The "parent" macro it is resolved to.
+ derive_macro_id: MacroCallId,
},
Attr {
ast_id: AstIdWithPath<ast::Item>,
@@ -1146,7 +1148,13 @@ impl DefCollector<'_> {
return Resolved::Yes;
}
}
- MacroDirectiveKind::Derive { ast_id, derive_attr, derive_pos, ctxt: call_site } => {
+ MacroDirectiveKind::Derive {
+ ast_id,
+ derive_attr,
+ derive_pos,
+ ctxt: call_site,
+ derive_macro_id,
+ } => {
let id = derive_macro_as_call_id(
self.db,
ast_id,
@@ -1155,6 +1163,7 @@ impl DefCollector<'_> {
*call_site,
self.def_map.krate,
resolver,
+ *derive_macro_id,
);
if let Ok((macro_id, def_id, call_id)) = id {
@@ -1224,6 +1233,8 @@ impl DefCollector<'_> {
_ => return Resolved::No,
};
+ let call_id =
+ attr_macro_as_call_id(self.db, file_ast_id, attr, self.def_map.krate, def);
if let MacroDefId {
kind:
MacroDefKind::BuiltInAttr(
@@ -1252,6 +1263,7 @@ impl DefCollector<'_> {
return recollect_without(self);
}
};
+
let ast_id = ast_id.with_value(ast_adt_id);
match attr.parse_path_comma_token_tree(self.db.upcast()) {
@@ -1267,6 +1279,7 @@ impl DefCollector<'_> {
derive_attr: attr.id,
derive_pos: idx,
ctxt: call_site.ctx,
+ derive_macro_id: call_id,
},
container: directive.container,
});
@@ -1301,10 +1314,6 @@ impl DefCollector<'_> {
return recollect_without(self);
}
- // Not resolved to a derive helper or the derive attribute, so try to treat as a normal attribute.
- let call_id =
- attr_macro_as_call_id(self.db, file_ast_id, attr, self.def_map.krate, def);
-
// Skip #[test]/#[bench] expansion, which would merely result in more memory usage
// due to duplicating functions into macro expansions
if matches!(
@@ -1460,13 +1469,20 @@ impl DefCollector<'_> {
));
}
}
- MacroDirectiveKind::Derive { ast_id, derive_attr, derive_pos, ctxt: _ } => {
+ MacroDirectiveKind::Derive {
+ ast_id,
+ derive_attr,
+ derive_pos,
+ derive_macro_id,
+ ..
+ } => {
self.def_map.diagnostics.push(DefDiagnostic::unresolved_macro_call(
directive.module_id,
MacroCallKind::Derive {
ast_id: ast_id.ast_id,
derive_attr_index: *derive_attr,
derive_index: *derive_pos as u32,
+ derive_macro_id: *derive_macro_id,
},
ast_id.path.clone(),
));