Skip to content

Forward compatibility hazard from coherence rules #23086

Closed
@nikomatsakis

Description

The current coherence rules are too smart. I think we should consider adding some limits to rein it in. In particular, imagine that crate A defines:

pub struct Foo { .. }

And crate B then defines:

extern crate A;
trait MyTrait { }
impl<T:Clone> MyTrait for T { }
impl MyTrait for A::Foo { }

This is currently accepted today, I believe. However, I think it should not be, because it means that now crate A cannot add an impl of Clone for Foo for fear of breaking crate B.

My proposed fix is to modify the coherence check so that you can't assume that a type from another crate won't implement a trait from another crate.

cc @aturon

Metadata

Assignees

Labels

B-RFC-approvedBlocker: Approved by a merged RFC but not yet implemented.

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions