logoalt Hacker News

FuzzywarmWalnut • today at 11:06 AM • 2 replies • view on HN

Worked on a variance-related lint once and the scary part is how rarely anyone writes down variance by hand, so bugs there just sit untested for a decade.


Replies

afdbcreid • today at 1:34 PM

Nobody writes variance at hand in Rust because it's impossible (since before 1.0). You sometimes need to enforce stricter variance than the default (can cause unsoundness and is very subtle but actual unsoundness here is rare) or give more permissive variance (harder and also cannot cause unsoundness, just annoyance).

When implementing the type system, however, variance does have to be treated with care. Historically it wasn't much, now it is.