That was really a bit surprising for me, but I think you are right. For cargo build
Cargo.lock is used automatically. But for cargo install
we have to pass the --locked
flag, otherwise the Cargo.lock is ignored. At least that is how I understand the comments in "cargo install" apparently ignores "Cargo.lock" as opposed to "cargo build" · Issue #7169 · rust-lang/cargo · GitHub. And the Cargo book seems to mention the --locked
flag only for cargo install
, see cargo install - The Cargo Book
1 Like
It's indeed a surprise, and I wasn't 100% sure about my interpretation of the code, but the issue you found confirms it.
It's a little confusing that the Cargo help gives the --locked
option separately, as if it should be used with build
, test
, and run
to use the cargo.lock
file.
2 Likes