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

No error shown when running cargo metadata on the sysroot fails #19281

Open
AlanHale25 opened this issue Mar 4, 2025 · 14 comments
Open

No error shown when running cargo metadata on the sysroot fails #19281

AlanHale25 opened this issue Mar 4, 2025 · 14 comments
Labels
C-support Category: support questions

Comments

@AlanHale25
Copy link

AlanHale25 commented Mar 4, 2025

rust-analyzer version:
0.4.2329

rustc version: 1.85.0

editor or extension: VSCode

relevant settings: Fresh VSCode and Rust-Analyzer installation

code snippet to reproduce:

// add your code here
@AlanHale25 AlanHale25 added the C-bug Category: bug label Mar 4, 2025
@lnicola
Copy link
Member

lnicola commented Mar 4, 2025

rustc version: (eg. output of rustc -V)

You're supposed to fill these in, but you probably have an old toolchain. Only 1.82 and newer are supported at the moment.

@lnicola lnicola added C-support Category: support questions and removed C-bug Category: bug labels Mar 4, 2025
@AlanHale25
Copy link
Author

rustc version: (eg. output of rustc -V)

You're supposed to fill these in, but you probably have an old toolchain. Only 1.82 and newer are supported at the moment.

Hi Sorry, I just filled it in now. I have version 1.85.0

@lnicola
Copy link
Member

lnicola commented Mar 4, 2025

Do you have rust-src installed or any errors in the status bar? Does it happen in a new project?

@AlanHale25
Copy link
Author

I have rust-src installed: PS C:\Users\Alan\Rust-Project> rustup component list
cargo-x86_64-pc-windows-msvc (installed)
clippy-x86_64-pc-windows-msvc (installed)
llvm-bitcode-linker-x86_64-pc-windows-msvc
llvm-tools-x86_64-pc-windows-msvc
rls-x86_64-pc-windows-msvc
rust-analysis-x86_64-pc-windows-msvc
rust-analyzer-x86_64-pc-windows-msvc (installed)
rust-docs-x86_64-pc-windows-msvc (installed)
rust-src (installed)

There are no errors on the status bar.
New projects also have the issue.
Code completions also seems to not be working.

@lnicola
Copy link
Member

lnicola commented Mar 4, 2025

What do you get for "rust-analyzer: Status"?

@AlanHale25
Copy link
Author

AlanHale25 commented Mar 4, 2025

When I run it rust-analyzer: Status via the command palette I get this huge json file:

Workspaces:
Loaded 140 packages across 1 workspace.
Workspace root folders: [AbsPath("C:\\Users\\axh444\\rust_project\\Cargo.toml")]
Analysis:
24mb of files
2356 trees, 128 preserved
29859 trees, 512 preserved (macros)
0b of library index symbols (0)
1766b of module index symbols (14)
645mb in total

Debug info:
101252 attribute query entries, 351986 total attributes (8mb for storing entries)
32028 ast id maps
324 block def maps
Version: 
1.85.0 (4d91de4e 2025-02-17)
[snip]

@lnicola
Copy link
Member

lnicola commented Mar 4, 2025

Sounds like it's working fine. Does it show Unknown even for something like let s = String::new();? Can you Go to definition on String?

@AlanHale25
Copy link
Author

Yes, it shows unknown for strings. Vec for vec of strings. It even shows unknown for hardcoded type. e.g
It shows unknown for my string if defined as below

let my_string: String = format!("Hello {}", "world");
my_string

I'm unable to go to string definition either.

@lnicola
Copy link
Member

lnicola commented Mar 4, 2025

Maybe your toolchain got corrupted? Try rustup toolchain remove 1.85 stable, rustup toolchain install stable --components rust-src.

@AlanHale25
Copy link
Author

AlanHale25 commented Mar 4, 2025

Uninstalling and reinstalling rust-analyzer and rustup via https://www.rust-lang.org/tools/install did not work, as in it still shows types as unknown.

I had faced this issue before on a previous new install. I did see an issue on here which advised on downloading a pack, that solved my problem at the time, but I can't find the issue it was written on now.

@ByteXiang
Copy link

#18560 (comment) . I've mentioned the same problem before, but using 1.81.0 all the time is fine. After updating the ruat-analyzer extension in VSCODE today, 1.18.0 also mentions { unknow } , which I found only for prelude pre-imported modules. I'm not sure if it has anything to do with the image source cargo has set up, but the company's internal network only synced crates up to 2024-08-01.

@AlanHale25
Copy link
Author

Finally managed to get it to work.
The issue was the std dependencies where not being built as I'm behind a corporate firewall.

The Solution was to include at $CARGO_HOME/config.toml; the config.toml should include your source and registry configuration (However you usually get through to the internet through the firewall.)

I got to the solution by attempting to run cargo metadata "~/.rustup/toolchains/stable-x86_64-pc-windows-msvc/lib/rustlib/src/rust/library" , Which failed with spurious network connection as the error message. That gave me the hint.

Thank you @ByteXiang your suggestion pointed me to the right direction. #17759

Thank you @lnicola for your effort and help.

@lnicola
Copy link
Member

lnicola commented Mar 4, 2025

So we don't show an error on cargo metadata? That sounds like a bug.

@AlanHale25
Copy link
Author

Yup, the error only appears after going to -> cd $(rustc --print sysroot)/lib/rustlib/src/rust/library && __CARGO_TEST_CHANNEL_OVERRIDE_DO_NOT_USE_THIS=nightly

And then running -> cargo metadata

@lnicola lnicola reopened this Mar 4, 2025
@lnicola lnicola changed the title Rust Analyzer only showing Unknown type No error shown when running cargo metadata on the sysroot fails Mar 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-support Category: support questions
Projects
None yet
Development

No branches or pull requests

3 participants