Skip to content
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

Explicit OIBIT impls hide the default impls #27554

Closed
wthrowe opened this Issue Aug 6, 2015 · 7 comments

Comments

Projects
None yet
7 participants
@wthrowe
Copy link
Contributor

wthrowe commented Aug 6, 2015

#![allow(dead_code)]

trait Foo {}
struct A<T>(T);
unsafe impl<T: Foo> Sync for A<T> {} // Comment this line and the code compiles

trait IsSync: Sync {}
struct X;
impl IsSync for A<X> {} // error: the trait `Foo` is not implemented for the type `X` [E0277]

fn main() {}

Nothing in this example opts out of Sync or contains a type that opts out, so everything should be Sync.

I suspect this is the same underlying issue as #23072, but unlike in that case this seems like something that should be allowed.

@Aatch Aatch added the A-traits label Aug 6, 2015

@wthrowe

This comment has been minimized.

Copy link
Contributor Author

wthrowe commented Aug 10, 2015

I've been experimenting with ways to fix this, and, oddly, there's a unit test checking that this doesn't work: https://github.com/rust-lang/rust/blob/master/src/test/compile-fail/typeck-default-trait-impl-precedence.rs

The OIBIT RFC seems pretty clear that this is supposed to be accepted, but I know that the rules specified there for negative impls are thought to be too lenient, so maybe this part is also frowned upon?

@nikomatsakis

This comment has been minimized.

Copy link
Contributor

nikomatsakis commented Oct 8, 2015

As explained in #23072, this was the semantics we implemented, which diverged somewhat from the RFC. It's interesting that this can come about without feature gates (though obvious in retrospect).

@nikomatsakis

This comment has been minimized.

Copy link
Contributor

nikomatsakis commented Oct 14, 2015

triage: P-medium

We discussed this last week in the language subteam meeting. Our conclusion was that there is (potentially) an issue here where the desired semantics are not entirely clear. It is backwards incompatible to fix it but deemed low risk, because the bad scenario is when one is trying to "add to" the default set that obey a particular trait (or remove further from the negative set, I suppose).

Some notes from our discussion:

The intent of an impl like this is somewhat unclear. Why did one write the impl in the first place? Was the goal to cover a case that the default rules would have excluded? Or was it perhaps to narrow down the default rules to a smaller set of acceptable cases (which kind of "opts out" by "opting in")? The latter is the current semantics; it does seem plausible that a naive read of the code might think that the impl was listing out the cases that are Sync, versus adding to an implicit set. A short-term fix we might use is to try and report errors if the impl is "unnecessary". Overall though our conclusion was the current semantics ought to be revisited with specialization in mind, since there is a lot of overlap (no pun intended!) between the situation here and that of specialization.

@brson

This comment has been minimized.

Copy link
Contributor

brson commented Jul 14, 2016

Nominating for retriage and updates. Old type system issue.

@arielb1 arielb1 removed the I-wrong label Jul 17, 2016

@arielb1

This comment has been minimized.

Copy link
Contributor

arielb1 commented Jul 17, 2016

Not I-wrong.

@nikomatsakis

This comment has been minimized.

Copy link
Contributor

nikomatsakis commented Jul 18, 2016

I believe that there is no bug here: the compiler is doing the right thing, essentially. I've been meaning for some time to write-up an amendment to the OIBIT (now: auto trait) RFC to talk about it for some time. My current thoughts (more-or-less) are embedded in this gist, which also covers the connection to negative reasoning.

@nikomatsakis

This comment has been minimized.

Copy link
Contributor

nikomatsakis commented Aug 4, 2016

Going to close this issue -- this is the desired semantics -- but we do need to write an amendment to the RFC, I think.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.