-
Notifications
You must be signed in to change notification settings - Fork 61
Description
In Tree Borrows, &raw const/mut expressions don't do anything -- the raw pointer created by this expression just has whatever tag the place they point to has. This makes code like the following legal:
let mut a = 0;
let ptr = &raw mut a;
a = 1;
*ptr = 2;*ptr and a are allowed to freely alias.
I think this best reflects programmer expectations. In the early days of Stacked Borrows, this came up as a surprise for multiple people, and one c2rust translation tool had to change the code they generate to deal with this. This also simplifies the model since we no longer have to (somewhat awkwardly) identify when a raw pointer is created from a "safe" place (reference/local/Box), and only retag those. This is in contrast to references which we can just always retag no matter where we encounter them.
This somewhat relates to the following questions:
- Must
letvariables (withoutmutorUnsafeCell) be read-only? #400: in TB, at least the aliasing model has nothing against mutating non-mutlocal variables. We would have to introduce a separate check for this purpose. - Differences between
*const Tand*mut T. Initially*const Tpointers are forever read-only? #257:*mutand*constcannot make a difference if raw pointers never get retagged.