Post #4333762
2026-07-11 04:11 UTC
Replies (1)
-
@Gankra@toot.cat 2026-07-11 05:04
@chandlerc@hachyderm.io the api correctness issues i’m thinking of were never an optimization thing, and were always just “the compiler let code compile that was a blatant use-after-free” (on my phone and going off memory, can elaborate more on any of these if you want more details) * pre-1.0 the rust compiler did not require you to specify the (co/in)variance of a type parameter, and if you declared a type parameter but failed to use it in the definition it actually defaulted to *bivariance* which is literally always incorrect. This resulted in some type like Iter(*const T) basically functioning as if it had no lifetime, oops! This class of bug was eliminated with the introduction of PhantomData (the RFC discusses it). * Rust has obscure support for letting pointers temporary dangle during destructors. You can make a (Box, Vec>) and make one point at the other, and rust won’t complain about the fact that the Vec definitely contains a dangling pointer when its destructor runs. The argument for this being ok is based on Vec’s Drop being parametric (it cannot observe that T is a reference), and this feature is used by rustc devs to do stuff with Arena allocators. “parametric drop” used to be safely inferred by the compiler but it was so buggy and complicated that it was eventually turned into an unsafe opt-in (see the “dropcheck eyepatch” RFC(s)). * The typechecker people have like 1000 war stories around the compiler failing to correctly handle corner cases of the type-erasure stuff you briefly discuss, especially around what lifetimes associated-types should be required to satisfy (not my area of expertese) * The compiler safely infers Send and Sync for ~every type, and the fact that this actually works great in practice is actually shocking to me whenever I think about it, but the secret sauce is that if your type contains *const T, *mut T, or UnsafeCell your type is opted out of this and you must manually unsafe-impl Send and Sync to opt back in (also *mut T makes you invariant in T as a secret bonus controversial safety guard). The fact that we have different types for “normal pointers” and “pointers unsafe code uses” is actually a really important sentinel for forcing the compiler to apply more conservative ~inference. “here there be dragons”. (probably the OIBIT RFC is the source on this)