mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 11:31:15 +00:00
Simplify unresolved proc-macro handling
This commit is contained in:
parent
7b11fdeb68
commit
882ae7105d
@ -637,10 +637,6 @@ impl<'a> AssocItemCollector<'a> {
|
|||||||
attr,
|
attr,
|
||||||
) {
|
) {
|
||||||
Ok(ResolvedAttr::Macro(call_id)) => {
|
Ok(ResolvedAttr::Macro(call_id)) => {
|
||||||
// If proc attribute macro expansion is disabled, skip expanding it here
|
|
||||||
if !self.db.expand_proc_attr_macros() {
|
|
||||||
continue 'attrs;
|
|
||||||
}
|
|
||||||
let loc = self.db.lookup_intern_macro_call(call_id);
|
let loc = self.db.lookup_intern_macro_call(call_id);
|
||||||
if let MacroDefKind::ProcMacro(_, exp, _) = loc.def.kind {
|
if let MacroDefKind::ProcMacro(_, exp, _) = loc.def.kind {
|
||||||
// If there's no expander for the proc macro (e.g. the
|
// If there's no expander for the proc macro (e.g. the
|
||||||
|
@ -83,7 +83,9 @@ pub(super) fn collect_defs(db: &dyn DefDatabase, def_map: DefMap, tree_id: TreeI
|
|||||||
let name = Name::new_text_dont_use(it.name.clone());
|
let name = Name::new_text_dont_use(it.name.clone());
|
||||||
(
|
(
|
||||||
name,
|
name,
|
||||||
if it.disabled {
|
if !db.expand_proc_attr_macros() {
|
||||||
|
CustomProcMacroExpander::dummy()
|
||||||
|
} else if it.disabled {
|
||||||
CustomProcMacroExpander::disabled()
|
CustomProcMacroExpander::disabled()
|
||||||
} else {
|
} else {
|
||||||
CustomProcMacroExpander::new(hir_expand::proc_macro::ProcMacroId::new(
|
CustomProcMacroExpander::new(hir_expand::proc_macro::ProcMacroId::new(
|
||||||
@ -1331,16 +1333,6 @@ impl DefCollector<'_> {
|
|||||||
|
|
||||||
let call_id = call_id();
|
let call_id = call_id();
|
||||||
if let MacroDefKind::ProcMacro(_, exp, _) = def.kind {
|
if let MacroDefKind::ProcMacro(_, exp, _) = def.kind {
|
||||||
// If proc attribute macro expansion is disabled, skip expanding it here
|
|
||||||
if !self.db.expand_proc_attr_macros() {
|
|
||||||
self.def_map.diagnostics.push(DefDiagnostic::unresolved_proc_macro(
|
|
||||||
directive.module_id,
|
|
||||||
self.db.lookup_intern_macro_call(call_id).kind,
|
|
||||||
def.krate,
|
|
||||||
));
|
|
||||||
return recollect_without(self);
|
|
||||||
}
|
|
||||||
|
|
||||||
// If there's no expander for the proc macro (e.g.
|
// If there's no expander for the proc macro (e.g.
|
||||||
// because proc macros are disabled, or building the
|
// because proc macros are disabled, or building the
|
||||||
// proc macro crate failed), report this and skip
|
// proc macro crate failed), report this and skip
|
||||||
|
@ -17,16 +17,47 @@ use crate::{
|
|||||||
|
|
||||||
#[derive(Debug, PartialEq, Eq)]
|
#[derive(Debug, PartialEq, Eq)]
|
||||||
pub enum DefDiagnosticKind {
|
pub enum DefDiagnosticKind {
|
||||||
UnresolvedModule { ast: AstId<ast::Module>, candidates: Box<[String]> },
|
UnresolvedModule {
|
||||||
UnresolvedExternCrate { ast: AstId<ast::ExternCrate> },
|
ast: AstId<ast::Module>,
|
||||||
UnresolvedImport { id: ItemTreeId<item_tree::Use>, index: Idx<ast::UseTree> },
|
candidates: Box<[String]>,
|
||||||
UnconfiguredCode { ast: ErasedAstId, cfg: CfgExpr, opts: CfgOptions },
|
},
|
||||||
UnresolvedProcMacro { ast: MacroCallKind, krate: CrateId },
|
UnresolvedExternCrate {
|
||||||
UnresolvedMacroCall { ast: MacroCallKind, path: ModPath },
|
ast: AstId<ast::ExternCrate>,
|
||||||
UnimplementedBuiltinMacro { ast: AstId<ast::Macro> },
|
},
|
||||||
InvalidDeriveTarget { ast: AstId<ast::Item>, id: usize },
|
UnresolvedImport {
|
||||||
MalformedDerive { ast: AstId<ast::Adt>, id: usize },
|
id: ItemTreeId<item_tree::Use>,
|
||||||
MacroDefError { ast: AstId<ast::Macro>, message: String },
|
index: Idx<ast::UseTree>,
|
||||||
|
},
|
||||||
|
UnconfiguredCode {
|
||||||
|
ast: ErasedAstId,
|
||||||
|
cfg: CfgExpr,
|
||||||
|
opts: CfgOptions,
|
||||||
|
},
|
||||||
|
/// A proc-macro that is lacking an expander, this might be due to build scripts not yet having
|
||||||
|
/// run or proc-macro expansion being disabled.
|
||||||
|
UnresolvedProcMacro {
|
||||||
|
ast: MacroCallKind,
|
||||||
|
krate: CrateId,
|
||||||
|
},
|
||||||
|
UnresolvedMacroCall {
|
||||||
|
ast: MacroCallKind,
|
||||||
|
path: ModPath,
|
||||||
|
},
|
||||||
|
UnimplementedBuiltinMacro {
|
||||||
|
ast: AstId<ast::Macro>,
|
||||||
|
},
|
||||||
|
InvalidDeriveTarget {
|
||||||
|
ast: AstId<ast::Item>,
|
||||||
|
id: usize,
|
||||||
|
},
|
||||||
|
MalformedDerive {
|
||||||
|
ast: AstId<ast::Adt>,
|
||||||
|
id: usize,
|
||||||
|
},
|
||||||
|
MacroDefError {
|
||||||
|
ast: AstId<ast::Macro>,
|
||||||
|
message: String,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||||
@ -92,10 +123,6 @@ impl DefDiagnostic {
|
|||||||
Self { in_module: container, kind: DefDiagnosticKind::UnconfiguredCode { ast, cfg, opts } }
|
Self { in_module: container, kind: DefDiagnosticKind::UnconfiguredCode { ast, cfg, opts } }
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: Whats the difference between this and unresolved_macro_call
|
|
||||||
// FIXME: This is used for a lot of things, unresolved proc macros, disabled proc macros, etc
|
|
||||||
// yet the diagnostic handler in ide-diagnostics has to figure out what happened because this
|
|
||||||
// struct loses all that information!
|
|
||||||
pub fn unresolved_proc_macro(
|
pub fn unresolved_proc_macro(
|
||||||
container: LocalModuleId,
|
container: LocalModuleId,
|
||||||
ast: MacroCallKind,
|
ast: MacroCallKind,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user