From 9229488089727b816ed19dcfbcaa07531c91535c Mon Sep 17 00:00:00 2001 From: Taylor Cramer Date: Tue, 18 Dec 2018 10:25:02 -0800 Subject: [PATCH] Rename Box/Arc/Rc::pinned to ::pin --- src/liballoc/boxed.rs | 4 +++- src/liballoc/rc.rs | 4 +++- src/liballoc/sync.rs | 4 +++- src/libcore/pin.rs | 2 +- src/test/run-pass/async-await.rs | 2 +- 5 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/liballoc/boxed.rs b/src/liballoc/boxed.rs index c8bbe4807a25a..a51bd9aa4c7b8 100644 --- a/src/liballoc/boxed.rs +++ b/src/liballoc/boxed.rs @@ -109,9 +109,11 @@ impl Box { box x } + /// Constructs a new `Pin>`. If `T` does not implement `Unpin`, then + /// `x` will be pinned in memory and unable to be moved. #[stable(feature = "pin", since = "1.33.0")] #[inline(always)] - pub fn pinned(x: T) -> Pin> { + pub fn pin(x: T) -> Pin> { (box x).into() } } diff --git a/src/liballoc/rc.rs b/src/liballoc/rc.rs index 875fcc7fb9744..f4ef8a627eb45 100644 --- a/src/liballoc/rc.rs +++ b/src/liballoc/rc.rs @@ -325,8 +325,10 @@ impl Rc { } } + /// Constructs a new `Pin>`. If `T` does not implement `Unpin`, then + /// `value` will be pinned in memory and unable to be moved. #[stable(feature = "pin", since = "1.33.0")] - pub fn pinned(value: T) -> Pin> { + pub fn pin(value: T) -> Pin> { unsafe { Pin::new_unchecked(Rc::new(value)) } } diff --git a/src/liballoc/sync.rs b/src/liballoc/sync.rs index c4f770eff7fc9..f2c474da0d427 100644 --- a/src/liballoc/sync.rs +++ b/src/liballoc/sync.rs @@ -303,8 +303,10 @@ impl Arc { Arc { ptr: Box::into_raw_non_null(x), phantom: PhantomData } } + /// Constructs a new `Pin>`. If `T` does not implement `Unpin`, then + /// `data` will be pinned in memory and unable to be moved. #[stable(feature = "pin", since = "1.33.0")] - pub fn pinned(data: T) -> Pin> { + pub fn pin(data: T) -> Pin> { unsafe { Pin::new_unchecked(Arc::new(data)) } } diff --git a/src/libcore/pin.rs b/src/libcore/pin.rs index be40e5da5e910..38ea96cec5d93 100644 --- a/src/libcore/pin.rs +++ b/src/libcore/pin.rs @@ -70,7 +70,7 @@ //! slice: NonNull::dangling(), //! _pin: PhantomPinned, //! }; -//! let mut boxed = Box::pinned(res); +//! let mut boxed = Box::pin(res); //! //! let slice = NonNull::from(&boxed.data); //! // we know this is safe because modifying a field doesn't move the whole struct diff --git a/src/test/run-pass/async-await.rs b/src/test/run-pass/async-await.rs index 996709fa86c33..d9eb801a20668 100644 --- a/src/test/run-pass/async-await.rs +++ b/src/test/run-pass/async-await.rs @@ -138,7 +138,7 @@ where F: FnOnce(u8) -> Fut, Fut: Future, { - let mut fut = Box::pinned(f(9)); + let mut fut = Box::pin(f(9)); let counter = Arc::new(Counter { wakes: AtomicUsize::new(0) }); let waker = local_waker_from_nonlocal(counter.clone()); assert_eq!(0, counter.wakes.load(atomic::Ordering::SeqCst));