Skip to content

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

Closed
@GoldsteinE

Description

@GoldsteinE

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions