Skip to content

Commit 7a30f62

Browse files
committed
Auto merge of rust-lang#12881 - Veykril:proc-srv, r=Veykril
fix: Fix server panicking on project loading when proc-macros are disabled Fixes rust-lang/rust-analyzer#12879
2 parents 1c75284 + c8ff70e commit 7a30f62

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

crates/rust-analyzer/src/cli/load_cargo.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@ pub fn load_workspace(
6666
};
6767

6868
let crate_graph = ws.to_crate_graph(
69-
&mut |_, path: &AbsPath| load_proc_macro(proc_macro_client.as_ref(), path, &[]),
69+
&mut |_, path: &AbsPath| {
70+
load_proc_macro(proc_macro_client.as_ref().map_err(|e| &**e), path, &[])
71+
},
7072
&mut |path: &AbsPath| {
7173
let contents = loader.load_sync(path);
7274
let path = vfs::VfsPath::from(path.to_path_buf());

crates/rust-analyzer/src/reload.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,10 @@ impl GlobalState {
390390

391391
let mut crate_graph = CrateGraph::default();
392392
for (idx, ws) in self.workspaces.iter().enumerate() {
393-
let proc_macro_client = self.proc_macro_clients[idx].as_ref();
393+
let proc_macro_client = match self.proc_macro_clients.get(idx) {
394+
Some(res) => res.as_ref().map_err(|e| &**e),
395+
None => Err("Proc macros are disabled"),
396+
};
394397
let mut load_proc_macro = move |crate_name: &str, path: &AbsPath| {
395398
load_proc_macro(
396399
proc_macro_client,
@@ -574,7 +577,7 @@ impl SourceRootConfig {
574577
/// Load the proc-macros for the given lib path, replacing all expanders whose names are in `dummy_replace`
575578
/// with an identity dummy expander.
576579
pub(crate) fn load_proc_macro(
577-
server: Result<&ProcMacroServer, &String>,
580+
server: Result<&ProcMacroServer, &str>,
578581
path: &AbsPath,
579582
dummy_replace: &[Box<str>],
580583
) -> ProcMacroLoadResult {

0 commit comments

Comments
 (0)