4

I know that there are a lot of similar questions regarding rust-analyzer and I've checked them out but couldn't find the solution to my problem so I decided to ask a question myself. I've decided to start learning Rust and I'm having issues with rust-analyzer. Here is my workspace structure:

I created a project using cargo and hoped that rust-analyzer will automatically register it but for some reason it fails. I get this error message

> rust-analyzer failed to load workspace: Failed to read Cargo metadata from Cargo.toml file /home/remax/Storage/Projects/rust/rusttest/hello_cargo/Cargo.toml, cargo 1.61.0 (a028ae4 2022-04-29): Failed to run `"/home/remax/.cargo/bin/cargo" "metadata" "--format-version" "1" "--manifest-path" "/home/remax/Storage/Projects/rust/rusttest/hello_cargo/Cargo.toml" "--filter-platform" "x86_64-unknown-linux-gnu"`: `cargo metadata` exited with an error: error: could not execute process `rustc -vV` (never executed)

Caused by:
  No such file or directory (os error 2)

I honestly have no idea what to do. My cargo version is 1.61.0

UPDATE: issue persists even with only rust project in workspace enter image description here

kosingas
  • 61
  • 1
  • 7
  • What does `which cargo` say in a terminal? – cdhowie Jun 12 '22 at 20:57
  • @cdhowie it says ~/.cargo/bin/cargo and here is my path variable /home/remax/.local/bin:/home/remax/bin:/home/remax/.cargo/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/home/remax/.composer/vendor/bin:/usr/bin/env/:/usr/bin/env/ You think that I should add ~/.cargo/bin/cargo to path? – kosingas Jun 12 '22 at 21:03
  • It already is in your path. It looks like cargo is failing to find rustc for some reason. Does `which rustc` also give a path? – cdhowie Jun 12 '22 at 21:12
  • @cdhowie ~/.cargo/bin/rustc here it is – kosingas Jun 12 '22 at 21:17
  • I think I solved it here. https://stackoverflow.com/questions/72062935/rust-analyzer-failed-to-discover-workspace-in-vscode – Antonio Pavicevac-Ortiz Jul 23 '22 at 15:58

5 Answers5

2

You missed the rustup step. It is stated in the rust-analyzer extension that you need to install rustup first.

Quick start

  1. install rustup
  2. install the rust-analyzer extension.
August Jelemson
  • 962
  • 1
  • 10
  • 29
2

I solved the issue by deleting the .vscode folder. Reinstalling rustup didn't help.

The issue started appearing when I created a lib and then deleted it.

0

rustup must be installed in the same system as Vscode. If you are using WLS Subsystem (like me), try installing rustup on Windows with the rustup-init.exe. Run/Debug won't work (probably - I don't know why, but there's always cargo run) but you'll still get all the other features.

medium-dimensional
  • 1,974
  • 10
  • 19
0

Upgrade your rust-analyzer extension to the pre-release(v0.4.1525) one. This fixed the issue on my Macbook Pro m1.

0

in Rust you don't have to create the Cargo.toml file manually for a new project. delete your current workspace then, make a new dir eg, mkdir "home/spitfire/Documents/rust" cd into rust make a new project file in the root dir in this case is rust

like this "cargo new learning" you will get an output like this Created binary (application) learning package

check the learning folder it will contain Cargo.toml go back to rust by doing .. reload vscode and enjoy rust