0

I thought I understaood dependency resolutions in rust, but clearly I dont.

I am working on a large project and it has this dep

 tempfile = "3.4"

cargo tree says

PS C:\play\gitui> cargo tree -i tempfile
tempfile v3.4.0
└── asyncgit v0.22.1 (C:\play\gitui\asyncgit)

(nothing special about this dependency, I was trying to resolve clippy complaints about multiple version of same crate and this was one of the crates pulling in a conflicting version)

When I run clippy I got

  error: multiple versions for dependency `windows-sys`: 0.42.0, 0.45.0

Some investigation shows that I probably should upgrade to 3.5

So i changed to

  tempfile = "3.5"

I now get a huge storm of multiple version conflicts. So I think OK I will go back to 3.4

   tempfile = "3.4"

but this is ignored, I am now stuck with 3.5. Cargo tree agrees

PS C:\play\gitui> cargo tree -i tempfile
tempfile v3.5.0
└── asyncgit v0.22.1 (C:\play\gitui\asyncgit)
    └── gitui v0.22.1 (C:\play\gitui)

OK so questions

  • given that 3.4 can be replaced by 3.5 anyway why didnt I get 3.5 in the first place
  • can I get back to using 3.4. So far I only found that deleting the directory and recloning works. Which seems a bit harsh

Further.

I have dependency on notify 5.1.0, that version depends on windows-sys 0.42.0 in its cargo.toml. This is one of the contributors to the version clash. But why doesnt it use 0.45.0 given that

  • its a more recent version that matches 0.42.0
  • I already have 0.45.0 in my tree for other dependeies
pm100
  • 48,078
  • 23
  • 82
  • 145
  • 0.42 and 0.45 are not compatible as far as cargo is concerned. See [semver compatibility](https://doc.rust-lang.org/cargo/reference/resolver.html#semver-compatibility) *"For example, 0.1.0 and 0.1.2 are compatible, but 0.1.0 and 0.2.0 are not."* – kmdreko Apr 16 '23 at 21:19
  • @kmdreko - well TIL. Its weird that 1.42.0 and 1.45.0 are compatible but 0.45.0 and 0.42.0 are not. I am sure people would think the first is 'version 1 point something' and the second 'version 0 point something'. In fact cargo treats 0.45.0 as 45.0. Odd, but it is what it is. – pm100 Apr 16 '23 at 22:05
  • @kmdreko - i also worked out my first question, cargo.lock is the repo so the version are locked. cargo update fixes that. Still not sure how to go back – pm100 Apr 16 '23 at 22:06
  • You can specify a specific version by using [`cargo update`](https://doc.rust-lang.org/cargo/commands/cargo-update.html#examples) with `--precise` (i.e. `cargo update -p tempfile --precise 3.4.0`) – kmdreko Apr 16 '23 at 22:31
  • @kmdreko put that last bit in an answer so you can get your tick – pm100 Apr 17 '23 at 14:24

0 Answers0