Sync Cargo.toml and Cargo.lock

I ran the cargo update command to update my dependencies.

Unfortunately, an upgrade of a particular crate broke, and my program doesn't compile anymore.

How do I force the Cargo.lock file to reflect Cargo.toml.

I looked at doing:

cargo update --manifest-path Cargo.toml

But that still reflects the broken, updated crate instead of the one in Cargo.toml.

Thanks for any advice!

I backed it out using git, but I'm wondering if there is a way to do this with cargo.

Note that version = "1.2.3" is the same as version = "^1.2.3" (versus specifying an exact version) and thus I suspect the contents of your Cargo.lock don't contradict what's in your Cargo.toml.

If you want Cargo to choose the minimal versions for your dependencies, I believe that is this unstable feature. Or the non-direct version immediately above.

Ah, I looked in the Cargo book and see I can do this by using rev plus the hash of the commit in the repo. I’ll try that out when I’m next to my computer.

Instead of editing Cargo.lock by hand, use the -p and --precise arguments to cargo update.

For example, if you want to lock your project to an exact version of the smallvec crate, run:

cargo update -p smallvec --precise 1.11.2
5 Likes

Great, thanks, that did it.

I ran cargo update which upgraded the crate to the broken one, and cargo update -p <CRATE> --precise <VERSION> downgraded Cargo.lock back to the working version.

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.