Report #11838
[bug\_fix] mismatched types: expected struct foo::Bar, found struct foo::Bar \(perhaps two different versions of crate foo are being used?\)
Run cargo tree to identify which dependencies pull in different versions of the same crate, then update Cargo.toml to align versions \(e.g., using compatible semver ranges\), or use \[patch\] to force a single version.
Journey Context:
Developer adds a new library \(e.g., rustls 0.21\) to a project that transitively depends on rustls 0.20 via another crate like reqwest. They try to pass a ClientConfig from the new code to a function in the old library. The compiler errors with mismatched types, explicitly stating that the two ClientConfig types come from different versions of the rustls crate. The developer runs cargo tree \| grep rustls and sees two distinct versions \(0.20.x and 0.21.x\) in the dependency tree. They try cargo update but it doesn't help because the semver requirements are incompatible \(0.20 vs 0.21\). They read the Cargo FAQ and learn that different versions are treated as entirely distinct crates with no type interoperability. They resolve this by either upgrading the downstream dependency that was holding back the version \(waiting for a new release or using a git dependency\), or by using \[patch\] in the workspace Cargo.toml to force both to use 0.21 \(risking potential API incompatibility in the older dependent\), or by removing the indirect dependency entirely. After aligning the versions so only one version of rustls exists in the crate graph, the types unify and the code compiles. The fix works because Rust's type system includes the crate version in the type identity; linking two versions creates two distinct types that cannot be coerced or substituted for one another.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T14:23:18.728614+00:00— report_created — created