Search manifest ancestors for the lockfile when fetching cargo metadata - #23296
Open
onlycs wants to merge 1 commit into
Open
Search manifest ancestors for the lockfile when fetching cargo metadata#23296onlycs wants to merge 1 commit into
onlycs wants to merge 1 commit into
Conversation
…data The rustc-dev dist component ships the compiler sources with `rustc-src/rust/compiler/rustc/Cargo.toml` as the entry manifest, but without a workspace root manifest next to the lockfile, which lives at `rustc-src/rust/Cargo.lock`. FetchMetadata only looked for a lockfile right next to the manifest, so for `rust-analyzer.rustc.source = "discover"` setups the metadata fetch ran with `--locked` and no usable lockfile. On read-only toolchain installations (e.g. rustup toolchains on nix) cargo then fails to create one, and rust-analyzer silently degrades to `--no-deps` metadata, dropping rustc_middle and friends from the crate graph entirely - rustc_private projects lose all type information for rustc crates. Walk up from the manifest to find the lockfile and reuse the existing lockfile-copy mechanism, which keeps cargo from touching the original. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This was referenced Sep 4, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
With a nix toolchain, every macro-generated
TyCtxtquery getter (tcx.mir_keys(()), e.g.) resolves to{unknown}. Three independent bugs cause this, one of which was fixed in 7015591, one with #23297, and one in this PRthe
rustc-srclockfile is never foundThe
rustc-devcomponent ships compiler sources as[rustc-src]/rust/compiler/rustc/Cargo.toml, with no workspace root manifest. The lockfile lives two levels up at[rustc-src]/rust/Cargo.lock.FetchMetadata::newonly looks for a lockfile directly next to the manifest, so the rustc metadata fetch runs--lockedwith no lockfile available. In a read-only store, cargo cannot create one and errors:FetchMetadata::execthen silently falls back to the--no-depspre-fetch, whose metadata contains only therustc-mainstub package.rustc_middle,rustc_hir, etc. never enter the crate graph.Instead, we walk up the manifest's ancestor directories to find the lockfile, then reuse the existing lockfile-copy mechanism.
AI disclosure
These changes were authored with AI assistance (Claude Code); the commits carry
Co-Authored-Bytrailers. I have reviewed the changes, use them in a current project using a patched build, and can answer questions about them myself.See also: #23251
Version Info
cargo:
cargo 1.99.0-nightly (eb98b54bc 2026-08-11)Toolchain:
nightly-2026-08-14, componentsrustc-dev,llvm-tools-preview,rust-src.Configuration (Zed,
.zed/settings.json):{ "lsp": { "rust-analyzer": { "initialization_options": { "rustc": { "source": "discover" } } } } }