Proc 宏“main”未扩展 + Rust 分析器未生成服务器

Zer*_*rok 3 rust rust-proc-macros rust-analyzer

我将这两个问题合二为一,因为它们可能是相关的。几天前,我开始在 main 函数之前的 [#actix_rt::main] 行中出现此错误:

proc macro `main` not expanded: cannot find proc-macro server in sysroot `C:\Users\zerok\.rustup\toolchains\stable-x86_64-pc-windows-gnu`
Run Code Online (Sandbox Code Playgroud)

与此同时,在 VSCode 中,我的 rust-analyzer 扩展开始失败。我卸载了它,重新启动 VSCode,然后重新安装。它不断地给出同样的错误:

Failed to spawn one or more proc-macro servers.
Run Code Online (Sandbox Code Playgroud)

我该如何解决这个问题?

小智 5

我在 Mac 上遇到了同样的问题,这是我的错误

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
Run Code Online (Sandbox Code Playgroud)

这是我的解决办法

# install rust-src
sudo rustup component add rust-src
Run Code Online (Sandbox Code Playgroud)

更多信息