Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 00fc758

Browse files
committed
Simplify unresolved proc-macro handling
1 parent 2445d53 commit 00fc758

File tree

3 files changed

+44
-29
lines changed

3 files changed

+44
-29
lines changed

src/tools/rust-analyzer/crates/hir-def/src/data.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -637,10 +637,6 @@ impl<'a> AssocItemCollector<'a> {
637637
attr,
638638
) {
639639
Ok(ResolvedAttr::Macro(call_id)) => {
640-
// If proc attribute macro expansion is disabled, skip expanding it here
641-
if !self.db.expand_proc_attr_macros() {
642-
continue 'attrs;
643-
}
644640
let loc = self.db.lookup_intern_macro_call(call_id);
645641
if let MacroDefKind::ProcMacro(_, exp, _) = loc.def.kind {
646642
// If there's no expander for the proc macro (e.g. the

src/tools/rust-analyzer/crates/hir-def/src/nameres/collector.rs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,9 @@ pub(super) fn collect_defs(db: &dyn DefDatabase, def_map: DefMap, tree_id: TreeI
8383
let name = Name::new_text_dont_use(it.name.clone());
8484
(
8585
name,
86-
if it.disabled {
86+
if !db.expand_proc_attr_macros() {
87+
CustomProcMacroExpander::dummy()
88+
} else if it.disabled {
8789
CustomProcMacroExpander::disabled()
8890
} else {
8991
CustomProcMacroExpander::new(hir_expand::proc_macro::ProcMacroId::new(
@@ -1331,16 +1333,6 @@ impl DefCollector<'_> {
13311333

13321334
let call_id = call_id();
13331335
if let MacroDefKind::ProcMacro(_, exp, _) = def.kind {
1334-
// If proc attribute macro expansion is disabled, skip expanding it here
1335-
if !self.db.expand_proc_attr_macros() {
1336-
self.def_map.diagnostics.push(DefDiagnostic::unresolved_proc_macro(
1337-
directive.module_id,
1338-
self.db.lookup_intern_macro_call(call_id).kind,
1339-
def.krate,
1340-
));
1341-
return recollect_without(self);
1342-
}
1343-
13441336
// If there's no expander for the proc macro (e.g.
13451337
// because proc macros are disabled, or building the
13461338
// proc macro crate failed), report this and skip

src/tools/rust-analyzer/crates/hir-def/src/nameres/diagnostics.rs

Lines changed: 41 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,47 @@ use crate::{
1717

1818
#[derive(Debug, PartialEq, Eq)]
1919
pub enum DefDiagnosticKind {
20-
UnresolvedModule { ast: AstId<ast::Module>, candidates: Box<[String]> },
21-
UnresolvedExternCrate { ast: AstId<ast::ExternCrate> },
22-
UnresolvedImport { id: ItemTreeId<item_tree::Use>, index: Idx<ast::UseTree> },
23-
UnconfiguredCode { ast: ErasedAstId, cfg: CfgExpr, opts: CfgOptions },
24-
UnresolvedProcMacro { ast: MacroCallKind, krate: CrateId },
25-
UnresolvedMacroCall { ast: MacroCallKind, path: ModPath },
26-
UnimplementedBuiltinMacro { ast: AstId<ast::Macro> },
27-
InvalidDeriveTarget { ast: AstId<ast::Item>, id: usize },
28-
MalformedDerive { ast: AstId<ast::Adt>, id: usize },
29-
MacroDefError { ast: AstId<ast::Macro>, message: String },
20+
UnresolvedModule {
21+
ast: AstId<ast::Module>,
22+
candidates: Box<[String]>,
23+
},
24+
UnresolvedExternCrate {
25+
ast: AstId<ast::ExternCrate>,
26+
},
27+
UnresolvedImport {
28+
id: ItemTreeId<item_tree::Use>,
29+
index: Idx<ast::UseTree>,
30+
},
31+
UnconfiguredCode {
32+
ast: ErasedAstId,
33+
cfg: CfgExpr,
34+
opts: CfgOptions,
35+
},
36+
/// A proc-macro that is lacking an expander, this might be due to build scripts not yet having
37+
/// run or proc-macro expansion being disabled.
38+
UnresolvedProcMacro {
39+
ast: MacroCallKind,
40+
krate: CrateId,
41+
},
42+
UnresolvedMacroCall {
43+
ast: MacroCallKind,
44+
path: ModPath,
45+
},
46+
UnimplementedBuiltinMacro {
47+
ast: AstId<ast::Macro>,
48+
},
49+
InvalidDeriveTarget {
50+
ast: AstId<ast::Item>,
51+
id: usize,
52+
},
53+
MalformedDerive {
54+
ast: AstId<ast::Adt>,
55+
id: usize,
56+
},
57+
MacroDefError {
58+
ast: AstId<ast::Macro>,
59+
message: String,
60+
},
3061
}
3162

3263
#[derive(Clone, Debug, PartialEq, Eq)]
@@ -92,10 +123,6 @@ impl DefDiagnostic {
92123
Self { in_module: container, kind: DefDiagnosticKind::UnconfiguredCode { ast, cfg, opts } }
93124
}
94125

95-
// FIXME: Whats the difference between this and unresolved_macro_call
96-
// FIXME: This is used for a lot of things, unresolved proc macros, disabled proc macros, etc
97-
// yet the diagnostic handler in ide-diagnostics has to figure out what happened because this
98-
// struct loses all that information!
99126
pub fn unresolved_proc_macro(
100127
container: LocalModuleId,
101128
ast: MacroCallKind,

0 commit comments

Comments
 (0)