r/ProgrammerHumor • • 18d ago

Meme modernCppVsOldCpp

Post image
2.0k Upvotes

323 comments sorted by

View all comments

Show parent comment

1

u/redlaWw 16d ago edited 16d ago

The problems with write only references are that you can't call drop through them if you overwrite data already there, and you can't fail to use the reference, otherwise you end up with still-uninitialised data (i.e. write only references must be linear, and Rust doesn't currently have truly linear types). They are working on language support for in-place initialisation, but it's hard because it conflicts with how the language was originally designed.

The reason you can't use a mutable reference that you've created unsafely is that Rust's optimiser assumes that mutable references can always be meaningfully dereferenced, which allows them to optimise them more effectively but imposes additional restrictions on how you use them.