
[[package]] entry records one exact name, version, and checksum.Understand it
Cargo.toml describes allowed versions while Cargo.lock records the exact chosen graph. Applications normally commit the lockfile so a later build does not silently select newer compatible releases.
Cargo.toml says which versions are acceptable; Cargo.lock records which exact package versions the resolver selected. If a manifest permits several compatible releases, the lockfile keeps subsequent ordinary builds on the same chosen graph until an update changes it. This helps a team reproduce a bug and compare results without silently pulling a newer dependency on every checkout.
An application normally commits its lockfile. A library crate may also commit one for its own development and tests, but downstream consumers resolve dependencies using their own lockfiles. The lockfile is therefore not a universal promise that every consumer uses the library author's exact dependency graph. If you are publishing a binary or deploying a service, review lockfile changes along with source changes, because a dependency update can alter behavior even when your own code is unchanged.
Try cargo update -p package_name in a disposable branch and inspect the lockfile diff. Run tests and, where relevant, a release build. To check whether a clean machine can reproduce the selected graph without modifying the lockfile, use cargo build --locked. Be aware that a lockfile pins versions, not the entire operating environment or external native libraries. Reproducibility improves when toolchain, build flags, and platform assumptions are recorded too.
Read the code
[[package]]
name = "smallvec"
version = "1.13.2"
checksum = "..."Each registry [[package]] entry records one exact name, version, and checksum.
Practice starter
# Cargo.toml
[dependencies]
smallvec = "=1.13.1"
# Cargo.lock, from an earlier build
[[package]]
name = "smallvec"
version = "1.13.2"Try it
The requirement was just changed to =1.13.1, and Cargo.lock still says 1.13.2. Predict what cargo build --locked does, then what plain cargo build does to the lockfile.
What success looks like: You can say why --locked refused to change the lockfile and which line a plain build rewrites.
Check your understanding
What does Cargo.lock pin?
Reveal the answer
- The exact resolved graph
- Only the root package name
- The Rust edition
Cargo.lock records the exact version of every package the resolver selected, not just the root.
Go deeper
Common misconception: “Cargo.lock pins only the dependencies named in Cargo.toml.”
Cargo.lock records the exact chosen graph, including transitive packages, while Cargo.toml only describes allowed versions.
- Find the package:
nameandversionrecord one resolved package:smallvecat exactly 1.13.2. - Find the checksum:
checksumholds the hash Cargo verifies against the downloaded package. It is shortened to...here. - Compare the manifest:
Cargo.tomlmight only ask for"1", yet ordinary builds keep using 1.13.2 until an update changes this entry.
Transfer challenge: Run cargo update -p smallvec in a disposable copy and read the lockfile diff. State what changed and what did not, then say why consumers of a library would not see this entry.
Connections
- Feature Design: Make optional capability additive and explicit
- Integration Tests: Test the public API as an outside user
Learn this lesson with AI
Paste this into Claude, Codex, Cursor or another agent connected to Crabrix Academy. It contains only this lesson’s public details.
I'm learning Rust with Crabrix Academy. Teach me this lesson with the Crabrix Academy tools. Lesson: Lockfile Reproducibility (courseId "projects", lessonId "lockfile-reproducibility") Link: https://crabrix.com/learn/projects/lockfile-reproducibility/ Goal: Cargo.toml describes allowed versions while Cargo.lock records the exact chosen graph. Practice: give me the lesson's exercise (crabrix_academy_get_exercise); I will write and run the code in Crabrix. Explain it step by step for my level, let me write the code myself, give hints before any solution, and do not mark anything as passed: only Crabrix checks do that.