Stable type identifiers: a missing piece for crABI and export
Rustc does not know about crate versions. The unique identity of a crate (internally called StableCrateId) is crate name + all -Cmetadata arguments + crate_type==bin + rustc version. Cargo hashes a whole bunch of things into -Cmetadata to ensure crates that cargo believes to be unique don't overlap in ABI. This includes not just the crate version, but also all dependencies as well as the origin of the crate (you can have two crates with the same version from different locations. eg one from crates.io and one from a local path). And the rustc version has to be hashed in to ensure you can link two cdylibs or two staticlibs containing the same dependency, yet compiled with different rustc versions together without causing symbol conflicts.
And then the path from crate root to type is not unique within a crate. The DefPath also contains disambiguators for each path component. This is necessary to handle things like anonymous types or
fn foo() {
{
struct Bar;
}
{
struct Bar;
}
}
where you did have my_crate[1234]::foo[0]::Bar[0] and my_crate[1234]::foo[0]::Bar[1] as different types.
Discussion in the ATmosphere