On Borrow Checking

Paul Backus snarwin at gmail.com
Sun May 4 16:53:55 UTC 2025


On Sunday, 4 May 2025 at 16:35:23 UTC, Dukc wrote:
> On Sunday, 4 May 2025 at 11:02:27 UTC, Paul Backus wrote:
>>
>> This page is the first result on Google for "unsafe rust". The 
>> fact that you got this wrong shows very clearly that you have 
>> not done your homework on this topic.
>
> I think you're a bit too fast with your judgement here.
>
> While the unsafe keyword doesn't directly turn off the borrow 
> checker, it does let you to work your way around it. I don't 
> know exactly how, but I'm sure it's possible; it's a systems 
> programming language after all. Most likely it involves calling 
> some sort of unsafe typecasting function. I think this is what 
> Walter means.

No, you're giving Walter too much credit here.

In context, he is clearly trying to claim that the 
@live/non- at live distinction in D is analogous to the safe/unsafe 
distinction in Rust w.r.t. borrow checking--i.e., that both 
languages have a mode with borrow checking, and a mode without 
it. The difference--he claims--is that in Rust, the mode with 
borrow checking is opt-out, and in D, it's opt-in.

The *actual* difference between D and Rust's approach is that 
Rust has two separate kinds of pointers: references, which are 
borrow-checked (in both safe and unsafe code), and raw pointers, 
which aren't. In other words, whether borrow checking is done or 
not is decided on a *type-by-type* basis, not a 
*function-by-function* basis.

The fact that Walter is (apparently) unaware of these facts shows 
that he has clearly not "studied the Rust specification," as he 
claims.


More information about the Digitalmars-d mailing list