On Borrow Checking

Paul Backus snarwin at gmail.com
Fri May 2 14:35:01 UTC 2025


On Friday, 2 May 2025 at 10:14:34 UTC, Dukc wrote:
> There's a difference.
>
> In Rust, as I understand it, if you have a function like
>
> ```Rust
> fn free(ptr: MyCustomPointer)
> {   // ...
> }
> ```
>
> it is 100% safe to use. The compiler will not let you 
> double-free or use after free, unless you use the `unsafe` 
> block to do so.
>
> But you can't have
>
> ```D
> @trusted void free(MyCustomPointer ptr)
> {   // ...
> }
> ```
>
> in D because it would be unsafe to use from a non-`@live` 
> function.

+100

Rust programmers don't put up with restrictions of the borrow 
checker just for fun. They do it because *it allows the compiler 
to verify the safety of their code.*

A borrow checker that can't be used for safety verification is 
like an oven mitt that can't be used to hold a hot pan. All it 
does is make things awkward and uncomfortable, and if you 
actually try to rely on it, you'll end up getting hurt.


More information about the Digitalmars-d mailing list