rust-analyzer: rust-analyzer fails with "error: config value `env` is not set"

rust-analyzer version: 0.3.2053-standalone

rustc version: rustc 1.79.0 (129f3b996 2024-06-10)

editor or extension: VSCode

relevant settings: RUSTC_WRAPPER="$HOME/.cargo/bin/sccache"

repository link (if public, optional):

code snippet to reproduce: N/A

environment: WSL 2, Ubuntu 22.04 x86_64

Error

When I open my workspace in VSCode, rust-analyzer doesn’t show any red underlines for syntactically incorrect code. When I look at the output of rust-analyzer in the OUTPUT tab, I see this:

2024-07-29T18:56:36.485666Z ERROR Failed to discover cargo config env: cd “/home/shane/src/redacted” && RUSTC_BOOTSTRAP=“1” RUSTUP_TOOLCHAIN=“/home/shane/.rustup/toolchains/stable-x86_64-unknown-linux-gnu” “/home/shane/.cargo/bin/cargo” “-Z” “unstable-options” “config” “get” “env” failed, exit status: 101 stderr: error: config value env is not set

Stack backtrace: 0: anyhow::error::<impl anyhow::Error>::msg 1: project_model::utf8_stdout 2: project_model::env::cargo_config_env 3: project_model::workspace::ProjectWorkspace::load 4: <core::iter::adapters::map::Map<I,F> as core::iter::traits::iterator::Iterator>::fold 5: <alloc::vec::Vec<T> as alloc::vec::spec_from_iter::SpecFromIter<T,I>>::from_iter 6: core::ops::function::FnOnce::call_once{{vtable.shim}} 7: std::sys_common::backtrace::__rust_begin_short_backtrace 8: core::ops::function::FnOnce::call_once{{vtable.shim}} 9: std::sys::pal::unix:🧵:Thread:🆕:thread_start 10: <unknown> 11: <unknown>

In case it is relevant, here is the Cargo.toml in the root of my workspace:

[workspace]
resolver = "2"
members = [ "hydra", "li_engine", "lich"]
exclude = [ "c_library_bindings" ]

[profile.release]
opt-level = "z"
strip = true
lto = true
#codegen-units = 1

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 3
  • Comments: 15 (7 by maintainers)

Commits related to this issue

Most upvoted comments

As a workaround you can simply add an empty env section to your .cargo/config.toml:

[env]

This repository is also affected by this issue. I cannot navigate the source (and I also get the error log about the [env], altough it appears to be harmless) on the last release (or prerelease) channel version, but I can in v0.3.2037

@alibektas I did some poking around and it seems that the last working version for me is v0.3.2037 (e9afba57a 2024-07-14). 0.3.2045 has the same problem, so it may not be related to this issue, which I think is a regression with the latest version 0.3.2053?

My project is on an older version of rustc, so I ran into #17662 , and I added the "rust-analyzer.server.extraEnv": { "RUSTUP_TOOLCHAIN": "stable" } workaround suggested there, then ran into this issue after running rustup toolchain install stable-aarch64-apple-darwin and upgrading to rustc 1.80.0.

I’m not sure what other details are relevant, if I should start bisecting, etc.