Skip to content

Commit c5a4988

Browse files
committed
future possibility: attribute / Box magic
1 parent 572f23b commit c5a4988

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

text/0000-maybe-dangling.md

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -203,11 +203,6 @@ Miri is adjusted as follows:
203203
This has the disadvantage that one risks memory leaks when all one wants to do is pass around data of some `T` without upholding reference liveness.
204204
For instance, the third example would have to remember to call `drop` on the `buffer`.
205205
This alternative has the advantage that we avoid introducing another type, and it is future-compatible with factoring that aspect of `ManuallyDrop` into a dedicated type in the future.
206-
- Another tempting alternative is to attach the special meaning not to a type, but an attribute.
207-
We could have a `#[maybe_dangling]` attribute that can be attached to ADTs, such that references and `Box` inside that type are not required to be dereferenceable or non-aliasing as the type gets moved around.
208-
This has the advantage that user can attach the attribute to their own type and directly access the fields, so e.g. `MyType` can have a `Box<T>` field and all of the magic of `Box` is still available,
209-
but the type can be moved around freely without worrying about aliasing. For the compiler and Miri implementation this would barely make a difference;
210-
we would simply stop recursing into fields when encountering any type with that attribute (rather than only stopping when encountering the magic `MaybeDangling` type).
211206
- Another alternative is to change the memory model such that the example code is fine as-is.
212207
There are several variants of this:
213208
- [Make all examples legal] All newtype wrappers behave the way `MaybeDangling` is specified in this RFC.
@@ -265,4 +260,6 @@ Notice that `UnsafeCell` acts "behind references" while `MaybeDangling`, like `M
265260
# Future possibilities
266261
[future-possibilities]: #future-possibilities
267262

268-
- None that the author can think of -- this arguably closes a gap in our ability to express and manipulate the aliasing guarantees of types that are being passed around.
263+
- One issue with this proposal is the "yet another wrapper type" syndrome, which leads to lots of syntactic salt and also means one loses the special `Box` magic (such as moving out of fields).
264+
This could be mitigated by either providing an attribute that attaches `MaybeDangling` semantics to an arbitrary type, or by making `Box` magic more widely available (`DerefMove`/`DerefPure`-style traits).
265+
Both of these are largely orthogonal to `MaybeDangling` though, and we'd probably want the `MaybeDangling` type as the "canonical" type for this even if the attribute existed (e.g., for cases like example 2).

0 commit comments

Comments
 (0)