Skip to content

Commit 86e0188

Browse files
committed
add example for why this is tied to pinning
1 parent 9327537 commit 86e0188

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

text/0000-unsafe-aliased.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,10 @@ However, it is not possible to write sound wrappers around `UnsafeAliased` such
399399
Because of that, the RFC proposes that we suggestively put pinning into the name of the type, so that people don't confuse it with a general mechanism for aliasing mutable references.
400400
It is more like the core primitive behind pinning, where whenever a type is pinned that is caused by an `UnsafePinned` field somewhere inside it.
401401

402+
For instance, it may be tempting to use an `UnsafeAliased` type to mark a single field in some struct as "separately aliased", and then a `Mutex<Struct>` would acquire ownership of the entire struct except for that field.
403+
However, due to `mem::swap`, that would not be sound.
404+
One cannot hand out an `&mut` to such aliased memory as part of a safe-to-use abstraction -- except by using pinning.
405+
402406
# Prior art
403407
[prior-art]: #prior-art
404408

0 commit comments

Comments
 (0)