Cargo.lock dependency versions do not update to match Cargo.toml dependency versions

I tried to contribute to this Rust Project repository that is attempting to develop a port of 'selecta' for Rust.

The code attempts to use the regex Crate. They imported the regex Crate by using extern crate regex; in their, and they used the regex Crate with use regex; in their file, and implemented regex Crate's methods with prefixes such as regex::quote and regex::Regex::new.

When I initially tried to run their codebase with cargo run or cargo test it gave me the following error:

src/ 4:20 error: can't find crate for `regex`
src/ extern crate regex;

I closed-out the above error by updating Cargo.toml with the following, and it now indicates that it is compiling with regex v0.1.20:

regex = "*"

However, now it gives me the following errors:

Compiling regex v0.1.20
/Users/lukeschoen/.cargo/registry/src/ 341:55 error: type `char` does not implement any method in scope named `next`
/Users/lukeschoen/.cargo/registry/src/                 let uregc = regc.to_uppercase().next().unwrap();
/Users/lukeschoen/.cargo/registry/src/ 342:57 error: type `char` does not implement any method in scope named `next`
/Users/lukeschoen/.cargo/registry/src/                 let utextc = textc.to_uppercase().next().unwrap();
/Users/lukeschoen/.cargo/registry/src/ 561:44 error: type `char` does not implement any method in scope named `next`
/Users/lukeschoen/.cargo/registry/src/         textc = textc.to_uppercase().next().unwrap();
/Users/lukeschoen/.cargo/registry/src/ 562:44 error: type `char` does not implement any method in scope named `next`
/Users/lukeschoen/.cargo/registry/src/         start = start.to_uppercase().next().unwrap();
/Users/lukeschoen/.cargo/registry/src/ 563:40 error: type `char` does not implement any method in scope named `next`
/Users/lukeschoen/.cargo/registry/src/         end = end.to_uppercase().next().unwrap();
error: aborting due to 5 previous errors
Could not compile `regex`.

I found the GitHub repo of the regex Crate Library, and it says to explicitly use version 0.1.8 instead, so I updated Cargo.toml to the following:

regex = "0.1.8"

But when I run cargo test or cargo run it still gives me the same error, and says it's still compiling to Compiling regex v0.1.20.

How do I go about making it compile using regex v0.1.8 instead WITHOUT resorting to modifying Cargo.lock manually?

Out of curiosity I decided to just modify Cargo.lock which still had 0.1.20 in it to instead have 0.1.8, and then ran cargo test, and it gave me the following error:

 Downloading regex v0.1.8
   Compiling regex v0.1.8
/Users/lukeschoen/.cargo/registry/src/ 777:52 error: obsolete syntax: `:`, `&mut:`, or `&:`
/Users/lukeschoen/.cargo/registry/src/         let text = re.replace_all(text, |&mut: refs: &Captures| -> String {
note: rely on inference instead

I was using the following version of Rust and Cargo, so my next step was to download the latest versions, by running the command curl -sS | sudo bash:
rustc 1.0.0-nightly (270a677d4 2015-03-07) (built 2015-03-07)
cargo 0.0.1-pre-nightly (dd7c7bd 2015-03-04) (built 2015-03-04)

After upgrading Rust and Cargo, I checked what versions were installed with rustc --version and cargo --version:
rustc 1.0.0-nightly (30e1f9a1c 2015-03-14) (built 2015-03-15)
cargo 0.0.1-pre-nightly (07cd618 2015-03-12) (built 2015-03-13)

I then ran cargo test and cargo run and it all compiled successfully, both when the Cargo.toml file has regex = "0.1.20" and also when it has an older version regex = "0.1.8", however the Cargo.lock file remains unchanged in all cases with regex 0.1.20, as shown below:

name = "selecta"
version = "0.0.1"
dependencies = [
 "regex 0.1.20 (registry+",

name = "regex"
version = "0.1.20"
source = "registry+"

Why doesn't the Cargo.lock file get updated so the versions contained within it match the latest versions defined in Cargo.toml?

UPDATE: Thanks to feedback from @BurntSushi and @steveklabnik.
cargo update by itself did not change the version in the Cargo.lock file. To change the version number in the Cargo.lock file from its existing value of "0.1.20" to "0.1.8", it was necessary to change the version in Cargo.toml to "**=**0.1.8" (with the equals sign) and then just run cargo test or cargo run, as both of these commands automatically perform the update from the index registry, compile the dependency version defined on Cargo.toml, and update the Cargo.lock file on this basis (which is what cargo update does), but they also run or test the code straight afterwards.

On this basis, I assume that in order for a Rust Project to automatically update the Cargo.lock file with the latest version of a dependency, it is necessary for the version number in the Cargo.toml to be "=*", rather than just "*" ??

Did you try running cargo update after you made changes to Cargo.toml?

Also worth noting, "0.1.0" does not mean exactly 0.1.0, it's a synonym for "^0.1.0". You want "=0.1.0" to get exact.


yea, that has bitten me a few times. It took me a while to find that in the docs.