# Feedback on \`cargo-upgrade\` to prepare it for merging

**URL:** <https://internals.rust-lang.org/t/feedback-on-cargo-upgrade-to-prepare-it-for-merging/17101>\
**Category:** cargo\
**Created:** [July 29, 2022, 5:08pm UTC](https://internals.rust-lang.org/t/feedback-on-cargo-upgrade-to-prepare-it-for-merging/17101 "2022-07-29T17:08:43Z")\
**Posts on this page:** 20\
**Page:** 2

<div class="post-metadata">

**Author:** ![epage](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/epage/32/3171_2.png) [@epage](https://internals.rust-lang.org/u/epage)\
**Post date:** [August 1, 2022, 7:07pm UTC](https://internals.rust-lang.org/t/feedback-on-cargo-upgrade-to-prepare-it-for-merging/17101/21 "2022-08-01T19:07:41Z")

</div>

> [@CAD97](#):
>
> `--resolver=minimal-direct` is useful and avoids the main issue with `--resolver=minimal` (relying on transitive deps to be minimal-versions-correct) by making it local.

To expand, there are two reasons for `minimal-direct`

- (original, unrelated reason) a practical way to move forward in testing minimum version requirements without being blocked on your transitive dependencies like with `minimal`
- So a library author can run `cargo upgrade --save` without upgrading compatible version requirements while still getting the benefits of all of their transitive dependencies being updated
  - Thinking more about this, they are unlikely to care about using minimal versions for `dev-dependencies` and would want the latest MSRV compatible version for those. Unsure how best to balance that

> Current temperature is that version resolution should stay unaware by default (but print a warning suggesting updating toolchains or downdating)

Maybe I missed a thread but I've seen one or two people say it should be unaware by default. I think its premature to say to convey that that is a consensus so far.

> Does `cargo update -p --precise` (already?) allow changing major versions? Downgrading?

Upgrading across major versions errors about being incompatible with the version req. Similarly downgrading must satisfy the existing version req.

> Can we reuse `--precise` such that `--save --precise` gets me full-precision dependencies?

That would be conflating two unrelated things with the flag.

I am still not in favor of editing precision. For others to catch up, see my [comment](https://github.com/killercup/cargo-edit/issues/750#issuecomment-1196853054)

> What is `--save --locked`? Is the manifest locked (causing an error; perhaps better spelled `--verify`), or is only the lockfile locked (giving `upgrade --to-lockfile`)?

This is the unfortunate part, `cargo update --locked` errors if a lockfile update would happen.

As mentioned earlier, I see a `minimal-direct` resolver replacing today's `cargo upgrade --to-lockfile`.

> How is a "pinned" dependency defined? ... Consider VersionReq which are not a single (implicit) caret operator to be pinned.

As of today, it is

- Renamed dependency (assuming the `tokio_01` case)
- An upper bound was placed on the dependency besides `^` (e.g. `=`)

For expanding the definition to all non `^` operators, how is `>` pinning?

> Does `cargo update` without any of the other new flags change behavior on `--pinned`?

`--pinned` opts you into modifying pinned dependencies. Since `cargo update` updates compatible pinned dependencies today, we can't change that. That means `--pinned` is restricted to only `--incompatible` upgrades.

> Does `--pinned --incompatible` opt into updating outside of the pinned region but within the same major version, or does it allow upgrading across different major versions?

We upgrade to latest, whatever that is, like all other `--incompatible` changes.

> When `--pinned`'s upper bound is changed, what form does it take?

I believe we keep the same upper bound operator

> Consider (actually[^1]) renamed dependencies as pinned.

Can you give a concrete example of how the "actually" case is different than the current behavior?

> With `--pinned` without `--incompatible`
> 
> - Update pinned dependencies as-if their top bound was a caret.

I worry about being able to clearly communicate the different versions of `--pinned` to the user and would prefer just one meaning.

---

<div class="post-metadata">

**Author:** ![Kixunil](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/kixunil/32/4110_2.png) [@Kixunil](https://internals.rust-lang.org/u/Kixunil)\
**Post date:** [August 4, 2022, 5:29pm UTC](https://internals.rust-lang.org/t/feedback-on-cargo-upgrade-to-prepare-it-for-merging/17101/22 "2022-08-04T17:29:54Z")

</div>

Can someone explain to me what is the point of bulk-upgrading non-breaking releases? Under normal circumstances you only upgrade when you require a new feature or simply because the dependency made a breaking change and you need to manually resolve it (and have desire to stay up-to-date).

Only two workflows make sense to me:

- `cargo upgrade some_dep $version` bumps minor version, equivalent to, but more convenient than manual edit
- `cargo upgrade --all-breaking` edits all deps that released breaking change and leaves it to you to fix possible errors afterwards

Note that upgrading dependencies in `Cargo.toml` "just because they were released" is bad. It makes the crate less flexible and would be problematic in various situations, e.g. if one wants to upgrade a crate that depends on other crate containing a regression that was discovered just recently.

I'd actually love some kind of lint to tell people not to update patch versions. Maybe if patch version is non-zero. `serde` would have to be excluded ofc (or convinced to use semver).

---

<div class="post-metadata">

**Author:** ![josh](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/josh/32/5934_2.png) [@josh](https://internals.rust-lang.org/u/josh)\
**Post date:** [August 4, 2022, 7:08pm UTC](https://internals.rust-lang.org/t/feedback-on-cargo-upgrade-to-prepare-it-for-merging/17101/23 "2022-08-04T19:08:35Z")

</div>

> [@Kixunil](#):
>
> Can someone explain to me what is the point of bulk-upgrading non-breaking releases?

Making `Cargo.toml` reflect what you're actually using and testing and putting through CI.

---

<div class="post-metadata">

**Author:** ![epage](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/epage/32/3171_2.png) [@epage](https://internals.rust-lang.org/u/epage)\
**Post date:** [August 4, 2022, 7:13pm UTC](https://internals.rust-lang.org/t/feedback-on-cargo-upgrade-to-prepare-it-for-merging/17101/24 "2022-08-04T19:13:04Z")

</div>

Bulk upgrading non-breaking is less common. This is why it is no longer the default in `cargo-upgrade`.

If you are already doing bulk lockfile upgrades, you probably should keep your version reqs in sync to ensure you don't use newer capabilities. This is especially important as long as `cargo install` does not use the lockfile by default (to ensure you get security updates)

This isn't always needed. This is why the proposal encourages investing more time in `-Zminimal-versions` so you can do `cargo update --minimal --incompatible --save`. That is a mouthful but we have to conscious of compatibility. I suspect it might be useful to have a manifest resolver field to enable that by default with a CLI flag to override it for `cargo update -p foo --save`.

---

<div class="post-metadata">

**Author:** ![kornel](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/kornel/32/2711_2.png) [@kornel](https://internals.rust-lang.org/u/kornel)\
**Post date:** [August 4, 2022, 8:59pm UTC](https://internals.rust-lang.org/t/feedback-on-cargo-upgrade-to-prepare-it-for-merging/17101/25 "2022-08-04T20:59:27Z")

</div>

Regarding terminology, would it be possible to avoid the word "pinned"? It clashes with `Pin`. Current Cargo docs don't use the term "pin", but refer to `=` as "exact" version.

---

<div class="post-metadata">

**Author:** ![kornel](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/kornel/32/2711_2.png) [@kornel](https://internals.rust-lang.org/u/kornel)\
**Post date:** [August 4, 2022, 9:04pm UTC](https://internals.rust-lang.org/t/feedback-on-cargo-upgrade-to-prepare-it-for-merging/17101/26 "2022-08-04T21:04:10Z")

</div>

Avoiding upgrading renamed dependencies is clever! But apart from that, I actually like current `cargo upgrade` behavior of just bumping everything to latest, and I think it's the most robust way when projects don't actually test with `-Z minimal-versions`:

> **[PSA: Please specify precise dependency versions in Cargo.toml](https://users.rust-lang.org/t/psa-please-specify-precise-dependency-versions-in-cargo-toml/71277)**
>
> When you specify dependency requirements, please include the patch version: serde = "1.0.130" # good! Cargo works well with versions specified this way. It is future-proof: the specified version is only the the minimum version, and still allows...

But some people are concerned with updating to very latest version, because it could be yanked. So upgrade to "latest - 1" maybe?

---

<div class="post-metadata">

**Author:** ![Nemo157](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/nemo157/32/11585_2.png) [@Nemo157](https://internals.rust-lang.org/u/Nemo157)\
**Post date:** [August 4, 2022, 9:28pm UTC](https://internals.rust-lang.org/t/feedback-on-cargo-upgrade-to-prepare-it-for-merging/17101/27 "2022-08-04T21:28:45Z")

</div>

For some crates latest - 1 could be years old. A more reliable indicator could be some sort of probation period, but I’d expect update and add to use the same behaviour for that; and again the appropriate period could vary wildly depending on the crate.

---

<div class="post-metadata">

**Author:** ![CAD97](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/cad97/32/3460_2.png) [@CAD97](https://internals.rust-lang.org/u/CAD97)\
**Post date:** [August 4, 2022, 10:41pm UTC](https://internals.rust-lang.org/t/feedback-on-cargo-upgrade-to-prepare-it-for-merging/17101/28 "2022-08-04T22:41:49Z")

</div>

> [@kornel](#):
>
> I actually like current `cargo upgrade` behavior of just bumping everything to latest

What version of cargo-upgrade are you using? Because it's not the default anymore; the default is currently to not upgrade within compatible versions.

Also @epage that PSA post is another argument for at least _allowing_ upgrade to change precision to patch. I doubt cargo wants to carry a list of ~~misbehaved~~ questionably semantically versioned crates to treat specially, and not specifying patch on such crates is a really bad idea.

I want some `cargo upgrade` command I can run such that both

- I don't downgrade from what's currently in my lockfile; and
- My manifest requires the direct dependency versions in my lockfile.

So far you're offering the second but not the first. This is sufficient if I'm already direct-minimal-versions correct, but if I'm not, now I've overwritten my lockfile witness of what version I _was_ working with and have to manually bisect to find it again, or more likely just give up and require the most recent of all my dependencies.

(As for yank avoidance: I absolutely think we should push to make it convention to publish a newer version if the most recent version has to be yanked. It can be a copy of the before version, but the goal is to always allow updating out of a yank unless the whole version has to be yanked for being unsalvageable.)

---

<div class="post-metadata">

**Author:** ![Kixunil](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/kixunil/32/4110_2.png) [@Kixunil](https://internals.rust-lang.org/u/Kixunil)\
**Post date:** [August 5, 2022, 8:52am UTC](https://internals.rust-lang.org/t/feedback-on-cargo-upgrade-to-prepare-it-for-merging/17101/29 "2022-08-05T08:52:15Z")

</div>

This makes me believe `Cargo.lock` should be committed even for libraries. (gotta run will reply to others when I'm back)

---

<div class="post-metadata">

**Author:** ![Kixunil](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/kixunil/32/4110_2.png) [@Kixunil](https://internals.rust-lang.org/u/Kixunil)\
**Post date:** [August 5, 2022, 11:01am UTC](https://internals.rust-lang.org/t/feedback-on-cargo-upgrade-to-prepare-it-for-merging/17101/30 "2022-08-05T11:01:45Z")

</div>

> [@epage](#):
>
> If you are already doing bulk lockfile upgrades, you probably should keep your version reqs in sync to ensure you don't use newer capabilities.

I don't understand this phrase. Nothing keeps you from using newer capabilities. Did you mean to say to ensure you do use new capabilities?

> [@epage](#):
>
> `cargo install` does not use the lockfile by default (to ensure you get security updates)

This is kinda ironic because if someone actually reviewed their deps and ensured the hashes in `Cargo.lock` match you trade supposed security fixes for supply chain attacks. The situation is not great and the solution isn't obvious.

> [@epage](#):
>
> investing more time in `-Zminimal-versions`

That sounds like a good thing, yes.

> [@kornel](#):
>
> some people are concerned with updating to very latest version, because it could be yanked. So upgrade to "latest - 1" maybe?

How about set patch to zero unless the dependency is known for not following semver (e.g. serde)? I myself tend to check when a feature I want to use was added, but I guess not everyone has the motivation to do that.

Anyway, reading these posts seems to indicate that [my idea of hiding new items](https://internals.rust-lang.org/t/version-based-visibility-to-make-the-language-ecosystem-more-stable/17124) is even more useful than I thought.

---

<div class="post-metadata">

**Author:** ![CAD97](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/cad97/32/3460_2.png) [@CAD97](https://internals.rust-lang.org/u/CAD97)\
**Post date:** [August 5, 2022, 12:36pm UTC](https://internals.rust-lang.org/t/feedback-on-cargo-upgrade-to-prepare-it-for-merging/17101/31 "2022-08-05T12:36:06Z")

</div>

> [@Kixunil](#):
>
> How about set patch to zero unless the dependency is known for not following semver (e.g. serde)? I myself tend to check when a feature I want to use was added, but I guess not everyone has the motivation to do that.

The problem is that cargo doesn't want to be carrying around a list of misbehaved crates. A third party crate could do this, but this is not something cargo should be in the business of doing.

> [@Kixunil](#):
>
> > [@epage](#):
> >
> > If you are already doing bulk lockfile upgrades, you probably should keep your version reqs in sync to ensure you don't use newer capabilities.
> 
> I don't understand this phrase. Nothing keeps you from using newer capabilities. Did you mean to say to ensure you do use new capabilities?

The purpose of upgrading the manifest is such that you don't use capabilities introduced in versions included in the lockfile but not guaranteed by the manifest, by making the manifest match the lockfile, ensuring that the new capabilities are actually available.

---

<div class="post-metadata">

**Author:** ![Kixunil](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/kixunil/32/4110_2.png) [@Kixunil](https://internals.rust-lang.org/u/Kixunil)\
**Post date:** [August 5, 2022, 1:12pm UTC](https://internals.rust-lang.org/t/feedback-on-cargo-upgrade-to-prepare-it-for-merging/17101/32 "2022-08-05T13:12:20Z")

</div>

Maybe complaints from users could make the crates behave? 🙂 I'd be perfectly OK with managing it manually for `serde`.

> [@CAD97](#):
>
> capabilities introduced in versions included in the lockfile but not guaranteed by the manifest

Not being in sync is a crate bug though. Checking with minimal versions should be the standard, maybe even the default `cargo publish` behavior.

---

<div class="post-metadata">

**Author:** ![Nemo157](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/nemo157/32/11585_2.png) [@Nemo157](https://internals.rust-lang.org/u/Nemo157)\
**Post date:** [August 5, 2022, 2:22pm UTC](https://internals.rust-lang.org/t/feedback-on-cargo-upgrade-to-prepare-it-for-merging/17101/33 "2022-08-05T14:22:03Z")

</div>

> [@Kixunil](#):
>
> How about set patch to zero

That assumes you’re not relying on bugs being fixed in a patch release.

---

<div class="post-metadata">

**Author:** ![RalfJung](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/ralfjung/32/2415_2.png) [@RalfJung](https://internals.rust-lang.org/u/RalfJung)\
**Post date:** [August 5, 2022, 2:47pm UTC](https://internals.rust-lang.org/t/feedback-on-cargo-upgrade-to-prepare-it-for-merging/17101/34 "2022-08-05T14:47:20Z")

</div>

> [@josh](#):
>
> Making `Cargo.toml` reflect what you're actually using and testing and putting through CI.

That's what we have lockfiles for, isn't it?

> [@Kixunil](#):
>
> This makes me believe `Cargo.lock` should be committed even for libraries.

Yes, definitely. I never understood why the usual recommendation is to not commit. I want the ability to go back to some old git commit and know which exact dependencies CI and maintainer used to test this code. That's literally what lockfiles are for. Cargo.toml cannot replace this, since dependencies could have released new patch releases since then.

---

<div class="post-metadata">

**Author:** ![epage](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/epage/32/3171_2.png) [@epage](https://internals.rust-lang.org/u/epage)\
**Post date:** [August 5, 2022, 4:39pm UTC](https://internals.rust-lang.org/t/feedback-on-cargo-upgrade-to-prepare-it-for-merging/17101/35 "2022-08-05T16:39:04Z")

</div>

> [@RalfJung](#):
>
> Yes, definitely. I never understood why the usual recommendation is to not commit. I want the ability to go back to some old git commit and know which exact dependencies CI and maintainer used to test this code. That's literally what lockfiles are for. Cargo.toml cannot replace this, since dependencies could have released new patch releases since then.

I've started to check in my Cargo.lock to help with MSRV testing. Unless/until we improve that, I wonder if we should change the recommendation.

---

<div class="post-metadata">

**Author:** ![epage](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/epage/32/3171_2.png) [@epage](https://internals.rust-lang.org/u/epage)\
**Post date:** [August 6, 2022, 3:35pm UTC](https://internals.rust-lang.org/t/feedback-on-cargo-upgrade-to-prepare-it-for-merging/17101/36 "2022-08-06T15:35:10Z")

</div>

> [@RalfJung](#):
>
> > [@josh](#):
> >
> > Making `Cargo.toml` reflect what you're actually using and testing and putting through CI.
> 
> That's what we have lockfiles for, isn't it?

If you are updating your lockfile, its likely to use new functionality and you should update your version requirements to match so that, for libs, your dependencies won't unintentionally use old versions. This direct people to avoid too-low of minimal versions while `-Zminimal-versions` testing in CI would be the enforcer

---

<div class="post-metadata">

**Author:** ![epage](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/epage/32/3171_2.png) [@epage](https://internals.rust-lang.org/u/epage)\
**Post date:** [August 6, 2022, 3:51pm UTC](https://internals.rust-lang.org/t/feedback-on-cargo-upgrade-to-prepare-it-for-merging/17101/37 "2022-08-06T15:51:40Z")

</div>

> [@CAD97](#):
>
> Also @epage that PSA post is another argument for at least _allowing_ upgrade to change precision to patch. I doubt cargo wants to carry a list of ~~misbehaved~~ questionably semantically versioned crates to treat specially, and not specifying patch on such crates is a really bad idea.

When the request came in for preserving precision, I had originally leaned against doing it for this reason. After mulling over it, I realized that this was too prescriptive. `cargo add` acts as the encouragement for fully specifying version requirements by unconditionally doing it. When `cargo upgrade` is run, I did not want to force things away from what the user might have done so explicitly, something they'd have to undo on every run as compared to someone who wanted fully explicit version reqs (and didn't use cargo-add) who'd just need to do it once.

A one time specifying of precision when dealing with a dependency not added by cargo-add does not seem to justify the cost to me in the UX. In part the cost is the hit to usability by overwhelming the user with options especially since this is meant to be a convenience especially for new users; users always have the option of doing things manually. The other cost is the supportability for the cargo team. Every new piece of functionality adds to the support burden of cargo and we need to be cognizant of that when adding commands, especially with the cargo team being under water at the moment. When merging cargo-add I kept the scope intentionally narrow to limit the support burden for the cargo team. One decision specifically was that these commands would not be for adjacent fixing up of styling or policy (e.g. cargo-add used to have a flag to force the sorting of dependencies). I feel editing of precision to be something different than what the user already specified in the manifest falls under that category,

---

<div class="post-metadata">

**Author:** ![epage](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/epage/32/3171_2.png) [@epage](https://internals.rust-lang.org/u/epage)\
**Post date:** [August 6, 2022, 3:56pm UTC](https://internals.rust-lang.org/t/feedback-on-cargo-upgrade-to-prepare-it-for-merging/17101/38 "2022-08-06T15:56:04Z")

</div>

> [@kornel](#):
>
> But some people are concerned with updating to very latest version, because it could be yanked. So upgrade to "latest - 1" maybe?

In terms of issue trackers or reddit discussions, I've not seen people complain about "update/upgrade to latest" before.

To not re-hash the whole "what is semver" discussion, we also have to keep in mind that dependencies following semver to the T can still not be safe to downgrade within patch releases because crates may be relying on bug fixes. There is not a safe heuristic for picking anything other than latest, independent of what crates like serde do.

---

<div class="post-metadata">

**Author:** ![josh](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/josh/32/5934_2.png) [@josh](https://internals.rust-lang.org/u/josh)\
**Post date:** [August 6, 2022, 8:34pm UTC](https://internals.rust-lang.org/t/feedback-on-cargo-upgrade-to-prepare-it-for-merging/17101/39 "2022-08-06T20:34:33Z")

</div>

I personally hope that `cargo update` will keep doing exactly what it does now (updating every version in `Cargo.toml` to the latest compatible version), and that `cargo update --incompatible` (or however we abbreviate that) will update everything to the latest available version even if it's a semver bump. `--skip-compatible` would be nice to have as well.

---

<div class="post-metadata">

**Author:** ![nicoburns](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/nicoburns/32/2313_2.png) [@nicoburns](https://internals.rust-lang.org/u/nicoburns)\
**Post date:** [August 8, 2022, 10:46pm UTC](https://internals.rust-lang.org/t/feedback-on-cargo-upgrade-to-prepare-it-for-merging/17101/40 "2022-08-08T22:46:16Z")

</div>

+1 for adding flags to `cargo update` rather than having `cargo update` and `cargo upgrade` doing subtly different things. This is pretty confusing. And also not at all consistent across ecosystems. I would suggest making a `cargo upgrade` an alias for `cargo update`.

Regarding flags, I think `--major`, `--minor`, `--patch` would be good, being both easy to remember and short to remember.

I would also suggest that the command should take any number of positional arguments where the value of the argument is either a crate name, or a crate name with a specified version (where that version can optionally be `latest`, or a prefix of a version (only specifying x.y rathe than x,y.z). So the following would all be valid invocations:

- `cargo update --minor`
- `cargo update --minor regex`
- `cargo update --patch serde serde_json`
- `cargo update csv@latest`
- `cargo update rand@latest time@0.3`

The above with `cargo upgrade` would also be valid. And it would be possible to specify a lower version to downgrade as well as upgrade with the same syntax.

I do think `--compatible` and `--incompatible` or incompatible could be nice, but I can't imagine myself wanting to type them interactively if I could avoid it

[Previous page](https://internals.rust-lang.org/t/feedback-on-cargo-upgrade-to-prepare-it-for-merging/17101.md?page=1)

[Next page](https://internals.rust-lang.org/t/feedback-on-cargo-upgrade-to-prepare-it-for-merging/17101.md?page=3)
