rust-lang / rust-lang/cargo

--locked doesn't prevent removing crates from workspace

Open
#8,399 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-lockfile A-workspaces C-bug S-needs-design
Dominant language
Rust
Stars
15.5k
Forks
3k
Avg merge
23h 30m
Merged PRs (30d)
51

Description

Using --locked doesn't prevent removing a crate from a workspace. I would expect cargo to fail when invoked with --locked on a removed crate, but instead it succeeds and instead doesn't modify Cargo.lock.

To reproduce

In an empty directory, create Cargo.toml with the following contents

[workspace]
members = ["foo", "bar"]

run

cargo new foo
cargo new bar
cargo build

Keep track of the current state of Cargo.lock (e.g. by checking everything into git.)

Now run

rm -rf bar

and edit Cargo.toml to

[workspace]
members = ["foo"]

run cargo build --locked

Behavior

This command will successfully build foo and will not modify Cargo.lock, i.e. Cargo.lock will still contain a reference to the bar crate. (Running cargo build leads to Cargo.lock being updated to remove references to bar, as expected.)

Expected

The expected behavior would be for the last command to fail with an error message saying Cargo.lock needs to be updated.

Version
cargo 1.44.1 (88ba85757 2020-06-11)

(on OS X)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the workspace setup with foo and bar, remove bar, edit Cargo.toml, and run cargo build --locked. Compare the behavior with an unlocked build and inspect how Cargo handles the workspace and Cargo.lock; done means the locked build fails when the lockfile still references the removed crate.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
build-system
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
50/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.