addendum re: interior mutability and pinning
authorRalf Jung <post@ralfj.de>
Tue, 10 Apr 2018 15:12:19 +0000 (17:12 +0200)
committerRalf Jung <post@ralfj.de>
Tue, 10 Apr 2018 17:05:33 +0000 (19:05 +0200)
ralf/_posts/2018-04-10-safe-intrusive-collections-with-pinning.md

index 362a4e3dc8e27d5d8403f005952de3f9122341fc..93cbad5ebb7b157a6d305f803ca3bec98c50a1dc 100644 (file)
@@ -266,7 +266,7 @@ Collection<T>.pin(ptr) := exists |entries: List<Pointer>|
   )
 ```
 Notice how we iterate over the elements of the list and make sure that we own whatever memory is to own there.
-(I love how `all` [really exists for iterators](https://doc.rust-lang.org/beta/std/iter/trait.Iterator.html#method.all) so I can express quantification over lists without any hassle. ;)
+(I love how `all` [really exists for iterators](https://doc.rust-lang.org/beta/std/iter/trait.Iterator.html#method.all) so I can express quantification over lists without any hassle. :)
 
 This invariant already justifies `print_all`: All the entries we are going to see there are in the list, so we have their `T.pin` at our disposal and are free to call `Debug::fmt`.
 
@@ -453,6 +453,8 @@ Removing `Pin::deref` (or restricting it to types that implement `Unpin`) would
 I spelled out the details [in the RFC issue](https://github.com/rust-lang/rfcs/pull/2349#issuecomment-372109981).
 So, if we want to declare that shared pinning is a typestate in its own right---which overall seems desirable---do we want it to be restricted like this due to an implementation detail of arbitrary self types?
 
+**Update:** @Diggsey [points out](https://github.com/rust-lang/rfcs/pull/2349#issuecomment-379230538) that we can still have a `PinRefCell` with a method like `fn get_pin(self: Pin<PinRefCell<T>>) -> Pin<T>`, as long as the `PinRefCell` never gives out mutable references. So it turns out that combining interior mutability and pinning should work fine, but having both pinned and unpinned interior mutability in the same type is where things start to go wrong due to `Pin::deref`.  **/Update**
+
 ## 4 Conclusion
 
 Leaving aside the last part about shared pinning, I am really excited how all of this fits together so nicely.