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 upThe new coherence rules disable very useful patterns #20974
Comments
This comment has been minimized.
This comment has been minimized.
|
One possible transformation of this would be to instead change the trait However, this just moves the problem elsewhere, as it becomes impossible to define modifiers for |
This comment has been minimized.
This comment has been minimized.
Aatch
added
the
A-traits
label
Jan 12, 2015
This comment has been minimized.
This comment has been minimized.
|
@darinmorrison Ugh, I guess that works but it is certainly not pretty and not something I could really readily adopt for a framework like Iron where implementing modifiers is going to be an extremely common task. FWIW this blocks building Iron on nightly/1.0-alpha. |
This comment has been minimized.
This comment has been minimized.
|
cc me |
This comment has been minimized.
This comment has been minimized.
|
@reem and I had a discussion about this on IRC today that covered much of the justification for the current rules (in brief, anyway) as well as some ideas for how to resolve it.. I'll try to write up my current thinking into a blog post or something, since reading IRC logs is a pain. |
This comment has been minimized.
This comment has been minimized.
Ogeon
commented
Jan 13, 2015
|
This is a different situation, but still... I noticed that it's not possible to implement a local trait for something implementing Fn with a generic type, like the handlers in rustful: impl<C: Cache, F: Fn(Context<C>, Response)> Handler for F {
type Cache = C;
fn handle_request(&self, context: Context<C>, response: Response) {
(*self)(context, response);
}
}
impl<C: Cache> Handler for fn(Context<C>, Response) {
type Cache = C;
fn handle_request(&self, context: Context<C>, response: Response) {
(*self)(context, response);
}
} |
This comment has been minimized.
This comment has been minimized.
|
See discuss thread http://discuss.rust-lang.org/t/orphan-rules/1322 and blog post http://smallcultfollowing.com/babysteps/blog/2015/01/14/little-orphan-impls/ |
This comment has been minimized.
This comment has been minimized.
|
If I understand the issue, I'm not sure the Iron code can work with the coherence model rust seems to want? Consider this (which is not what Iron does, I know, but for the sake of argument): // crate 1
pub enum Status { .. };
// crate 2
trait Modifier<M>;
impl<T> Modifier<T> for Status { .. } // ***
// crate 3
struct Response { };
impl Modifier<Response> for Status { .. }It seems like, under any proposed coherence scheme, crate 2 would always have the option of adding the marked implementation (if the library author decides to do so at some point in the future), which would then become incoherent with crate 3. Is that right? Is that something the coherence rules are intended to prevent? |
This comment has been minimized.
This comment has been minimized.
|
The above case will fail with a conflicting implementation (different than
|
This comment has been minimized.
This comment has been minimized.
|
OK, got it. Thanks. |
reem commentedJan 12, 2015
Specifically that input parameters cannot be used as proof of coherence, i.e.
impl ExternTrait<LocalType> for ExternType, is no longer allowed.I've hit this in Iron pretty hard, with this simplified example:
Crate 1: (rust-modifier)
Crate 2: (hyper)
Crate 3: (iron)