2 ms·
Is there a way to make it safe-by-default, such that I can't accidentally stray beyond what the compiler can prove safe?
by nicoburns 6y ago
Is there a way to make it safe-by-default, such that I can't accidentally stray beyond what the compiler can prove safe?
- cle 6y agoTry accessing a struct property that isn't in the declaration, or accessing a value after it has been freed (out of scope). You'll get a compile error. D has lots of memory safety features. It is not the same set of features as Rust. It's wildly incorrect to suggest that Rust has a monopoly on memory safety.
- mhh__ 6y agoThere was a proposal to do just that in our DIP (D improvement proposal) pipeline that nearly made it but it (probably correctly) received enormous backlash. However, if you use @safe (that's the attribute) the compiler will hard-error if you call any code that you use that isn't explicitly also either @safe or @trusted. There is also DIP1000 and DIP1021 which both loosen @safe semantics to perform semantic analysis to allow safe memory behaviour (A small borrow checker in effect, this will hopefully be bigger soon).