Issue With Rust Analyzer As Well As 'rust-src'

Hello,

I am new to Rust and having some trouble with the Rust Analyzer extension for VSCode on MacOS. The error I am getting with Rust Analyzer is:

rust-analyzer failed to load workspace: Failed to find sysroot for Cargo.toml file /Users/apple/rustApps/guessing_game/Cargo.toml. Is rust-src installed?: can't load standard library from sysroot /Users/apple/.rustup/toolchains/stable-x86_64-apple-darwin (discovered via rustc --print sysroot) try installing the Rust source the same way you installed rustc

In my efforts to root cause this issue I used the command: 'rustup show' and received the following results:

Default host: x86_64-apple-darwin
rustup home: /Users/apple/.rustup

stable-x86_64-apple-darwin (default)
rustc 1.65.0 (897e37553 2022-11-02)

According to ChatGPT the rust-src component should have been listed with the results. When I discovered I could not find the rust-src component in the results from 'rustup show', I went ahead and tried to install rust-src with 'rustup component add rust-src', this is the info and error i received:

info: downloading component 'rust-src'
info: retrying download for 'https://static.rust-lang.org/dist/2022-11-03/rust-src-1.65.0.tar.xz'
info: retrying download for 'https://static.rust-lang.org/dist/2022-11-03/rust-src-1.65.0.tar.xz'
info: retrying download for 'https://static.rust-lang.org/dist/2022-11-03/rust-src-1.65.0.tar.xz'
info: retrying download for 'https://static.rust-lang.org/dist/2022-11-03/rust-src-1.65.0.tar.xz'
error: component download failed for rust-src: could not download file from 'https://static.rust-lang.org/dist/2022-11-03/rust-src-1.65.0.tar.xz' to '/Users/apple/.rustup/downloads/7dfdbecad68d9fbc64574eb403aa4815adef563dd6fb1d8a1be3b9fff364deb2.partial'

What do you believe should be my next steps to resolve the issue(s) I am having with Rust Analyzer and rust-src?

rustup component add rust-src should work. Are you able to download https://static.rust-lang.org/dist/2022-11-03/rust-src-1.65.0.tar.xz manually? And can you try removing /Users/apple/.rustup/downloads and trying again.

3 Likes

Thank you very much, @bjorn3, your solution worked perfectly.

  1. The first thing I did was remove rustup from /Users/apple/.rustup/downloads.

  2. I ran rustup component add rust-src afterwards and received the following error:

error: rustup could not choose a version of rustup to run, because one wasn't specified explicitly, and no default is configured.
help: run 'rustup default stable' to download the latest stable release of Rust and set it as your default toolchain.

  1. I ran rustup default stable and waited for all the downloads to be completed.

  2. Lastly I ran rustup component add rust-src, and now everything works.

Again, thank you!