The problem with a write-only slice is that overwriting an existing value forces one of these three things to happen, even if the feature is built-in to the language:
- disallow write-only slices of Drop-implementing data (this cannot be done directly in Rust’s type system, but only allowing Copy data is probably close enough).
- leak whatever resource the destructor is supposed to free (this is what I did).
- violate the write-only contract (this is what @llogiq wom does, and I should probably tell him that his lint will have to implement 1 or 2 to be sound).
This problem does not exist if no overwriting happens (namely, the write-only reference is to uninitialized data, and must be written exactly once), but that would have to be a true linear type.
Edit: Added support for iteration to that demo. Maybe I should put this on GitHub…