3 ms·
To be clear, even without `--locked`, cargo will use the dependencies from the lockfile, as long as the lockfile is not out of date compared to Cargo.toml. How
by Diggsey 5y ago
To be clear, even without `--locked`, cargo will use the dependencies from the lockfile, as long as the lockfile is not out of date compared to Cargo.toml.
However, for development, you normally want cargo to update the lockfile after you change something in `Cargo.toml` (like adding a new dependency).
The `--locked` option is particularly useful in CI though, where you want it to fail if the lockfile is out of date, rather than update the lockfile and continue.
- steveklabnik 5y agoTo spell it out in even more detail: I add foo = "1.0.0" to my Cargo.toml. The latest release of foo is 1.0.1. I invoke "cargo build." Cargo builds my project, using 1.0.1 (since "1.0.0" is short for "^1.0.0"), and records that in the lockfile. Now foo releases 1.1.0. I invoke "cargo build". Cargo uses the lockfile, and nothing changes. I still build with 1.0.1, because that's what's in the lockfile. Now, let's say I go in and change my Cargo.toml to use 1.1.0. This is where the behavior differs: 'cargo build' will say "oh, you've changed your Cargo.toml, let's perform resolution again" and will update your Cargo.lock to have 1.1.0. 'cargo build --locked' will say "error, you have changed your Cargo.toml but the lockfile was not updated." That's why --locked is useful in CI; it will make sure that the lock you've committed is up to date. It doesn't imply that Cargo ignores the lockfile by default, only that it will update your Cargo.lock when you change your Cargo.toml, because that implies you're asking for a change in your dependencies.
- dathinab 5y ago> will update your Cargo.lock to have 1.1.0. 1.1.0 or later, as it's `^1.1.0`.
- steveklabnik 5y agoSure, though in this example, with the versions I listed as released, there is nothing later, so it's the same in this case.