Proc macro "main" not expanded + Rust-analyzer not spawning server
Asked Answered
M

6

6

I join these two questions in one, as they maybe are related. A few days ago, I started having this error in the [#actix_rt::main] line, before the main function:

proc macro `main` not expanded: cannot find proc-macro server in sysroot `C:\Users\zerok\.rustup\toolchains\stable-x86_64-pc-windows-gnu`

At the same time, in VSCode my rust-analyzer extension started failing. I uninstalled it, restarted VSCode, and reinstalled. It keeps giving the same error over and over:

Failed to spawn one or more proc-macro servers.

How can I fix this problem?

Monoatomic answered 4/5, 2023 at 9:2 Comment(0)
M
5

Soon after posting the question, I finally found out how to install the toolchain, which seems to have fixed both errors:

rustup toolchain install stable-x86_64-pc-windows-gnu

After that, I clicked on the rust-analyzer box on the bottom of VSCode, clicked in "Restart Server", and everything worked after the command completion.

Monoatomic answered 4/5, 2023 at 9:12 Comment(1)
Good to know: proc macro expansion is no longer supported in toolchains older than 1.64 - you can check your toolchain version using rustc -V. See this discussionCroaker
M
6

I had the same problem on Mac, this my error

Failed to spawn one or more proc-macro servers.

- cannot find proc-macro-srv, the workspace 
`/Users/xxxx/vscode/rust/guessing_game` is missing a sysroot

Failed to find sysroot for Cargo.toml file 
/Users/xxxx/vscode/rust/guessing_game/Cargo.toml. Is rust-src installed? 
can't load standard library from sysroot

/Users/xxxx/.rustup/toolchains/stable-x86_64-apple-darwin

(discovered via `rustc --print sysroot`)

try installing the Rust source the same way you installed rustc

here's my fix

# install rust-src
sudo rustup component add rust-src

More information

Mata answered 7/9, 2023 at 3:32 Comment(0)
M
5

Soon after posting the question, I finally found out how to install the toolchain, which seems to have fixed both errors:

rustup toolchain install stable-x86_64-pc-windows-gnu

After that, I clicked on the rust-analyzer box on the bottom of VSCode, clicked in "Restart Server", and everything worked after the command completion.

Monoatomic answered 4/5, 2023 at 9:12 Comment(1)
Good to know: proc macro expansion is no longer supported in toolchains older than 1.64 - you can check your toolchain version using rustc -V. See this discussionCroaker
C
5

My problem was related to a setting on VS Code

"rust-analyzer.cargo.sysroot": "discover"

Don't know how but the above setting was set to null. The default is "discover".

Click answered 22/10, 2023 at 20:7 Comment(3)
This was the fix for me. Thank youDisastrous
Thank you! That resolved my problem. I don't know why, my vscode jusc change default behaviour too.Careaga
Took a lot of searching to find this solution. Thanks.Prothorax
R
1

I had a different problem that I just figured out. I'm on my work laptop and I had previously installed just using MacPorts, since I like it but I didn't want to install a full rust toolchain on this machine as we didn't have any Rust projects yet. Now a few months later I installed rustup and got the warning about there being an outdated preexisting toolchain elsewhere on the machine, which left me super confused because I didn't remember installing it, but I went through with it anyways since I thought I could figure it out. The other answers didn't work for me since I already had rust-src installed, but after trying to run rustc --print sysroot and doing a bit of detective work with zsh -xl thanks to this answer I realized MacPorts was fighting with the rest of my shell config and overriding $PATH.

So the solution for me was removing the old toolchains (and MacPorts entirely), and confirming that my $PATH was set up properly. I still couldn't get rust-analyzer to cooperate afterwards, but running rustc --print sysroot and setting "rust-analyzer.cargo.sysroot": "/path/to/sysroot" with the output of that command fixed the problem, I just had to restart rust-analyzer afterwards.

Ricketts answered 8/9, 2023 at 18:42 Comment(0)
B
0

i had the same issue in VsCode fixed with :

rustup update
rustup component add rust-src
Betthezul answered 11/3, 2024 at 18:28 Comment(0)
G
0

To disable this specifically in VSCode settings, edit your settings.json configuration for your User:

// @see {@link https://rust-analyzer.github.io/manual.html#unresolved-proc-macro}
"rust-analyzer.diagnostics.disabled": ["unresolved-proc-macro"],

Installing the rust-analyzer

$ rustup component add rust-analyzer
$ brew install rust-analyzer

More Information

VSCode Rust Analyzer GitHub Tree

Download the latest release of rust-analyzer as rustup add rust-analyzer does not contain the latest release

Graft answered 21/7, 2024 at 16:15 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.