From: Ralf Jung Date: Fri, 2 Jun 2023 12:29:52 +0000 (+0200) Subject: clarification X-Git-Url: https://git.ralfj.de/web.git/commitdiff_plain/2464f025ad1cfccd9d49904adbda813ef1cafdda?ds=sidebyside;hp=bfa3f651654789ba700d2368cb7099b3af9c8132 clarification --- diff --git a/personal/_posts/2023-06-02-tree-borrows.md b/personal/_posts/2023-06-02-tree-borrows.md index e651835..ef7f803 100644 --- a/personal/_posts/2023-06-02-tree-borrows.md +++ b/personal/_posts/2023-06-02-tree-borrows.md @@ -152,7 +152,7 @@ First of all, another [major issue](https://github.com/rust-lang/unsafe-code-gui This falls out of how TB handles the aliasing allowed with `UnsafeCell`: they are treated like casts to raw pointers, so reborrowing an `&Cell` just inherits the tag (and therefore the permissions) of the parent pointer. More controversially, TB also changes how precisely things become read-only when an `&T` involves `UnsafeCell` somewhere inside `T`. -In particular, for `&(i32, Cell)`, TB allows mutating the first field, since it just treats the entire reference as "this allows aliasing". +In particular, for `&(i32, Cell)`, TB allows mutating *both* fields, including the first field which is a regular `i32`, since it just treats the entire reference as "this allows aliasing". In contrast, SB actually figured out that the first 4 bytes are read-only and only the last 4 bytes allow mutation via aliased pointers. The reason for this design decision is that the general philosophy with TB was to err on the side of allowing more code, having less UB (which is the opposite direction than what I used with SB).