Better error message for when proc-macros have not yet been built

This commit is contained in:
Lukas Wirth 2024-01-31 10:54:52 +01:00
parent 4bf6b160a9
commit 91dab4d720
2 changed files with 8 additions and 2 deletions

View file

@ -32,7 +32,7 @@ pub(crate) fn unresolved_proc_macro(
let severity = if config_enabled { Severity::Error } else { Severity::WeakWarning }; let severity = if config_enabled { Severity::Error } else { Severity::WeakWarning };
let def_map = ctx.sema.db.crate_def_map(d.krate); let def_map = ctx.sema.db.crate_def_map(d.krate);
let message = if config_enabled { let message = if config_enabled {
def_map.proc_macro_loading_error().unwrap_or("proc macro not found in the built dylib") def_map.proc_macro_loading_error().unwrap_or("internal error")
} else { } else {
match d.kind { match d.kind {
hir::MacroKind::Attr if proc_macros_enabled => "attribute macro expansion is disabled", hir::MacroKind::Attr if proc_macros_enabled => "attribute macro expansion is disabled",

View file

@ -528,10 +528,16 @@ impl GlobalState {
(crate_graph, proc_macros, crate_graph_file_dependencies) (crate_graph, proc_macros, crate_graph_file_dependencies)
}; };
let mut change = Change::new();
if self.config.expand_proc_macros() { if self.config.expand_proc_macros() {
change.set_proc_macros(
crate_graph
.iter()
.map(|id| (id, Err("Proc-macros have not been built yet".to_owned())))
.collect(),
);
self.fetch_proc_macros_queue.request_op(cause, proc_macro_paths); self.fetch_proc_macros_queue.request_op(cause, proc_macro_paths);
} }
let mut change = Change::new();
change.set_crate_graph(crate_graph); change.set_crate_graph(crate_graph);
self.analysis_host.apply_change(change); self.analysis_host.apply_change(change);
self.crate_graph_file_dependencies = crate_graph_file_dependencies; self.crate_graph_file_dependencies = crate_graph_file_dependencies;