Rust-Analyzer in VScode is failing "Cargo metadata fetch"

Hello everyone,

I am somewhat new to rust and still trying to understand how things work.

In my development setup I need to configure private crates registry and it will replace public crates.io. Things are working fine from the terminal including the (cargo metadata fetch) but it's failing when rust-analyzer in vs-code try to request metadata.

Looking at the error logs below cargo is complaining, not sure why it is behaving differently from terminal and within the vscode. Also more details here - Rust-analyzer in vs-code is failing to fetch "cargo metadata" · rust-lang/rust-analyzer · Discussion #14387 · GitHub

appreciate any kind of help.

Error log:
[ERROR rust_analyzer::main_loop] FetchWorkspaceError:
rust-analyzer failed to load workspace: Failed to read Cargo metadata from Cargo.toml file /xxxxxx/sd_monitor/Cargo.toml, Some(Version { major: 1, minor: 65, patch: 0 }): Failed to run cd "/xxxxxxx/sd_monitor" && "cargo" "metadata" "--format-version" "1" "--features" "" "--manifest-path" "/xxxxxx/sd_monitor/Cargo.toml" "--filter-platform" "x86_64-unknown-linux-gnu": cargo metadata exited with an error: error: failed to get hyper as a dependency of package sd_monitor v0.1.0 (/xxxxxx/sd_monitor)

Caused by:
failed to load source for dependency hyper

Caused by:
Unable to update registry crates-io

Caused by:
could not find a configured source with the name crates-io-mirror when attempting to lookup crates-io (configuration in /xxxxxx/sd_monitor/.cargo/config.toml)

Hello there,

I might be way-off, but I usually get that sort of error, when I do not add a linked project to .vscode/settings.json:

{
  "rust-analyzer.LinkedProjects": [
    "./relative-to-root/path/to/Cargo.toml"
  ]
}

Otherwise, I am out of ideas. Hope this helps

This didn't help, thanks for the suggestion.

Here is the root cause for my issue - Rust-analyzer in vs-code is failing to fetch "cargo metadata" · rust-lang/rust-analyzer · Discussion #14387 · GitHub

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.