On Borrow Checking
jmh530
john.michael.hall at gmail.com
Fri May 2 10:33:14 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.
>
> If we had a way to say that "this function can be called from
> `@safe`, if and only if it's usage is guarded with `@live`"
> then it would be equal to the Rust borrow checker.
I was trying to make this point before, but think you do it
better here.
More information about the Digitalmars-d
mailing list