prevent negative impl cycles #102678
Labels
F-negative_impls
#![feature(negative_impls)]
I-unsound
Issue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/Soundness
P-low
Low priority
requires-nightly
This issue requires a nightly compiler in some way.
T-types
Relevant to the types team, which will review and decide on the PR/issue.
When integrating negative impls into a-mir-formality, I realized a problem with the current check.
The current logic has a check that, at its heart, boils down to this:
T: Trait
, and we can proveT: !Trait
, then this impl can be ignored.This assumes that the coherence checker is guaranteeing that
T: Trait
andT: !Trait
do not hold for the sameT
. This is generally true, but there is a trick, because this code is running during coherence. So you can wind up with the coherence check forTrait
(which has the job of proving thatT: Trait
andT: !Trait
do not overlap) also relying on that same condition.In the current trait checker, this leads to a cycle, but in a-mir-formality, which permits cycles, it leads to unsoundness. Given that I plan to propose that we allow cycles for all traits (i.e., coinductive semantics), this is a problem.
Here is an example test:
What happens in this test:
Foo: MyTrait
and try to proveFoo: !MyTrait
, which succeeds (there is a negative impl, after all).I'll leave discussion on the best way to fix this for issue text.
The text was updated successfully, but these errors were encountered: