From 36d22d82aa202bb199967e9512281e9a53db42c9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 21:33:14 +0200 Subject: Adding upstream version 115.7.0esr. Signed-off-by: Daniel Baumann --- .../pin-project/examples/enum-default-expanded.rs | 101 +++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 third_party/rust/pin-project/examples/enum-default-expanded.rs (limited to 'third_party/rust/pin-project/examples/enum-default-expanded.rs') diff --git a/third_party/rust/pin-project/examples/enum-default-expanded.rs b/third_party/rust/pin-project/examples/enum-default-expanded.rs new file mode 100644 index 0000000000..459ca39b03 --- /dev/null +++ b/third_party/rust/pin-project/examples/enum-default-expanded.rs @@ -0,0 +1,101 @@ +// Original code (./enum-default.rs): +// +// ```rust +// #![allow(dead_code)] +// +// use pin_project::pin_project; +// +// #[pin_project(project = EnumProj)] +// enum Enum { +// Pinned(#[pin] T), +// Unpinned(U), +// } +// +// fn main() {} +// ``` + +#![allow(dead_code, unused_imports, unused_parens, unknown_lints, renamed_and_removed_lints)] +#![allow( + clippy::needless_lifetimes, + clippy::just_underscores_and_digits, + clippy::used_underscore_binding +)] + +use pin_project::pin_project; + +// #[pin_project(project = EnumProj)] +enum Enum { + Pinned(/* #[pin] */ T), + Unpinned(U), +} + +enum EnumProj<'pin, T, U> +where + Enum: 'pin, +{ + Pinned(::pin_project::__private::Pin<&'pin mut (T)>), + Unpinned(&'pin mut (U)), +} + +const _: () = { + // When `#[pin_project]` is used on enums, only named projection types and + // methods are generated because there is no way to access variants of + // projected types without naming it. + // (When `#[pin_project]` is used on structs, both methods are always generated.) + + impl Enum { + fn project<'pin>( + self: ::pin_project::__private::Pin<&'pin mut Self>, + ) -> EnumProj<'pin, T, U> { + unsafe { + match self.get_unchecked_mut() { + Self::Pinned(_0) => { + EnumProj::Pinned(::pin_project::__private::Pin::new_unchecked(_0)) + } + Self::Unpinned(_0) => EnumProj::Unpinned(_0), + } + } + } + } + + // Automatically create the appropriate conditional `Unpin` implementation. + // + // See ./struct-default-expanded.rs and https://github.com/taiki-e/pin-project/pull/53. + // for details. + struct __Enum<'pin, T, U> { + __pin_project_use_generics: ::pin_project::__private::AlwaysUnpin< + 'pin, + (::pin_project::__private::PhantomData, ::pin_project::__private::PhantomData), + >, + __field0: T, + } + impl<'pin, T, U> ::pin_project::__private::Unpin for Enum where + __Enum<'pin, T, U>: ::pin_project::__private::Unpin + { + } + // A dummy impl of `UnsafeUnpin`, to ensure that the user cannot implement it. + #[doc(hidden)] + unsafe impl<'pin, T, U> ::pin_project::UnsafeUnpin for Enum where + __Enum<'pin, T, U>: ::pin_project::__private::Unpin + { + } + + // Ensure that enum does not implement `Drop`. + // + // See ./struct-default-expanded.rs for details. + trait EnumMustNotImplDrop {} + #[allow(clippy::drop_bounds, drop_bounds)] + impl EnumMustNotImplDrop for T {} + impl EnumMustNotImplDrop for Enum {} + // A dummy impl of `PinnedDrop`, to ensure that users don't accidentally + // write a non-functional `PinnedDrop` impls. + #[doc(hidden)] + impl ::pin_project::__private::PinnedDrop for Enum { + unsafe fn drop(self: ::pin_project::__private::Pin<&mut Self>) {} + } + + // We don't need to check for `#[repr(packed)]`, + // since it does not apply to enums. +}; + +fn main() {} -- cgit v1.2.3