Fix case of ignored/broken proc macro

This commit is contained in:
Florian Diebold 2022-07-01 18:45:09 +02:00
parent e71519572c
commit 9a12d0d6f2

View File

@ -2,7 +2,7 @@
use std::{mem, sync::Arc};
use hir_expand::{name::Name, AstId, ExpandResult, HirFileId, InFile, MacroCallId};
use hir_expand::{name::Name, AstId, ExpandResult, HirFileId, InFile, MacroCallId, MacroDefKind};
use syntax::ast;
use crate::{
@ -498,6 +498,17 @@ impl<'a> AssocItemCollector<'a> {
if !self.db.enable_proc_attr_macros() {
continue 'attrs;
}
let loc = self.db.lookup_intern_macro_call(call_id);
if let MacroDefKind::ProcMacro(exp, ..) = loc.def.kind {
// If there's no expander for the proc macro (e.g. the
// proc macro is ignored, or building the proc macro
// crate failed), skip expansion like we would if it was
// disabled. This is analogous to the handling in
// `DefCollector::collect_macros`.
if exp.is_dummy() {
continue 'attrs;
}
}
match self.expander.enter_expand_id(self.db, call_id) {
ExpandResult { value: Some((mark, mac)), .. } => {
self.collect_macro_items(mark, mac);