diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
commit | 2aa4a82499d4becd2284cdb482213d541b8804dd (patch) | |
tree | b80bf8bf13c3766139fbacc530efd0dd9d54394c /third_party/rust/pin-project/examples/enum-default-expanded.rs | |
parent | Initial commit. (diff) | |
download | firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.tar.xz firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.zip |
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/rust/pin-project/examples/enum-default-expanded.rs')
-rw-r--r-- | third_party/rust/pin-project/examples/enum-default-expanded.rs | 86 |
1 files changed, 86 insertions, 0 deletions
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..568f9b2c23 --- /dev/null +++ b/third_party/rust/pin-project/examples/enum-default-expanded.rs @@ -0,0 +1,86 @@ +// Original code (./enum-default.rs): +// +// ```rust +// #![allow(dead_code)] +// +// use pin_project::pin_project; +// +// #[pin_project] +// enum Enum<T, U> { +// Pinned(#[pin] T), +// Unpinned(U), +// } +// +// fn main() {} +// ``` + +#![allow(dead_code, unused_imports, unused_parens)] + +use pin_project::pin_project; + +enum Enum<T, U> { + Pinned(/* #[pin] */ T), + Unpinned(U), +} + +#[allow(clippy::mut_mut)] // This lint warns `&mut &mut <ty>`. +#[allow(dead_code)] // This lint warns unused fields/variants. +enum __EnumProjection<'pin, T, U> { + Pinned(::core::pin::Pin<&'pin mut (T)>), + Unpinned(&'pin mut (U)), +} + +#[allow(dead_code)] // This lint warns unused fields/variants. +enum __EnumProjectionRef<'pin, T, U> { + Pinned(::core::pin::Pin<&'pin (T)>), + Unpinned(&'pin (U)), +} + +impl<T, U> Enum<T, U> { + fn project<'pin>(self: ::core::pin::Pin<&'pin mut Self>) -> __EnumProjection<'pin, T, U> { + unsafe { + match self.get_unchecked_mut() { + Enum::Pinned(_0) => __EnumProjection::Pinned(::core::pin::Pin::new_unchecked(_0)), + Enum::Unpinned(_0) => __EnumProjection::Unpinned(_0), + } + } + } + fn project_ref<'pin>(self: ::core::pin::Pin<&'pin Self>) -> __EnumProjectionRef<'pin, T, U> { + unsafe { + match self.get_ref() { + Enum::Pinned(_0) => { + __EnumProjectionRef::Pinned(::core::pin::Pin::new_unchecked(_0)) + } + Enum::Unpinned(_0) => __EnumProjectionRef::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. +#[allow(non_snake_case)] +fn __unpin_scope_Enum() { + struct __Enum<'pin, T, U> { + __pin_project_use_generics: ::pin_project::__private::AlwaysUnpin<'pin, (T, U)>, + __field0: T, + } + impl<'pin, T, U> ::core::marker::Unpin for Enum<T, U> where __Enum<'pin, T, U>: ::core::marker::Unpin + {} +} + +// Ensure that enum does not implement `Drop`. +// +// See ./struct-default-expanded.rs for details. +trait EnumMustNotImplDrop {} +#[allow(clippy::drop_bounds)] +impl<T: ::core::ops::Drop> EnumMustNotImplDrop for T {} +#[allow(single_use_lifetimes)] +impl<T, U> EnumMustNotImplDrop for Enum<T, U> {} + +// We don't need to check for '#[repr(packed)]', +// since it does not apply to enums. + +fn main() {} |