Closed lf- closed 1 week ago
This is two separate issues on rust's end.
Cargo.lock
file shipped with the rust-src component is a literal copy of the Cargo.lock
in the rust repo and as such contains not just the standard library, but also the compiler and most tools. As such when using this file in the rust-src component, cargo will attempt to update it by removing all references to non-existent and unused crates. This fails if it is readonly.Cargo.lock
file as the Cargo.toml
file next to it specifying all workspace members is missing. As such it will look for library/core/Cargo.lock
when getting the metadata for libcore and create it from scratch if it doesn't exist. Just copying the workspace Cargo.toml
file won't work as it references the compile and most tools. If those are missing, it will just error out.Ugh. That's pretty ugly.
I wonder if rust-analyzer could somehow special case core since presumably the cargo metadata is known?
I believe that this is upstream issue https://github.com/rust-lang/rust/issues/95736
This somewhat related to https://github.com/rust-lang/rust-analyzer/issues/7637 I guess, where we'd like to have library
be a separate workspace (from r-a's point of view at least)
https://github.com/rust-lang/cargo/issues/10096 is also related.
I'll close this, I am pretty sure the cause for OP's problem was their editor telling r-a that the sysroot was a loaded lsp workspace causing us to attempt to run cargo metadata on it
For some reason, I started having rust-analyzer calling Cargo in such a way that Cargo is attempting to recreate the lock file of
core
, which is very much not something that should happen. I actually think rust-analyzer should probably pass--frozen
for such an invocation, since it does not currently, and such a command could actually succeed in messing up the global rust sources if they weren't on a read-only filesystem such as/nix/store
.This means that I get load errors. It seems to be that the lockfile is attempted to be updated because of some
rand
dependency of core?You can get the broken project version from here. I am using Nix for everything including r-a on this project, since it's a rust/C++ plugin. https://github.com/lf-/nix-otel/tree/41fba6dccbca74fdee3a1c6a8e88c9b49b4c50d4
r-a provided by Nix is invoked from within the
nix develop
shell using a shim that callsdirenv exec
.To reproduce the broken Cargo command, run this from any computer with Nix:
rust-analyzer version: 2022-10-03
rustc version: 1.63.0, from nix
relevant settings: (eg. client settings, or environment variables like
CARGO
,RUSTUP_HOME
orCARGO_HOME
)RA_LOG for the log below:
Extensive rust-analyzer log:
https://gist.github.com/lf-/32dd8e796e2b9d6fe91ba0c9a7879398