8 ms·
The borrow checker better described as compile time rwlock with all possible deadlocks caught as compiler errors
by ironhaven 11mo ago
The borrow checker better described as compile time rwlock with all possible deadlocks caught as compiler errors
- gpm 11mo agoIt'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 11mo 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.
- gpm 11mo agoNo I'm rather explicitly considering the joint behavior or the borrow checker and RAII. With only RAII you don't get the last reference part. Yes, there are exceptions, it's a roughly correct analogy not a precise description.