Skip to content

Cargo update -p <localcrate> in a workspace has inconsistent behaviors #12599

Closed
@roblabla

Description

@roblabla

Cargo's handling of cargo update -p <cratename> is extremely inconsistent. Depending on how local crates are named or how up-to-date the Cargo.toml is compared to the Cargo.lock file, it will behave very differently with regards to git dependencies.

I have created a repository explaining the problems I found @ https://github.com/roblabla/cargo-wtf-why-are-you-drunk/

In that repository, you'll find two examples of inconsistencies in the behavior of cargo update -p:

  • In the first one, we show that cargo seems to handle git dependencies differently depending on whether it's got "work" to do on local crates or not. In particular, in my local monorepo, if I bump the version of a local crate in Cargo.toml, then cargo update -p <crate> will update the local lockfile to bump the versions of crate and nothing else. However, if I don't bump the version and run the same cargo update -p <crate> command, cargo will update the git dependencies.

    This discrepancy is especially frustrating, as it complicates our release process by making bumping the version more complicated.

  • In the second one, we show that whether or not cargo updates the git dependencies after bumping the version seem to depend on how your local crates in your workspace are named. This makes any call to cargo update -p <crate> inherently fragile, as what it does will depend on how your dependencies are named.

Possible Solutions

IMO, cargo update -p <crate> should never update an unrelated git dependency, as it does not match what the user intended.

Rust version:

rust 1.71.0 (8ede3aae2 2023-07-12)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions