On Borrow Checking

Walter Bright newshound2 at digitalmars.com
Sun May 4 19:47:28 UTC 2025


On 5/4/2025 3:57 AM, Paul Backus wrote:
> Even if you do this, you still cannot manually free memory in @safe code, like 
> you can in Rust.

Actually, you can in D.

The borrow checker doesn't know anything about free'ing memory. What it does 
know is the ownership of the pointer transferred to the function, or not. That's 
all it needs to know.


> Borrow checking, in itself, is not a useful feature--it's just a bunch of 
> arbitrary hoops the programmer has to jump through. It is useful in Rust ONLY 
> because of the additional safety analysis it enables. In D, the borrow checker 
> does not enable any additional safety analysis, so why would the programmer ever 
> want to jump through its hoops?

The check it does is enforce the style of only one mutable pointer being live at 
a time, which prevents double frees. It enforces that a mutable pointer is not 
left dangling, which prevents omitted frees.


More information about the Digitalmars-d mailing list