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.rs | 34 |
1 files changed, 21 insertions, 13 deletions
diff --git a/crates/hir-def/src/nameres/collector.rs b/crates/hir-def/src/nameres/collector.rs index 1f095846b1..9901df2af0 100644 --- a/crates/hir-def/src/nameres/collector.rs +++ b/crates/hir-def/src/nameres/collector.rs @@ -421,22 +421,22 @@ impl DefCollector<'_> { } } - /// When the fixed-point loop reaches a stable state, we might still have some unresolved - /// attributes (or unexpanded attribute proc macros) left over. This takes one of them, and - /// feeds the item it's applied to back into name resolution. + /// When the fixed-point loop reaches a stable state, we might still have + /// some unresolved attributes left over. This takes one of them, and feeds + /// the item it's applied to back into name resolution. /// /// This effectively ignores the fact that the macro is there and just treats the items as /// normal code. /// - /// This improves UX when proc macros are turned off or don't work, and replicates the behavior - /// before we supported proc. attribute macros. + /// This improves UX for unresolved attributes, and replicates the + /// behavior before we supported proc. attribute macros. fn reseed_with_unresolved_attribute(&mut self) -> ReachedFixedPoint { cov_mark::hit!(unresolved_attribute_fallback); let mut unresolved_macros = mem::take(&mut self.unresolved_macros); let pos = unresolved_macros.iter().position(|directive| { if let MacroDirectiveKind::Attr { ast_id, mod_item, attr, tree } = &directive.kind { - self.def_map.diagnostics.push(DefDiagnostic::unresolved_proc_macro( + self.def_map.diagnostics.push(DefDiagnostic::unresolved_macro_call( directive.module_id, MacroCallKind::Attr { ast_id: ast_id.ast_id, @@ -444,7 +444,7 @@ impl DefCollector<'_> { invoc_attr_index: attr.id.ast_index, is_derive: false, }, - None, + attr.path().clone(), )); self.skip_attrs.insert(ast_id.ast_id.with_value(*mod_item), attr.id); @@ -1218,10 +1218,6 @@ impl DefCollector<'_> { return recollect_without(self); } - if !self.db.enable_proc_attr_macros() { - return true; - } - // 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, @@ -1233,6 +1229,16 @@ impl DefCollector<'_> { ); let loc: MacroCallLoc = self.db.lookup_intern_macro_call(call_id); + // If proc attribute macro expansion is disabled, skip expanding it here + if !self.db.enable_proc_attr_macros() { + self.def_map.diagnostics.push(DefDiagnostic::unresolved_proc_macro( + directive.module_id, + loc.kind, + Some(loc.def.krate), + )); + return recollect_without(self); + } + // Skip #[test]/#[bench] expansion, which would merely result in more memory usage // due to duplicating functions into macro expansions if matches!( @@ -1245,8 +1251,10 @@ impl DefCollector<'_> { if let MacroDefKind::ProcMacro(exp, ..) = loc.def.kind { if exp.is_dummy() { - // Proc macros that cannot be expanded are treated as not - // resolved, in order to fall back later. + // If there's no expander for the proc macro (e.g. + // because proc macros are disabled, or building the + // proc macro crate failed), report this and skip + // expansion like we would if it was disabled self.def_map.diagnostics.push(DefDiagnostic::unresolved_proc_macro( directive.module_id, loc.kind, |