mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-08 01:28:18 +03:00
Rollup merge of #64530 - taiki-e:docs-pin-lifetimes, r=Centril
Elide lifetimes in `Pin<&(mut) Self>`
This commit is contained in:
@@ -295,7 +295,7 @@ pub fn as_mut(&mut self) -> Option<&mut T> {
|
||||
/// [`Pin`]: ../pin/struct.Pin.html
|
||||
#[inline]
|
||||
#[stable(feature = "pin", since = "1.33.0")]
|
||||
pub fn as_pin_ref<'a>(self: Pin<&'a Option<T>>) -> Option<Pin<&'a T>> {
|
||||
pub fn as_pin_ref(self: Pin<&Self>) -> Option<Pin<&T>> {
|
||||
unsafe {
|
||||
Pin::get_ref(self).as_ref().map(|x| Pin::new_unchecked(x))
|
||||
}
|
||||
@@ -306,7 +306,7 @@ pub fn as_pin_ref<'a>(self: Pin<&'a Option<T>>) -> Option<Pin<&'a T>> {
|
||||
/// [`Pin`]: ../pin/struct.Pin.html
|
||||
#[inline]
|
||||
#[stable(feature = "pin", since = "1.33.0")]
|
||||
pub fn as_pin_mut<'a>(self: Pin<&'a mut Option<T>>) -> Option<Pin<&'a mut T>> {
|
||||
pub fn as_pin_mut(self: Pin<&mut Self>) -> Option<Pin<&mut T>> {
|
||||
unsafe {
|
||||
Pin::get_unchecked_mut(self).as_mut().map(|x| Pin::new_unchecked(x))
|
||||
}
|
||||
|
||||
+2
-2
@@ -233,7 +233,7 @@
|
||||
//! # type Field = i32;
|
||||
//! # struct Struct { field: Field }
|
||||
//! impl Struct {
|
||||
//! fn pin_get_field<'a>(self: Pin<&'a mut Self>) -> &'a mut Field {
|
||||
//! fn pin_get_field(self: Pin<&mut Self>) -> &mut Field {
|
||||
//! // This is okay because `field` is never considered pinned.
|
||||
//! unsafe { &mut self.get_unchecked_mut().field }
|
||||
//! }
|
||||
@@ -257,7 +257,7 @@
|
||||
//! # type Field = i32;
|
||||
//! # struct Struct { field: Field }
|
||||
//! impl Struct {
|
||||
//! fn pin_get_field<'a>(self: Pin<&'a mut Self>) -> Pin<&'a mut Field> {
|
||||
//! fn pin_get_field(self: Pin<&mut Self>) -> Pin<&mut Field> {
|
||||
//! // This is okay because `field` is pinned when `self` is.
|
||||
//! unsafe { self.map_unchecked_mut(|s| &mut s.field) }
|
||||
//! }
|
||||
|
||||
Reference in New Issue
Block a user