Repository navigation
Fix: cargo installing from a directory source fails for binary packages with no dependencies. - #17552
Merged
Merged
Conversation
…h no dependencies
Collaborator
|
r? @epage rustbot has assigned @epage. Use Why was this reviewer chosen?The reviewer was selected based on:
|
Contributor
|
r? @Muscraft |
Suryansh-Dey
force-pushed
the
option
branch
2 times, most recently
from
October 6, 2026 15:23
a662fd4 to
0091e02
Compare
weihanglo
reviewed
Oct 7, 2026
| self.root.display() | ||
| ) | ||
| })?; | ||
| fn packages(&self) -> CargoResult<Ref<'_, HashMap<PackageId, (Package, Checksum)>>> { |
Member
There was a problem hiding this comment.
What do you think of restructuring it like this?
It could keep the loading logic at its original indentation, so code diff gets much smaller.
- Keep the package loading logic in
fn update, perhaps rename toload_packagesand returning the hash map. - Change
RefCelltoOnceCell, as the map is never mutated once initialized. This should be fine becauseDirectorySource::invalidate_cachenever really invalidates loaded packages.
If we ever need that, it is an impl detail we can change. fn packagesbecomes a thin accessor:(fn packages(&self) -> CargoResult<&HashMap<...>> { self.packages.try_borrow_with(|| self.load_packages()) }
try_borrow_withcomes fromOnceExtbtw)
Contributor
Author
There was a problem hiding this comment.
I also thought about this but was afraid of changing Ref to Once. Done!
weihanglo
approved these changes
Oct 8, 2026
Contributor
Author
I also learnt a lot from you, thank you. |
rust-bors Bot
pushed a commit
to rust-lang/rust
that referenced
this pull request
Oct 14, 2026
Update cargo submodule 14 commits in 29c5daa1afc262323364e039bb70c83372cc702c..3960fa69bb617e3d93c4ddc087c1b32bf12ad907 2026-10-07 22:13:48 +0000 to 2026-10-12 19:29:05 +0000 - refactor: modernize some API usages for 1.99 (rust-lang/cargo#17584) - Removed some dead workspace tests (rust-lang/cargo#17582) - Bypass rustup proxy when RUSTUP_TOOLCHAIN is an absolute path (rust-lang/cargo#17562) - chore: Add an LLM disclosure to the PR template (rust-lang/cargo#17580) - Restrict workspace-relative dep-info to workspace packages (rust-lang/cargo#17575) - fix(layout): exclude a build-dir created as a parent from backups (rust-lang/cargo#17560) - Avoid absolute paths in fingerprints if they are relative to the workspace root (rust-lang/cargo#17573) - chore(deps): update msrv (3 versions) to v1.97 (rust-lang/cargo#17572) - fix(job): Allow explicit child process breakaway on Windows (rust-lang/cargo#17527) - fix(git): Add future-incompat warning in prep for removing auto-detection (rust-lang/cargo#17568) - fix(config): Don't process includes for `credentials.toml` files (rust-lang/cargo#17569) - doc(builtin-dep): Document the builtin package ID spec format (rust-lang/cargo#17564) - test(mock-std): Set stable crate versions to 0.0.0 (rust-lang/cargo#17565) - Fix: cargo installing from a directory source fails for binary packages with no dependencies. (rust-lang/cargo#17552) r? ghost
rust-bors Bot
pushed a commit
to rust-lang/rust
that referenced
this pull request
Oct 14, 2026
Update cargo submodule 14 commits in 29c5daa1afc262323364e039bb70c83372cc702c..3960fa69bb617e3d93c4ddc087c1b32bf12ad907 2026-10-07 22:13:48 +0000 to 2026-10-12 19:29:05 +0000 - refactor: modernize some API usages for 1.99 (rust-lang/cargo#17584) - Removed some dead workspace tests (rust-lang/cargo#17582) - Bypass rustup proxy when RUSTUP_TOOLCHAIN is an absolute path (rust-lang/cargo#17562) - chore: Add an LLM disclosure to the PR template (rust-lang/cargo#17580) - Restrict workspace-relative dep-info to workspace packages (rust-lang/cargo#17575) - fix(layout): exclude a build-dir created as a parent from backups (rust-lang/cargo#17560) - Avoid absolute paths in fingerprints if they are relative to the workspace root (rust-lang/cargo#17573) - chore(deps): update msrv (3 versions) to v1.97 (rust-lang/cargo#17572) - fix(job): Allow explicit child process breakaway on Windows (rust-lang/cargo#17527) - fix(git): Add future-incompat warning in prep for removing auto-detection (rust-lang/cargo#17568) - fix(config): Don't process includes for `credentials.toml` files (rust-lang/cargo#17569) - doc(builtin-dep): Document the builtin package ID spec format (rust-lang/cargo#17564) - test(mock-std): Set stable crate versions to 0.0.0 (rust-lang/cargo#17565) - Fix: cargo installing from a directory source fails for binary packages with no dependencies. (rust-lang/cargo#17552) r? ghost
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.
What does this PR try to resolve?
closes #17458
The issue originates from using
updated:booland functions directly accessingpackagesvariable which can be uninitialized.cargo/src/sources/directory.rs
Lines 188 to 191 in bb2126c
Rather than spreading
if !self.updated.get() { self.update()?; }intodownload()andverify(), we can make direct uninitialized access impossible by design:Approach:
packages: RefCell<HashMap<PackageId, (Package, Checksum)>>->packages: RefCell<Option<HashMap<PackageId, (Package, Checksum)>>>So that anybody tries to accessdirectorySource.packagedirectly (out of habit) gets an compiler error.update()method with.packages()method which will immediately return ifpackage.is_some()else it will populate packages and return it (lazy behavior). This way we will not need this check everywhere fixing the problem forever by just a refactor. Also removes theupdated:bool.If team doesn't like this approach I am ready for changes.
How to test and review this PR?
Run
cargo test --test testsuite directory::install_without_dependenciesManual: Steps metioned in this issue