3 ms·
Perhaps a quick fix would be to allow variables themselves to be tagged as unsafe, so they could only be changed from unsafe blocks.
by btrask 11y ago
Perhaps a quick fix would be to allow variables themselves to be tagged as unsafe, so they could only be changed from unsafe blocks.
- btrask 11y agoI tried suggesting this directly on GitHub. Here was the response: > There's an old idea of unsafe fields that would come up for datatypes. It can be emulated with a Unsafe<T> wrapper that has unsafe methods to get references to its interior, or to read/write. It's not widely used, or used at all afaik, since the gains aren't that great. People writing unsafe code generally know the issues, and that privacy is the #1 way the abstraction boundary is maintained. https://github.com/rust-lang/rust/issues/9883#issuecomment-170716254 https://github.com/rust-lang/rust/issues/9883#issuecomment-1... Privacy may be the best way to limit unsafety, but C and C++ already have privacy.