@@ -380,10 +380,13 @@ impl<P: Deref> Pin<P> {
380
380
/// use std::pin::Pin;
381
381
///
382
382
/// fn move_pinned_ref<T>(mut a: T, mut b: T) {
383
- /// unsafe { let p = Pin::new_unchecked(&mut a); } // should mean `a` can never move again
383
+ /// unsafe {
384
+ /// let p: Pin<&mut T> = Pin::new_unchecked(&mut a);
385
+ /// // This should mean the pointee `a` can never move again.
386
+ /// }
384
387
/// mem::swap(&mut a, &mut b);
385
388
/// // The address of `a` changed to `b`'s stack slot, so `a` got moved even
386
- /// // though we have previously pinned it!
389
+ /// // though we have previously pinned it! We have violated the pinning API contract.
387
390
/// }
388
391
/// ```
389
392
/// A value, once pinned, must remain pinned forever (unless its type implements `Unpin`).
@@ -396,12 +399,15 @@ impl<P: Deref> Pin<P> {
396
399
///
397
400
/// fn move_pinned_rc<T>(mut x: Rc<T>) {
398
401
/// let pinned = unsafe { Pin::new_unchecked(x.clone()) };
399
- /// { let p: Pin<&T> = pinned.as_ref(); } // should mean the pointee can never move again
402
+ /// {
403
+ /// let p: Pin<&T> = pinned.as_ref();
404
+ /// // This should mean the pointee can never move again.
405
+ /// }
400
406
/// drop(pinned);
401
407
/// let content = Rc::get_mut(&mut x).unwrap();
402
408
/// // Now, if `x` was the only reference, we have a mutable reference to
403
409
/// // data that we pinned above, which we could use to move it as we have
404
- /// // seen in the previous example.
410
+ /// // seen in the previous example. We have violated the pinning API contract.
405
411
/// }
406
412
/// ```
407
413
///
0 commit comments