Cargo build not using versions mentioned in cargo.toml

Hello Guys, I am currently using rust 1.64. when i am running cargo build --release command, latest versions of crates are getting downloaded even though i specified exact version for each crate that i want to use in cargo.toml. some of them are not compatible with rust 1.64 because of which compilation is failing. for example i mentioned actix-web = "=4.0.1" in my cargo.toml but version 4.3.1 is present in cargo.lock that gets generated and some of the dependencies of actix-web 4.3.1 require atleast rust 1.65.
this is the first line of cargo build --release command's output -> Updating index.

package `time v0.3.21` cannot be built because it requires rustc 1.65.0 or newer, while the currently active rustc version is 1.64.0

Cargo will default to the latest semver compatible version and record this choice in Cargo.lock. After that it will only update it if you use cargo update or a change in Cargo.toml necessitates the update. You can use cargo update -p some_crate --precise 0.1.1 to force some_crate version 0.1.1 to be recorded in Cargo.lock.

In your case while you forced actix-web 4.0.1, this doesn't apply to any of the dependencies of actix-web. By the way if you publish a library please don't force a specific version. If one library forces one version and another library requires a newer but semver compatible version, it is not possible to use both libraries in the same workspace and cargo will fail with a confusing error message.


so, the most simple way to resolve this error is by updating rust version?


1 Like

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.