diff options
author | Chih-Hung Hsieh <chh@google.com> | 2020-10-26 16:54:29 -0700 |
---|---|---|
committer | Chih-Hung Hsieh <chh@google.com> | 2020-10-26 16:57:40 -0700 |
commit | 127364b149c24623fd15786790a98af3b5355389 (patch) | |
tree | 55ba197683b0a0093a2767fcb1f576490157f8a1 /src | |
parent | c112e35face1579eba180108bda3da10b61d9926 (diff) | |
download | pin-project-127364b149c24623fd15786790a98af3b5355389.tar.gz |
Upgrade rust/crates/pin-project to 1.0.1
* Add missing patches, needed by external_updater
Test: make
Test: tools/external_updater/updater.sh update --refresh --keep_date rust/crates/pin-project
Change-Id: I3738561830ce97903036460713eb3b74700b889e
Diffstat (limited to 'src')
-rw-r--r-- | src/lib.rs | 97 |
1 files changed, 64 insertions, 33 deletions
@@ -27,24 +27,58 @@ //! //! [*code like this will be generated*][struct-default-expanded] //! +//! To use `#[pin_project]` on enums, you need to name the projection type +//! returned from the method. +//! +//! ```rust +//! use pin_project::pin_project; +//! use std::pin::Pin; +//! +//! #[pin_project(project = EnumProj)] +//! enum Enum<T, U> { +//! Pinned(#[pin] T), +//! Unpinned(U), +//! } +//! +//! impl<T, U> Enum<T, U> { +//! fn method(self: Pin<&mut Self>) { +//! match self.project() { +//! EnumProj::Pinned(x) => { +//! let _: Pin<&mut T> = x; +//! } +//! EnumProj::Unpinned(y) => { +//! let _: &mut U = y; +//! } +//! } +//! } +//! } +//! ``` +//! +//! [*code like this will be generated*][enum-default-expanded] +//! //! See [`#[pin_project]`][`pin_project`] attribute for more details, and //! see [examples] directory for more examples and generated code. //! -//! [`pin_project`]: attr.pin_project.html //! [examples]: https://github.com/taiki-e/pin-project/blob/master/examples/README.md -//! [pin-projection]: https://doc.rust-lang.org/nightly/std/pin/index.html#projections-and-structural-pinning +//! [enum-default-expanded]: https://github.com/taiki-e/pin-project/blob/master/examples/enum-default-expanded.rs +//! [pin-projection]: core::pin#projections-and-structural-pinning //! [struct-default-expanded]: https://github.com/taiki-e/pin-project/blob/master/examples/struct-default-expanded.rs #![no_std] -#![doc(html_root_url = "https://docs.rs/pin-project/0.4.23")] +#![doc(html_root_url = "https://docs.rs/pin-project/1.0.1")] #![doc(test( no_crate_inject, attr(deny(warnings, rust_2018_idioms, single_use_lifetimes), allow(dead_code)) ))] -#![warn(missing_docs, rust_2018_idioms, single_use_lifetimes, unreachable_pub)] +#![warn(future_incompatible, rust_2018_idioms, single_use_lifetimes, unreachable_pub)] +#![warn(missing_docs)] #![warn(clippy::all, clippy::default_trait_access)] -// mem::take and #[non_exhaustive] requires Rust 1.40 -#![allow(clippy::mem_replace_with_default, clippy::manual_non_exhaustive)] +// mem::take and #[non_exhaustive] requires Rust 1.40, matches! requires Rust 1.42 +#![allow( + clippy::mem_replace_with_default, + clippy::manual_non_exhaustive, + clippy::match_like_matches_macro +)] #![allow(clippy::needless_doctest_main)] // ANDROID: Use std to allow building as a dylib. @@ -56,25 +90,14 @@ pub use pin_project_internal::pin_project; #[doc(inline)] pub use pin_project_internal::pinned_drop; -#[allow(deprecated)] -#[doc(inline)] -pub use pin_project_internal::project; - -#[allow(deprecated)] -#[doc(inline)] -pub use pin_project_internal::project_ref; - -#[allow(deprecated)] -#[doc(inline)] -pub use pin_project_internal::project_replace; - /// A trait used for custom implementations of [`Unpin`]. -/// This trait is used in conjunction with the `UnsafeUnpin` -/// argument to [`#[pin_project]`][`pin_project`] +/// +/// This trait is used in conjunction with the `UnsafeUnpin` argument to +/// the [`#[pin_project]`][macro@pin_project] attribute. /// /// The Rust [`Unpin`] trait is safe to implement - by itself, -/// implementing it cannot lead to undefined behavior. Undefined -/// behavior can only occur when other unsafe code is used. +/// implementing it cannot lead to [undefined behavior][undefined-behavior]. +/// Undefined behavior can only occur when other unsafe code is used. /// /// It turns out that using pin projections, which requires unsafe code, /// imposes additional requirements on an [`Unpin`] impl. Normally, all of this @@ -112,19 +135,19 @@ pub use pin_project_internal::project_replace; /// use pin_project::{pin_project, UnsafeUnpin}; /// /// #[pin_project(UnsafeUnpin)] -/// struct Foo<K, V> { +/// struct Struct<K, V> { /// #[pin] /// field_1: K, /// field_2: V, /// } /// -/// unsafe impl<K, V> UnsafeUnpin for Foo<K, V> where K: Unpin + Clone {} +/// unsafe impl<K, V> UnsafeUnpin for Struct<K, V> where K: Unpin + Clone {} /// ``` /// /// [`PhantomPinned`]: core::marker::PhantomPinned -/// [`pin_project`]: attr.pin_project.html -/// [pin-projection]: https://doc.rust-lang.org/nightly/std/pin/index.html#projections-and-structural-pinning /// [cargo-geiger]: https://github.com/rust-secure-code/cargo-geiger +/// [pin-projection]: core::pin#projections-and-structural-pinning +/// [undefined-behavior]: https://doc.rust-lang.org/reference/behavior-considered-undefined.html pub unsafe trait UnsafeUnpin {} // Not public API. @@ -144,18 +167,26 @@ pub mod __private { #[doc(hidden)] pub use pin_project_internal::__PinProjectInternalDerive; + // An internal trait used for custom implementations of [`Drop`]. + // + // **Do not call or implement this trait directly.** + // + // # Why this trait is private and `#[pinned_drop]` attribute is needed? + // // Implementing `PinnedDrop::drop` is safe, but calling it is not safe. // This is because destructors can be called multiple times in safe code and - // [double dropping is unsound](https://github.com/rust-lang/rust/pull/62360). + // [double dropping is unsound][rust-lang/rust#62360]. // // Ideally, it would be desirable to be able to forbid manual calls in // the same way as [`Drop::drop`], but the library cannot do it. So, by using - // macros and replacing them with private traits, we prevent users from - // calling `PinnedDrop::drop`. + // macros and replacing them with private traits, + // this crate prevent users from calling `PinnedDrop::drop` in safe code. // - // Users can implement [`Drop`] safely using `#[pinned_drop]` and can drop a - // type that implements `PinnedDrop` using the [`drop`] function safely. - // **Do not call or implement this trait directly.** + // This allows implementing [`Drop`] safely using `#[pinned_drop]`. + // Also by using the [`drop`] function just like dropping a type that directly + // implements [`Drop`], can drop safely a type that implements `PinnedDrop`. + // + // [rust-lang/rust#62360]: https://github.com/rust-lang/rust/pull/62360 #[doc(hidden)] pub trait PinnedDrop { #[doc(hidden)] @@ -223,7 +254,7 @@ pub mod __private { // // See https://github.com/taiki-e/pin-project/pull/53 for more details. #[doc(hidden)] - pub struct AlwaysUnpin<'a, T: ?Sized>(PhantomData<&'a ()>, PhantomData<T>); + pub struct AlwaysUnpin<'a, T>(PhantomData<&'a ()>, PhantomData<T>); impl<T> Unpin for AlwaysUnpin<'_, T> {} |