top | item 45691487

(no title)

ironhaven | 4 months ago

The borrow checker better described as compile time rwlock with all possible deadlocks caught as compiler errors

discuss

order

gpm|4 months ago

It's that as well, but that part of the description doesn't catch how objects are automatically freed once the last reference to them (the owning one) is dropped.

Meanwhile my description doesn't fully capture how it guarantees unique access for writing, while yours does.

cesarb|4 months ago

> but that part of the description doesn't catch how objects are automatically freed once the last reference to them (the owning one) is dropped.

You're confusing the borrow checker with RAII.

Dropping the last reference to an object does nothing (and even the exclusive &mut is not an "owning" reference). Dropping the object itself is what automatically frees it. See also Box::leak.