Skip to content

Commit 497439c

Browse files
committed
take a bit more space for new_unchecked examples
1 parent 811af42 commit 497439c

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/libcore/pin.rs

+10-4
Original file line numberDiff line numberDiff line change
@@ -380,10 +380,13 @@ impl<P: Deref> Pin<P> {
380380
/// use std::pin::Pin;
381381
///
382382
/// 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+
/// }
384387
/// mem::swap(&mut a, &mut b);
385388
/// // 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.
387390
/// }
388391
/// ```
389392
/// A value, once pinned, must remain pinned forever (unless its type implements `Unpin`).
@@ -396,12 +399,15 @@ impl<P: Deref> Pin<P> {
396399
///
397400
/// fn move_pinned_rc<T>(mut x: Rc<T>) {
398401
/// 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+
/// }
400406
/// drop(pinned);
401407
/// let content = Rc::get_mut(&mut x).unwrap();
402408
/// // Now, if `x` was the only reference, we have a mutable reference to
403409
/// // 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.
405411
/// }
406412
/// ```
407413
///

0 commit comments

Comments
 (0)