Looking for a deep understanding of how rustc handles multiple versions of the same crate

Hi all, I've been working on a dependency solver and I'm now writing the documentation for advanced usage such as allowing multiple versions of the same package. To ground the explanation on concrete usage, I'm looking for references of how multiple versions are handled by cargo/rustc.

I'm aware that cargo allows multiple versions of the same package, as long as they cross a major version frontier (like 0.7 and 0.8 or 2.0 and 3.0, but not 2.0 and 2.1). What I'd especially like to know more is what rustc thinks of multiple versions when compiling code. I can imagine two simple rules, and would love to know if there is some reference that can confirm or refute those.

(1) Either the compiler is very strict and interactions between different versions are strictly prohibited. So if function f takes a parameter of type X as defined in v2.0 and is passed a parameter of type X as defined in v3.0, it's a compilation error.

(2) Or the compiler is less strict, and as long as the data has a compatible shape, and its usage in function f is compatible then compilation succeeds.

Does someone know or can point me in the right direction?

I'm fairly certain it's your option A: types from different crates are considered different types. This is why things like the semver trick exist:

https://github.com/dtolnay/semver-trick

1 Like

It’s the first option :wink:

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.