rust-analyzer: Rust-analyzer error on pre-release branch of vscode extension

rust-analyzer version: rust-analyzer 2022-02-14 (installed via pacman)

rustc version: rustc 1.58.1 (db9d1b20b 2022-01-20) (installed via rustup and branch is stable)

Hello! I am taking this error on vscode.

rust-analyzer failed to load workspace: "cargo" "--version" failed, exit status: 1
stderr:
error: no override and no default toolchain set

I am using pre-release of vscode extension, that’s why i open a issue despite your info about it. I tried adding CARGO path but it didn’t work. I hope it’ll be helpful bug report for you!

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 49 (21 by maintainers)

Most upvoted comments

Maybe you also need RUSTUP_HOME?

Works. Thank you so much for your help, let’s go back to work.

Anyways symlink is working too! I don’t know why did it give error when my first try, but it worked! That was related to alternative paths.

It looks like your rustup installation doesn’t have a default toolchain configured. Try running rustup default stable to use stable rustc as default.

I had this issue - it was because I’m using WSL to run an Ubuntu command line in Windows and VS Code in Windows itself (doh).

Yeah that is the answer to that error normally but then I still don’t get it.

$ rustup default stable
info: using existing install for 'stable-x86_64-unknown-linux-gnu'
info: default toolchain set to 'stable-x86_64-unknown-linux-gnu'

  stable-x86_64-unknown-linux-gnu unchanged - rustc 1.59.0 (9d1b2106e 2022-02-23)

I fully understand what you mean, it’s not a big issue, I just put stuff in opt because my home. I was expecting the symlink to work.

I tried to remove the json config and set the CARGO env var in /etc/environment.d/90cargo-path.conf which seems fine but no luck neither. Other processes have also those var.

$ ps aux | grep code | grep analyzer
greg        4198  0.0  0.0 1041864 11496 ?       Sl   20:52   0:00 /home/greg/.vscode/extensions/matklad.rust-analyzer-0.2.964/server/rust-analyzer
greg@debby:~$ sudo cat /proc/4198/environ | tr '\0' '\n' | grep CARGO
CARGO=/opt/rust/.cargo/bin/cargo
CARGO_HOME=/opt/rust/.cargo
rust-analyzer failed to load workspace: "/opt/rust/.cargo/bin/cargo" "--version" failed, exit status: 1
stderr:
error: no override and no default toolchain set

I’m not sure, then. I would check that CARGO_HOME is set for Code. You can figure out it’s PID (look in the tree view of ps auwxf or htop) and check using sudo cat /proc/$PID/env | tr '\0' '\n'.

What do you mean by “they”?

Nevermind.

rust-analyzer appears to work when using alternate paths, but only if you configure them properly.

Yes it was great with alternate parhs but it suddenly stopped working.

So… what do you think will they get a bugfix about this bug (“rust-analyzer doesn’t detect when using alternative paths”)?

What do you mean by “they”?

Anyway, rust-analyzer appears to work when using alternate paths, but only if you configure them properly. If you only set those environment variables for the shell, rust-analyzer has no way of knowing about them.

But ~/.cargo should work either, am i right?

In your setup? I don’t know.

If you want to make environment variables visible to Code, you can set them in a .desktop file, in /etc/environment, in ~/.pam_environment (which is deprecated AFAIK) or in ~/.config/environment.d (which works at least in GNOME and/or systemd).

Okay, you should have mentioned that in the original post. I’ll update the issue template to ask for customizations like this.

Did you try to run Code from the terminal? If you’re using a DE and you’re setting RUSTUP_HOME and/or CARGO_HOME in your shell’s config, Code is not going to pick them up and rust-analyzer might become confused.

In any case, I don’t think we’ve tested this configuration. There is some auto-detection for ~/.cargo/bin/cargo, but only that.

The output of command -v is less relevant because Code doesn’t go through the shell (unless you start it from the terminal, in which case it might pick a different version of cargo and friends.

So is it’s not from a package and it’s not a symlink (or is it?), where did /usr/bin/cargo come from?

You misundestood. I dualboot Debian & Arch. In Debian I installed rustup via rust’s site. In Arch I installed from pacman.

Does cargo --version work for you? Also try if restarting your editor fixes it.

cargo --version gives cargo 1.58.0 (f01b232bc 2022-01-19) restarting editor doesn’t fix 😦