# Cargo - Publish crate from workspace where a newer version of another crate depends on that version

**URL:** <https://users.rust-lang.org/t/cargo-publish-crate-from-workspace-where-a-newer-version-of-another-crate-depends-on-that-version/136241>\
**Category:** uncategorized\
**Created:** [November 14, 2025, 7:37am UTC](https://users.rust-lang.org/t/cargo-publish-crate-from-workspace-where-a-newer-version-of-another-crate-depends-on-that-version/136241 "2025-11-14T07:37:20Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Schard](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/schard/32/43802_2.png) [@Schard](https://users.rust-lang.org/u/Schard)\
**Post date:** [November 14, 2025, 7:37am UTC](https://users.rust-lang.org/t/cargo-publish-crate-from-workspace-where-a-newer-version-of-another-crate-depends-on-that-version/136241/1 "2025-11-14T07:37:20Z")

</div>

So, I just wrote these two commit messages, to be able to publish a new version of a crate in between those:

```rust
    Restore correct dependency.

...

    Cargo won't publish any crate in the same workspace with a new version if another crate in the same workspace depends on that very version of the crate, which is not published yet. So we need to artificially temporarily break the dependencies of the other crate to allow publishing its dependency.

```

The workspace contains a crate providing a trait and another one providing a derive macro for that trait.  
I made changes to the trait (make it `unsafe`) and adjusted the derive macro accordingly.  
Then I bumped the versions of both crates and updated the dependency in the main crate to the new one.  
Then I tried to first publish the macro crate, since the other crate relies on its new version:

```rust
~/RustroverProjects/repr-discriminant/repr-discriminant> cargo publish -p repr-discriminant-derive 
    Updating crates.io index
    Updating crates.io index
error: failed to select a version for the requirement `repr-discriminant-derive = "^1.2"`
candidate versions found which didn't match: 1.1.7, 1.1.6, 1.1.5
location searched: crates.io index
required by package `repr-discriminant v2.1.0 (/home/neumann/RustroverProjects/repr-discriminant/repr-discriminant)`

```

Well, shoot.  
How do I handle these kind of changes if cargo forbids me to publish a dependency first.  
Why does this even fail? I never tried to publish `repr-discriminant` anyway.  
I hacked around this, by artificially breaking the version constraints with the commits mentioned above, but this is very unergonomic. How do I correctly deal with this kind of dependent changes?

---

<div class="post-metadata">

**Author:** ![jofas](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/jofas/32/30690_2.png) [@jofas](https://users.rust-lang.org/u/jofas)\
**Post date:** [November 14, 2025, 8:09am UTC](https://users.rust-lang.org/t/cargo-publish-crate-from-workspace-where-a-newer-version-of-another-crate-depends-on-that-version/136241/2 "2025-11-14T08:09:43Z")

</div>

How do you declare the `repr-discriminant-derive` dependency in `repr-discriminant`? Simply

```rust
repr-discriminant-derive = "^1.2"

```

as the error message suggests?

You might need to change that to

```rust
repr-discriminant-derive = { path = "path/to/repr-discriminant-derive", version = "^1.2" }

```

for `cargo publish` to be able to build `repr-discriminant` locally during the publishing of `repr-discriminant-derive`. At least this is my [setup](https://github.com/jofas/struct_field_names_as_array/blob/6bb25e430b548a42405fa47484cbc99cf3d0e9a3/struct-field-names-as-array/Cargo.toml#L23) and I never had such an error before.

---

<div class="post-metadata">

**Author:** ![Ddystopia](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/ddystopia/32/34903_2.png) [@Ddystopia](https://users.rust-lang.org/u/Ddystopia)\
**Post date:** [November 14, 2025, 9:44am UTC](https://users.rust-lang.org/t/cargo-publish-crate-from-workspace-where-a-newer-version-of-another-crate-depends-on-that-version/136241/3 "2025-11-14T09:44:24Z")

</div>

I personally deal with it by publishing in a specific order and bumping versions gradually, but yeah, it is an awful experience from cargo.

---

<div class="post-metadata">

**Author:** ![Schard](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/schard/32/43802_2.png) [@Schard](https://users.rust-lang.org/u/Schard)\
**Post date:** [November 14, 2025, 9:50am UTC](https://users.rust-lang.org/t/cargo-publish-crate-from-workspace-where-a-newer-version-of-another-crate-depends-on-that-version/136241/4 "2025-11-14T09:50:07Z")

</div>

> [@jofas](#):
>
> You might need to change that to
> 
> `repr-discriminant-derive = { path = "path/to/repr-discriminant-derive", version = "^1.`

I don't like this solution because it requires the user to have downloaded the other crate to the respective folder. This is not how I like to publish my crates.  
If you suggest an intermediate change, imho this is not less worse than artificially breaking the version constraints to satisfy cargo.

> [@Ddystopia](#):
>
> I personally deal with it by publishing in a specific order and bumping versions gradually, but yeah, it is an awful experience from cargo.

I don't like this either, since I want to separate my software development and VCS workflow from my crate publishing workflow. I don't want cargo to force me to change one crate, and then publish it, before I can make related changes to another crate. In my case it'd be especially bad: I'd need to implement a derive macro for a trait that does not exist yet.

---

<div class="post-metadata">

**Author:** ![jofas](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/jofas/32/30690_2.png) [@jofas](https://users.rust-lang.org/u/jofas)\
**Post date:** [November 14, 2025, 10:11am UTC](https://users.rust-lang.org/t/cargo-publish-crate-from-workspace-where-a-newer-version-of-another-crate-depends-on-that-version/136241/5 "2025-11-14T10:11:17Z")

</div>

> [@Schard](#):
>
> it requires the user to have downloaded the other crate to the respective folder.

This is [not true](https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html#multiple-locations) if your user downloads the `repr-discriminant` crate from [crates.io](http://crates.io).

---

<div class="post-metadata">

**Author:** ![Schard](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/schard/32/43802_2.png) [@Schard](https://users.rust-lang.org/u/Schard)\
**Post date:** [November 14, 2025, 10:53am UTC](https://users.rust-lang.org/t/cargo-publish-crate-from-workspace-where-a-newer-version-of-another-crate-depends-on-that-version/136241/6 "2025-11-14T10:53:42Z")

</div>

Interesting. I didn't know that there's a fallback to the registry. Is this a new feature of cargo or was this always possible? I faintly remember that using local paths, also relative ones, was discouraged once due to the concerns I mentioned above.

---

<div class="post-metadata">

**Author:** ![jofas](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/jofas/32/30690_2.png) [@jofas](https://users.rust-lang.org/u/jofas)\
**Post date:** [November 14, 2025, 11:08am UTC](https://users.rust-lang.org/t/cargo-publish-crate-from-workspace-where-a-newer-version-of-another-crate-depends-on-that-version/136241/7 "2025-11-14T11:08:18Z")

</div>

The docs on multiple locations were written 6 years ago:

> <https://github.com/rust-lang/cargo/pull/7733>
>
> This is a collection of documentation updates that have been in my todo list for… a while. Each change is in a separate commit.
> 
> The "features" chapter will probably get significant changes in the future, as it is pretty bare right now. Similarly the "workspace" chapter could probably use more examples.
> 
> Closes #3062
> Closes #3817
> Closes #3971
> Closes #4212
> Closes #4438
> Closes #4756
> Closes #5822
> Closes #6913
> Closes #7055

If Cargo ever treated the combination of `path`/`git` with `version` differently, I don't recall it.

---

<div class="post-metadata">

**Author:** ![system](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/system/32/51372_2.png) [@system](https://users.rust-lang.org/u/system)\
**Post date:** [February 12, 2026, 11:08am UTC](https://users.rust-lang.org/t/cargo-publish-crate-from-workspace-where-a-newer-version-of-another-crate-depends-on-that-version/136241/8 "2026-02-12T11:08:43Z")

</div>

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.
