Cargo fails to select version for crate

Cargo can't resolve dependencies when you must have two different semver compatible version of a crate. Bug or feature?

Example - main Cargo.toml

[package]
name = "failing-example"
version = "0.1.0"

[dependencies]
a = { path = "a" }
b = { path = "b" }

a/Cargo.toml:

[package]
name = "a"
version = "0.1.0"

[dependencies]
libc = "= 0.2.43"

b/Cargo.toml:

[package]
name = "b"
version = "0.1.0"

[dependencies]
libc = "= 0.2.42"

Trying to compile:

    Updating registry `https://github.com/rust-lang/crates.io-index`
error: failed to select a version for `libc`.
    ... required by package `b v0.1.0 (file:///C:/Users/kuviman/failing-example/b)`
    ... which is depended on by `hello v0.1.0 (file:///C:/Users/kuviman/failing-example)`
versions that meet the requirements `= 0.2.42` are: 0.2.42

all possible versions conflict with previously selected packages.

previously selected package `libc v0.2.43`
    ... which is depended on by `a v0.1.0 (file:///C:/Users/kuviman/failing-example/a)`
    ... which is depended on by `hello v0.1.0 (file:///C:/Users/kuviman/failing-example)`

failed to select a version for `libc` which could resolve this conflict

If dependencies were semver-incompatible, this would compile.

In the actual project, do I have to fix my dependencies (this is deeply nested actually)? Maybe by duplicating the errored crate so there is no conflict. Or is there a better solution?

Why do you depend on exactly 0.2.42 and 0.2.43? The easiest way to fix this is to not do that.

Yup. Never use = requirements unless there's a known catastrophic bug in a later version that you must avoid, and then still use <=X, >=Y.

Well, I am not using them directly. They are in a dependency of my dependency (and there is tilde requirements, but problem is the same). Basically I can not use my dependencies as is, I guess the simplest fix is to patch them and remove tilde requrements.

But, why should I do that? Maybe there is a reason for such requirements, and I can break stuff while trying to make cargo happy.

Tilde range may be just a mistake. I suspect people may expect ranges to work the same as in Node.js which requires something like this.

If you don't publish your crate, then patch section is a good solution.

Otherwise file a bug with the problematic crate or fork it.