-
-
Notifications
You must be signed in to change notification settings - Fork 14.8k
Coherence violation when inherent method is added to type #62320
Copy link
Copy link
Open
Labels
A-trait-systemArea: Trait systemArea: Trait systemT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-typesRelevant to the types team, which will review and decide on the PR/issue.Relevant to the types team, which will review and decide on the PR/issue.
Metadata
Metadata
Assignees
Labels
A-trait-systemArea: Trait systemArea: Trait systemT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-typesRelevant to the types team, which will review and decide on the PR/issue.Relevant to the types team, which will review and decide on the PR/issue.
Type
Fields
Give feedbackNo fields configured for issues without a type.
It seems that because inherent methods are always called before trait methods, when a dependency adds an inherent method to a struct (which should be a backwards-compatible change to its API requiring no major semver bump) your code that was previously calling a trait method on that struct will (silently) switch to calling the inherent method.
As an example, I could make an extension trait for
Optiondefining a method namedfoo, publishmy_cool_crate, and then if an inherent method namedfoois added toOptionin a new version ofcorethen my crate can suddenly behave differently despite merely upgrading my Rust compiler. Perhaps it could also fail to compile (like if the signature is "compatible" at the callsite but then a typechecking error happens elsewhere).I'm not sure if this is a coherence violation or not, or whether this has already been observed/discussed elsewhere. (Had no luck when I searched for github issues about it.)