Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rust-analyzer in VScode encounters problem when starting server #15927

Closed
Do7and opened this issue Nov 18, 2023 · 10 comments · Fixed by #16537
Closed

Rust-analyzer in VScode encounters problem when starting server #15927

Do7and opened this issue Nov 18, 2023 · 10 comments · Fixed by #16537
Assignees
Labels
A-cargo cargo related issues C-bug Category: bug

Comments

@Do7and
Copy link

Do7and commented Nov 18, 2023

I want to use rust-analyzer in vscode so I install the extension by vscode, but when I start to use it, it throws error :[ERROR project_model::rustc_cfg] failed to get rustc cfgs e=系统找不到指定的文件。 (os error 2). And maybe due to this error, I cannot find the "RUN doc-test" button where I write the doc test which can be detected by "cargo doc --open" command.

I take other's example as referrence, but in my rust-analyzer it doesn't work.
image

rust-analyzer version:v0.3.1730
rustc version: 1.74.0

relevant settings: NO rust-analyzer*-like setting in setting.json

@Do7and Do7and added the C-bug Category: bug label Nov 18, 2023
@Veykril
Copy link
Member

Veykril commented Nov 18, 2023

系统找不到指定的文件 = The system can not find the file specified

How did you install rust? It seems rust-analyzer is unable to run rustc --print cfg as rustc does not resolve to a command for it

@Do7and
Copy link
Author

Do7and commented Nov 18, 2023

系统找不到指定的文件 = The system can not find the file specified

How did you install rust? It seems rust-analyzer is unable to run rustc --print cfg as rustc does not resolve to a command for it

I have surely installed rust.
I installed it through https://www.rust-lang.org/learn/get-started using its rustup-init.exe.
And I run rustc --print cfg in the same directory with my code above, it seems no problem.
image

And in my env path there exists cargo bin directory which contains rustc.exe and so on

I do not know how this rustc_cfg work in this extension, because when I use Everything to search rust_cfg on my local there shows no result.

@0xd34db100d
Copy link

0xd34db100d commented Nov 25, 2023

Got the same error too on server extension startup and also got installed rust in path:
изображение

@Veykril Veykril added the A-cargo cargo related issues label Nov 25, 2023
@AndersHogqvist
Copy link

I just installed Rust as well as rust-analyzer and have the same issue. I can run rustc --print cfg in the terminal but rust-analyzer seems to live in its own environment where it can't find rustc.

@lnicola
Copy link
Member

lnicola commented Feb 2, 2024

@AndersHogqvist if you're on Linux or MacOS, see this part of the manual:

image

and #1811.

@AndersHogqvist
Copy link

AndersHogqvist commented Feb 2, 2024

I'm on Windows. In PowerShell:

C:\playground > rustc --print sysroot
C:\Users\SEANHOG1\.rustup\toolchains\stable-x86_64-pc-windows-msvc

Tried specifying the path in settings.json with / instead of \\ but that didn't help either:

"rust-analyzer.cargo.sysroot": "C:/Users/SEANHOG1/.rustup/toolchains/stable-x86_64-pc-windows-msvc"
[ERROR project_model::rustc_cfg] failed to get rustc cfgs e=failed to discover rustc in sysroot: "C:\\Users\\SEANHOG1\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc"

@AndersHogqvist
Copy link

Oh, rustup component add rust-src and restarting rust-analyzer solved it! :-)

@lnicola
Copy link
Member

lnicola commented Feb 2, 2024

I wanted to suggest that, but I'm looking at

let rustc = self.root.join("bin/rustc");
and wondering how it can work on Windows.

@Veykril
Copy link
Member

Veykril commented Feb 2, 2024

It can't, that's a bug

@ShadowDrakken
Copy link

Same issue occurring here...
ERROR project_model::rustc_cfg: failed to get rustc cfgs e=failed to discover rustc in sysroot: "<redacted>\\Rust\\rustup\\toolchains\\stable-x86_64-pc-windows-msvc"

Caused by:
The system cannot find the file specified. (os error 2)

PS> rustc --version
rustc 1.76.0 (07dca489a 2024-02-04)

PS> rustup component add rust-src
info: component 'rust-src' is up to date

PS>dir (rustc --print sysroot)
Directory: <redacted>\Rust\rustup\toolchains\stable-x86_64-pc-windows-msvc

Mode LastWriteTime Length Name


d----- 2/10/2024 2:57 PM bin
d----- 2/10/2024 2:57 PM etc
d----- 2/10/2024 2:57 PM lib
d----- 2/10/2024 2:57 PM libexec
d----- 2/10/2024 2:58 PM share

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-cargo cargo related issues C-bug Category: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants