Skip to content

fix: Spawn proc-macro servers on requests clearing the client cache - #22865

Merged
Veykril merged 2 commits into
rust-lang:masterfrom
zargovv:master
Jul 19, 2026
Merged

fix: Spawn proc-macro servers on requests clearing the client cache#22865
Veykril merged 2 commits into
rust-lang:masterfrom
zargovv:master

Conversation

@zargovv

@zargovv zargovv commented Jul 19, 2026

Copy link
Copy Markdown
Contributor

This PR fixes the proc-macro-srv is not running error that occurs on Rebuild proc-macros operation.

The proc_macro_clients cache is cleared in handle_workspace_reload and handle_workspace_rebuild, thus requiring an additional check to spawn new clients.

Error is thrown here

None => Err(ProcMacroLoadingError::ProcMacroSrvError(
"proc-macro-srv is not running".into(),
)),

Cause

proc_macro_clients is cleared in the following two places:

pub(crate) fn handle_workspace_reload(state: &mut GlobalState, _: ()) -> anyhow::Result<()> {
state.proc_macro_clients = Arc::from_iter([]);
state.build_deps_changed = false;

and
pub(crate) fn handle_proc_macros_rebuild(state: &mut GlobalState, _: ()) -> anyhow::Result<()> {
state.proc_macro_clients = Arc::from_iter([]);
state.build_deps_changed = false;

Resolution

Add is_empty check to the previously removed length check.

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 19, 2026
@ChayimFriedman2

Copy link
Copy Markdown
Contributor

@Veykril that was your change (#22766).

@Veykril
Veykril enabled auto-merge July 19, 2026 15:51
@Veykril
Veykril added this pull request to the merge queue Jul 19, 2026
Merged via the queue into rust-lang:master with commit 081ddc9 Jul 19, 2026
18 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 19, 2026
Wilfred added a commit to Wilfred/rust-analyzer that referenced this pull request Aug 10, 2026
fetch_proc_macros() zips proc_macro_clients with a per-workspace
vec. We therefore require proc_macro_clients to have an item for every
workspace, or we get "proc-macro-srv is not running" and no macro
expansion for some workspaces.

This issue is more noticeable when using a discovery command, where it's
common to have have several workspaces, but it can occur in plain
cargo repositories too.

The logic was essentially `if !same_workspaces`, but this doesn't
actually work. When a new workspace is added, switch_workspaces()
updates self.workspaces, pushes to fetch_build_data_queue, and returns
early.

When we actually check the proc macro clients, on the second
invocation, we're seeing the *new* self.workspaces already and it
looks like nothing has changed!

This was broken in rust-lang#22766, and only partially
fixed in rust-lang#22865. Revert the code, and expand
the doc comments.

A better solution would be to track proc macro initialisation state
properly, but this fixes r-a on the >1 workspaces case today.

AI disclosure: Bisected with help by AI.
Wilfred added a commit to Wilfred/rust-analyzer that referenced this pull request Aug 10, 2026
fetch_proc_macros() zips proc_macro_clients with a per-workspace
vec. We therefore require proc_macro_clients to have an item for every
workspace, or we get "proc-macro-srv is not running" and no macro
expansion for some workspaces.

This issue is more noticeable when using a discovery command, where it's
common to have have several workspaces, but it can occur in plain
cargo repositories too.

The logic was essentially `if !same_workspaces`, but this doesn't
actually work. When a new workspace is added, switch_workspaces()
updates self.workspaces, pushes to fetch_build_data_queue, and returns
early.

When we actually check the proc macro clients, on the second
invocation, we're seeing the *new* self.workspaces already and it
looks like nothing has changed!

This was broken in rust-lang#22766, and only partially
fixed in rust-lang#22865. Revert the code, and expand
the doc comments.

A better solution would be to track proc macro initialisation state
properly, but this fixes r-a on the >1 workspaces case today.

AI disclosure: Bisected with help by AI.
lnicola pushed a commit to lnicola/rust that referenced this pull request Aug 17, 2026
fetch_proc_macros() zips proc_macro_clients with a per-workspace
vec. We therefore require proc_macro_clients to have an item for every
workspace, or we get "proc-macro-srv is not running" and no macro
expansion for some workspaces.

This issue is more noticeable when using a discovery command, where it's
common to have have several workspaces, but it can occur in plain
cargo repositories too.

The logic was essentially `if !same_workspaces`, but this doesn't
actually work. When a new workspace is added, switch_workspaces()
updates self.workspaces, pushes to fetch_build_data_queue, and returns
early.

When we actually check the proc macro clients, on the second
invocation, we're seeing the *new* self.workspaces already and it
looks like nothing has changed!

This was broken in rust-lang/rust-analyzer#22766, and only partially
fixed in rust-lang/rust-analyzer#22865. Revert the code, and expand
the doc comments.

A better solution would be to track proc macro initialisation state
properly, but this fixes r-a on the >1 workspaces case today.

AI disclosure: Bisected with help by AI.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants