-
Notifications
You must be signed in to change notification settings - Fork 13k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The new coherence rules disable very useful patterns #20974
Comments
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 |
@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. |
cc me |
@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 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);
}
} |
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/ |
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? |
The above case will fail with a conflicting implementation (different than
|
OK, got it. Thanks. |
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)
The text was updated successfully, but these errors were encountered: