Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upMore flexible coherence rules that permit overlap #1053
Comments
This was referenced Apr 10, 2015
This comment has been minimized.
This comment has been minimized.
|
A discussion with niko today revealed that a naive specialization feature could cause the drop check rule (RFC 769) to break. In particular, if we allow one to:
Then one could end up in a situation where the |
This comment has been minimized.
This comment has been minimized.
|
Hi. I think negative bounds as discussed in RFC #586 would be very valuable, with the following modification to avoid the problem of backwards incompatibility: Doing this would limit the usefulness of negative bounds somewhat (because It might be worth doing, also, that if there exists a Types defined in std should negatively implement various traits where a backwards compatible commitment to not implementing that trait exists. This is a backwards compatible change. Adding negative bounds to traits which should not logically cohere (e.g. Some sort of specification system would be useful in addition to this for a lot of the use cases you've highlighted, but this alone would open up a lot of more straightforward cases, such as enabling new traits to 'piggyback' on standardized or otherwise commonly imported traits without violating coherence rules (e.g. the trait |
This comment has been minimized.
This comment has been minimized.
|
Here's an interesting case: trait Foo { }
trait Bar {
type Baz;
}
impl<T> Foo for T where T: Bar<Baz=u32> { }
impl<T> Foo for T where T: Bar<Baz=i32> { }This is currently incoherent, because the coherence rules do not allow us to infer that the intersection between
In my own use case for this, I want to provide blanket impls for functions that return one of two different types. |
Centril
added
the
T-lang
label
Feb 23, 2018
This comment has been minimized.
This comment has been minimized.
|
cc #2451. |
nikomatsakis commentedApr 10, 2015
There is a need for more flexible coherence rules, and in particular a way to permit overlap in some cases. There are numerous proposals for how to go about achieving that. Here is a summary:
Note that a prime concern here is forwards compatibility. See RFC #1023 (and this internals thread) for details.
RFCs and other links: