Description
We currently permit negative impls (feature-gated, #68318) for both auto- and regular traits. However, the semantics of negative impls are somewhat unresolved. The current trait checker's implementation in particular does not work well with "conditional" negative impls -- in other words, negative impls that do not apply to all instances of a type. Further, the semantics of such impls when combined with auto traits are not fully agreed upon.
Consider:
auto trait Foo { }
struct Bar<T> { }
impl<T: Copy> !Foo for Bar<T> { }
The question is, does Bar<Box<T>>
implement Foo
? There is some disagreement about what would be expected here.
As a temporary step, the plan is to forbid impls of this kind using similar logic to what we use for Drop
impls. There was a PR in this direction #74648.
Another similar step would be to forbid negative impls for traits that have multiple generic parameters:
trait Foo<A> { }
impl<A, B> !Foo<A> for B { } // error
There is no particular reason that we can't support multiple parameters, but I suspect that the drop logic is not designed to handle cases like this.
Related issues: