5
lorentz
319d

Rust should support explicit variance declarations. Explicit declarations are like the main feature of the language, variance is a critically important part of a type's public interface, and &mut-s that are never reassigned and should thus inherit the referee's variance are extremely common. If the language can't recognize this, I should be able to declare it with a single unsafe rather than constantly casting to and from 'static.

Comments
  • 3
    I didn't understand the words but it sounded sensible so I upvoted
  • 0
    @jestdotty I can't create a safe wrapper because in Rust if you have a &mut you can always call nem::swap to replace it with another &mut with the same lifetime. That's why &mut is invariant. What I might just be able to do is make the unsafe behaviour more explicit and easier to manually verify..
  • 0
    @jestdotty Actually, I managed to make the datastructure covariant by just changing a couple internal &mut-s into &-s and sticking things in RefCells. I don't see how this ensures the preconditions of covariance, but for the time being I've had my fill of deducing inferred relations via compilation failure probes and this is a massive tangent anyway so I might investigate later.
Add Comment