r/cpp
•
u/steveklabnik1
•
Oct 24 '24
•
1
Why Safety Profiles Failed
https://www.circle-lang.org/draft-profiles.html
180
Upvotes
View all comments
Show parent comment
2
u/duneroadrunner Oct 28 '24
Perfect. Ship it! :)
But you can see it being useful, no? I mean, you could imagine a case where you're holding on to a mutable reference to one element while cycling through references to other elements in the map. (Particularly if you add support for obtaining
HMSlicesfrom otherHMSlices. Hang on...)Ok here's my Rust-illiterate version that supports it. And for some reason the miri interpreter isn't complaining about it this time. :)
I'm not sure if this investigation is turning out to be an argument in favor of or against the "universal prohibition of mutable" aliasing policy. On one hand it sort of convinces me that you can probably enhance the Rust standard containers such that you can probably always avoid the worse case (of having to make (arbitrarily) expensive copies). On the other hand, for your own custom data structures, you might have to resort to unsafe code to do it. But even though they're not enforced in unsafe code, the aliasing restrictions remain. Arguably making unsafe Rust even more treacherous than unsafe C++. But then there are helpful bug catching tools for unsafe code like the miri interpreter apparently. I'm assuming the theoretical consequences of violating the alias restrictions are in the same category as UB in C++?