Refactor: Fix: impl XX for associated type conflict in another crate #1331
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Changelog
Refactor: Fix: impl XX for associated type conflict in another crate
This commit addressed an issue of implementing trait for associated
types, by replacing implementation for associated type with concrete
type
pb::Vote
.Related issues: Implementations conflict when using associated type across crates rust-lang/rust#51445
The minimized reproduce repo is:
https://github.com/drmingdrmer/conflict-trait-in-main
Explanation:
If one crate
lib.rs
implements a trait(Default
) for an associatedtype(
<() as Container>::Item
, which isFoo
), in another cratemain.rs
, it seems the compiler treats the associated type(<() as Container>::Item
) as a generic typeT
and assumesT
wouldbe any type and results in the conflict with a local type that tries to
implement
Default
, while actuallyFoo
andWow
are actuallydifferent types.
lib.rs
:main.rs
:cargo build
yield this error:This change is