Skip to content

rustc.source = "discover" tries to write Cargo.lock in rustc source dir #13900

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
GoldsteinE opened this issue Jan 6, 2023 · 1 comment
Closed

Comments

@GoldsteinE
Copy link

My rustc source is installed on read-only filesystem (in Nix store). When I try to use rust-analyzer on out-of-tree project that uses rustc_private crates, I get the following error:

[ERROR][2023-01-06 18:37:49] .../vim/lsp/rpc.lua:734	"rpc"	"rust-analyzer"	"stderr"	'[ERROR rust_analyzer::lsp_utils] rust-analyzer failed to load workspace: Failed to read Cargo metadata for Rust sources: Failed to run `"cargo" "metadata" "--format-version" "1" "--all-features" "--manifest-path" "/nix/store/686jpzdz5zxlfhy682gc2qyf98ri413l-rust-minimal-1.68.0-nightly-2022-12-13/lib/rustlib/rustc-src/rust/compiler/rustc/Cargo.toml" "--filter-platform" "x86_64-unknown-linux-gnu"`: `cargo metadata` exited with an error:     Updating crates.io index\nerror: failed to write /nix/store/686jpzdz5zxlfhy682gc2qyf98ri413l-rust-minimal-1.68.0-nightly-2022-12-13/lib/rustlib/rustc-src/rust/compiler/rustc/Cargo.lock\n\nCaused by:\n  failed to open: /nix/store/686jpzdz5zxlfhy682gc2qyf98ri413l-rust-minimal-1.68.0-nightly-2022-12-13/lib/rustlib/rustc-src/rust/compiler/rustc/Cargo.lock\n\nCaused by:\n  Read-only file system (os error 30)\n\n'

I think that rust-analyzer shouldn’t try to write anything inside of rustc-src directory, since it can be installed globally (e.g. with Nix or other third-party package manager).

rust-analyzer version: (eg. output of "rust-analyzer: Show RA Version" command, accessible in VSCode via Ctrl/⌘+Shift+P)

rust-analyzer 1.68.0-nightly (37d7de3 2022-12-12)

rustc version: (eg. output of rustc -V)

rustc 1.68.0-nightly (37d7de337 2022-12-12)

relevant settings: (eg. client settings, or environment variables like CARGO, RUSTUP_HOME or CARGO_HOME)

  1. rust-analyzer.rustc-source is set to "discover"
  2. In Cargo.toml, package.metadata.rust-analyzer.rustc_private is set to true
@bjorn3
Copy link
Member

bjorn3 commented Jan 6, 2023

Rust-analyzer runs cargo metadata in the rustc source directory. This updates the Cargo.lock file if it is outdated and due to the way the rustc-src component is created, it is indeed outdated as it mentions the standard library crates too, which only exist in the rust-src component, not the rustc-src component. Cargo doesn't have an option to not update Cargo.lock, other than --locked, which instead errors if Cargo.lock is not up to date.

Closing in favor of rust-lang/cargo#10096

@bjorn3 bjorn3 closed this as completed Jan 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants