From c1311073c0eab8a9f0566dbe0753f80865912a01 Mon Sep 17 00:00:00 2001 From: Haibo Huang Date: Tue, 9 Feb 2021 17:42:22 -0800 Subject: Upgrade rust/crates/pin-project to 1.0.5 Test: make Change-Id: Ib3aa891d12640b626e328863102306eb9f973622 --- tests/auxiliary/mod.rs | 32 --- tests/cfg.rs | 171 +++++--------- tests/compiletest.rs | 10 +- tests/drop_order.rs | 3 +- tests/expand/README.md | 17 ++ tests/expand/default/enum.expanded.rs | 131 +++++++++++ tests/expand/default/enum.rs | 14 ++ tests/expand/default/struct.expanded.rs | 113 ++++++++++ tests/expand/default/struct.rs | 10 + tests/expand/default/tuple_struct.expanded.rs | 101 +++++++++ tests/expand/default/tuple_struct.rs | 6 + tests/expand/multifields/enum.expanded.rs | 246 +++++++++++++++++++++ tests/expand/multifields/enum.rs | 17 ++ tests/expand/multifields/struct.expanded.rs | 181 +++++++++++++++ tests/expand/multifields/struct.rs | 13 ++ tests/expand/multifields/tuple_struct.expanded.rs | 157 +++++++++++++ tests/expand/multifields/tuple_struct.rs | 6 + tests/expand/naming/enum-all.expanded.rs | 187 ++++++++++++++++ tests/expand/naming/enum-all.rs | 14 ++ tests/expand/naming/enum-mut.expanded.rs | 90 ++++++++ tests/expand/naming/enum-mut.rs | 14 ++ tests/expand/naming/enum-none.expanded.rs | 53 +++++ tests/expand/naming/enum-none.rs | 14 ++ tests/expand/naming/enum-own.expanded.rs | 112 ++++++++++ tests/expand/naming/enum-own.rs | 14 ++ tests/expand/naming/enum-ref.expanded.rs | 93 ++++++++ tests/expand/naming/enum-ref.rs | 14 ++ tests/expand/naming/struct-all.expanded.rs | 145 ++++++++++++ tests/expand/naming/struct-all.rs | 10 + tests/expand/naming/struct-mut.expanded.rs | 111 ++++++++++ tests/expand/naming/struct-mut.rs | 10 + tests/expand/naming/struct-none.expanded.rs | 113 ++++++++++ tests/expand/naming/struct-none.rs | 10 + tests/expand/naming/struct-own.expanded.rs | 147 ++++++++++++ tests/expand/naming/struct-own.rs | 10 + tests/expand/naming/struct-ref.expanded.rs | 113 ++++++++++ tests/expand/naming/struct-ref.rs | 10 + tests/expand/naming/tuple_struct-all.expanded.rs | 124 +++++++++++ tests/expand/naming/tuple_struct-all.rs | 6 + tests/expand/naming/tuple_struct-mut.expanded.rs | 96 ++++++++ tests/expand/naming/tuple_struct-mut.rs | 6 + tests/expand/naming/tuple_struct-none.expanded.rs | 101 +++++++++ tests/expand/naming/tuple_struct-none.rs | 6 + tests/expand/naming/tuple_struct-own.expanded.rs | 132 +++++++++++ tests/expand/naming/tuple_struct-own.rs | 6 + tests/expand/naming/tuple_struct-ref.expanded.rs | 98 ++++++++ tests/expand/naming/tuple_struct-ref.rs | 6 + tests/expand/not_unpin/enum.expanded.rs | 121 ++++++++++ tests/expand/not_unpin/enum.rs | 14 ++ tests/expand/not_unpin/struct.expanded.rs | 104 +++++++++ tests/expand/not_unpin/struct.rs | 10 + tests/expand/not_unpin/tuple_struct.expanded.rs | 92 ++++++++ tests/expand/not_unpin/tuple_struct.rs | 6 + tests/expand/pinned_drop/enum.expanded.rs | 142 ++++++++++++ tests/expand/pinned_drop/enum.rs | 22 ++ tests/expand/pinned_drop/struct.expanded.rs | 124 +++++++++++ tests/expand/pinned_drop/struct.rs | 18 ++ tests/expand/pinned_drop/tuple_struct.expanded.rs | 112 ++++++++++ tests/expand/pinned_drop/tuple_struct.rs | 14 ++ tests/expand/project_replace/enum.expanded.rs | 112 ++++++++++ tests/expand/project_replace/enum.rs | 14 ++ tests/expand/project_replace/struct.expanded.rs | 147 ++++++++++++ tests/expand/project_replace/struct.rs | 10 + .../project_replace/tuple_struct.expanded.rs | 132 +++++++++++ tests/expand/project_replace/tuple_struct.rs | 6 + tests/expand/pub/enum.expanded.rs | 131 +++++++++++ tests/expand/pub/enum.rs | 14 ++ tests/expand/pub/struct.expanded.rs | 113 ++++++++++ tests/expand/pub/struct.rs | 10 + tests/expand/pub/tuple_struct.expanded.rs | 101 +++++++++ tests/expand/pub/tuple_struct.rs | 6 + tests/expand/unsafe_unpin/enum.expanded.rs | 115 ++++++++++ tests/expand/unsafe_unpin/enum.rs | 16 ++ tests/expand/unsafe_unpin/struct.expanded.rs | 98 ++++++++ tests/expand/unsafe_unpin/struct.rs | 12 + tests/expand/unsafe_unpin/tuple_struct.expanded.rs | 86 +++++++ tests/expand/unsafe_unpin/tuple_struct.rs | 8 + tests/expandtest.rs | 41 ++++ tests/lint.rs | 160 ++++++++++++-- tests/lint.txt | 157 ------------- tests/pin_project.rs | 5 +- tests/pinned_drop.rs | 3 +- tests/proper_unpin.rs | 12 +- tests/ui/cfg/packed_sneaky-span-issue-1.rs | 4 +- tests/ui/cfg/packed_sneaky-span-issue-1.stderr | 10 + tests/ui/cfg/packed_sneaky-span-issue-2.rs | 4 +- tests/ui/cfg/packed_sneaky-span-issue-2.stderr | 10 + tests/ui/cfg/unsupported.rs | 4 +- tests/ui/cfg/unsupported.stderr | 9 + .../ui/pin_project/project_replace_unsized.stderr | 38 ++-- .../project_replace_unsized_fn_params.stderr | 38 ++-- .../marker_trait_attr-feature-gate.rs | 2 +- tests/ui/unstable-features/marker_trait_attr.rs | 2 +- .../overlapping_marker_traits-feature-gate.rs | 2 +- .../unstable-features/overlapping_marker_traits.rs | 2 +- tests/ui/unstable-features/trivial_bounds-bug.rs | 2 +- .../trivial_bounds-feature-gate.rs | 2 +- tests/ui/unstable-features/trivial_bounds.rs | 2 +- tests/unsafe_unpin.rs | 3 +- 99 files changed, 5119 insertions(+), 396 deletions(-) create mode 100644 tests/expand/README.md create mode 100644 tests/expand/default/enum.expanded.rs create mode 100644 tests/expand/default/enum.rs create mode 100644 tests/expand/default/struct.expanded.rs create mode 100644 tests/expand/default/struct.rs create mode 100644 tests/expand/default/tuple_struct.expanded.rs create mode 100644 tests/expand/default/tuple_struct.rs create mode 100644 tests/expand/multifields/enum.expanded.rs create mode 100644 tests/expand/multifields/enum.rs create mode 100644 tests/expand/multifields/struct.expanded.rs create mode 100644 tests/expand/multifields/struct.rs create mode 100644 tests/expand/multifields/tuple_struct.expanded.rs create mode 100644 tests/expand/multifields/tuple_struct.rs create mode 100644 tests/expand/naming/enum-all.expanded.rs create mode 100644 tests/expand/naming/enum-all.rs create mode 100644 tests/expand/naming/enum-mut.expanded.rs create mode 100644 tests/expand/naming/enum-mut.rs create mode 100644 tests/expand/naming/enum-none.expanded.rs create mode 100644 tests/expand/naming/enum-none.rs create mode 100644 tests/expand/naming/enum-own.expanded.rs create mode 100644 tests/expand/naming/enum-own.rs create mode 100644 tests/expand/naming/enum-ref.expanded.rs create mode 100644 tests/expand/naming/enum-ref.rs create mode 100644 tests/expand/naming/struct-all.expanded.rs create mode 100644 tests/expand/naming/struct-all.rs create mode 100644 tests/expand/naming/struct-mut.expanded.rs create mode 100644 tests/expand/naming/struct-mut.rs create mode 100644 tests/expand/naming/struct-none.expanded.rs create mode 100644 tests/expand/naming/struct-none.rs create mode 100644 tests/expand/naming/struct-own.expanded.rs create mode 100644 tests/expand/naming/struct-own.rs create mode 100644 tests/expand/naming/struct-ref.expanded.rs create mode 100644 tests/expand/naming/struct-ref.rs create mode 100644 tests/expand/naming/tuple_struct-all.expanded.rs create mode 100644 tests/expand/naming/tuple_struct-all.rs create mode 100644 tests/expand/naming/tuple_struct-mut.expanded.rs create mode 100644 tests/expand/naming/tuple_struct-mut.rs create mode 100644 tests/expand/naming/tuple_struct-none.expanded.rs create mode 100644 tests/expand/naming/tuple_struct-none.rs create mode 100644 tests/expand/naming/tuple_struct-own.expanded.rs create mode 100644 tests/expand/naming/tuple_struct-own.rs create mode 100644 tests/expand/naming/tuple_struct-ref.expanded.rs create mode 100644 tests/expand/naming/tuple_struct-ref.rs create mode 100644 tests/expand/not_unpin/enum.expanded.rs create mode 100644 tests/expand/not_unpin/enum.rs create mode 100644 tests/expand/not_unpin/struct.expanded.rs create mode 100644 tests/expand/not_unpin/struct.rs create mode 100644 tests/expand/not_unpin/tuple_struct.expanded.rs create mode 100644 tests/expand/not_unpin/tuple_struct.rs create mode 100644 tests/expand/pinned_drop/enum.expanded.rs create mode 100644 tests/expand/pinned_drop/enum.rs create mode 100644 tests/expand/pinned_drop/struct.expanded.rs create mode 100644 tests/expand/pinned_drop/struct.rs create mode 100644 tests/expand/pinned_drop/tuple_struct.expanded.rs create mode 100644 tests/expand/pinned_drop/tuple_struct.rs create mode 100644 tests/expand/project_replace/enum.expanded.rs create mode 100644 tests/expand/project_replace/enum.rs create mode 100644 tests/expand/project_replace/struct.expanded.rs create mode 100644 tests/expand/project_replace/struct.rs create mode 100644 tests/expand/project_replace/tuple_struct.expanded.rs create mode 100644 tests/expand/project_replace/tuple_struct.rs create mode 100644 tests/expand/pub/enum.expanded.rs create mode 100644 tests/expand/pub/enum.rs create mode 100644 tests/expand/pub/struct.expanded.rs create mode 100644 tests/expand/pub/struct.rs create mode 100644 tests/expand/pub/tuple_struct.expanded.rs create mode 100644 tests/expand/pub/tuple_struct.rs create mode 100644 tests/expand/unsafe_unpin/enum.expanded.rs create mode 100644 tests/expand/unsafe_unpin/enum.rs create mode 100644 tests/expand/unsafe_unpin/struct.expanded.rs create mode 100644 tests/expand/unsafe_unpin/struct.rs create mode 100644 tests/expand/unsafe_unpin/tuple_struct.expanded.rs create mode 100644 tests/expand/unsafe_unpin/tuple_struct.rs create mode 100644 tests/expandtest.rs delete mode 100644 tests/lint.txt (limited to 'tests') diff --git a/tests/auxiliary/mod.rs b/tests/auxiliary/mod.rs index a0eb7c2..1457099 100644 --- a/tests/auxiliary/mod.rs +++ b/tests/auxiliary/mod.rs @@ -1,9 +1,4 @@ #![allow(dead_code, unused_macros)] -#![allow(box_pointers, unreachable_pub)] -#![allow(clippy::restriction)] - -use std::{env, fs, path::Path, process::Command}; -use tempfile::Builder; macro_rules! assert_unpin { ($ty:ty) => { @@ -15,30 +10,3 @@ macro_rules! assert_not_unpin { static_assertions::assert_not_impl_all!($ty: Unpin); }; } - -#[rustversion::attr(since(1.46), track_caller)] -pub fn assert_diff(expected_path: impl AsRef, actual: impl AsRef) { - let actual = actual.as_ref(); - let manifest_dir = Path::new(env!("CARGO_MANIFEST_DIR")); - let expected_path = &manifest_dir.join(expected_path); - (|| -> Result<(), Box> { - let expected = fs::read_to_string(expected_path)?; - if expected != actual { - if env::var_os("CI").is_some() { - let outdir = Builder::new().prefix("assert_diff").tempdir()?; - let actual_path = &outdir.path().join(expected_path.file_name().unwrap()); - fs::write(actual_path, actual)?; - let status = Command::new("git") - .args(&["--no-pager", "diff", "--no-index", "--"]) - .args(&[expected_path, actual_path]) - .status()?; - assert!(!status.success()); - panic!("assertion failed"); - } else { - fs::write(expected_path, actual)?; - } - } - Ok(()) - })() - .unwrap_or_else(|e| panic!("{}", e)) -} diff --git a/tests/cfg.rs b/tests/cfg.rs index 2fdcfbb..2f5387b 100644 --- a/tests/cfg.rs +++ b/tests/cfg.rs @@ -6,16 +6,14 @@ #[macro_use] mod auxiliary; -use pin_project::pin_project; use std::{marker::PhantomPinned, pin::Pin}; -#[cfg(target_os = "linux")] -struct Linux; -#[cfg(not(target_os = "linux"))] -struct Other; +use pin_project::pin_project; + +struct Always; // Use this type to check that `cfg(any())` is working properly. -struct Any(PhantomPinned); +struct Never(PhantomPinned); #[test] fn cfg() { @@ -23,63 +21,45 @@ fn cfg() { #[pin_project(project_replace)] struct SameName { - #[cfg(target_os = "linux")] + #[cfg(not(any()))] #[pin] - inner: Linux, - #[cfg(not(target_os = "linux"))] - #[pin] - inner: Other, + inner: Always, #[cfg(any())] #[pin] - any: Any, + inner: Never, } assert_unpin!(SameName); - #[cfg(target_os = "linux")] - let _ = SameName { inner: Linux }; - #[cfg(not(target_os = "linux"))] - let _ = SameName { inner: Other }; + let _ = SameName { inner: Always }; #[pin_project(project_replace)] struct DifferentName { - #[cfg(target_os = "linux")] - #[pin] - l: Linux, - #[cfg(not(target_os = "linux"))] + #[cfg(not(any()))] #[pin] - o: Other, + a: Always, #[cfg(any())] #[pin] - a: Any, + n: Never, } assert_unpin!(DifferentName); - #[cfg(target_os = "linux")] - let _ = DifferentName { l: Linux }; - #[cfg(not(target_os = "linux"))] - let _ = DifferentName { o: Other }; + let _ = DifferentName { a: Always }; #[pin_project(project_replace)] struct TupleStruct( - #[cfg(target_os = "linux")] + #[cfg(not(any()))] #[pin] - Linux, - #[cfg(not(target_os = "linux"))] - #[pin] - Other, + Always, #[cfg(any())] #[pin] - Any, + Never, ); assert_unpin!(TupleStruct); - #[cfg(target_os = "linux")] - let _ = TupleStruct(Linux); - #[cfg(not(target_os = "linux"))] - let _ = TupleStruct(Other); + let _ = TupleStruct(Always); // enums @@ -89,30 +69,21 @@ fn cfg() { project_replace = VariantProjOwn, )] enum Variant { - #[cfg(target_os = "linux")] - Inner(#[pin] Linux), - #[cfg(not(target_os = "linux"))] - Inner(#[pin] Other), - - #[cfg(target_os = "linux")] - Linux(#[pin] Linux), - #[cfg(not(target_os = "linux"))] - Other(#[pin] Other), + #[cfg(not(any()))] + Inner(#[pin] Always), + #[cfg(any())] + Inner(#[pin] Never), + + #[cfg(not(any()))] + A(#[pin] Always), #[cfg(any())] - Any(#[pin] Any), + N(#[pin] Never), } assert_unpin!(Variant); - #[cfg(target_os = "linux")] - let _ = Variant::Inner(Linux); - #[cfg(not(target_os = "linux"))] - let _ = Variant::Inner(Other); - - #[cfg(target_os = "linux")] - let _ = Variant::Linux(Linux); - #[cfg(not(target_os = "linux"))] - let _ = Variant::Other(Other); + let _ = Variant::Inner(Always); + let _ = Variant::A(Always); #[pin_project( project = FieldProj, @@ -121,111 +92,71 @@ fn cfg() { )] enum Field { SameName { - #[cfg(target_os = "linux")] - #[pin] - inner: Linux, - #[cfg(not(target_os = "linux"))] + #[cfg(not(any()))] #[pin] - inner: Other, + inner: Always, #[cfg(any())] #[pin] - any: Any, + inner: Never, }, DifferentName { - #[cfg(target_os = "linux")] + #[cfg(not(any()))] #[pin] - l: Linux, - #[cfg(not(target_os = "linux"))] - #[pin] - w: Other, + a: Always, #[cfg(any())] #[pin] - any: Any, + n: Never, }, TupleVariant( - #[cfg(target_os = "linux")] - #[pin] - Linux, - #[cfg(not(target_os = "linux"))] + #[cfg(not(any()))] #[pin] - Other, + Always, #[cfg(any())] #[pin] - Any, + Never, ), } assert_unpin!(Field); - #[cfg(target_os = "linux")] - let _ = Field::SameName { inner: Linux }; - #[cfg(not(target_os = "linux"))] - let _ = Field::SameName { inner: Other }; - - #[cfg(target_os = "linux")] - let _ = Field::DifferentName { l: Linux }; - #[cfg(not(target_os = "linux"))] - let _ = Field::DifferentName { w: Other }; - - #[cfg(target_os = "linux")] - let _ = Field::TupleVariant(Linux); - #[cfg(not(target_os = "linux"))] - let _ = Field::TupleVariant(Other); + let _ = Field::SameName { inner: Always }; + let _ = Field::DifferentName { a: Always }; + let _ = Field::TupleVariant(Always); } #[test] fn cfg_attr() { #[pin_project(project_replace)] struct SameCfg { - #[cfg(target_os = "linux")] - #[cfg_attr(target_os = "linux", pin)] - inner: Linux, - #[cfg(not(target_os = "linux"))] - #[cfg_attr(not(target_os = "linux"), pin)] - inner: Other, + #[cfg(not(any()))] + #[cfg_attr(not(any()), pin)] + inner: Always, #[cfg(any())] #[cfg_attr(any(), pin)] - any: Any, + inner: Never, } assert_unpin!(SameCfg); - #[cfg(target_os = "linux")] - let mut x = SameCfg { inner: Linux }; - #[cfg(not(target_os = "linux"))] - let mut x = SameCfg { inner: Other }; - + let mut x = SameCfg { inner: Always }; let x = Pin::new(&mut x).project(); - #[cfg(target_os = "linux")] - let _: Pin<&mut Linux> = x.inner; - #[cfg(not(target_os = "linux"))] - let _: Pin<&mut Other> = x.inner; + let _: Pin<&mut Always> = x.inner; #[pin_project(project_replace)] struct DifferentCfg { - #[cfg(target_os = "linux")] - #[cfg_attr(target_os = "linux", pin)] - inner: Linux, - #[cfg(not(target_os = "linux"))] - #[cfg_attr(target_os = "linux", pin)] - inner: Other, - #[cfg(any())] + #[cfg(not(any()))] #[cfg_attr(any(), pin)] - any: Any, + inner: Always, + #[cfg(any())] + #[cfg_attr(not(any()), pin)] + inner: Never, } assert_unpin!(DifferentCfg); - #[cfg(target_os = "linux")] - let mut x = DifferentCfg { inner: Linux }; - #[cfg(not(target_os = "linux"))] - let mut x = DifferentCfg { inner: Other }; - + let mut x = DifferentCfg { inner: Always }; let x = Pin::new(&mut x).project(); - #[cfg(target_os = "linux")] - let _: Pin<&mut Linux> = x.inner; - #[cfg(not(target_os = "linux"))] - let _: &mut Other = x.inner; + let _: &mut Always = x.inner; #[cfg_attr(not(any()), pin_project)] struct Foo { diff --git a/tests/compiletest.rs b/tests/compiletest.rs index 85b1db8..e3d713a 100644 --- a/tests/compiletest.rs +++ b/tests/compiletest.rs @@ -3,8 +3,7 @@ use std::env; -// Run `./dev.sh +$toolchain test --test compiletest` to update this. -#[rustversion::attr(before(2020-11-25), ignore)] // Note: This date is commit-date and the day before the toolchain date. +#[rustversion::attr(before(2021-01-08), ignore)] // Note: This date is commit-date and the day before the toolchain date. #[test] fn ui() { if env::var_os("CI").is_none() { @@ -12,10 +11,5 @@ fn ui() { } let t = trybuild::TestCases::new(); - t.compile_fail("tests/ui/cfg/*.rs"); - t.compile_fail("tests/ui/not_unpin/*.rs"); - t.compile_fail("tests/ui/pin_project/*.rs"); - t.compile_fail("tests/ui/pinned_drop/*.rs"); - t.compile_fail("tests/ui/unsafe_unpin/*.rs"); - t.compile_fail("tests/ui/unstable-features/*.rs"); + t.compile_fail("tests/ui/*/*.rs"); } diff --git a/tests/drop_order.rs b/tests/drop_order.rs index 1557188..8ced56e 100644 --- a/tests/drop_order.rs +++ b/tests/drop_order.rs @@ -2,9 +2,10 @@ // Refs: https://doc.rust-lang.org/reference/destructors.html -use pin_project::pin_project; use std::{cell::Cell, pin::Pin, thread}; +use pin_project::pin_project; + struct D<'a>(&'a Cell, usize); impl Drop for D<'_> { diff --git a/tests/expand/README.md b/tests/expand/README.md new file mode 100644 index 0000000..e3e708d --- /dev/null +++ b/tests/expand/README.md @@ -0,0 +1,17 @@ +# Expansion tests + +Similar to ui tests, but instead of checking the compiler output, this checks +the code generated by macros. + +See [examples](../../examples/README.md) for descriptions of what the generated +code does, and why it needs to be generated. + +To run this test, run the following command: + +```sh +cargo +nightly test --test expandtest +``` + +Locally, this test updates the files in the `expand` directory if there are +changes to the generated code. If there are any changes to the files in the +`expand` directory after running the test, please commit them. diff --git a/tests/expand/default/enum.expanded.rs b/tests/expand/default/enum.expanded.rs new file mode 100644 index 0000000..490c6b0 --- /dev/null +++ b/tests/expand/default/enum.expanded.rs @@ -0,0 +1,131 @@ +use pin_project::pin_project; +# [pin (__private (project = EnumProj , project_ref = EnumProjRef))] +enum Enum { + Struct { + #[pin] + pinned: T, + unpinned: U, + }, + Tuple(#[pin] T, U), + Unit, +} +#[allow(box_pointers)] +#[allow(deprecated)] +#[allow(explicit_outlives_requirements)] +#[allow(single_use_lifetimes)] +#[allow(unreachable_pub)] +#[allow(clippy::unknown_clippy_lints)] +#[allow(clippy::pattern_type_mismatch)] +#[allow(clippy::redundant_pub_crate)] +#[allow(dead_code)] +#[allow(clippy::mut_mut)] +#[allow(clippy::type_repetition_in_bounds)] +enum EnumProj<'pin, T, U> +where + Enum: 'pin, +{ + Struct { + pinned: ::pin_project::__private::Pin<&'pin mut (T)>, + unpinned: &'pin mut (U), + }, + Tuple(::pin_project::__private::Pin<&'pin mut (T)>, &'pin mut (U)), + Unit, +} +#[allow(box_pointers)] +#[allow(deprecated)] +#[allow(explicit_outlives_requirements)] +#[allow(single_use_lifetimes)] +#[allow(unreachable_pub)] +#[allow(clippy::unknown_clippy_lints)] +#[allow(clippy::pattern_type_mismatch)] +#[allow(clippy::redundant_pub_crate)] +#[allow(dead_code)] +#[allow(clippy::ref_option_ref)] +#[allow(clippy::type_repetition_in_bounds)] +enum EnumProjRef<'pin, T, U> +where + Enum: 'pin, +{ + Struct { + pinned: ::pin_project::__private::Pin<&'pin (T)>, + unpinned: &'pin (U), + }, + Tuple(::pin_project::__private::Pin<&'pin (T)>, &'pin (U)), + Unit, +} +#[allow(box_pointers)] +#[allow(deprecated)] +#[allow(explicit_outlives_requirements)] +#[allow(single_use_lifetimes)] +#[allow(unreachable_pub)] +#[allow(clippy::unknown_clippy_lints)] +#[allow(clippy::pattern_type_mismatch)] +#[allow(clippy::redundant_pub_crate)] +#[allow(clippy::used_underscore_binding)] +const _: () = { + impl Enum { + fn project<'pin>( + self: ::pin_project::__private::Pin<&'pin mut Self>, + ) -> EnumProj<'pin, T, U> { + unsafe { + match self.get_unchecked_mut() { + Self::Struct { pinned, unpinned } => EnumProj::Struct { + pinned: ::pin_project::__private::Pin::new_unchecked(pinned), + unpinned, + }, + Self::Tuple(_0, _1) => { + EnumProj::Tuple(::pin_project::__private::Pin::new_unchecked(_0), _1) + } + Self::Unit => EnumProj::Unit, + } + } + } + #[allow(clippy::missing_const_for_fn)] + fn project_ref<'pin>( + self: ::pin_project::__private::Pin<&'pin Self>, + ) -> EnumProjRef<'pin, T, U> { + unsafe { + match self.get_ref() { + Self::Struct { pinned, unpinned } => EnumProjRef::Struct { + pinned: ::pin_project::__private::Pin::new_unchecked(pinned), + unpinned, + }, + Self::Tuple(_0, _1) => { + EnumProjRef::Tuple(::pin_project::__private::Pin::new_unchecked(_0), _1) + } + Self::Unit => EnumProjRef::Unit, + } + } + } + } + #[allow(missing_debug_implementations)] + struct __Enum<'pin, T, U> { + __pin_project_use_generics: ::pin_project::__private::AlwaysUnpin< + 'pin, + ( + ::pin_project::__private::PhantomData, + ::pin_project::__private::PhantomData, + ), + >, + __field0: T, + __field1: T, + } + impl<'pin, T, U> ::pin_project::__private::Unpin for Enum where + __Enum<'pin, T, U>: ::pin_project::__private::Unpin + { + } + #[doc(hidden)] + unsafe impl<'pin, T, U> ::pin_project::UnsafeUnpin for Enum where + __Enum<'pin, T, U>: ::pin_project::__private::Unpin + { + } + trait EnumMustNotImplDrop {} + #[allow(clippy::drop_bounds, drop_bounds)] + impl EnumMustNotImplDrop for T {} + impl EnumMustNotImplDrop for Enum {} + #[doc(hidden)] + impl ::pin_project::__private::PinnedDrop for Enum { + unsafe fn drop(self: ::pin_project::__private::Pin<&mut Self>) {} + } +}; +fn main() {} diff --git a/tests/expand/default/enum.rs b/tests/expand/default/enum.rs new file mode 100644 index 0000000..ff05615 --- /dev/null +++ b/tests/expand/default/enum.rs @@ -0,0 +1,14 @@ +use pin_project::pin_project; + +#[pin_project(project = EnumProj, project_ref = EnumProjRef)] +enum Enum { + Struct { + #[pin] + pinned: T, + unpinned: U, + }, + Tuple(#[pin] T, U), + Unit, +} + +fn main() {} diff --git a/tests/expand/default/struct.expanded.rs b/tests/expand/default/struct.expanded.rs new file mode 100644 index 0000000..ac878b8 --- /dev/null +++ b/tests/expand/default/struct.expanded.rs @@ -0,0 +1,113 @@ +use pin_project::pin_project; +#[pin(__private())] +struct Struct { + #[pin] + pinned: T, + unpinned: U, +} +#[allow(box_pointers)] +#[allow(deprecated)] +#[allow(explicit_outlives_requirements)] +#[allow(single_use_lifetimes)] +#[allow(unreachable_pub)] +#[allow(clippy::unknown_clippy_lints)] +#[allow(clippy::pattern_type_mismatch)] +#[allow(clippy::redundant_pub_crate)] +#[allow(clippy::used_underscore_binding)] +const _: () = { + #[allow(box_pointers)] + #[allow(deprecated)] + #[allow(explicit_outlives_requirements)] + #[allow(single_use_lifetimes)] + #[allow(unreachable_pub)] + #[allow(clippy::unknown_clippy_lints)] + #[allow(clippy::pattern_type_mismatch)] + #[allow(clippy::redundant_pub_crate)] + #[allow(dead_code)] + #[allow(clippy::mut_mut)] + #[allow(clippy::type_repetition_in_bounds)] + struct __StructProjection<'pin, T, U> + where + Struct: 'pin, + { + pinned: ::pin_project::__private::Pin<&'pin mut (T)>, + unpinned: &'pin mut (U), + } + #[allow(box_pointers)] + #[allow(deprecated)] + #[allow(explicit_outlives_requirements)] + #[allow(single_use_lifetimes)] + #[allow(unreachable_pub)] + #[allow(clippy::unknown_clippy_lints)] + #[allow(clippy::pattern_type_mismatch)] + #[allow(clippy::redundant_pub_crate)] + #[allow(dead_code)] + #[allow(clippy::ref_option_ref)] + #[allow(clippy::type_repetition_in_bounds)] + struct __StructProjectionRef<'pin, T, U> + where + Struct: 'pin, + { + pinned: ::pin_project::__private::Pin<&'pin (T)>, + unpinned: &'pin (U), + } + impl Struct { + fn project<'pin>( + self: ::pin_project::__private::Pin<&'pin mut Self>, + ) -> __StructProjection<'pin, T, U> { + unsafe { + let Self { pinned, unpinned } = self.get_unchecked_mut(); + __StructProjection { + pinned: ::pin_project::__private::Pin::new_unchecked(pinned), + unpinned, + } + } + } + #[allow(clippy::missing_const_for_fn)] + fn project_ref<'pin>( + self: ::pin_project::__private::Pin<&'pin Self>, + ) -> __StructProjectionRef<'pin, T, U> { + unsafe { + let Self { pinned, unpinned } = self.get_ref(); + __StructProjectionRef { + pinned: ::pin_project::__private::Pin::new_unchecked(pinned), + unpinned, + } + } + } + } + #[forbid(safe_packed_borrows)] + fn __assert_not_repr_packed(this: &Struct) { + let _ = &this.pinned; + let _ = &this.unpinned; + } + #[allow(missing_debug_implementations)] + struct __Struct<'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 Struct where + __Struct<'pin, T, U>: ::pin_project::__private::Unpin + { + } + #[doc(hidden)] + unsafe impl<'pin, T, U> ::pin_project::UnsafeUnpin for Struct where + __Struct<'pin, T, U>: ::pin_project::__private::Unpin + { + } + trait StructMustNotImplDrop {} + #[allow(clippy::drop_bounds, drop_bounds)] + impl StructMustNotImplDrop for T {} + impl StructMustNotImplDrop for Struct {} + #[doc(hidden)] + impl ::pin_project::__private::PinnedDrop for Struct { + unsafe fn drop(self: ::pin_project::__private::Pin<&mut Self>) {} + } +}; +fn main() {} diff --git a/tests/expand/default/struct.rs b/tests/expand/default/struct.rs new file mode 100644 index 0000000..474f0a1 --- /dev/null +++ b/tests/expand/default/struct.rs @@ -0,0 +1,10 @@ +use pin_project::pin_project; + +#[pin_project] +struct Struct { + #[pin] + pinned: T, + unpinned: U, +} + +fn main() {} diff --git a/tests/expand/default/tuple_struct.expanded.rs b/tests/expand/default/tuple_struct.expanded.rs new file mode 100644 index 0000000..0c5cc1d --- /dev/null +++ b/tests/expand/default/tuple_struct.expanded.rs @@ -0,0 +1,101 @@ +use pin_project::pin_project; +#[pin(__private())] +struct TupleStruct(#[pin] T, U); +#[allow(box_pointers)] +#[allow(deprecated)] +#[allow(explicit_outlives_requirements)] +#[allow(single_use_lifetimes)] +#[allow(unreachable_pub)] +#[allow(clippy::unknown_clippy_lints)] +#[allow(clippy::pattern_type_mismatch)] +#[allow(clippy::redundant_pub_crate)] +#[allow(clippy::used_underscore_binding)] +const _: () = { + #[allow(box_pointers)] + #[allow(deprecated)] + #[allow(explicit_outlives_requirements)] + #[allow(single_use_lifetimes)] + #[allow(unreachable_pub)] + #[allow(clippy::unknown_clippy_lints)] + #[allow(clippy::pattern_type_mismatch)] + #[allow(clippy::redundant_pub_crate)] + #[allow(dead_code)] + #[allow(clippy::mut_mut)] + #[allow(clippy::type_repetition_in_bounds)] + struct __TupleStructProjection<'pin, T, U>( + ::pin_project::__private::Pin<&'pin mut (T)>, + &'pin mut (U), + ) + where + TupleStruct: 'pin; + #[allow(box_pointers)] + #[allow(deprecated)] + #[allow(explicit_outlives_requirements)] + #[allow(single_use_lifetimes)] + #[allow(unreachable_pub)] + #[allow(clippy::unknown_clippy_lints)] + #[allow(clippy::pattern_type_mismatch)] + #[allow(clippy::redundant_pub_crate)] + #[allow(dead_code)] + #[allow(clippy::ref_option_ref)] + #[allow(clippy::type_repetition_in_bounds)] + struct __TupleStructProjectionRef<'pin, T, U>( + ::pin_project::__private::Pin<&'pin (T)>, + &'pin (U), + ) + where + TupleStruct: 'pin; + impl TupleStruct { + fn project<'pin>( + self: ::pin_project::__private::Pin<&'pin mut Self>, + ) -> __TupleStructProjection<'pin, T, U> { + unsafe { + let Self(_0, _1) = self.get_unchecked_mut(); + __TupleStructProjection(::pin_project::__private::Pin::new_unchecked(_0), _1) + } + } + #[allow(clippy::missing_const_for_fn)] + fn project_ref<'pin>( + self: ::pin_project::__private::Pin<&'pin Self>, + ) -> __TupleStructProjectionRef<'pin, T, U> { + unsafe { + let Self(_0, _1) = self.get_ref(); + __TupleStructProjectionRef(::pin_project::__private::Pin::new_unchecked(_0), _1) + } + } + } + #[forbid(safe_packed_borrows)] + fn __assert_not_repr_packed(this: &TupleStruct) { + let _ = &this.0; + let _ = &this.1; + } + #[allow(missing_debug_implementations)] + struct __TupleStruct<'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 TupleStruct where + __TupleStruct<'pin, T, U>: ::pin_project::__private::Unpin + { + } + #[doc(hidden)] + unsafe impl<'pin, T, U> ::pin_project::UnsafeUnpin for TupleStruct where + __TupleStruct<'pin, T, U>: ::pin_project::__private::Unpin + { + } + trait TupleStructMustNotImplDrop {} + #[allow(clippy::drop_bounds, drop_bounds)] + impl TupleStructMustNotImplDrop for T {} + impl TupleStructMustNotImplDrop for TupleStruct {} + #[doc(hidden)] + impl ::pin_project::__private::PinnedDrop for TupleStruct { + unsafe fn drop(self: ::pin_project::__private::Pin<&mut Self>) {} + } +}; +fn main() {} diff --git a/tests/expand/default/tuple_struct.rs b/tests/expand/default/tuple_struct.rs new file mode 100644 index 0000000..398b14f --- /dev/null +++ b/tests/expand/default/tuple_struct.rs @@ -0,0 +1,6 @@ +use pin_project::pin_project; + +#[pin_project] +struct TupleStruct(#[pin] T, U); + +fn main() {} diff --git a/tests/expand/multifields/enum.expanded.rs b/tests/expand/multifields/enum.expanded.rs new file mode 100644 index 0000000..75e1efe --- /dev/null +++ b/tests/expand/multifields/enum.expanded.rs @@ -0,0 +1,246 @@ +use pin_project::pin_project; +# [pin (__private (project = EnumProj , project_ref = EnumProjRef , project_replace = EnumProjOwn))] +enum Enum { + Struct { + #[pin] + pinned1: T, + #[pin] + pinned2: T, + unpinned1: U, + unpinned2: U, + }, + Tuple(#[pin] T, #[pin] T, U, U), + Unit, +} +#[allow(box_pointers)] +#[allow(deprecated)] +#[allow(explicit_outlives_requirements)] +#[allow(single_use_lifetimes)] +#[allow(unreachable_pub)] +#[allow(clippy::unknown_clippy_lints)] +#[allow(clippy::pattern_type_mismatch)] +#[allow(clippy::redundant_pub_crate)] +#[allow(dead_code)] +#[allow(clippy::mut_mut)] +#[allow(clippy::type_repetition_in_bounds)] +enum EnumProj<'pin, T, U> +where + Enum: 'pin, +{ + Struct { + pinned1: ::pin_project::__private::Pin<&'pin mut (T)>, + pinned2: ::pin_project::__private::Pin<&'pin mut (T)>, + unpinned1: &'pin mut (U), + unpinned2: &'pin mut (U), + }, + Tuple( + ::pin_project::__private::Pin<&'pin mut (T)>, + ::pin_project::__private::Pin<&'pin mut (T)>, + &'pin mut (U), + &'pin mut (U), + ), + Unit, +} +#[allow(box_pointers)] +#[allow(deprecated)] +#[allow(explicit_outlives_requirements)] +#[allow(single_use_lifetimes)] +#[allow(unreachable_pub)] +#[allow(clippy::unknown_clippy_lints)] +#[allow(clippy::pattern_type_mismatch)] +#[allow(clippy::redundant_pub_crate)] +#[allow(dead_code)] +#[allow(clippy::ref_option_ref)] +#[allow(clippy::type_repetition_in_bounds)] +enum EnumProjRef<'pin, T, U> +where + Enum: 'pin, +{ + Struct { + pinned1: ::pin_project::__private::Pin<&'pin (T)>, + pinned2: ::pin_project::__private::Pin<&'pin (T)>, + unpinned1: &'pin (U), + unpinned2: &'pin (U), + }, + Tuple( + ::pin_project::__private::Pin<&'pin (T)>, + ::pin_project::__private::Pin<&'pin (T)>, + &'pin (U), + &'pin (U), + ), + Unit, +} +#[allow(box_pointers)] +#[allow(deprecated)] +#[allow(explicit_outlives_requirements)] +#[allow(single_use_lifetimes)] +#[allow(unreachable_pub)] +#[allow(clippy::unknown_clippy_lints)] +#[allow(clippy::pattern_type_mismatch)] +#[allow(clippy::redundant_pub_crate)] +#[allow(dead_code)] +#[allow(variant_size_differences)] +#[allow(clippy::large_enum_variant)] +enum EnumProjOwn { + Struct { + pinned1: ::pin_project::__private::PhantomData, + pinned2: ::pin_project::__private::PhantomData, + unpinned1: U, + unpinned2: U, + }, + Tuple( + ::pin_project::__private::PhantomData, + ::pin_project::__private::PhantomData, + U, + U, + ), + Unit, +} +#[allow(box_pointers)] +#[allow(deprecated)] +#[allow(explicit_outlives_requirements)] +#[allow(single_use_lifetimes)] +#[allow(unreachable_pub)] +#[allow(clippy::unknown_clippy_lints)] +#[allow(clippy::pattern_type_mismatch)] +#[allow(clippy::redundant_pub_crate)] +#[allow(clippy::used_underscore_binding)] +const _: () = { + impl Enum { + fn project<'pin>( + self: ::pin_project::__private::Pin<&'pin mut Self>, + ) -> EnumProj<'pin, T, U> { + unsafe { + match self.get_unchecked_mut() { + Self::Struct { + pinned1, + pinned2, + unpinned1, + unpinned2, + } => EnumProj::Struct { + pinned1: ::pin_project::__private::Pin::new_unchecked(pinned1), + pinned2: ::pin_project::__private::Pin::new_unchecked(pinned2), + unpinned1, + unpinned2, + }, + Self::Tuple(_0, _1, _2, _3) => EnumProj::Tuple( + ::pin_project::__private::Pin::new_unchecked(_0), + ::pin_project::__private::Pin::new_unchecked(_1), + _2, + _3, + ), + Self::Unit => EnumProj::Unit, + } + } + } + #[allow(clippy::missing_const_for_fn)] + fn project_ref<'pin>( + self: ::pin_project::__private::Pin<&'pin Self>, + ) -> EnumProjRef<'pin, T, U> { + unsafe { + match self.get_ref() { + Self::Struct { + pinned1, + pinned2, + unpinned1, + unpinned2, + } => EnumProjRef::Struct { + pinned1: ::pin_project::__private::Pin::new_unchecked(pinned1), + pinned2: ::pin_project::__private::Pin::new_unchecked(pinned2), + unpinned1, + unpinned2, + }, + Self::Tuple(_0, _1, _2, _3) => EnumProjRef::Tuple( + ::pin_project::__private::Pin::new_unchecked(_0), + ::pin_project::__private::Pin::new_unchecked(_1), + _2, + _3, + ), + Self::Unit => EnumProjRef::Unit, + } + } + } + fn project_replace( + self: ::pin_project::__private::Pin<&mut Self>, + __replacement: Self, + ) -> EnumProjOwn { + unsafe { + let __self_ptr: *mut Self = self.get_unchecked_mut(); + let __guard = ::pin_project::__private::UnsafeOverwriteGuard { + target: __self_ptr, + value: ::pin_project::__private::ManuallyDrop::new(__replacement), + }; + match &mut *__self_ptr { + Self::Struct { + pinned1, + pinned2, + unpinned1, + unpinned2, + } => { + let __result = EnumProjOwn::Struct { + pinned1: ::pin_project::__private::PhantomData, + pinned2: ::pin_project::__private::PhantomData, + unpinned1: ::pin_project::__private::ptr::read(unpinned1), + unpinned2: ::pin_project::__private::ptr::read(unpinned2), + }; + { + let __guard = ::pin_project::__private::UnsafeDropInPlaceGuard(pinned2); + let __guard = ::pin_project::__private::UnsafeDropInPlaceGuard(pinned1); + } + __result + } + Self::Tuple(_0, _1, _2, _3) => { + let __result = EnumProjOwn::Tuple( + ::pin_project::__private::PhantomData, + ::pin_project::__private::PhantomData, + ::pin_project::__private::ptr::read(_2), + ::pin_project::__private::ptr::read(_3), + ); + { + let __guard = ::pin_project::__private::UnsafeDropInPlaceGuard(_1); + let __guard = ::pin_project::__private::UnsafeDropInPlaceGuard(_0); + } + __result + } + Self::Unit => { + let __result = EnumProjOwn::Unit; + {} + __result + } + } + } + } + } + #[allow(missing_debug_implementations)] + struct __Enum<'pin, T, U> { + __pin_project_use_generics: ::pin_project::__private::AlwaysUnpin< + 'pin, + ( + ::pin_project::__private::PhantomData, + ::pin_project::__private::PhantomData, + ), + >, + __field0: T, + __field1: T, + __field2: T, + __field3: T, + } + impl<'pin, T, U> ::pin_project::__private::Unpin for Enum where + __Enum<'pin, T, U>: ::pin_project::__private::Unpin + { + } + #[doc(hidden)] + unsafe impl<'pin, T, U> ::pin_project::UnsafeUnpin for Enum where + __Enum<'pin, T, U>: ::pin_project::__private::Unpin + { + } + trait EnumMustNotImplDrop {} + #[allow(clippy::drop_bounds, drop_bounds)] + impl EnumMustNotImplDrop for T {} + impl EnumMustNotImplDrop for Enum {} + #[doc(hidden)] + impl ::pin_project::__private::PinnedDrop for Enum { + unsafe fn drop(self: ::pin_project::__private::Pin<&mut Self>) {} + } +}; +fn main() {} diff --git a/tests/expand/multifields/enum.rs b/tests/expand/multifields/enum.rs new file mode 100644 index 0000000..754d48c --- /dev/null +++ b/tests/expand/multifields/enum.rs @@ -0,0 +1,17 @@ +use pin_project::pin_project; + +#[pin_project(project = EnumProj, project_ref = EnumProjRef, project_replace = EnumProjOwn)] +enum Enum { + Struct { + #[pin] + pinned1: T, + #[pin] + pinned2: T, + unpinned1: U, + unpinned2: U, + }, + Tuple(#[pin] T, #[pin] T, U, U), + Unit, +} + +fn main() {} diff --git a/tests/expand/multifields/struct.expanded.rs b/tests/expand/multifields/struct.expanded.rs new file mode 100644 index 0000000..bd4e6e3 --- /dev/null +++ b/tests/expand/multifields/struct.expanded.rs @@ -0,0 +1,181 @@ +use pin_project::pin_project; +#[pin(__private(project_replace))] +struct Struct { + #[pin] + pinned1: T, + #[pin] + pinned2: T, + unpinned1: U, + unpinned2: U, +} +#[allow(box_pointers)] +#[allow(deprecated)] +#[allow(explicit_outlives_requirements)] +#[allow(single_use_lifetimes)] +#[allow(unreachable_pub)] +#[allow(clippy::unknown_clippy_lints)] +#[allow(clippy::pattern_type_mismatch)] +#[allow(clippy::redundant_pub_crate)] +#[allow(clippy::used_underscore_binding)] +const _: () = { + #[allow(box_pointers)] + #[allow(deprecated)] + #[allow(explicit_outlives_requirements)] + #[allow(single_use_lifetimes)] + #[allow(unreachable_pub)] + #[allow(clippy::unknown_clippy_lints)] + #[allow(clippy::pattern_type_mismatch)] + #[allow(clippy::redundant_pub_crate)] + #[allow(dead_code)] + #[allow(clippy::mut_mut)] + #[allow(clippy::type_repetition_in_bounds)] + struct __StructProjection<'pin, T, U> + where + Struct: 'pin, + { + pinned1: ::pin_project::__private::Pin<&'pin mut (T)>, + pinned2: ::pin_project::__private::Pin<&'pin mut (T)>, + unpinned1: &'pin mut (U), + unpinned2: &'pin mut (U), + } + #[allow(box_pointers)] + #[allow(deprecated)] + #[allow(explicit_outlives_requirements)] + #[allow(single_use_lifetimes)] + #[allow(unreachable_pub)] + #[allow(clippy::unknown_clippy_lints)] + #[allow(clippy::pattern_type_mismatch)] + #[allow(clippy::redundant_pub_crate)] + #[allow(dead_code)] + #[allow(clippy::ref_option_ref)] + #[allow(clippy::type_repetition_in_bounds)] + struct __StructProjectionRef<'pin, T, U> + where + Struct: 'pin, + { + pinned1: ::pin_project::__private::Pin<&'pin (T)>, + pinned2: ::pin_project::__private::Pin<&'pin (T)>, + unpinned1: &'pin (U), + unpinned2: &'pin (U), + } + #[allow(box_pointers)] + #[allow(deprecated)] + #[allow(explicit_outlives_requirements)] + #[allow(single_use_lifetimes)] + #[allow(unreachable_pub)] + #[allow(clippy::unknown_clippy_lints)] + #[allow(clippy::pattern_type_mismatch)] + #[allow(clippy::redundant_pub_crate)] + #[allow(dead_code)] + struct __StructProjectionOwned { + pinned1: ::pin_project::__private::PhantomData, + pinned2: ::pin_project::__private::PhantomData, + unpinned1: U, + unpinned2: U, + } + impl Struct { + fn project<'pin>( + self: ::pin_project::__private::Pin<&'pin mut Self>, + ) -> __StructProjection<'pin, T, U> { + unsafe { + let Self { + pinned1, + pinned2, + unpinned1, + unpinned2, + } = self.get_unchecked_mut(); + __StructProjection { + pinned1: ::pin_project::__private::Pin::new_unchecked(pinned1), + pinned2: ::pin_project::__private::Pin::new_unchecked(pinned2), + unpinned1, + unpinned2, + } + } + } + #[allow(clippy::missing_const_for_fn)] + fn project_ref<'pin>( + self: ::pin_project::__private::Pin<&'pin Self>, + ) -> __StructProjectionRef<'pin, T, U> { + unsafe { + let Self { + pinned1, + pinned2, + unpinned1, + unpinned2, + } = self.get_ref(); + __StructProjectionRef { + pinned1: ::pin_project::__private::Pin::new_unchecked(pinned1), + pinned2: ::pin_project::__private::Pin::new_unchecked(pinned2), + unpinned1, + unpinned2, + } + } + } + fn project_replace( + self: ::pin_project::__private::Pin<&mut Self>, + __replacement: Self, + ) -> __StructProjectionOwned { + unsafe { + let __self_ptr: *mut Self = self.get_unchecked_mut(); + let __guard = ::pin_project::__private::UnsafeOverwriteGuard { + target: __self_ptr, + value: ::pin_project::__private::ManuallyDrop::new(__replacement), + }; + let Self { + pinned1, + pinned2, + unpinned1, + unpinned2, + } = &mut *__self_ptr; + let __result = __StructProjectionOwned { + pinned1: ::pin_project::__private::PhantomData, + pinned2: ::pin_project::__private::PhantomData, + unpinned1: ::pin_project::__private::ptr::read(unpinned1), + unpinned2: ::pin_project::__private::ptr::read(unpinned2), + }; + { + let __guard = ::pin_project::__private::UnsafeDropInPlaceGuard(pinned2); + let __guard = ::pin_project::__private::UnsafeDropInPlaceGuard(pinned1); + } + __result + } + } + } + #[forbid(safe_packed_borrows)] + fn __assert_not_repr_packed(this: &Struct) { + let _ = &this.pinned1; + let _ = &this.pinned2; + let _ = &this.unpinned1; + let _ = &this.unpinned2; + } + #[allow(missing_debug_implementations)] + struct __Struct<'pin, T, U> { + __pin_project_use_generics: ::pin_project::__private::AlwaysUnpin< + 'pin, + ( + ::pin_project::__private::PhantomData, + ::pin_project::__private::PhantomData, + ), + >, + __field0: T, + __field1: T, + } + impl<'pin, T, U> ::pin_project::__private::Unpin for Struct where + __Struct<'pin, T, U>: ::pin_project::__private::Unpin + { + } + #[doc(hidden)] + unsafe impl<'pin, T, U> ::pin_project::UnsafeUnpin for Struct where + __Struct<'pin, T, U>: ::pin_project::__private::Unpin + { + } + trait StructMustNotImplDrop {} + #[allow(clippy::drop_bounds, drop_bounds)] + impl StructMustNotImplDrop for T {} + impl StructMustNotImplDrop for Struct {} + #[doc(hidden)] + impl ::pin_project::__private::PinnedDrop for Struct { + unsafe fn drop(self: ::pin_project::__private::Pin<&mut Self>) {} + } +}; +fn main() {} diff --git a/tests/expand/multifields/struct.rs b/tests/expand/multifields/struct.rs new file mode 100644 index 0000000..3b319bf --- /dev/null +++ b/tests/expand/multifields/struct.rs @@ -0,0 +1,13 @@ +use pin_project::pin_project; + +#[pin_project(project_replace)] +struct Struct { + #[pin] + pinned1: T, + #[pin] + pinned2: T, + unpinned1: U, + unpinned2: U, +} + +fn main() {} diff --git a/tests/expand/multifields/tuple_struct.expanded.rs b/tests/expand/multifields/tuple_struct.expanded.rs new file mode 100644 index 0000000..1ec045c --- /dev/null +++ b/tests/expand/multifields/tuple_struct.expanded.rs @@ -0,0 +1,157 @@ +use pin_project::pin_project; +#[pin(__private(project_replace))] +struct TupleStruct(#[pin] T, #[pin] T, U, U); +#[allow(box_pointers)] +#[allow(deprecated)] +#[allow(explicit_outlives_requirements)] +#[allow(single_use_lifetimes)] +#[allow(unreachable_pub)] +#[allow(clippy::unknown_clippy_lints)] +#[allow(clippy::pattern_type_mismatch)] +#[allow(clippy::redundant_pub_crate)] +#[allow(clippy::used_underscore_binding)] +const _: () = { + #[allow(box_pointers)] + #[allow(deprecated)] + #[allow(explicit_outlives_requirements)] + #[allow(single_use_lifetimes)] + #[allow(unreachable_pub)] + #[allow(clippy::unknown_clippy_lints)] + #[allow(clippy::pattern_type_mismatch)] + #[allow(clippy::redundant_pub_crate)] + #[allow(dead_code)] + #[allow(clippy::mut_mut)] + #[allow(clippy::type_repetition_in_bounds)] + struct __TupleStructProjection<'pin, T, U>( + ::pin_project::__private::Pin<&'pin mut (T)>, + ::pin_project::__private::Pin<&'pin mut (T)>, + &'pin mut (U), + &'pin mut (U), + ) + where + TupleStruct: 'pin; + #[allow(box_pointers)] + #[allow(deprecated)] + #[allow(explicit_outlives_requirements)] + #[allow(single_use_lifetimes)] + #[allow(unreachable_pub)] + #[allow(clippy::unknown_clippy_lints)] + #[allow(clippy::pattern_type_mismatch)] + #[allow(clippy::redundant_pub_crate)] + #[allow(dead_code)] + #[allow(clippy::ref_option_ref)] + #[allow(clippy::type_repetition_in_bounds)] + struct __TupleStructProjectionRef<'pin, T, U>( + ::pin_project::__private::Pin<&'pin (T)>, + ::pin_project::__private::Pin<&'pin (T)>, + &'pin (U), + &'pin (U), + ) + where + TupleStruct: 'pin; + #[allow(box_pointers)] + #[allow(deprecated)] + #[allow(explicit_outlives_requirements)] + #[allow(single_use_lifetimes)] + #[allow(unreachable_pub)] + #[allow(clippy::unknown_clippy_lints)] + #[allow(clippy::pattern_type_mismatch)] + #[allow(clippy::redundant_pub_crate)] + #[allow(dead_code)] + struct __TupleStructProjectionOwned( + ::pin_project::__private::PhantomData, + ::pin_project::__private::PhantomData, + U, + U, + ); + impl TupleStruct { + fn project<'pin>( + self: ::pin_project::__private::Pin<&'pin mut Self>, + ) -> __TupleStructProjection<'pin, T, U> { + unsafe { + let Self(_0, _1, _2, _3) = self.get_unchecked_mut(); + __TupleStructProjection( + ::pin_project::__private::Pin::new_unchecked(_0), + ::pin_project::__private::Pin::new_unchecked(_1), + _2, + _3, + ) + } + } + #[allow(clippy::missing_const_for_fn)] + fn project_ref<'pin>( + self: ::pin_project::__private::Pin<&'pin Self>, + ) -> __TupleStructProjectionRef<'pin, T, U> { + unsafe { + let Self(_0, _1, _2, _3) = self.get_ref(); + __TupleStructProjectionRef( + ::pin_project::__private::Pin::new_unchecked(_0), + ::pin_project::__private::Pin::new_unchecked(_1), + _2, + _3, + ) + } + } + fn project_replace( + self: ::pin_project::__private::Pin<&mut Self>, + __replacement: Self, + ) -> __TupleStructProjectionOwned { + unsafe { + let __self_ptr: *mut Self = self.get_unchecked_mut(); + let __guard = ::pin_project::__private::UnsafeOverwriteGuard { + target: __self_ptr, + value: ::pin_project::__private::ManuallyDrop::new(__replacement), + }; + let Self(_0, _1, _2, _3) = &mut *__self_ptr; + let __result = __TupleStructProjectionOwned( + ::pin_project::__private::PhantomData, + ::pin_project::__private::PhantomData, + ::pin_project::__private::ptr::read(_2), + ::pin_project::__private::ptr::read(_3), + ); + { + let __guard = ::pin_project::__private::UnsafeDropInPlaceGuard(_1); + let __guard = ::pin_project::__private::UnsafeDropInPlaceGuard(_0); + } + __result + } + } + } + #[forbid(safe_packed_borrows)] + fn __assert_not_repr_packed(this: &TupleStruct) { + let _ = &this.0; + let _ = &this.1; + let _ = &this.2; + let _ = &this.3; + } + #[allow(missing_debug_implementations)] + struct __TupleStruct<'pin, T, U> { + __pin_project_use_generics: ::pin_project::__private::AlwaysUnpin< + 'pin, + ( + ::pin_project::__private::PhantomData, + ::pin_project::__private::PhantomData, + ), + >, + __field0: T, + __field1: T, + } + impl<'pin, T, U> ::pin_project::__private::Unpin for TupleStruct where + __TupleStruct<'pin, T, U>: ::pin_project::__private::Unpin + { + } + #[doc(hidden)] + unsafe impl<'pin, T, U> ::pin_project::UnsafeUnpin for TupleStruct where + __TupleStruct<'pin, T, U>: ::pin_project::__private::Unpin + { + } + trait TupleStructMustNotImplDrop {} + #[allow(clippy::drop_bounds, drop_bounds)] + impl TupleStructMustNotImplDrop for T {} + impl TupleStructMustNotImplDrop for TupleStruct {} + #[doc(hidden)] + impl ::pin_project::__private::PinnedDrop for TupleStruct { + unsafe fn drop(self: ::pin_project::__private::Pin<&mut Self>) {} + } +}; +fn main() {} diff --git a/tests/expand/multifields/tuple_struct.rs b/tests/expand/multifields/tuple_struct.rs new file mode 100644 index 0000000..bc92eee --- /dev/null +++ b/tests/expand/multifields/tuple_struct.rs @@ -0,0 +1,6 @@ +use pin_project::pin_project; + +#[pin_project(project_replace)] +struct TupleStruct(#[pin] T, #[pin] T, U, U); + +fn main() {} diff --git a/tests/expand/naming/enum-all.expanded.rs b/tests/expand/naming/enum-all.expanded.rs new file mode 100644 index 0000000..22d1b8f --- /dev/null +++ b/tests/expand/naming/enum-all.expanded.rs @@ -0,0 +1,187 @@ +use pin_project::pin_project; +# [pin (__private (project = Proj , project_ref = ProjRef , project_replace = ProjOwn))] +enum Enum { + Struct { + #[pin] + pinned: T, + unpinned: U, + }, + Tuple(#[pin] T, U), + Unit, +} +#[allow(box_pointers)] +#[allow(deprecated)] +#[allow(explicit_outlives_requirements)] +#[allow(single_use_lifetimes)] +#[allow(unreachable_pub)] +#[allow(clippy::unknown_clippy_lints)] +#[allow(clippy::pattern_type_mismatch)] +#[allow(clippy::redundant_pub_crate)] +#[allow(dead_code)] +#[allow(clippy::mut_mut)] +#[allow(clippy::type_repetition_in_bounds)] +enum Proj<'pin, T, U> +where + Enum: 'pin, +{ + Struct { + pinned: ::pin_project::__private::Pin<&'pin mut (T)>, + unpinned: &'pin mut (U), + }, + Tuple(::pin_project::__private::Pin<&'pin mut (T)>, &'pin mut (U)), + Unit, +} +#[allow(box_pointers)] +#[allow(deprecated)] +#[allow(explicit_outlives_requirements)] +#[allow(single_use_lifetimes)] +#[allow(unreachable_pub)] +#[allow(clippy::unknown_clippy_lints)] +#[allow(clippy::pattern_type_mismatch)] +#[allow(clippy::redundant_pub_crate)] +#[allow(dead_code)] +#[allow(clippy::ref_option_ref)] +#[allow(clippy::type_repetition_in_bounds)] +enum ProjRef<'pin, T, U> +where + Enum: 'pin, +{ + Struct { + pinned: ::pin_project::__private::Pin<&'pin (T)>, + unpinned: &'pin (U), + }, + Tuple(::pin_project::__private::Pin<&'pin (T)>, &'pin (U)), + Unit, +} +#[allow(box_pointers)] +#[allow(deprecated)] +#[allow(explicit_outlives_requirements)] +#[allow(single_use_lifetimes)] +#[allow(unreachable_pub)] +#[allow(clippy::unknown_clippy_lints)] +#[allow(clippy::pattern_type_mismatch)] +#[allow(clippy::redundant_pub_crate)] +#[allow(dead_code)] +#[allow(variant_size_differences)] +#[allow(clippy::large_enum_variant)] +enum ProjOwn { + Struct { + pinned: ::pin_project::__private::PhantomData, + unpinned: U, + }, + Tuple(::pin_project::__private::PhantomData, U), + Unit, +} +#[allow(box_pointers)] +#[allow(deprecated)] +#[allow(explicit_outlives_requirements)] +#[allow(single_use_lifetimes)] +#[allow(unreachable_pub)] +#[allow(clippy::unknown_clippy_lints)] +#[allow(clippy::pattern_type_mismatch)] +#[allow(clippy::redundant_pub_crate)] +#[allow(clippy::used_underscore_binding)] +const _: () = { + impl Enum { + fn project<'pin>(self: ::pin_project::__private::Pin<&'pin mut Self>) -> Proj<'pin, T, U> { + unsafe { + match self.get_unchecked_mut() { + Self::Struct { pinned, unpinned } => Proj::Struct { + pinned: ::pin_project::__private::Pin::new_unchecked(pinned), + unpinned, + }, + Self::Tuple(_0, _1) => { + Proj::Tuple(::pin_project::__private::Pin::new_unchecked(_0), _1) + } + Self::Unit => Proj::Unit, + } + } + } + #[allow(clippy::missing_const_for_fn)] + fn project_ref<'pin>( + self: ::pin_project::__private::Pin<&'pin Self>, + ) -> ProjRef<'pin, T, U> { + unsafe { + match self.get_ref() { + Self::Struct { pinned, unpinned } => ProjRef::Struct { + pinned: ::pin_project::__private::Pin::new_unchecked(pinned), + unpinned, + }, + Self::Tuple(_0, _1) => { + ProjRef::Tuple(::pin_project::__private::Pin::new_unchecked(_0), _1) + } + Self::Unit => ProjRef::Unit, + } + } + } + fn project_replace( + self: ::pin_project::__private::Pin<&mut Self>, + __replacement: Self, + ) -> ProjOwn { + unsafe { + let __self_ptr: *mut Self = self.get_unchecked_mut(); + let __guard = ::pin_project::__private::UnsafeOverwriteGuard { + target: __self_ptr, + value: ::pin_project::__private::ManuallyDrop::new(__replacement), + }; + match &mut *__self_ptr { + Self::Struct { pinned, unpinned } => { + let __result = ProjOwn::Struct { + pinned: ::pin_project::__private::PhantomData, + unpinned: ::pin_project::__private::ptr::read(unpinned), + }; + { + let __guard = ::pin_project::__private::UnsafeDropInPlaceGuard(pinned); + } + __result + } + Self::Tuple(_0, _1) => { + let __result = ProjOwn::Tuple( + ::pin_project::__private::PhantomData, + ::pin_project::__private::ptr::read(_1), + ); + { + let __guard = ::pin_project::__private::UnsafeDropInPlaceGuard(_0); + } + __result + } + Self::Unit => { + let __result = ProjOwn::Unit; + {} + __result + } + } + } + } + } + #[allow(missing_debug_implementations)] + struct __Enum<'pin, T, U> { + __pin_project_use_generics: ::pin_project::__private::AlwaysUnpin< + 'pin, + ( + ::pin_project::__private::PhantomData, + ::pin_project::__private::PhantomData, + ), + >, + __field0: T, + __field1: T, + } + impl<'pin, T, U> ::pin_project::__private::Unpin for Enum where + __Enum<'pin, T, U>: ::pin_project::__private::Unpin + { + } + #[doc(hidden)] + unsafe impl<'pin, T, U> ::pin_project::UnsafeUnpin for Enum where + __Enum<'pin, T, U>: ::pin_project::__private::Unpin + { + } + trait EnumMustNotImplDrop {} + #[allow(clippy::drop_bounds, drop_bounds)] + impl EnumMustNotImplDrop for T {} + impl EnumMustNotImplDrop for Enum {} + #[doc(hidden)] + impl ::pin_project::__private::PinnedDrop for Enum { + unsafe fn drop(self: ::pin_project::__private::Pin<&mut Self>) {} + } +}; +fn main() {} diff --git a/tests/expand/naming/enum-all.rs b/tests/expand/naming/enum-all.rs new file mode 100644 index 0000000..dd513e6 --- /dev/null +++ b/tests/expand/naming/enum-all.rs @@ -0,0 +1,14 @@ +use pin_project::pin_project; + +#[pin_project(project = Proj, project_ref = ProjRef, project_replace = ProjOwn)] +enum Enum { + Struct { + #[pin] + pinned: T, + unpinned: U, + }, + Tuple(#[pin] T, U), + Unit, +} + +fn main() {} diff --git a/tests/expand/naming/enum-mut.expanded.rs b/tests/expand/naming/enum-mut.expanded.rs new file mode 100644 index 0000000..fec425c --- /dev/null +++ b/tests/expand/naming/enum-mut.expanded.rs @@ -0,0 +1,90 @@ +use pin_project::pin_project; +# [pin (__private (project = Proj))] +enum Enum { + Struct { + #[pin] + pinned: T, + unpinned: U, + }, + Tuple(#[pin] T, U), + Unit, +} +#[allow(box_pointers)] +#[allow(deprecated)] +#[allow(explicit_outlives_requirements)] +#[allow(single_use_lifetimes)] +#[allow(unreachable_pub)] +#[allow(clippy::unknown_clippy_lints)] +#[allow(clippy::pattern_type_mismatch)] +#[allow(clippy::redundant_pub_crate)] +#[allow(dead_code)] +#[allow(clippy::mut_mut)] +#[allow(clippy::type_repetition_in_bounds)] +enum Proj<'pin, T, U> +where + Enum: 'pin, +{ + Struct { + pinned: ::pin_project::__private::Pin<&'pin mut (T)>, + unpinned: &'pin mut (U), + }, + Tuple(::pin_project::__private::Pin<&'pin mut (T)>, &'pin mut (U)), + Unit, +} +#[allow(box_pointers)] +#[allow(deprecated)] +#[allow(explicit_outlives_requirements)] +#[allow(single_use_lifetimes)] +#[allow(unreachable_pub)] +#[allow(clippy::unknown_clippy_lints)] +#[allow(clippy::pattern_type_mismatch)] +#[allow(clippy::redundant_pub_crate)] +#[allow(clippy::used_underscore_binding)] +const _: () = { + impl Enum { + fn project<'pin>(self: ::pin_project::__private::Pin<&'pin mut Self>) -> Proj<'pin, T, U> { + unsafe { + match self.get_unchecked_mut() { + Self::Struct { pinned, unpinned } => Proj::Struct { + pinned: ::pin_project::__private::Pin::new_unchecked(pinned), + unpinned, + }, + Self::Tuple(_0, _1) => { + Proj::Tuple(::pin_project::__private::Pin::new_unchecked(_0), _1) + } + Self::Unit => Proj::Unit, + } + } + } + } + #[allow(missing_debug_implementations)] + struct __Enum<'pin, T, U> { + __pin_project_use_generics: ::pin_project::__private::AlwaysUnpin< + 'pin, + ( + ::pin_project::__private::PhantomData, + ::pin_project::__private::PhantomData, + ), + >, + __field0: T, + __field1: T, + } + impl<'pin, T, U> ::pin_project::__private::Unpin for Enum where + __Enum<'pin, T, U>: ::pin_project::__private::Unpin + { + } + #[doc(hidden)] + unsafe impl<'pin, T, U> ::pin_project::UnsafeUnpin for Enum where + __Enum<'pin, T, U>: ::pin_project::__private::Unpin + { + } + trait EnumMustNotImplDrop {} + #[allow(clippy::drop_bounds, drop_bounds)] + impl EnumMustNotImplDrop for T {} + impl EnumMustNotImplDrop for Enum {} + #[doc(hidden)] + impl ::pin_project::__private::PinnedDrop for Enum { + unsafe fn drop(self: ::pin_project::__private::Pin<&mut Self>) {} + } +}; +fn main() {} diff --git a/tests/expand/naming/enum-mut.rs b/tests/expand/naming/enum-mut.rs new file mode 100644 index 0000000..818276f --- /dev/null +++ b/tests/expand/naming/enum-mut.rs @@ -0,0 +1,14 @@ +use pin_project::pin_project; + +#[pin_project(project = Proj)] +enum Enum { + Struct { + #[pin] + pinned: T, + unpinned: U, + }, + Tuple(#[pin] T, U), + Unit, +} + +fn main() {} diff --git a/tests/expand/naming/enum-none.expanded.rs b/tests/expand/naming/enum-none.expanded.rs new file mode 100644 index 0000000..a44ee5f --- /dev/null +++ b/tests/expand/naming/enum-none.expanded.rs @@ -0,0 +1,53 @@ +use pin_project::pin_project; +#[pin(__private())] +enum Enum { + Struct { + #[pin] + pinned: T, + unpinned: U, + }, + Tuple(#[pin] T, U), + Unit, +} +#[allow(box_pointers)] +#[allow(deprecated)] +#[allow(explicit_outlives_requirements)] +#[allow(single_use_lifetimes)] +#[allow(unreachable_pub)] +#[allow(clippy::unknown_clippy_lints)] +#[allow(clippy::pattern_type_mismatch)] +#[allow(clippy::redundant_pub_crate)] +#[allow(clippy::used_underscore_binding)] +const _: () = { + impl Enum {} + #[allow(missing_debug_implementations)] + struct __Enum<'pin, T, U> { + __pin_project_use_generics: ::pin_project::__private::AlwaysUnpin< + 'pin, + ( + ::pin_project::__private::PhantomData, + ::pin_project::__private::PhantomData, + ), + >, + __field0: T, + __field1: T, + } + impl<'pin, T, U> ::pin_project::__private::Unpin for Enum where + __Enum<'pin, T, U>: ::pin_project::__private::Unpin + { + } + #[doc(hidden)] + unsafe impl<'pin, T, U> ::pin_project::UnsafeUnpin for Enum where + __Enum<'pin, T, U>: ::pin_project::__private::Unpin + { + } + trait EnumMustNotImplDrop {} + #[allow(clippy::drop_bounds, drop_bounds)] + impl EnumMustNotImplDrop for T {} + impl EnumMustNotImplDrop for Enum {} + #[doc(hidden)] + impl ::pin_project::__private::PinnedDrop for Enum { + unsafe fn drop(self: ::pin_project::__private::Pin<&mut Self>) {} + } +}; +fn main() {} diff --git a/tests/expand/naming/enum-none.rs b/tests/expand/naming/enum-none.rs new file mode 100644 index 0000000..a87438d --- /dev/null +++ b/tests/expand/naming/enum-none.rs @@ -0,0 +1,14 @@ +use pin_project::pin_project; + +#[pin_project] +enum Enum { + Struct { + #[pin] + pinned: T, + unpinned: U, + }, + Tuple(#[pin] T, U), + Unit, +} + +fn main() {} diff --git a/tests/expand/naming/enum-own.expanded.rs b/tests/expand/naming/enum-own.expanded.rs new file mode 100644 index 0000000..091ad37 --- /dev/null +++ b/tests/expand/naming/enum-own.expanded.rs @@ -0,0 +1,112 @@ +use pin_project::pin_project; +# [pin (__private (project_replace = ProjOwn))] +enum Enum { + Struct { + #[pin] + pinned: T, + unpinned: U, + }, + Tuple(#[pin] T, U), + Unit, +} +#[allow(box_pointers)] +#[allow(deprecated)] +#[allow(explicit_outlives_requirements)] +#[allow(single_use_lifetimes)] +#[allow(unreachable_pub)] +#[allow(clippy::unknown_clippy_lints)] +#[allow(clippy::pattern_type_mismatch)] +#[allow(clippy::redundant_pub_crate)] +#[allow(dead_code)] +#[allow(variant_size_differences)] +#[allow(clippy::large_enum_variant)] +enum ProjOwn { + Struct { + pinned: ::pin_project::__private::PhantomData, + unpinned: U, + }, + Tuple(::pin_project::__private::PhantomData, U), + Unit, +} +#[allow(box_pointers)] +#[allow(deprecated)] +#[allow(explicit_outlives_requirements)] +#[allow(single_use_lifetimes)] +#[allow(unreachable_pub)] +#[allow(clippy::unknown_clippy_lints)] +#[allow(clippy::pattern_type_mismatch)] +#[allow(clippy::redundant_pub_crate)] +#[allow(clippy::used_underscore_binding)] +const _: () = { + impl Enum { + fn project_replace( + self: ::pin_project::__private::Pin<&mut Self>, + __replacement: Self, + ) -> ProjOwn { + unsafe { + let __self_ptr: *mut Self = self.get_unchecked_mut(); + let __guard = ::pin_project::__private::UnsafeOverwriteGuard { + target: __self_ptr, + value: ::pin_project::__private::ManuallyDrop::new(__replacement), + }; + match &mut *__self_ptr { + Self::Struct { pinned, unpinned } => { + let __result = ProjOwn::Struct { + pinned: ::pin_project::__private::PhantomData, + unpinned: ::pin_project::__private::ptr::read(unpinned), + }; + { + let __guard = ::pin_project::__private::UnsafeDropInPlaceGuard(pinned); + } + __result + } + Self::Tuple(_0, _1) => { + let __result = ProjOwn::Tuple( + ::pin_project::__private::PhantomData, + ::pin_project::__private::ptr::read(_1), + ); + { + let __guard = ::pin_project::__private::UnsafeDropInPlaceGuard(_0); + } + __result + } + Self::Unit => { + let __result = ProjOwn::Unit; + {} + __result + } + } + } + } + } + #[allow(missing_debug_implementations)] + struct __Enum<'pin, T, U> { + __pin_project_use_generics: ::pin_project::__private::AlwaysUnpin< + 'pin, + ( + ::pin_project::__private::PhantomData, + ::pin_project::__private::PhantomData, + ), + >, + __field0: T, + __field1: T, + } + impl<'pin, T, U> ::pin_project::__private::Unpin for Enum where + __Enum<'pin, T, U>: ::pin_project::__private::Unpin + { + } + #[doc(hidden)] + unsafe impl<'pin, T, U> ::pin_project::UnsafeUnpin for Enum where + __Enum<'pin, T, U>: ::pin_project::__private::Unpin + { + } + trait EnumMustNotImplDrop {} + #[allow(clippy::drop_bounds, drop_bounds)] + impl EnumMustNotImplDrop for T {} + impl EnumMustNotImplDrop for Enum {} + #[doc(hidden)] + impl ::pin_project::__private::PinnedDrop for Enum { + unsafe fn drop(self: ::pin_project::__private::Pin<&mut Self>) {} + } +}; +fn main() {} diff --git a/tests/expand/naming/enum-own.rs b/tests/expand/naming/enum-own.rs new file mode 100644 index 0000000..cf88697 --- /dev/null +++ b/tests/expand/naming/enum-own.rs @@ -0,0 +1,14 @@ +use pin_project::pin_project; + +#[pin_project(project_replace = ProjOwn)] +enum Enum { + Struct { + #[pin] + pinned: T, + unpinned: U, + }, + Tuple(#[pin] T, U), + Unit, +} + +fn main() {} diff --git a/tests/expand/naming/enum-ref.expanded.rs b/tests/expand/naming/enum-ref.expanded.rs new file mode 100644 index 0000000..5d3c4c9 --- /dev/null +++ b/tests/expand/naming/enum-ref.expanded.rs @@ -0,0 +1,93 @@ +use pin_project::pin_project; +# [pin (__private (project_ref = ProjRef))] +enum Enum { + Struct { + #[pin] + pinned: T, + unpinned: U, + }, + Tuple(#[pin] T, U), + Unit, +} +#[allow(box_pointers)] +#[allow(deprecated)] +#[allow(explicit_outlives_requirements)] +#[allow(single_use_lifetimes)] +#[allow(unreachable_pub)] +#[allow(clippy::unknown_clippy_lints)] +#[allow(clippy::pattern_type_mismatch)] +#[allow(clippy::redundant_pub_crate)] +#[allow(dead_code)] +#[allow(clippy::ref_option_ref)] +#[allow(clippy::type_repetition_in_bounds)] +enum ProjRef<'pin, T, U> +where + Enum: 'pin, +{ + Struct { + pinned: ::pin_project::__private::Pin<&'pin (T)>, + unpinned: &'pin (U), + }, + Tuple(::pin_project::__private::Pin<&'pin (T)>, &'pin (U)), + Unit, +} +#[allow(box_pointers)] +#[allow(deprecated)] +#[allow(explicit_outlives_requirements)] +#[allow(single_use_lifetimes)] +#[allow(unreachable_pub)] +#[allow(clippy::unknown_clippy_lints)] +#[allow(clippy::pattern_type_mismatch)] +#[allow(clippy::redundant_pub_crate)] +#[allow(clippy::used_underscore_binding)] +const _: () = { + impl Enum { + #[allow(clippy::missing_const_for_fn)] + fn project_ref<'pin>( + self: ::pin_project::__private::Pin<&'pin Self>, + ) -> ProjRef<'pin, T, U> { + unsafe { + match self.get_ref() { + Self::Struct { pinned, unpinned } => ProjRef::Struct { + pinned: ::pin_project::__private::Pin::new_unchecked(pinned), + unpinned, + }, + Self::Tuple(_0, _1) => { + ProjRef::Tuple(::pin_project::__private::Pin::new_unchecked(_0), _1) + } + Self::Unit => ProjRef::Unit, + } + } + } + } + #[allow(missing_debug_implementations)] + struct __Enum<'pin, T, U> { + __pin_project_use_generics: ::pin_project::__private::AlwaysUnpin< + 'pin, + ( + ::pin_project::__private::PhantomData, + ::pin_project::__private::PhantomData, + ), + >, + __field0: T, + __field1: T, + } + impl<'pin, T, U> ::pin_project::__private::Unpin for Enum where + __Enum<'pin, T, U>: ::pin_project::__private::Unpin + { + } + #[doc(hidden)] + unsafe impl<'pin, T, U> ::pin_project::UnsafeUnpin for Enum where + __Enum<'pin, T, U>: ::pin_project::__private::Unpin + { + } + trait EnumMustNotImplDrop {} + #[allow(clippy::drop_bounds, drop_bounds)] + impl EnumMustNotImplDrop for T {} + impl EnumMustNotImplDrop for Enum {} + #[doc(hidden)] + impl ::pin_project::__private::PinnedDrop for Enum { + unsafe fn drop(self: ::pin_project::__private::Pin<&mut Self>) {} + } +}; +fn main() {} diff --git a/tests/expand/naming/enum-ref.rs b/tests/expand/naming/enum-ref.rs new file mode 100644 index 0000000..b1ff805 --- /dev/null +++ b/tests/expand/naming/enum-ref.rs @@ -0,0 +1,14 @@ +use pin_project::pin_project; + +#[pin_project(project_ref = ProjRef)] +enum Enum { + Struct { + #[pin] + pinned: T, + unpinned: U, + }, + Tuple(#[pin] T, U), + Unit, +} + +fn main() {} diff --git a/tests/expand/naming/struct-all.expanded.rs b/tests/expand/naming/struct-all.expanded.rs new file mode 100644 index 0000000..660a05a --- /dev/null +++ b/tests/expand/naming/struct-all.expanded.rs @@ -0,0 +1,145 @@ +use pin_project::pin_project; +# [pin (__private (project = Proj , project_ref = ProjRef , project_replace = ProjOwn))] +struct Struct { + #[pin] + pinned: T, + unpinned: U, +} +#[allow(box_pointers)] +#[allow(deprecated)] +#[allow(explicit_outlives_requirements)] +#[allow(single_use_lifetimes)] +#[allow(unreachable_pub)] +#[allow(clippy::unknown_clippy_lints)] +#[allow(clippy::pattern_type_mismatch)] +#[allow(clippy::redundant_pub_crate)] +#[allow(dead_code)] +#[allow(clippy::mut_mut)] +#[allow(clippy::type_repetition_in_bounds)] +struct Proj<'pin, T, U> +where + Struct: 'pin, +{ + pinned: ::pin_project::__private::Pin<&'pin mut (T)>, + unpinned: &'pin mut (U), +} +#[allow(box_pointers)] +#[allow(deprecated)] +#[allow(explicit_outlives_requirements)] +#[allow(single_use_lifetimes)] +#[allow(unreachable_pub)] +#[allow(clippy::unknown_clippy_lints)] +#[allow(clippy::pattern_type_mismatch)] +#[allow(clippy::redundant_pub_crate)] +#[allow(dead_code)] +#[allow(clippy::ref_option_ref)] +#[allow(clippy::type_repetition_in_bounds)] +struct ProjRef<'pin, T, U> +where + Struct: 'pin, +{ + pinned: ::pin_project::__private::Pin<&'pin (T)>, + unpinned: &'pin (U), +} +#[allow(box_pointers)] +#[allow(deprecated)] +#[allow(explicit_outlives_requirements)] +#[allow(single_use_lifetimes)] +#[allow(unreachable_pub)] +#[allow(clippy::unknown_clippy_lints)] +#[allow(clippy::pattern_type_mismatch)] +#[allow(clippy::redundant_pub_crate)] +#[allow(dead_code)] +struct ProjOwn { + pinned: ::pin_project::__private::PhantomData, + unpinned: U, +} +#[allow(box_pointers)] +#[allow(deprecated)] +#[allow(explicit_outlives_requirements)] +#[allow(single_use_lifetimes)] +#[allow(unreachable_pub)] +#[allow(clippy::unknown_clippy_lints)] +#[allow(clippy::pattern_type_mismatch)] +#[allow(clippy::redundant_pub_crate)] +#[allow(clippy::used_underscore_binding)] +const _: () = { + impl Struct { + fn project<'pin>(self: ::pin_project::__private::Pin<&'pin mut Self>) -> Proj<'pin, T, U> { + unsafe { + let Self { pinned, unpinned } = self.get_unchecked_mut(); + Proj { + pinned: ::pin_project::__private::Pin::new_unchecked(pinned), + unpinned, + } + } + } + #[allow(clippy::missing_const_for_fn)] + fn project_ref<'pin>( + self: ::pin_project::__private::Pin<&'pin Self>, + ) -> ProjRef<'pin, T, U> { + unsafe { + let Self { pinned, unpinned } = self.get_ref(); + ProjRef { + pinned: ::pin_project::__private::Pin::new_unchecked(pinned), + unpinned, + } + } + } + fn project_replace( + self: ::pin_project::__private::Pin<&mut Self>, + __replacement: Self, + ) -> ProjOwn { + unsafe { + let __self_ptr: *mut Self = self.get_unchecked_mut(); + let __guard = ::pin_project::__private::UnsafeOverwriteGuard { + target: __self_ptr, + value: ::pin_project::__private::ManuallyDrop::new(__replacement), + }; + let Self { pinned, unpinned } = &mut *__self_ptr; + let __result = ProjOwn { + pinned: ::pin_project::__private::PhantomData, + unpinned: ::pin_project::__private::ptr::read(unpinned), + }; + { + let __guard = ::pin_project::__private::UnsafeDropInPlaceGuard(pinned); + } + __result + } + } + } + #[forbid(safe_packed_borrows)] + fn __assert_not_repr_packed(this: &Struct) { + let _ = &this.pinned; + let _ = &this.unpinned; + } + #[allow(missing_debug_implementations)] + struct __Struct<'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 Struct where + __Struct<'pin, T, U>: ::pin_project::__private::Unpin + { + } + #[doc(hidden)] + unsafe impl<'pin, T, U> ::pin_project::UnsafeUnpin for Struct where + __Struct<'pin, T, U>: ::pin_project::__private::Unpin + { + } + trait StructMustNotImplDrop {} + #[allow(clippy::drop_bounds, drop_bounds)] + impl StructMustNotImplDrop for T {} + impl StructMustNotImplDrop for Struct {} + #[doc(hidden)] + impl ::pin_project::__private::PinnedDrop for Struct { + unsafe fn drop(self: ::pin_project::__private::Pin<&mut Self>) {} + } +}; +fn main() {} diff --git a/tests/expand/naming/struct-all.rs b/tests/expand/naming/struct-all.rs new file mode 100644 index 0000000..c229ba4 --- /dev/null +++ b/tests/expand/naming/struct-all.rs @@ -0,0 +1,10 @@ +use pin_project::pin_project; + +#[pin_project(project = Proj, project_ref = ProjRef, project_replace = ProjOwn)] +struct Struct { + #[pin] + pinned: T, + unpinned: U, +} + +fn main() {} diff --git a/tests/expand/naming/struct-mut.expanded.rs b/tests/expand/naming/struct-mut.expanded.rs new file mode 100644 index 0000000..91552e7 --- /dev/null +++ b/tests/expand/naming/struct-mut.expanded.rs @@ -0,0 +1,111 @@ +use pin_project::pin_project; +# [pin (__private (project = Proj))] +struct Struct { + #[pin] + pinned: T, + unpinned: U, +} +#[allow(box_pointers)] +#[allow(deprecated)] +#[allow(explicit_outlives_requirements)] +#[allow(single_use_lifetimes)] +#[allow(unreachable_pub)] +#[allow(clippy::unknown_clippy_lints)] +#[allow(clippy::pattern_type_mismatch)] +#[allow(clippy::redundant_pub_crate)] +#[allow(dead_code)] +#[allow(clippy::mut_mut)] +#[allow(clippy::type_repetition_in_bounds)] +struct Proj<'pin, T, U> +where + Struct: 'pin, +{ + pinned: ::pin_project::__private::Pin<&'pin mut (T)>, + unpinned: &'pin mut (U), +} +#[allow(box_pointers)] +#[allow(deprecated)] +#[allow(explicit_outlives_requirements)] +#[allow(single_use_lifetimes)] +#[allow(unreachable_pub)] +#[allow(clippy::unknown_clippy_lints)] +#[allow(clippy::pattern_type_mismatch)] +#[allow(clippy::redundant_pub_crate)] +#[allow(clippy::used_underscore_binding)] +const _: () = { + #[allow(box_pointers)] + #[allow(deprecated)] + #[allow(explicit_outlives_requirements)] + #[allow(single_use_lifetimes)] + #[allow(unreachable_pub)] + #[allow(clippy::unknown_clippy_lints)] + #[allow(clippy::pattern_type_mismatch)] + #[allow(clippy::redundant_pub_crate)] + #[allow(dead_code)] + #[allow(clippy::ref_option_ref)] + #[allow(clippy::type_repetition_in_bounds)] + struct __StructProjectionRef<'pin, T, U> + where + Struct: 'pin, + { + pinned: ::pin_project::__private::Pin<&'pin (T)>, + unpinned: &'pin (U), + } + impl Struct { + fn project<'pin>(self: ::pin_project::__private::Pin<&'pin mut Self>) -> Proj<'pin, T, U> { + unsafe { + let Self { pinned, unpinned } = self.get_unchecked_mut(); + Proj { + pinned: ::pin_project::__private::Pin::new_unchecked(pinned), + unpinned, + } + } + } + #[allow(clippy::missing_const_for_fn)] + fn project_ref<'pin>( + self: ::pin_project::__private::Pin<&'pin Self>, + ) -> __StructProjectionRef<'pin, T, U> { + unsafe { + let Self { pinned, unpinned } = self.get_ref(); + __StructProjectionRef { + pinned: ::pin_project::__private::Pin::new_unchecked(pinned), + unpinned, + } + } + } + } + #[forbid(safe_packed_borrows)] + fn __assert_not_repr_packed(this: &Struct) { + let _ = &this.pinned; + let _ = &this.unpinned; + } + #[allow(missing_debug_implementations)] + struct __Struct<'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 Struct where + __Struct<'pin, T, U>: ::pin_project::__private::Unpin + { + } + #[doc(hidden)] + unsafe impl<'pin, T, U> ::pin_project::UnsafeUnpin for Struct where + __Struct<'pin, T, U>: ::pin_project::__private::Unpin + { + } + trait StructMustNotImplDrop {} + #[allow(clippy::drop_bounds, drop_bounds)] + impl StructMustNotImplDrop for T {} + impl StructMustNotImplDrop for Struct {} + #[doc(hidden)] + impl ::pin_project::__private::PinnedDrop for Struct { + unsafe fn drop(self: ::pin_project::__private::Pin<&mut Self>) {} + } +}; +fn main() {} diff --git a/tests/expand/naming/struct-mut.rs b/tests/expand/naming/struct-mut.rs new file mode 100644 index 0000000..2f554d3 --- /dev/null +++ b/tests/expand/naming/struct-mut.rs @@ -0,0 +1,10 @@ +use pin_project::pin_project; + +#[pin_project(project = Proj)] +struct Struct { + #[pin] + pinned: T, + unpinned: U, +} + +fn main() {} diff --git a/tests/expand/naming/struct-none.expanded.rs b/tests/expand/naming/struct-none.expanded.rs new file mode 100644 index 0000000..ac878b8 --- /dev/null +++ b/tests/expand/naming/struct-none.expanded.rs @@ -0,0 +1,113 @@ +use pin_project::pin_project; +#[pin(__private())] +struct Struct { + #[pin] + pinned: T, + unpinned: U, +} +#[allow(box_pointers)] +#[allow(deprecated)] +#[allow(explicit_outlives_requirements)] +#[allow(single_use_lifetimes)] +#[allow(unreachable_pub)] +#[allow(clippy::unknown_clippy_lints)] +#[allow(clippy::pattern_type_mismatch)] +#[allow(clippy::redundant_pub_crate)] +#[allow(clippy::used_underscore_binding)] +const _: () = { + #[allow(box_pointers)] + #[allow(deprecated)] + #[allow(explicit_outlives_requirements)] + #[allow(single_use_lifetimes)] + #[allow(unreachable_pub)] + #[allow(clippy::unknown_clippy_lints)] + #[allow(clippy::pattern_type_mismatch)] + #[allow(clippy::redundant_pub_crate)] + #[allow(dead_code)] + #[allow(clippy::mut_mut)] + #[allow(clippy::type_repetition_in_bounds)] + struct __StructProjection<'pin, T, U> + where + Struct: 'pin, + { + pinned: ::pin_project::__private::Pin<&'pin mut (T)>, + unpinned: &'pin mut (U), + } + #[allow(box_pointers)] + #[allow(deprecated)] + #[allow(explicit_outlives_requirements)] + #[allow(single_use_lifetimes)] + #[allow(unreachable_pub)] + #[allow(clippy::unknown_clippy_lints)] + #[allow(clippy::pattern_type_mismatch)] + #[allow(clippy::redundant_pub_crate)] + #[allow(dead_code)] + #[allow(clippy::ref_option_ref)] + #[allow(clippy::type_repetition_in_bounds)] + struct __StructProjectionRef<'pin, T, U> + where + Struct: 'pin, + { + pinned: ::pin_project::__private::Pin<&'pin (T)>, + unpinned: &'pin (U), + } + impl Struct { + fn project<'pin>( + self: ::pin_project::__private::Pin<&'pin mut Self>, + ) -> __StructProjection<'pin, T, U> { + unsafe { + let Self { pinned, unpinned } = self.get_unchecked_mut(); + __StructProjection { + pinned: ::pin_project::__private::Pin::new_unchecked(pinned), + unpinned, + } + } + } + #[allow(clippy::missing_const_for_fn)] + fn project_ref<'pin>( + self: ::pin_project::__private::Pin<&'pin Self>, + ) -> __StructProjectionRef<'pin, T, U> { + unsafe { + let Self { pinned, unpinned } = self.get_ref(); + __StructProjectionRef { + pinned: ::pin_project::__private::Pin::new_unchecked(pinned), + unpinned, + } + } + } + } + #[forbid(safe_packed_borrows)] + fn __assert_not_repr_packed(this: &Struct) { + let _ = &this.pinned; + let _ = &this.unpinned; + } + #[allow(missing_debug_implementations)] + struct __Struct<'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 Struct where + __Struct<'pin, T, U>: ::pin_project::__private::Unpin + { + } + #[doc(hidden)] + unsafe impl<'pin, T, U> ::pin_project::UnsafeUnpin for Struct where + __Struct<'pin, T, U>: ::pin_project::__private::Unpin + { + } + trait StructMustNotImplDrop {} + #[allow(clippy::drop_bounds, drop_bounds)] + impl StructMustNotImplDrop for T {} + impl StructMustNotImplDrop for Struct {} + #[doc(hidden)] + impl ::pin_project::__private::PinnedDrop for Struct { + unsafe fn drop(self: ::pin_project::__private::Pin<&mut Self>) {} + } +}; +fn main() {} diff --git a/tests/expand/naming/struct-none.rs b/tests/expand/naming/struct-none.rs new file mode 100644 index 0000000..474f0a1 --- /dev/null +++ b/tests/expand/naming/struct-none.rs @@ -0,0 +1,10 @@ +use pin_project::pin_project; + +#[pin_project] +struct Struct { + #[pin] + pinned: T, + unpinned: U, +} + +fn main() {} diff --git a/tests/expand/naming/struct-own.expanded.rs b/tests/expand/naming/struct-own.expanded.rs new file mode 100644 index 0000000..6f4de78 --- /dev/null +++ b/tests/expand/naming/struct-own.expanded.rs @@ -0,0 +1,147 @@ +use pin_project::pin_project; +# [pin (__private (project_replace = ProjOwn))] +struct Struct { + #[pin] + pinned: T, + unpinned: U, +} +#[allow(box_pointers)] +#[allow(deprecated)] +#[allow(explicit_outlives_requirements)] +#[allow(single_use_lifetimes)] +#[allow(unreachable_pub)] +#[allow(clippy::unknown_clippy_lints)] +#[allow(clippy::pattern_type_mismatch)] +#[allow(clippy::redundant_pub_crate)] +#[allow(dead_code)] +struct ProjOwn { + pinned: ::pin_project::__private::PhantomData, + unpinned: U, +} +#[allow(box_pointers)] +#[allow(deprecated)] +#[allow(explicit_outlives_requirements)] +#[allow(single_use_lifetimes)] +#[allow(unreachable_pub)] +#[allow(clippy::unknown_clippy_lints)] +#[allow(clippy::pattern_type_mismatch)] +#[allow(clippy::redundant_pub_crate)] +#[allow(clippy::used_underscore_binding)] +const _: () = { + #[allow(box_pointers)] + #[allow(deprecated)] + #[allow(explicit_outlives_requirements)] + #[allow(single_use_lifetimes)] + #[allow(unreachable_pub)] + #[allow(clippy::unknown_clippy_lints)] + #[allow(clippy::pattern_type_mismatch)] + #[allow(clippy::redundant_pub_crate)] + #[allow(dead_code)] + #[allow(clippy::mut_mut)] + #[allow(clippy::type_repetition_in_bounds)] + struct __StructProjection<'pin, T, U> + where + Struct: 'pin, + { + pinned: ::pin_project::__private::Pin<&'pin mut (T)>, + unpinned: &'pin mut (U), + } + #[allow(box_pointers)] + #[allow(deprecated)] + #[allow(explicit_outlives_requirements)] + #[allow(single_use_lifetimes)] + #[allow(unreachable_pub)] + #[allow(clippy::unknown_clippy_lints)] + #[allow(clippy::pattern_type_mismatch)] + #[allow(clippy::redundant_pub_crate)] + #[allow(dead_code)] + #[allow(clippy::ref_option_ref)] + #[allow(clippy::type_repetition_in_bounds)] + struct __StructProjectionRef<'pin, T, U> + where + Struct: 'pin, + { + pinned: ::pin_project::__private::Pin<&'pin (T)>, + unpinned: &'pin (U), + } + impl Struct { + fn project<'pin>( + self: ::pin_project::__private::Pin<&'pin mut Self>, + ) -> __StructProjection<'pin, T, U> { + unsafe { + let Self { pinned, unpinned } = self.get_unchecked_mut(); + __StructProjection { + pinned: ::pin_project::__private::Pin::new_unchecked(pinned), + unpinned, + } + } + } + #[allow(clippy::missing_const_for_fn)] + fn project_ref<'pin>( + self: ::pin_project::__private::Pin<&'pin Self>, + ) -> __StructProjectionRef<'pin, T, U> { + unsafe { + let Self { pinned, unpinned } = self.get_ref(); + __StructProjectionRef { + pinned: ::pin_project::__private::Pin::new_unchecked(pinned), + unpinned, + } + } + } + fn project_replace( + self: ::pin_project::__private::Pin<&mut Self>, + __replacement: Self, + ) -> ProjOwn { + unsafe { + let __self_ptr: *mut Self = self.get_unchecked_mut(); + let __guard = ::pin_project::__private::UnsafeOverwriteGuard { + target: __self_ptr, + value: ::pin_project::__private::ManuallyDrop::new(__replacement), + }; + let Self { pinned, unpinned } = &mut *__self_ptr; + let __result = ProjOwn { + pinned: ::pin_project::__private::PhantomData, + unpinned: ::pin_project::__private::ptr::read(unpinned), + }; + { + let __guard = ::pin_project::__private::UnsafeDropInPlaceGuard(pinned); + } + __result + } + } + } + #[forbid(safe_packed_borrows)] + fn __assert_not_repr_packed(this: &Struct) { + let _ = &this.pinned; + let _ = &this.unpinned; + } + #[allow(missing_debug_implementations)] + struct __Struct<'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 Struct where + __Struct<'pin, T, U>: ::pin_project::__private::Unpin + { + } + #[doc(hidden)] + unsafe impl<'pin, T, U> ::pin_project::UnsafeUnpin for Struct where + __Struct<'pin, T, U>: ::pin_project::__private::Unpin + { + } + trait StructMustNotImplDrop {} + #[allow(clippy::drop_bounds, drop_bounds)] + impl StructMustNotImplDrop for T {} + impl StructMustNotImplDrop for Struct {} + #[doc(hidden)] + impl ::pin_project::__private::PinnedDrop for Struct { + unsafe fn drop(self: ::pin_project::__private::Pin<&mut Self>) {} + } +}; +fn main() {} diff --git a/tests/expand/naming/struct-own.rs b/tests/expand/naming/struct-own.rs new file mode 100644 index 0000000..4924362 --- /dev/null +++ b/tests/expand/naming/struct-own.rs @@ -0,0 +1,10 @@ +use pin_project::pin_project; + +#[pin_project(project_replace = ProjOwn)] +struct Struct { + #[pin] + pinned: T, + unpinned: U, +} + +fn main() {} diff --git a/tests/expand/naming/struct-ref.expanded.rs b/tests/expand/naming/struct-ref.expanded.rs new file mode 100644 index 0000000..3296c02 --- /dev/null +++ b/tests/expand/naming/struct-ref.expanded.rs @@ -0,0 +1,113 @@ +use pin_project::pin_project; +# [pin (__private (project_ref = ProjRef))] +struct Struct { + #[pin] + pinned: T, + unpinned: U, +} +#[allow(box_pointers)] +#[allow(deprecated)] +#[allow(explicit_outlives_requirements)] +#[allow(single_use_lifetimes)] +#[allow(unreachable_pub)] +#[allow(clippy::unknown_clippy_lints)] +#[allow(clippy::pattern_type_mismatch)] +#[allow(clippy::redundant_pub_crate)] +#[allow(dead_code)] +#[allow(clippy::ref_option_ref)] +#[allow(clippy::type_repetition_in_bounds)] +struct ProjRef<'pin, T, U> +where + Struct: 'pin, +{ + pinned: ::pin_project::__private::Pin<&'pin (T)>, + unpinned: &'pin (U), +} +#[allow(box_pointers)] +#[allow(deprecated)] +#[allow(explicit_outlives_requirements)] +#[allow(single_use_lifetimes)] +#[allow(unreachable_pub)] +#[allow(clippy::unknown_clippy_lints)] +#[allow(clippy::pattern_type_mismatch)] +#[allow(clippy::redundant_pub_crate)] +#[allow(clippy::used_underscore_binding)] +const _: () = { + #[allow(box_pointers)] + #[allow(deprecated)] + #[allow(explicit_outlives_requirements)] + #[allow(single_use_lifetimes)] + #[allow(unreachable_pub)] + #[allow(clippy::unknown_clippy_lints)] + #[allow(clippy::pattern_type_mismatch)] + #[allow(clippy::redundant_pub_crate)] + #[allow(dead_code)] + #[allow(clippy::mut_mut)] + #[allow(clippy::type_repetition_in_bounds)] + struct __StructProjection<'pin, T, U> + where + Struct: 'pin, + { + pinned: ::pin_project::__private::Pin<&'pin mut (T)>, + unpinned: &'pin mut (U), + } + impl Struct { + fn project<'pin>( + self: ::pin_project::__private::Pin<&'pin mut Self>, + ) -> __StructProjection<'pin, T, U> { + unsafe { + let Self { pinned, unpinned } = self.get_unchecked_mut(); + __StructProjection { + pinned: ::pin_project::__private::Pin::new_unchecked(pinned), + unpinned, + } + } + } + #[allow(clippy::missing_const_for_fn)] + fn project_ref<'pin>( + self: ::pin_project::__private::Pin<&'pin Self>, + ) -> ProjRef<'pin, T, U> { + unsafe { + let Self { pinned, unpinned } = self.get_ref(); + ProjRef { + pinned: ::pin_project::__private::Pin::new_unchecked(pinned), + unpinned, + } + } + } + } + #[forbid(safe_packed_borrows)] + fn __assert_not_repr_packed(this: &Struct) { + let _ = &this.pinned; + let _ = &this.unpinned; + } + #[allow(missing_debug_implementations)] + struct __Struct<'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 Struct where + __Struct<'pin, T, U>: ::pin_project::__private::Unpin + { + } + #[doc(hidden)] + unsafe impl<'pin, T, U> ::pin_project::UnsafeUnpin for Struct where + __Struct<'pin, T, U>: ::pin_project::__private::Unpin + { + } + trait StructMustNotImplDrop {} + #[allow(clippy::drop_bounds, drop_bounds)] + impl StructMustNotImplDrop for T {} + impl StructMustNotImplDrop for Struct {} + #[doc(hidden)] + impl ::pin_project::__private::PinnedDrop for Struct { + unsafe fn drop(self: ::pin_project::__private::Pin<&mut Self>) {} + } +}; +fn main() {} diff --git a/tests/expand/naming/struct-ref.rs b/tests/expand/naming/struct-ref.rs new file mode 100644 index 0000000..4e29a16 --- /dev/null +++ b/tests/expand/naming/struct-ref.rs @@ -0,0 +1,10 @@ +use pin_project::pin_project; + +#[pin_project(project_ref = ProjRef)] +struct Struct { + #[pin] + pinned: T, + unpinned: U, +} + +fn main() {} diff --git a/tests/expand/naming/tuple_struct-all.expanded.rs b/tests/expand/naming/tuple_struct-all.expanded.rs new file mode 100644 index 0000000..b78ebf8 --- /dev/null +++ b/tests/expand/naming/tuple_struct-all.expanded.rs @@ -0,0 +1,124 @@ +use pin_project::pin_project; +# [pin (__private (project = Proj , project_ref = ProjRef , project_replace = ProjOwn))] +struct TupleStruct(#[pin] T, U); +#[allow(box_pointers)] +#[allow(deprecated)] +#[allow(explicit_outlives_requirements)] +#[allow(single_use_lifetimes)] +#[allow(unreachable_pub)] +#[allow(clippy::unknown_clippy_lints)] +#[allow(clippy::pattern_type_mismatch)] +#[allow(clippy::redundant_pub_crate)] +#[allow(dead_code)] +#[allow(clippy::mut_mut)] +#[allow(clippy::type_repetition_in_bounds)] +struct Proj<'pin, T, U>(::pin_project::__private::Pin<&'pin mut (T)>, &'pin mut (U)) +where + TupleStruct: 'pin; +#[allow(box_pointers)] +#[allow(deprecated)] +#[allow(explicit_outlives_requirements)] +#[allow(single_use_lifetimes)] +#[allow(unreachable_pub)] +#[allow(clippy::unknown_clippy_lints)] +#[allow(clippy::pattern_type_mismatch)] +#[allow(clippy::redundant_pub_crate)] +#[allow(dead_code)] +#[allow(clippy::ref_option_ref)] +#[allow(clippy::type_repetition_in_bounds)] +struct ProjRef<'pin, T, U>(::pin_project::__private::Pin<&'pin (T)>, &'pin (U)) +where + TupleStruct: 'pin; +#[allow(box_pointers)] +#[allow(deprecated)] +#[allow(explicit_outlives_requirements)] +#[allow(single_use_lifetimes)] +#[allow(unreachable_pub)] +#[allow(clippy::unknown_clippy_lints)] +#[allow(clippy::pattern_type_mismatch)] +#[allow(clippy::redundant_pub_crate)] +#[allow(dead_code)] +struct ProjOwn(::pin_project::__private::PhantomData, U); +#[allow(box_pointers)] +#[allow(deprecated)] +#[allow(explicit_outlives_requirements)] +#[allow(single_use_lifetimes)] +#[allow(unreachable_pub)] +#[allow(clippy::unknown_clippy_lints)] +#[allow(clippy::pattern_type_mismatch)] +#[allow(clippy::redundant_pub_crate)] +#[allow(clippy::used_underscore_binding)] +const _: () = { + impl TupleStruct { + fn project<'pin>(self: ::pin_project::__private::Pin<&'pin mut Self>) -> Proj<'pin, T, U> { + unsafe { + let Self(_0, _1) = self.get_unchecked_mut(); + Proj(::pin_project::__private::Pin::new_unchecked(_0), _1) + } + } + #[allow(clippy::missing_const_for_fn)] + fn project_ref<'pin>( + self: ::pin_project::__private::Pin<&'pin Self>, + ) -> ProjRef<'pin, T, U> { + unsafe { + let Self(_0, _1) = self.get_ref(); + ProjRef(::pin_project::__private::Pin::new_unchecked(_0), _1) + } + } + fn project_replace( + self: ::pin_project::__private::Pin<&mut Self>, + __replacement: Self, + ) -> ProjOwn { + unsafe { + let __self_ptr: *mut Self = self.get_unchecked_mut(); + let __guard = ::pin_project::__private::UnsafeOverwriteGuard { + target: __self_ptr, + value: ::pin_project::__private::ManuallyDrop::new(__replacement), + }; + let Self(_0, _1) = &mut *__self_ptr; + let __result = ProjOwn( + ::pin_project::__private::PhantomData, + ::pin_project::__private::ptr::read(_1), + ); + { + let __guard = ::pin_project::__private::UnsafeDropInPlaceGuard(_0); + } + __result + } + } + } + #[forbid(safe_packed_borrows)] + fn __assert_not_repr_packed(this: &TupleStruct) { + let _ = &this.0; + let _ = &this.1; + } + #[allow(missing_debug_implementations)] + struct __TupleStruct<'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 TupleStruct where + __TupleStruct<'pin, T, U>: ::pin_project::__private::Unpin + { + } + #[doc(hidden)] + unsafe impl<'pin, T, U> ::pin_project::UnsafeUnpin for TupleStruct where + __TupleStruct<'pin, T, U>: ::pin_project::__private::Unpin + { + } + trait TupleStructMustNotImplDrop {} + #[allow(clippy::drop_bounds, drop_bounds)] + impl TupleStructMustNotImplDrop for T {} + impl TupleStructMustNotImplDrop for TupleStruct {} + #[doc(hidden)] + impl ::pin_project::__private::PinnedDrop for TupleStruct { + unsafe fn drop(self: ::pin_project::__private::Pin<&mut Self>) {} + } +}; +fn main() {} diff --git a/tests/expand/naming/tuple_struct-all.rs b/tests/expand/naming/tuple_struct-all.rs new file mode 100644 index 0000000..0d95cb0 --- /dev/null +++ b/tests/expand/naming/tuple_struct-all.rs @@ -0,0 +1,6 @@ +use pin_project::pin_project; + +#[pin_project(project = Proj, project_ref = ProjRef, project_replace = ProjOwn)] +struct TupleStruct(#[pin] T, U); + +fn main() {} diff --git a/tests/expand/naming/tuple_struct-mut.expanded.rs b/tests/expand/naming/tuple_struct-mut.expanded.rs new file mode 100644 index 0000000..96aa951 --- /dev/null +++ b/tests/expand/naming/tuple_struct-mut.expanded.rs @@ -0,0 +1,96 @@ +use pin_project::pin_project; +# [pin (__private (project = Proj))] +struct TupleStruct(#[pin] T, U); +#[allow(box_pointers)] +#[allow(deprecated)] +#[allow(explicit_outlives_requirements)] +#[allow(single_use_lifetimes)] +#[allow(unreachable_pub)] +#[allow(clippy::unknown_clippy_lints)] +#[allow(clippy::pattern_type_mismatch)] +#[allow(clippy::redundant_pub_crate)] +#[allow(dead_code)] +#[allow(clippy::mut_mut)] +#[allow(clippy::type_repetition_in_bounds)] +struct Proj<'pin, T, U>(::pin_project::__private::Pin<&'pin mut (T)>, &'pin mut (U)) +where + TupleStruct: 'pin; +#[allow(box_pointers)] +#[allow(deprecated)] +#[allow(explicit_outlives_requirements)] +#[allow(single_use_lifetimes)] +#[allow(unreachable_pub)] +#[allow(clippy::unknown_clippy_lints)] +#[allow(clippy::pattern_type_mismatch)] +#[allow(clippy::redundant_pub_crate)] +#[allow(clippy::used_underscore_binding)] +const _: () = { + #[allow(box_pointers)] + #[allow(deprecated)] + #[allow(explicit_outlives_requirements)] + #[allow(single_use_lifetimes)] + #[allow(unreachable_pub)] + #[allow(clippy::unknown_clippy_lints)] + #[allow(clippy::pattern_type_mismatch)] + #[allow(clippy::redundant_pub_crate)] + #[allow(dead_code)] + #[allow(clippy::ref_option_ref)] + #[allow(clippy::type_repetition_in_bounds)] + struct __TupleStructProjectionRef<'pin, T, U>( + ::pin_project::__private::Pin<&'pin (T)>, + &'pin (U), + ) + where + TupleStruct: 'pin; + impl TupleStruct { + fn project<'pin>(self: ::pin_project::__private::Pin<&'pin mut Self>) -> Proj<'pin, T, U> { + unsafe { + let Self(_0, _1) = self.get_unchecked_mut(); + Proj(::pin_project::__private::Pin::new_unchecked(_0), _1) + } + } + #[allow(clippy::missing_const_for_fn)] + fn project_ref<'pin>( + self: ::pin_project::__private::Pin<&'pin Self>, + ) -> __TupleStructProjectionRef<'pin, T, U> { + unsafe { + let Self(_0, _1) = self.get_ref(); + __TupleStructProjectionRef(::pin_project::__private::Pin::new_unchecked(_0), _1) + } + } + } + #[forbid(safe_packed_borrows)] + fn __assert_not_repr_packed(this: &TupleStruct) { + let _ = &this.0; + let _ = &this.1; + } + #[allow(missing_debug_implementations)] + struct __TupleStruct<'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 TupleStruct where + __TupleStruct<'pin, T, U>: ::pin_project::__private::Unpin + { + } + #[doc(hidden)] + unsafe impl<'pin, T, U> ::pin_project::UnsafeUnpin for TupleStruct where + __TupleStruct<'pin, T, U>: ::pin_project::__private::Unpin + { + } + trait TupleStructMustNotImplDrop {} + #[allow(clippy::drop_bounds, drop_bounds)] + impl TupleStructMustNotImplDrop for T {} + impl TupleStructMustNotImplDrop for TupleStruct {} + #[doc(hidden)] + impl ::pin_project::__private::PinnedDrop for TupleStruct { + unsafe fn drop(self: ::pin_project::__private::Pin<&mut Self>) {} + } +}; +fn main() {} diff --git a/tests/expand/naming/tuple_struct-mut.rs b/tests/expand/naming/tuple_struct-mut.rs new file mode 100644 index 0000000..e9779a6 --- /dev/null +++ b/tests/expand/naming/tuple_struct-mut.rs @@ -0,0 +1,6 @@ +use pin_project::pin_project; + +#[pin_project(project = Proj)] +struct TupleStruct(#[pin] T, U); + +fn main() {} diff --git a/tests/expand/naming/tuple_struct-none.expanded.rs b/tests/expand/naming/tuple_struct-none.expanded.rs new file mode 100644 index 0000000..0c5cc1d --- /dev/null +++ b/tests/expand/naming/tuple_struct-none.expanded.rs @@ -0,0 +1,101 @@ +use pin_project::pin_project; +#[pin(__private())] +struct TupleStruct(#[pin] T, U); +#[allow(box_pointers)] +#[allow(deprecated)] +#[allow(explicit_outlives_requirements)] +#[allow(single_use_lifetimes)] +#[allow(unreachable_pub)] +#[allow(clippy::unknown_clippy_lints)] +#[allow(clippy::pattern_type_mismatch)] +#[allow(clippy::redundant_pub_crate)] +#[allow(clippy::used_underscore_binding)] +const _: () = { + #[allow(box_pointers)] + #[allow(deprecated)] + #[allow(explicit_outlives_requirements)] + #[allow(single_use_lifetimes)] + #[allow(unreachable_pub)] + #[allow(clippy::unknown_clippy_lints)] + #[allow(clippy::pattern_type_mismatch)] + #[allow(clippy::redundant_pub_crate)] + #[allow(dead_code)] + #[allow(clippy::mut_mut)] + #[allow(clippy::type_repetition_in_bounds)] + struct __TupleStructProjection<'pin, T, U>( + ::pin_project::__private::Pin<&'pin mut (T)>, + &'pin mut (U), + ) + where + TupleStruct: 'pin; + #[allow(box_pointers)] + #[allow(deprecated)] + #[allow(explicit_outlives_requirements)] + #[allow(single_use_lifetimes)] + #[allow(unreachable_pub)] + #[allow(clippy::unknown_clippy_lints)] + #[allow(clippy::pattern_type_mismatch)] + #[allow(clippy::redundant_pub_crate)] + #[allow(dead_code)] + #[allow(clippy::ref_option_ref)] + #[allow(clippy::type_repetition_in_bounds)] + struct __TupleStructProjectionRef<'pin, T, U>( + ::pin_project::__private::Pin<&'pin (T)>, + &'pin (U), + ) + where + TupleStruct: 'pin; + impl TupleStruct { + fn project<'pin>( + self: ::pin_project::__private::Pin<&'pin mut Self>, + ) -> __TupleStructProjection<'pin, T, U> { + unsafe { + let Self(_0, _1) = self.get_unchecked_mut(); + __TupleStructProjection(::pin_project::__private::Pin::new_unchecked(_0), _1) + } + } + #[allow(clippy::missing_const_for_fn)] + fn project_ref<'pin>( + self: ::pin_project::__private::Pin<&'pin Self>, + ) -> __TupleStructProjectionRef<'pin, T, U> { + unsafe { + let Self(_0, _1) = self.get_ref(); + __TupleStructProjectionRef(::pin_project::__private::Pin::new_unchecked(_0), _1) + } + } + } + #[forbid(safe_packed_borrows)] + fn __assert_not_repr_packed(this: &TupleStruct) { + let _ = &this.0; + let _ = &this.1; + } + #[allow(missing_debug_implementations)] + struct __TupleStruct<'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 TupleStruct where + __TupleStruct<'pin, T, U>: ::pin_project::__private::Unpin + { + } + #[doc(hidden)] + unsafe impl<'pin, T, U> ::pin_project::UnsafeUnpin for TupleStruct where + __TupleStruct<'pin, T, U>: ::pin_project::__private::Unpin + { + } + trait TupleStructMustNotImplDrop {} + #[allow(clippy::drop_bounds, drop_bounds)] + impl TupleStructMustNotImplDrop for T {} + impl TupleStructMustNotImplDrop for TupleStruct {} + #[doc(hidden)] + impl ::pin_project::__private::PinnedDrop for TupleStruct { + unsafe fn drop(self: ::pin_project::__private::Pin<&mut Self>) {} + } +}; +fn main() {} diff --git a/tests/expand/naming/tuple_struct-none.rs b/tests/expand/naming/tuple_struct-none.rs new file mode 100644 index 0000000..398b14f --- /dev/null +++ b/tests/expand/naming/tuple_struct-none.rs @@ -0,0 +1,6 @@ +use pin_project::pin_project; + +#[pin_project] +struct TupleStruct(#[pin] T, U); + +fn main() {} diff --git a/tests/expand/naming/tuple_struct-own.expanded.rs b/tests/expand/naming/tuple_struct-own.expanded.rs new file mode 100644 index 0000000..08d9ae3 --- /dev/null +++ b/tests/expand/naming/tuple_struct-own.expanded.rs @@ -0,0 +1,132 @@ +use pin_project::pin_project; +# [pin (__private (project_replace = ProjOwn))] +struct TupleStruct(#[pin] T, U); +#[allow(box_pointers)] +#[allow(deprecated)] +#[allow(explicit_outlives_requirements)] +#[allow(single_use_lifetimes)] +#[allow(unreachable_pub)] +#[allow(clippy::unknown_clippy_lints)] +#[allow(clippy::pattern_type_mismatch)] +#[allow(clippy::redundant_pub_crate)] +#[allow(dead_code)] +struct ProjOwn(::pin_project::__private::PhantomData, U); +#[allow(box_pointers)] +#[allow(deprecated)] +#[allow(explicit_outlives_requirements)] +#[allow(single_use_lifetimes)] +#[allow(unreachable_pub)] +#[allow(clippy::unknown_clippy_lints)] +#[allow(clippy::pattern_type_mismatch)] +#[allow(clippy::redundant_pub_crate)] +#[allow(clippy::used_underscore_binding)] +const _: () = { + #[allow(box_pointers)] + #[allow(deprecated)] + #[allow(explicit_outlives_requirements)] + #[allow(single_use_lifetimes)] + #[allow(unreachable_pub)] + #[allow(clippy::unknown_clippy_lints)] + #[allow(clippy::pattern_type_mismatch)] + #[allow(clippy::redundant_pub_crate)] + #[allow(dead_code)] + #[allow(clippy::mut_mut)] + #[allow(clippy::type_repetition_in_bounds)] + struct __TupleStructProjection<'pin, T, U>( + ::pin_project::__private::Pin<&'pin mut (T)>, + &'pin mut (U), + ) + where + TupleStruct: 'pin; + #[allow(box_pointers)] + #[allow(deprecated)] + #[allow(explicit_outlives_requirements)] + #[allow(single_use_lifetimes)] + #[allow(unreachable_pub)] + #[allow(clippy::unknown_clippy_lints)] + #[allow(clippy::pattern_type_mismatch)] + #[allow(clippy::redundant_pub_crate)] + #[allow(dead_code)] + #[allow(clippy::ref_option_ref)] + #[allow(clippy::type_repetition_in_bounds)] + struct __TupleStructProjectionRef<'pin, T, U>( + ::pin_project::__private::Pin<&'pin (T)>, + &'pin (U), + ) + where + TupleStruct: 'pin; + impl TupleStruct { + fn project<'pin>( + self: ::pin_project::__private::Pin<&'pin mut Self>, + ) -> __TupleStructProjection<'pin, T, U> { + unsafe { + let Self(_0, _1) = self.get_unchecked_mut(); + __TupleStructProjection(::pin_project::__private::Pin::new_unchecked(_0), _1) + } + } + #[allow(clippy::missing_const_for_fn)] + fn project_ref<'pin>( + self: ::pin_project::__private::Pin<&'pin Self>, + ) -> __TupleStructProjectionRef<'pin, T, U> { + unsafe { + let Self(_0, _1) = self.get_ref(); + __TupleStructProjectionRef(::pin_project::__private::Pin::new_unchecked(_0), _1) + } + } + fn project_replace( + self: ::pin_project::__private::Pin<&mut Self>, + __replacement: Self, + ) -> ProjOwn { + unsafe { + let __self_ptr: *mut Self = self.get_unchecked_mut(); + let __guard = ::pin_project::__private::UnsafeOverwriteGuard { + target: __self_ptr, + value: ::pin_project::__private::ManuallyDrop::new(__replacement), + }; + let Self(_0, _1) = &mut *__self_ptr; + let __result = ProjOwn( + ::pin_project::__private::PhantomData, + ::pin_project::__private::ptr::read(_1), + ); + { + let __guard = ::pin_project::__private::UnsafeDropInPlaceGuard(_0); + } + __result + } + } + } + #[forbid(safe_packed_borrows)] + fn __assert_not_repr_packed(this: &TupleStruct) { + let _ = &this.0; + let _ = &this.1; + } + #[allow(missing_debug_implementations)] + struct __TupleStruct<'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 TupleStruct where + __TupleStruct<'pin, T, U>: ::pin_project::__private::Unpin + { + } + #[doc(hidden)] + unsafe impl<'pin, T, U> ::pin_project::UnsafeUnpin for TupleStruct where + __TupleStruct<'pin, T, U>: ::pin_project::__private::Unpin + { + } + trait TupleStructMustNotImplDrop {} + #[allow(clippy::drop_bounds, drop_bounds)] + impl TupleStructMustNotImplDrop for T {} + impl TupleStructMustNotImplDrop for TupleStruct {} + #[doc(hidden)] + impl ::pin_project::__private::PinnedDrop for TupleStruct { + unsafe fn drop(self: ::pin_project::__private::Pin<&mut Self>) {} + } +}; +fn main() {} diff --git a/tests/expand/naming/tuple_struct-own.rs b/tests/expand/naming/tuple_struct-own.rs new file mode 100644 index 0000000..a15ad40 --- /dev/null +++ b/tests/expand/naming/tuple_struct-own.rs @@ -0,0 +1,6 @@ +use pin_project::pin_project; + +#[pin_project(project_replace = ProjOwn)] +struct TupleStruct(#[pin] T, U); + +fn main() {} diff --git a/tests/expand/naming/tuple_struct-ref.expanded.rs b/tests/expand/naming/tuple_struct-ref.expanded.rs new file mode 100644 index 0000000..e06bf0c --- /dev/null +++ b/tests/expand/naming/tuple_struct-ref.expanded.rs @@ -0,0 +1,98 @@ +use pin_project::pin_project; +# [pin (__private (project_ref = ProjRef))] +struct TupleStruct(#[pin] T, U); +#[allow(box_pointers)] +#[allow(deprecated)] +#[allow(explicit_outlives_requirements)] +#[allow(single_use_lifetimes)] +#[allow(unreachable_pub)] +#[allow(clippy::unknown_clippy_lints)] +#[allow(clippy::pattern_type_mismatch)] +#[allow(clippy::redundant_pub_crate)] +#[allow(dead_code)] +#[allow(clippy::ref_option_ref)] +#[allow(clippy::type_repetition_in_bounds)] +struct ProjRef<'pin, T, U>(::pin_project::__private::Pin<&'pin (T)>, &'pin (U)) +where + TupleStruct: 'pin; +#[allow(box_pointers)] +#[allow(deprecated)] +#[allow(explicit_outlives_requirements)] +#[allow(single_use_lifetimes)] +#[allow(unreachable_pub)] +#[allow(clippy::unknown_clippy_lints)] +#[allow(clippy::pattern_type_mismatch)] +#[allow(clippy::redundant_pub_crate)] +#[allow(clippy::used_underscore_binding)] +const _: () = { + #[allow(box_pointers)] + #[allow(deprecated)] + #[allow(explicit_outlives_requirements)] + #[allow(single_use_lifetimes)] + #[allow(unreachable_pub)] + #[allow(clippy::unknown_clippy_lints)] + #[allow(clippy::pattern_type_mismatch)] + #[allow(clippy::redundant_pub_crate)] + #[allow(dead_code)] + #[allow(clippy::mut_mut)] + #[allow(clippy::type_repetition_in_bounds)] + struct __TupleStructProjection<'pin, T, U>( + ::pin_project::__private::Pin<&'pin mut (T)>, + &'pin mut (U), + ) + where + TupleStruct: 'pin; + impl TupleStruct { + fn project<'pin>( + self: ::pin_project::__private::Pin<&'pin mut Self>, + ) -> __TupleStructProjection<'pin, T, U> { + unsafe { + let Self(_0, _1) = self.get_unchecked_mut(); + __TupleStructProjection(::pin_project::__private::Pin::new_unchecked(_0), _1) + } + } + #[allow(clippy::missing_const_for_fn)] + fn project_ref<'pin>( + self: ::pin_project::__private::Pin<&'pin Self>, + ) -> ProjRef<'pin, T, U> { + unsafe { + let Self(_0, _1) = self.get_ref(); + ProjRef(::pin_project::__private::Pin::new_unchecked(_0), _1) + } + } + } + #[forbid(safe_packed_borrows)] + fn __assert_not_repr_packed(this: &TupleStruct) { + let _ = &this.0; + let _ = &this.1; + } + #[allow(missing_debug_implementations)] + struct __TupleStruct<'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 TupleStruct where + __TupleStruct<'pin, T, U>: ::pin_project::__private::Unpin + { + } + #[doc(hidden)] + unsafe impl<'pin, T, U> ::pin_project::UnsafeUnpin for TupleStruct where + __TupleStruct<'pin, T, U>: ::pin_project::__private::Unpin + { + } + trait TupleStructMustNotImplDrop {} + #[allow(clippy::drop_bounds, drop_bounds)] + impl TupleStructMustNotImplDrop for T {} + impl TupleStructMustNotImplDrop for TupleStruct {} + #[doc(hidden)] + impl ::pin_project::__private::PinnedDrop for TupleStruct { + unsafe fn drop(self: ::pin_project::__private::Pin<&mut Self>) {} + } +}; +fn main() {} diff --git a/tests/expand/naming/tuple_struct-ref.rs b/tests/expand/naming/tuple_struct-ref.rs new file mode 100644 index 0000000..cc61edf --- /dev/null +++ b/tests/expand/naming/tuple_struct-ref.rs @@ -0,0 +1,6 @@ +use pin_project::pin_project; + +#[pin_project(project_ref = ProjRef)] +struct TupleStruct(#[pin] T, U); + +fn main() {} diff --git a/tests/expand/not_unpin/enum.expanded.rs b/tests/expand/not_unpin/enum.expanded.rs new file mode 100644 index 0000000..8d25786 --- /dev/null +++ b/tests/expand/not_unpin/enum.expanded.rs @@ -0,0 +1,121 @@ +use pin_project::pin_project; +# [pin (__private (! Unpin , project = EnumProj , project_ref = EnumProjRef))] +enum Enum { + Struct { + #[pin] + pinned: T, + unpinned: U, + }, + Tuple(#[pin] T, U), + Unit, +} +#[allow(box_pointers)] +#[allow(deprecated)] +#[allow(explicit_outlives_requirements)] +#[allow(single_use_lifetimes)] +#[allow(unreachable_pub)] +#[allow(clippy::unknown_clippy_lints)] +#[allow(clippy::pattern_type_mismatch)] +#[allow(clippy::redundant_pub_crate)] +#[allow(dead_code)] +#[allow(clippy::mut_mut)] +#[allow(clippy::type_repetition_in_bounds)] +enum EnumProj<'pin, T, U> +where + Enum: 'pin, +{ + Struct { + pinned: ::pin_project::__private::Pin<&'pin mut (T)>, + unpinned: &'pin mut (U), + }, + Tuple(::pin_project::__private::Pin<&'pin mut (T)>, &'pin mut (U)), + Unit, +} +#[allow(box_pointers)] +#[allow(deprecated)] +#[allow(explicit_outlives_requirements)] +#[allow(single_use_lifetimes)] +#[allow(unreachable_pub)] +#[allow(clippy::unknown_clippy_lints)] +#[allow(clippy::pattern_type_mismatch)] +#[allow(clippy::redundant_pub_crate)] +#[allow(dead_code)] +#[allow(clippy::ref_option_ref)] +#[allow(clippy::type_repetition_in_bounds)] +enum EnumProjRef<'pin, T, U> +where + Enum: 'pin, +{ + Struct { + pinned: ::pin_project::__private::Pin<&'pin (T)>, + unpinned: &'pin (U), + }, + Tuple(::pin_project::__private::Pin<&'pin (T)>, &'pin (U)), + Unit, +} +#[allow(box_pointers)] +#[allow(deprecated)] +#[allow(explicit_outlives_requirements)] +#[allow(single_use_lifetimes)] +#[allow(unreachable_pub)] +#[allow(clippy::unknown_clippy_lints)] +#[allow(clippy::pattern_type_mismatch)] +#[allow(clippy::redundant_pub_crate)] +#[allow(clippy::used_underscore_binding)] +const _: () = { + impl Enum { + fn project<'pin>( + self: ::pin_project::__private::Pin<&'pin mut Self>, + ) -> EnumProj<'pin, T, U> { + unsafe { + match self.get_unchecked_mut() { + Self::Struct { pinned, unpinned } => EnumProj::Struct { + pinned: ::pin_project::__private::Pin::new_unchecked(pinned), + unpinned, + }, + Self::Tuple(_0, _1) => { + EnumProj::Tuple(::pin_project::__private::Pin::new_unchecked(_0), _1) + } + Self::Unit => EnumProj::Unit, + } + } + } + #[allow(clippy::missing_const_for_fn)] + fn project_ref<'pin>( + self: ::pin_project::__private::Pin<&'pin Self>, + ) -> EnumProjRef<'pin, T, U> { + unsafe { + match self.get_ref() { + Self::Struct { pinned, unpinned } => EnumProjRef::Struct { + pinned: ::pin_project::__private::Pin::new_unchecked(pinned), + unpinned, + }, + Self::Tuple(_0, _1) => { + EnumProjRef::Tuple(::pin_project::__private::Pin::new_unchecked(_0), _1) + } + Self::Unit => EnumProjRef::Unit, + } + } + } + } + impl<'pin, T, U> ::pin_project::__private::Unpin for Enum where + ::pin_project::__private::Wrapper<'pin, ::pin_project::__private::PhantomPinned>: + ::pin_project::__private::Unpin + { + } + #[doc(hidden)] + unsafe impl<'pin, T, U> ::pin_project::UnsafeUnpin for Enum where + ::pin_project::__private::Wrapper<'pin, ::pin_project::__private::PhantomPinned>: + ::pin_project::__private::Unpin + { + } + trait EnumMustNotImplDrop {} + #[allow(clippy::drop_bounds, drop_bounds)] + impl EnumMustNotImplDrop for T {} + impl EnumMustNotImplDrop for Enum {} + #[doc(hidden)] + impl ::pin_project::__private::PinnedDrop for Enum { + unsafe fn drop(self: ::pin_project::__private::Pin<&mut Self>) {} + } +}; +fn main() {} diff --git a/tests/expand/not_unpin/enum.rs b/tests/expand/not_unpin/enum.rs new file mode 100644 index 0000000..ac0b3b8 --- /dev/null +++ b/tests/expand/not_unpin/enum.rs @@ -0,0 +1,14 @@ +use pin_project::pin_project; + +#[pin_project(!Unpin, project = EnumProj, project_ref = EnumProjRef)] +enum Enum { + Struct { + #[pin] + pinned: T, + unpinned: U, + }, + Tuple(#[pin] T, U), + Unit, +} + +fn main() {} diff --git a/tests/expand/not_unpin/struct.expanded.rs b/tests/expand/not_unpin/struct.expanded.rs new file mode 100644 index 0000000..9d58022 --- /dev/null +++ b/tests/expand/not_unpin/struct.expanded.rs @@ -0,0 +1,104 @@ +use pin_project::pin_project; +# [pin (__private (! Unpin))] +struct Struct { + #[pin] + pinned: T, + unpinned: U, +} +#[allow(box_pointers)] +#[allow(deprecated)] +#[allow(explicit_outlives_requirements)] +#[allow(single_use_lifetimes)] +#[allow(unreachable_pub)] +#[allow(clippy::unknown_clippy_lints)] +#[allow(clippy::pattern_type_mismatch)] +#[allow(clippy::redundant_pub_crate)] +#[allow(clippy::used_underscore_binding)] +const _: () = { + #[allow(box_pointers)] + #[allow(deprecated)] + #[allow(explicit_outlives_requirements)] + #[allow(single_use_lifetimes)] + #[allow(unreachable_pub)] + #[allow(clippy::unknown_clippy_lints)] + #[allow(clippy::pattern_type_mismatch)] + #[allow(clippy::redundant_pub_crate)] + #[allow(dead_code)] + #[allow(clippy::mut_mut)] + #[allow(clippy::type_repetition_in_bounds)] + struct __StructProjection<'pin, T, U> + where + Struct: 'pin, + { + pinned: ::pin_project::__private::Pin<&'pin mut (T)>, + unpinned: &'pin mut (U), + } + #[allow(box_pointers)] + #[allow(deprecated)] + #[allow(explicit_outlives_requirements)] + #[allow(single_use_lifetimes)] + #[allow(unreachable_pub)] + #[allow(clippy::unknown_clippy_lints)] + #[allow(clippy::pattern_type_mismatch)] + #[allow(clippy::redundant_pub_crate)] + #[allow(dead_code)] + #[allow(clippy::ref_option_ref)] + #[allow(clippy::type_repetition_in_bounds)] + struct __StructProjectionRef<'pin, T, U> + where + Struct: 'pin, + { + pinned: ::pin_project::__private::Pin<&'pin (T)>, + unpinned: &'pin (U), + } + impl Struct { + fn project<'pin>( + self: ::pin_project::__private::Pin<&'pin mut Self>, + ) -> __StructProjection<'pin, T, U> { + unsafe { + let Self { pinned, unpinned } = self.get_unchecked_mut(); + __StructProjection { + pinned: ::pin_project::__private::Pin::new_unchecked(pinned), + unpinned, + } + } + } + #[allow(clippy::missing_const_for_fn)] + fn project_ref<'pin>( + self: ::pin_project::__private::Pin<&'pin Self>, + ) -> __StructProjectionRef<'pin, T, U> { + unsafe { + let Self { pinned, unpinned } = self.get_ref(); + __StructProjectionRef { + pinned: ::pin_project::__private::Pin::new_unchecked(pinned), + unpinned, + } + } + } + } + #[forbid(safe_packed_borrows)] + fn __assert_not_repr_packed(this: &Struct) { + let _ = &this.pinned; + let _ = &this.unpinned; + } + impl<'pin, T, U> ::pin_project::__private::Unpin for Struct where + ::pin_project::__private::Wrapper<'pin, ::pin_project::__private::PhantomPinned>: + ::pin_project::__private::Unpin + { + } + #[doc(hidden)] + unsafe impl<'pin, T, U> ::pin_project::UnsafeUnpin for Struct where + ::pin_project::__private::Wrapper<'pin, ::pin_project::__private::PhantomPinned>: + ::pin_project::__private::Unpin + { + } + trait StructMustNotImplDrop {} + #[allow(clippy::drop_bounds, drop_bounds)] + impl StructMustNotImplDrop for T {} + impl StructMustNotImplDrop for Struct {} + #[doc(hidden)] + impl ::pin_project::__private::PinnedDrop for Struct { + unsafe fn drop(self: ::pin_project::__private::Pin<&mut Self>) {} + } +}; +fn main() {} diff --git a/tests/expand/not_unpin/struct.rs b/tests/expand/not_unpin/struct.rs new file mode 100644 index 0000000..233e6d4 --- /dev/null +++ b/tests/expand/not_unpin/struct.rs @@ -0,0 +1,10 @@ +use pin_project::pin_project; + +#[pin_project(!Unpin)] +struct Struct { + #[pin] + pinned: T, + unpinned: U, +} + +fn main() {} diff --git a/tests/expand/not_unpin/tuple_struct.expanded.rs b/tests/expand/not_unpin/tuple_struct.expanded.rs new file mode 100644 index 0000000..525513e --- /dev/null +++ b/tests/expand/not_unpin/tuple_struct.expanded.rs @@ -0,0 +1,92 @@ +use pin_project::pin_project; +# [pin (__private (! Unpin))] +struct TupleStruct(#[pin] T, U); +#[allow(box_pointers)] +#[allow(deprecated)] +#[allow(explicit_outlives_requirements)] +#[allow(single_use_lifetimes)] +#[allow(unreachable_pub)] +#[allow(clippy::unknown_clippy_lints)] +#[allow(clippy::pattern_type_mismatch)] +#[allow(clippy::redundant_pub_crate)] +#[allow(clippy::used_underscore_binding)] +const _: () = { + #[allow(box_pointers)] + #[allow(deprecated)] + #[allow(explicit_outlives_requirements)] + #[allow(single_use_lifetimes)] + #[allow(unreachable_pub)] + #[allow(clippy::unknown_clippy_lints)] + #[allow(clippy::pattern_type_mismatch)] + #[allow(clippy::redundant_pub_crate)] + #[allow(dead_code)] + #[allow(clippy::mut_mut)] + #[allow(clippy::type_repetition_in_bounds)] + struct __TupleStructProjection<'pin, T, U>( + ::pin_project::__private::Pin<&'pin mut (T)>, + &'pin mut (U), + ) + where + TupleStruct: 'pin; + #[allow(box_pointers)] + #[allow(deprecated)] + #[allow(explicit_outlives_requirements)] + #[allow(single_use_lifetimes)] + #[allow(unreachable_pub)] + #[allow(clippy::unknown_clippy_lints)] + #[allow(clippy::pattern_type_mismatch)] + #[allow(clippy::redundant_pub_crate)] + #[allow(dead_code)] + #[allow(clippy::ref_option_ref)] + #[allow(clippy::type_repetition_in_bounds)] + struct __TupleStructProjectionRef<'pin, T, U>( + ::pin_project::__private::Pin<&'pin (T)>, + &'pin (U), + ) + where + TupleStruct: 'pin; + impl TupleStruct { + fn project<'pin>( + self: ::pin_project::__private::Pin<&'pin mut Self>, + ) -> __TupleStructProjection<'pin, T, U> { + unsafe { + let Self(_0, _1) = self.get_unchecked_mut(); + __TupleStructProjection(::pin_project::__private::Pin::new_unchecked(_0), _1) + } + } + #[allow(clippy::missing_const_for_fn)] + fn project_ref<'pin>( + self: ::pin_project::__private::Pin<&'pin Self>, + ) -> __TupleStructProjectionRef<'pin, T, U> { + unsafe { + let Self(_0, _1) = self.get_ref(); + __TupleStructProjectionRef(::pin_project::__private::Pin::new_unchecked(_0), _1) + } + } + } + #[forbid(safe_packed_borrows)] + fn __assert_not_repr_packed(this: &TupleStruct) { + let _ = &this.0; + let _ = &this.1; + } + impl<'pin, T, U> ::pin_project::__private::Unpin for TupleStruct where + ::pin_project::__private::Wrapper<'pin, ::pin_project::__private::PhantomPinned>: + ::pin_project::__private::Unpin + { + } + #[doc(hidden)] + unsafe impl<'pin, T, U> ::pin_project::UnsafeUnpin for TupleStruct where + ::pin_project::__private::Wrapper<'pin, ::pin_project::__private::PhantomPinned>: + ::pin_project::__private::Unpin + { + } + trait TupleStructMustNotImplDrop {} + #[allow(clippy::drop_bounds, drop_bounds)] + impl TupleStructMustNotImplDrop for T {} + impl TupleStructMustNotImplDrop for TupleStruct {} + #[doc(hidden)] + impl ::pin_project::__private::PinnedDrop for TupleStruct { + unsafe fn drop(self: ::pin_project::__private::Pin<&mut Self>) {} + } +}; +fn main() {} diff --git a/tests/expand/not_unpin/tuple_struct.rs b/tests/expand/not_unpin/tuple_struct.rs new file mode 100644 index 0000000..c8065db --- /dev/null +++ b/tests/expand/not_unpin/tuple_struct.rs @@ -0,0 +1,6 @@ +use pin_project::pin_project; + +#[pin_project(!Unpin)] +struct TupleStruct(#[pin] T, U); + +fn main() {} diff --git a/tests/expand/pinned_drop/enum.expanded.rs b/tests/expand/pinned_drop/enum.expanded.rs new file mode 100644 index 0000000..7978ba3 --- /dev/null +++ b/tests/expand/pinned_drop/enum.expanded.rs @@ -0,0 +1,142 @@ +use pin_project::{pin_project, pinned_drop}; +use std::pin::Pin; +# [pin (__private (PinnedDrop , project = EnumProj , project_ref = EnumProjRef))] +enum Enum { + Struct { + #[pin] + pinned: T, + unpinned: U, + }, + Tuple(#[pin] T, U), + Unit, +} +#[allow(box_pointers)] +#[allow(deprecated)] +#[allow(explicit_outlives_requirements)] +#[allow(single_use_lifetimes)] +#[allow(unreachable_pub)] +#[allow(clippy::unknown_clippy_lints)] +#[allow(clippy::pattern_type_mismatch)] +#[allow(clippy::redundant_pub_crate)] +#[allow(dead_code)] +#[allow(clippy::mut_mut)] +#[allow(clippy::type_repetition_in_bounds)] +enum EnumProj<'pin, T, U> +where + Enum: 'pin, +{ + Struct { + pinned: ::pin_project::__private::Pin<&'pin mut (T)>, + unpinned: &'pin mut (U), + }, + Tuple(::pin_project::__private::Pin<&'pin mut (T)>, &'pin mut (U)), + Unit, +} +#[allow(box_pointers)] +#[allow(deprecated)] +#[allow(explicit_outlives_requirements)] +#[allow(single_use_lifetimes)] +#[allow(unreachable_pub)] +#[allow(clippy::unknown_clippy_lints)] +#[allow(clippy::pattern_type_mismatch)] +#[allow(clippy::redundant_pub_crate)] +#[allow(dead_code)] +#[allow(clippy::ref_option_ref)] +#[allow(clippy::type_repetition_in_bounds)] +enum EnumProjRef<'pin, T, U> +where + Enum: 'pin, +{ + Struct { + pinned: ::pin_project::__private::Pin<&'pin (T)>, + unpinned: &'pin (U), + }, + Tuple(::pin_project::__private::Pin<&'pin (T)>, &'pin (U)), + Unit, +} +#[allow(box_pointers)] +#[allow(deprecated)] +#[allow(explicit_outlives_requirements)] +#[allow(single_use_lifetimes)] +#[allow(unreachable_pub)] +#[allow(clippy::unknown_clippy_lints)] +#[allow(clippy::pattern_type_mismatch)] +#[allow(clippy::redundant_pub_crate)] +#[allow(clippy::used_underscore_binding)] +const _: () = { + impl Enum { + fn project<'pin>( + self: ::pin_project::__private::Pin<&'pin mut Self>, + ) -> EnumProj<'pin, T, U> { + unsafe { + match self.get_unchecked_mut() { + Self::Struct { pinned, unpinned } => EnumProj::Struct { + pinned: ::pin_project::__private::Pin::new_unchecked(pinned), + unpinned, + }, + Self::Tuple(_0, _1) => { + EnumProj::Tuple(::pin_project::__private::Pin::new_unchecked(_0), _1) + } + Self::Unit => EnumProj::Unit, + } + } + } + #[allow(clippy::missing_const_for_fn)] + fn project_ref<'pin>( + self: ::pin_project::__private::Pin<&'pin Self>, + ) -> EnumProjRef<'pin, T, U> { + unsafe { + match self.get_ref() { + Self::Struct { pinned, unpinned } => EnumProjRef::Struct { + pinned: ::pin_project::__private::Pin::new_unchecked(pinned), + unpinned, + }, + Self::Tuple(_0, _1) => { + EnumProjRef::Tuple(::pin_project::__private::Pin::new_unchecked(_0), _1) + } + Self::Unit => EnumProjRef::Unit, + } + } + } + } + #[allow(missing_debug_implementations)] + struct __Enum<'pin, T, U> { + __pin_project_use_generics: ::pin_project::__private::AlwaysUnpin< + 'pin, + ( + ::pin_project::__private::PhantomData, + ::pin_project::__private::PhantomData, + ), + >, + __field0: T, + __field1: T, + } + impl<'pin, T, U> ::pin_project::__private::Unpin for Enum where + __Enum<'pin, T, U>: ::pin_project::__private::Unpin + { + } + #[doc(hidden)] + unsafe impl<'pin, T, U> ::pin_project::UnsafeUnpin for Enum where + __Enum<'pin, T, U>: ::pin_project::__private::Unpin + { + } + impl ::pin_project::__private::Drop for Enum { + fn drop(&mut self) { + unsafe { + let __pinned_self = ::pin_project::__private::Pin::new_unchecked(self); + ::pin_project::__private::PinnedDrop::drop(__pinned_self); + } + } + } +}; +impl ::pin_project::__private::PinnedDrop for Enum { + unsafe fn drop(self: Pin<&mut Self>) { + #[allow(clippy::needless_pass_by_value)] + fn __drop_inner(__self: Pin<&mut Enum>) { + fn __drop_inner() {} + let _ = __self; + } + __drop_inner(self); + } +} +fn main() {} diff --git a/tests/expand/pinned_drop/enum.rs b/tests/expand/pinned_drop/enum.rs new file mode 100644 index 0000000..f5b8aa4 --- /dev/null +++ b/tests/expand/pinned_drop/enum.rs @@ -0,0 +1,22 @@ +use pin_project::{pin_project, pinned_drop}; +use std::pin::Pin; + +#[pin_project(PinnedDrop, project = EnumProj, project_ref = EnumProjRef)] +enum Enum { + Struct { + #[pin] + pinned: T, + unpinned: U, + }, + Tuple(#[pin] T, U), + Unit, +} + +#[pinned_drop] +impl PinnedDrop for Enum { + fn drop(self: Pin<&mut Self>) { + let _ = self; + } +} + +fn main() {} diff --git a/tests/expand/pinned_drop/struct.expanded.rs b/tests/expand/pinned_drop/struct.expanded.rs new file mode 100644 index 0000000..1bdeda4 --- /dev/null +++ b/tests/expand/pinned_drop/struct.expanded.rs @@ -0,0 +1,124 @@ +use pin_project::{pin_project, pinned_drop}; +use std::pin::Pin; +#[pin(__private(PinnedDrop))] +struct Struct { + #[pin] + pinned: T, + unpinned: U, +} +#[allow(box_pointers)] +#[allow(deprecated)] +#[allow(explicit_outlives_requirements)] +#[allow(single_use_lifetimes)] +#[allow(unreachable_pub)] +#[allow(clippy::unknown_clippy_lints)] +#[allow(clippy::pattern_type_mismatch)] +#[allow(clippy::redundant_pub_crate)] +#[allow(clippy::used_underscore_binding)] +const _: () = { + #[allow(box_pointers)] + #[allow(deprecated)] + #[allow(explicit_outlives_requirements)] + #[allow(single_use_lifetimes)] + #[allow(unreachable_pub)] + #[allow(clippy::unknown_clippy_lints)] + #[allow(clippy::pattern_type_mismatch)] + #[allow(clippy::redundant_pub_crate)] + #[allow(dead_code)] + #[allow(clippy::mut_mut)] + #[allow(clippy::type_repetition_in_bounds)] + struct __StructProjection<'pin, T, U> + where + Struct: 'pin, + { + pinned: ::pin_project::__private::Pin<&'pin mut (T)>, + unpinned: &'pin mut (U), + } + #[allow(box_pointers)] + #[allow(deprecated)] + #[allow(explicit_outlives_requirements)] + #[allow(single_use_lifetimes)] + #[allow(unreachable_pub)] + #[allow(clippy::unknown_clippy_lints)] + #[allow(clippy::pattern_type_mismatch)] + #[allow(clippy::redundant_pub_crate)] + #[allow(dead_code)] + #[allow(clippy::ref_option_ref)] + #[allow(clippy::type_repetition_in_bounds)] + struct __StructProjectionRef<'pin, T, U> + where + Struct: 'pin, + { + pinned: ::pin_project::__private::Pin<&'pin (T)>, + unpinned: &'pin (U), + } + impl Struct { + fn project<'pin>( + self: ::pin_project::__private::Pin<&'pin mut Self>, + ) -> __StructProjection<'pin, T, U> { + unsafe { + let Self { pinned, unpinned } = self.get_unchecked_mut(); + __StructProjection { + pinned: ::pin_project::__private::Pin::new_unchecked(pinned), + unpinned, + } + } + } + #[allow(clippy::missing_const_for_fn)] + fn project_ref<'pin>( + self: ::pin_project::__private::Pin<&'pin Self>, + ) -> __StructProjectionRef<'pin, T, U> { + unsafe { + let Self { pinned, unpinned } = self.get_ref(); + __StructProjectionRef { + pinned: ::pin_project::__private::Pin::new_unchecked(pinned), + unpinned, + } + } + } + } + #[forbid(safe_packed_borrows)] + fn __assert_not_repr_packed(this: &Struct) { + let _ = &this.pinned; + let _ = &this.unpinned; + } + #[allow(missing_debug_implementations)] + struct __Struct<'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 Struct where + __Struct<'pin, T, U>: ::pin_project::__private::Unpin + { + } + #[doc(hidden)] + unsafe impl<'pin, T, U> ::pin_project::UnsafeUnpin for Struct where + __Struct<'pin, T, U>: ::pin_project::__private::Unpin + { + } + impl ::pin_project::__private::Drop for Struct { + fn drop(&mut self) { + unsafe { + let __pinned_self = ::pin_project::__private::Pin::new_unchecked(self); + ::pin_project::__private::PinnedDrop::drop(__pinned_self); + } + } + } +}; +impl ::pin_project::__private::PinnedDrop for Struct { + unsafe fn drop(self: Pin<&mut Self>) { + #[allow(clippy::needless_pass_by_value)] + fn __drop_inner(__self: Pin<&mut Struct>) { + fn __drop_inner() {} + let _ = __self; + } + __drop_inner(self); + } +} +fn main() {} diff --git a/tests/expand/pinned_drop/struct.rs b/tests/expand/pinned_drop/struct.rs new file mode 100644 index 0000000..948e6cc --- /dev/null +++ b/tests/expand/pinned_drop/struct.rs @@ -0,0 +1,18 @@ +use pin_project::{pin_project, pinned_drop}; +use std::pin::Pin; + +#[pin_project(PinnedDrop)] +struct Struct { + #[pin] + pinned: T, + unpinned: U, +} + +#[pinned_drop] +impl PinnedDrop for Struct { + fn drop(self: Pin<&mut Self>) { + let _ = self; + } +} + +fn main() {} diff --git a/tests/expand/pinned_drop/tuple_struct.expanded.rs b/tests/expand/pinned_drop/tuple_struct.expanded.rs new file mode 100644 index 0000000..f6cf250 --- /dev/null +++ b/tests/expand/pinned_drop/tuple_struct.expanded.rs @@ -0,0 +1,112 @@ +use pin_project::{pin_project, pinned_drop}; +use std::pin::Pin; +#[pin(__private(PinnedDrop))] +struct TupleStruct(#[pin] T, U); +#[allow(box_pointers)] +#[allow(deprecated)] +#[allow(explicit_outlives_requirements)] +#[allow(single_use_lifetimes)] +#[allow(unreachable_pub)] +#[allow(clippy::unknown_clippy_lints)] +#[allow(clippy::pattern_type_mismatch)] +#[allow(clippy::redundant_pub_crate)] +#[allow(clippy::used_underscore_binding)] +const _: () = { + #[allow(box_pointers)] + #[allow(deprecated)] + #[allow(explicit_outlives_requirements)] + #[allow(single_use_lifetimes)] + #[allow(unreachable_pub)] + #[allow(clippy::unknown_clippy_lints)] + #[allow(clippy::pattern_type_mismatch)] + #[allow(clippy::redundant_pub_crate)] + #[allow(dead_code)] + #[allow(clippy::mut_mut)] + #[allow(clippy::type_repetition_in_bounds)] + struct __TupleStructProjection<'pin, T, U>( + ::pin_project::__private::Pin<&'pin mut (T)>, + &'pin mut (U), + ) + where + TupleStruct: 'pin; + #[allow(box_pointers)] + #[allow(deprecated)] + #[allow(explicit_outlives_requirements)] + #[allow(single_use_lifetimes)] + #[allow(unreachable_pub)] + #[allow(clippy::unknown_clippy_lints)] + #[allow(clippy::pattern_type_mismatch)] + #[allow(clippy::redundant_pub_crate)] + #[allow(dead_code)] + #[allow(clippy::ref_option_ref)] + #[allow(clippy::type_repetition_in_bounds)] + struct __TupleStructProjectionRef<'pin, T, U>( + ::pin_project::__private::Pin<&'pin (T)>, + &'pin (U), + ) + where + TupleStruct: 'pin; + impl TupleStruct { + fn project<'pin>( + self: ::pin_project::__private::Pin<&'pin mut Self>, + ) -> __TupleStructProjection<'pin, T, U> { + unsafe { + let Self(_0, _1) = self.get_unchecked_mut(); + __TupleStructProjection(::pin_project::__private::Pin::new_unchecked(_0), _1) + } + } + #[allow(clippy::missing_const_for_fn)] + fn project_ref<'pin>( + self: ::pin_project::__private::Pin<&'pin Self>, + ) -> __TupleStructProjectionRef<'pin, T, U> { + unsafe { + let Self(_0, _1) = self.get_ref(); + __TupleStructProjectionRef(::pin_project::__private::Pin::new_unchecked(_0), _1) + } + } + } + #[forbid(safe_packed_borrows)] + fn __assert_not_repr_packed(this: &TupleStruct) { + let _ = &this.0; + let _ = &this.1; + } + #[allow(missing_debug_implementations)] + struct __TupleStruct<'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 TupleStruct where + __TupleStruct<'pin, T, U>: ::pin_project::__private::Unpin + { + } + #[doc(hidden)] + unsafe impl<'pin, T, U> ::pin_project::UnsafeUnpin for TupleStruct where + __TupleStruct<'pin, T, U>: ::pin_project::__private::Unpin + { + } + impl ::pin_project::__private::Drop for TupleStruct { + fn drop(&mut self) { + unsafe { + let __pinned_self = ::pin_project::__private::Pin::new_unchecked(self); + ::pin_project::__private::PinnedDrop::drop(__pinned_self); + } + } + } +}; +impl ::pin_project::__private::PinnedDrop for TupleStruct { + unsafe fn drop(self: Pin<&mut Self>) { + #[allow(clippy::needless_pass_by_value)] + fn __drop_inner(__self: Pin<&mut TupleStruct>) { + fn __drop_inner() {} + let _ = __self; + } + __drop_inner(self); + } +} +fn main() {} diff --git a/tests/expand/pinned_drop/tuple_struct.rs b/tests/expand/pinned_drop/tuple_struct.rs new file mode 100644 index 0000000..a536039 --- /dev/null +++ b/tests/expand/pinned_drop/tuple_struct.rs @@ -0,0 +1,14 @@ +use pin_project::{pin_project, pinned_drop}; +use std::pin::Pin; + +#[pin_project(PinnedDrop)] +struct TupleStruct(#[pin] T, U); + +#[pinned_drop] +impl PinnedDrop for TupleStruct { + fn drop(self: Pin<&mut Self>) { + let _ = self; + } +} + +fn main() {} diff --git a/tests/expand/project_replace/enum.expanded.rs b/tests/expand/project_replace/enum.expanded.rs new file mode 100644 index 0000000..6af358b --- /dev/null +++ b/tests/expand/project_replace/enum.expanded.rs @@ -0,0 +1,112 @@ +use pin_project::pin_project; +# [pin (__private (project_replace = EnumProjOwn))] +enum Enum { + Struct { + #[pin] + pinned: T, + unpinned: U, + }, + Tuple(#[pin] T, U), + Unit, +} +#[allow(box_pointers)] +#[allow(deprecated)] +#[allow(explicit_outlives_requirements)] +#[allow(single_use_lifetimes)] +#[allow(unreachable_pub)] +#[allow(clippy::unknown_clippy_lints)] +#[allow(clippy::pattern_type_mismatch)] +#[allow(clippy::redundant_pub_crate)] +#[allow(dead_code)] +#[allow(variant_size_differences)] +#[allow(clippy::large_enum_variant)] +enum EnumProjOwn { + Struct { + pinned: ::pin_project::__private::PhantomData, + unpinned: U, + }, + Tuple(::pin_project::__private::PhantomData, U), + Unit, +} +#[allow(box_pointers)] +#[allow(deprecated)] +#[allow(explicit_outlives_requirements)] +#[allow(single_use_lifetimes)] +#[allow(unreachable_pub)] +#[allow(clippy::unknown_clippy_lints)] +#[allow(clippy::pattern_type_mismatch)] +#[allow(clippy::redundant_pub_crate)] +#[allow(clippy::used_underscore_binding)] +const _: () = { + impl Enum { + fn project_replace( + self: ::pin_project::__private::Pin<&mut Self>, + __replacement: Self, + ) -> EnumProjOwn { + unsafe { + let __self_ptr: *mut Self = self.get_unchecked_mut(); + let __guard = ::pin_project::__private::UnsafeOverwriteGuard { + target: __self_ptr, + value: ::pin_project::__private::ManuallyDrop::new(__replacement), + }; + match &mut *__self_ptr { + Self::Struct { pinned, unpinned } => { + let __result = EnumProjOwn::Struct { + pinned: ::pin_project::__private::PhantomData, + unpinned: ::pin_project::__private::ptr::read(unpinned), + }; + { + let __guard = ::pin_project::__private::UnsafeDropInPlaceGuard(pinned); + } + __result + } + Self::Tuple(_0, _1) => { + let __result = EnumProjOwn::Tuple( + ::pin_project::__private::PhantomData, + ::pin_project::__private::ptr::read(_1), + ); + { + let __guard = ::pin_project::__private::UnsafeDropInPlaceGuard(_0); + } + __result + } + Self::Unit => { + let __result = EnumProjOwn::Unit; + {} + __result + } + } + } + } + } + #[allow(missing_debug_implementations)] + struct __Enum<'pin, T, U> { + __pin_project_use_generics: ::pin_project::__private::AlwaysUnpin< + 'pin, + ( + ::pin_project::__private::PhantomData, + ::pin_project::__private::PhantomData, + ), + >, + __field0: T, + __field1: T, + } + impl<'pin, T, U> ::pin_project::__private::Unpin for Enum where + __Enum<'pin, T, U>: ::pin_project::__private::Unpin + { + } + #[doc(hidden)] + unsafe impl<'pin, T, U> ::pin_project::UnsafeUnpin for Enum where + __Enum<'pin, T, U>: ::pin_project::__private::Unpin + { + } + trait EnumMustNotImplDrop {} + #[allow(clippy::drop_bounds, drop_bounds)] + impl EnumMustNotImplDrop for T {} + impl EnumMustNotImplDrop for Enum {} + #[doc(hidden)] + impl ::pin_project::__private::PinnedDrop for Enum { + unsafe fn drop(self: ::pin_project::__private::Pin<&mut Self>) {} + } +}; +fn main() {} diff --git a/tests/expand/project_replace/enum.rs b/tests/expand/project_replace/enum.rs new file mode 100644 index 0000000..d737f64 --- /dev/null +++ b/tests/expand/project_replace/enum.rs @@ -0,0 +1,14 @@ +use pin_project::pin_project; + +#[pin_project(project_replace = EnumProjOwn)] +enum Enum { + Struct { + #[pin] + pinned: T, + unpinned: U, + }, + Tuple(#[pin] T, U), + Unit, +} + +fn main() {} diff --git a/tests/expand/project_replace/struct.expanded.rs b/tests/expand/project_replace/struct.expanded.rs new file mode 100644 index 0000000..d210810 --- /dev/null +++ b/tests/expand/project_replace/struct.expanded.rs @@ -0,0 +1,147 @@ +use pin_project::pin_project; +#[pin(__private(project_replace))] +struct Struct { + #[pin] + pinned: T, + unpinned: U, +} +#[allow(box_pointers)] +#[allow(deprecated)] +#[allow(explicit_outlives_requirements)] +#[allow(single_use_lifetimes)] +#[allow(unreachable_pub)] +#[allow(clippy::unknown_clippy_lints)] +#[allow(clippy::pattern_type_mismatch)] +#[allow(clippy::redundant_pub_crate)] +#[allow(clippy::used_underscore_binding)] +const _: () = { + #[allow(box_pointers)] + #[allow(deprecated)] + #[allow(explicit_outlives_requirements)] + #[allow(single_use_lifetimes)] + #[allow(unreachable_pub)] + #[allow(clippy::unknown_clippy_lints)] + #[allow(clippy::pattern_type_mismatch)] + #[allow(clippy::redundant_pub_crate)] + #[allow(dead_code)] + #[allow(clippy::mut_mut)] + #[allow(clippy::type_repetition_in_bounds)] + struct __StructProjection<'pin, T, U> + where + Struct: 'pin, + { + pinned: ::pin_project::__private::Pin<&'pin mut (T)>, + unpinned: &'pin mut (U), + } + #[allow(box_pointers)] + #[allow(deprecated)] + #[allow(explicit_outlives_requirements)] + #[allow(single_use_lifetimes)] + #[allow(unreachable_pub)] + #[allow(clippy::unknown_clippy_lints)] + #[allow(clippy::pattern_type_mismatch)] + #[allow(clippy::redundant_pub_crate)] + #[allow(dead_code)] + #[allow(clippy::ref_option_ref)] + #[allow(clippy::type_repetition_in_bounds)] + struct __StructProjectionRef<'pin, T, U> + where + Struct: 'pin, + { + pinned: ::pin_project::__private::Pin<&'pin (T)>, + unpinned: &'pin (U), + } + #[allow(box_pointers)] + #[allow(deprecated)] + #[allow(explicit_outlives_requirements)] + #[allow(single_use_lifetimes)] + #[allow(unreachable_pub)] + #[allow(clippy::unknown_clippy_lints)] + #[allow(clippy::pattern_type_mismatch)] + #[allow(clippy::redundant_pub_crate)] + #[allow(dead_code)] + struct __StructProjectionOwned { + pinned: ::pin_project::__private::PhantomData, + unpinned: U, + } + impl Struct { + fn project<'pin>( + self: ::pin_project::__private::Pin<&'pin mut Self>, + ) -> __StructProjection<'pin, T, U> { + unsafe { + let Self { pinned, unpinned } = self.get_unchecked_mut(); + __StructProjection { + pinned: ::pin_project::__private::Pin::new_unchecked(pinned), + unpinned, + } + } + } + #[allow(clippy::missing_const_for_fn)] + fn project_ref<'pin>( + self: ::pin_project::__private::Pin<&'pin Self>, + ) -> __StructProjectionRef<'pin, T, U> { + unsafe { + let Self { pinned, unpinned } = self.get_ref(); + __StructProjectionRef { + pinned: ::pin_project::__private::Pin::new_unchecked(pinned), + unpinned, + } + } + } + fn project_replace( + self: ::pin_project::__private::Pin<&mut Self>, + __replacement: Self, + ) -> __StructProjectionOwned { + unsafe { + let __self_ptr: *mut Self = self.get_unchecked_mut(); + let __guard = ::pin_project::__private::UnsafeOverwriteGuard { + target: __self_ptr, + value: ::pin_project::__private::ManuallyDrop::new(__replacement), + }; + let Self { pinned, unpinned } = &mut *__self_ptr; + let __result = __StructProjectionOwned { + pinned: ::pin_project::__private::PhantomData, + unpinned: ::pin_project::__private::ptr::read(unpinned), + }; + { + let __guard = ::pin_project::__private::UnsafeDropInPlaceGuard(pinned); + } + __result + } + } + } + #[forbid(safe_packed_borrows)] + fn __assert_not_repr_packed(this: &Struct) { + let _ = &this.pinned; + let _ = &this.unpinned; + } + #[allow(missing_debug_implementations)] + struct __Struct<'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 Struct where + __Struct<'pin, T, U>: ::pin_project::__private::Unpin + { + } + #[doc(hidden)] + unsafe impl<'pin, T, U> ::pin_project::UnsafeUnpin for Struct where + __Struct<'pin, T, U>: ::pin_project::__private::Unpin + { + } + trait StructMustNotImplDrop {} + #[allow(clippy::drop_bounds, drop_bounds)] + impl StructMustNotImplDrop for T {} + impl StructMustNotImplDrop for Struct {} + #[doc(hidden)] + impl ::pin_project::__private::PinnedDrop for Struct { + unsafe fn drop(self: ::pin_project::__private::Pin<&mut Self>) {} + } +}; +fn main() {} diff --git a/tests/expand/project_replace/struct.rs b/tests/expand/project_replace/struct.rs new file mode 100644 index 0000000..5865526 --- /dev/null +++ b/tests/expand/project_replace/struct.rs @@ -0,0 +1,10 @@ +use pin_project::pin_project; + +#[pin_project(project_replace)] +struct Struct { + #[pin] + pinned: T, + unpinned: U, +} + +fn main() {} diff --git a/tests/expand/project_replace/tuple_struct.expanded.rs b/tests/expand/project_replace/tuple_struct.expanded.rs new file mode 100644 index 0000000..a48d502 --- /dev/null +++ b/tests/expand/project_replace/tuple_struct.expanded.rs @@ -0,0 +1,132 @@ +use pin_project::pin_project; +#[pin(__private(project_replace))] +struct TupleStruct(#[pin] T, U); +#[allow(box_pointers)] +#[allow(deprecated)] +#[allow(explicit_outlives_requirements)] +#[allow(single_use_lifetimes)] +#[allow(unreachable_pub)] +#[allow(clippy::unknown_clippy_lints)] +#[allow(clippy::pattern_type_mismatch)] +#[allow(clippy::redundant_pub_crate)] +#[allow(clippy::used_underscore_binding)] +const _: () = { + #[allow(box_pointers)] + #[allow(deprecated)] + #[allow(explicit_outlives_requirements)] + #[allow(single_use_lifetimes)] + #[allow(unreachable_pub)] + #[allow(clippy::unknown_clippy_lints)] + #[allow(clippy::pattern_type_mismatch)] + #[allow(clippy::redundant_pub_crate)] + #[allow(dead_code)] + #[allow(clippy::mut_mut)] + #[allow(clippy::type_repetition_in_bounds)] + struct __TupleStructProjection<'pin, T, U>( + ::pin_project::__private::Pin<&'pin mut (T)>, + &'pin mut (U), + ) + where + TupleStruct: 'pin; + #[allow(box_pointers)] + #[allow(deprecated)] + #[allow(explicit_outlives_requirements)] + #[allow(single_use_lifetimes)] + #[allow(unreachable_pub)] + #[allow(clippy::unknown_clippy_lints)] + #[allow(clippy::pattern_type_mismatch)] + #[allow(clippy::redundant_pub_crate)] + #[allow(dead_code)] + #[allow(clippy::ref_option_ref)] + #[allow(clippy::type_repetition_in_bounds)] + struct __TupleStructProjectionRef<'pin, T, U>( + ::pin_project::__private::Pin<&'pin (T)>, + &'pin (U), + ) + where + TupleStruct: 'pin; + #[allow(box_pointers)] + #[allow(deprecated)] + #[allow(explicit_outlives_requirements)] + #[allow(single_use_lifetimes)] + #[allow(unreachable_pub)] + #[allow(clippy::unknown_clippy_lints)] + #[allow(clippy::pattern_type_mismatch)] + #[allow(clippy::redundant_pub_crate)] + #[allow(dead_code)] + struct __TupleStructProjectionOwned(::pin_project::__private::PhantomData, U); + impl TupleStruct { + fn project<'pin>( + self: ::pin_project::__private::Pin<&'pin mut Self>, + ) -> __TupleStructProjection<'pin, T, U> { + unsafe { + let Self(_0, _1) = self.get_unchecked_mut(); + __TupleStructProjection(::pin_project::__private::Pin::new_unchecked(_0), _1) + } + } + #[allow(clippy::missing_const_for_fn)] + fn project_ref<'pin>( + self: ::pin_project::__private::Pin<&'pin Self>, + ) -> __TupleStructProjectionRef<'pin, T, U> { + unsafe { + let Self(_0, _1) = self.get_ref(); + __TupleStructProjectionRef(::pin_project::__private::Pin::new_unchecked(_0), _1) + } + } + fn project_replace( + self: ::pin_project::__private::Pin<&mut Self>, + __replacement: Self, + ) -> __TupleStructProjectionOwned { + unsafe { + let __self_ptr: *mut Self = self.get_unchecked_mut(); + let __guard = ::pin_project::__private::UnsafeOverwriteGuard { + target: __self_ptr, + value: ::pin_project::__private::ManuallyDrop::new(__replacement), + }; + let Self(_0, _1) = &mut *__self_ptr; + let __result = __TupleStructProjectionOwned( + ::pin_project::__private::PhantomData, + ::pin_project::__private::ptr::read(_1), + ); + { + let __guard = ::pin_project::__private::UnsafeDropInPlaceGuard(_0); + } + __result + } + } + } + #[forbid(safe_packed_borrows)] + fn __assert_not_repr_packed(this: &TupleStruct) { + let _ = &this.0; + let _ = &this.1; + } + #[allow(missing_debug_implementations)] + struct __TupleStruct<'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 TupleStruct where + __TupleStruct<'pin, T, U>: ::pin_project::__private::Unpin + { + } + #[doc(hidden)] + unsafe impl<'pin, T, U> ::pin_project::UnsafeUnpin for TupleStruct where + __TupleStruct<'pin, T, U>: ::pin_project::__private::Unpin + { + } + trait TupleStructMustNotImplDrop {} + #[allow(clippy::drop_bounds, drop_bounds)] + impl TupleStructMustNotImplDrop for T {} + impl TupleStructMustNotImplDrop for TupleStruct {} + #[doc(hidden)] + impl ::pin_project::__private::PinnedDrop for TupleStruct { + unsafe fn drop(self: ::pin_project::__private::Pin<&mut Self>) {} + } +}; +fn main() {} diff --git a/tests/expand/project_replace/tuple_struct.rs b/tests/expand/project_replace/tuple_struct.rs new file mode 100644 index 0000000..c4d05f5 --- /dev/null +++ b/tests/expand/project_replace/tuple_struct.rs @@ -0,0 +1,6 @@ +use pin_project::pin_project; + +#[pin_project(project_replace)] +struct TupleStruct(#[pin] T, U); + +fn main() {} diff --git a/tests/expand/pub/enum.expanded.rs b/tests/expand/pub/enum.expanded.rs new file mode 100644 index 0000000..42396ac --- /dev/null +++ b/tests/expand/pub/enum.expanded.rs @@ -0,0 +1,131 @@ +use pin_project::pin_project; +# [pin (__private (project = EnumProj , project_ref = EnumProjRef))] +pub enum Enum { + Struct { + #[pin] + pinned: T, + unpinned: U, + }, + Tuple(#[pin] T, U), + Unit, +} +#[allow(box_pointers)] +#[allow(deprecated)] +#[allow(explicit_outlives_requirements)] +#[allow(single_use_lifetimes)] +#[allow(unreachable_pub)] +#[allow(clippy::unknown_clippy_lints)] +#[allow(clippy::pattern_type_mismatch)] +#[allow(clippy::redundant_pub_crate)] +#[allow(dead_code)] +#[allow(clippy::mut_mut)] +#[allow(clippy::type_repetition_in_bounds)] +pub(crate) enum EnumProj<'pin, T, U> +where + Enum: 'pin, +{ + Struct { + pinned: ::pin_project::__private::Pin<&'pin mut (T)>, + unpinned: &'pin mut (U), + }, + Tuple(::pin_project::__private::Pin<&'pin mut (T)>, &'pin mut (U)), + Unit, +} +#[allow(box_pointers)] +#[allow(deprecated)] +#[allow(explicit_outlives_requirements)] +#[allow(single_use_lifetimes)] +#[allow(unreachable_pub)] +#[allow(clippy::unknown_clippy_lints)] +#[allow(clippy::pattern_type_mismatch)] +#[allow(clippy::redundant_pub_crate)] +#[allow(dead_code)] +#[allow(clippy::ref_option_ref)] +#[allow(clippy::type_repetition_in_bounds)] +pub(crate) enum EnumProjRef<'pin, T, U> +where + Enum: 'pin, +{ + Struct { + pinned: ::pin_project::__private::Pin<&'pin (T)>, + unpinned: &'pin (U), + }, + Tuple(::pin_project::__private::Pin<&'pin (T)>, &'pin (U)), + Unit, +} +#[allow(box_pointers)] +#[allow(deprecated)] +#[allow(explicit_outlives_requirements)] +#[allow(single_use_lifetimes)] +#[allow(unreachable_pub)] +#[allow(clippy::unknown_clippy_lints)] +#[allow(clippy::pattern_type_mismatch)] +#[allow(clippy::redundant_pub_crate)] +#[allow(clippy::used_underscore_binding)] +const _: () = { + impl Enum { + pub(crate) fn project<'pin>( + self: ::pin_project::__private::Pin<&'pin mut Self>, + ) -> EnumProj<'pin, T, U> { + unsafe { + match self.get_unchecked_mut() { + Self::Struct { pinned, unpinned } => EnumProj::Struct { + pinned: ::pin_project::__private::Pin::new_unchecked(pinned), + unpinned, + }, + Self::Tuple(_0, _1) => { + EnumProj::Tuple(::pin_project::__private::Pin::new_unchecked(_0), _1) + } + Self::Unit => EnumProj::Unit, + } + } + } + #[allow(clippy::missing_const_for_fn)] + pub(crate) fn project_ref<'pin>( + self: ::pin_project::__private::Pin<&'pin Self>, + ) -> EnumProjRef<'pin, T, U> { + unsafe { + match self.get_ref() { + Self::Struct { pinned, unpinned } => EnumProjRef::Struct { + pinned: ::pin_project::__private::Pin::new_unchecked(pinned), + unpinned, + }, + Self::Tuple(_0, _1) => { + EnumProjRef::Tuple(::pin_project::__private::Pin::new_unchecked(_0), _1) + } + Self::Unit => EnumProjRef::Unit, + } + } + } + } + #[allow(missing_debug_implementations)] + pub struct __Enum<'pin, T, U> { + __pin_project_use_generics: ::pin_project::__private::AlwaysUnpin< + 'pin, + ( + ::pin_project::__private::PhantomData, + ::pin_project::__private::PhantomData, + ), + >, + __field0: T, + __field1: T, + } + impl<'pin, T, U> ::pin_project::__private::Unpin for Enum where + __Enum<'pin, T, U>: ::pin_project::__private::Unpin + { + } + #[doc(hidden)] + unsafe impl<'pin, T, U> ::pin_project::UnsafeUnpin for Enum where + __Enum<'pin, T, U>: ::pin_project::__private::Unpin + { + } + trait EnumMustNotImplDrop {} + #[allow(clippy::drop_bounds, drop_bounds)] + impl EnumMustNotImplDrop for T {} + impl EnumMustNotImplDrop for Enum {} + #[doc(hidden)] + impl ::pin_project::__private::PinnedDrop for Enum { + unsafe fn drop(self: ::pin_project::__private::Pin<&mut Self>) {} + } +}; +fn main() {} diff --git a/tests/expand/pub/enum.rs b/tests/expand/pub/enum.rs new file mode 100644 index 0000000..7c8577f --- /dev/null +++ b/tests/expand/pub/enum.rs @@ -0,0 +1,14 @@ +use pin_project::pin_project; + +#[pin_project(project = EnumProj, project_ref = EnumProjRef)] +pub enum Enum { + Struct { + #[pin] + pinned: T, + unpinned: U, + }, + Tuple(#[pin] T, U), + Unit, +} + +fn main() {} diff --git a/tests/expand/pub/struct.expanded.rs b/tests/expand/pub/struct.expanded.rs new file mode 100644 index 0000000..34b1c79 --- /dev/null +++ b/tests/expand/pub/struct.expanded.rs @@ -0,0 +1,113 @@ +use pin_project::pin_project; +#[pin(__private())] +pub struct Struct { + #[pin] + pub pinned: T, + pub unpinned: U, +} +#[allow(box_pointers)] +#[allow(deprecated)] +#[allow(explicit_outlives_requirements)] +#[allow(single_use_lifetimes)] +#[allow(unreachable_pub)] +#[allow(clippy::unknown_clippy_lints)] +#[allow(clippy::pattern_type_mismatch)] +#[allow(clippy::redundant_pub_crate)] +#[allow(clippy::used_underscore_binding)] +const _: () = { + #[allow(box_pointers)] + #[allow(deprecated)] + #[allow(explicit_outlives_requirements)] + #[allow(single_use_lifetimes)] + #[allow(unreachable_pub)] + #[allow(clippy::unknown_clippy_lints)] + #[allow(clippy::pattern_type_mismatch)] + #[allow(clippy::redundant_pub_crate)] + #[allow(dead_code)] + #[allow(clippy::mut_mut)] + #[allow(clippy::type_repetition_in_bounds)] + pub(crate) struct __StructProjection<'pin, T, U> + where + Struct: 'pin, + { + pub pinned: ::pin_project::__private::Pin<&'pin mut (T)>, + pub unpinned: &'pin mut (U), + } + #[allow(box_pointers)] + #[allow(deprecated)] + #[allow(explicit_outlives_requirements)] + #[allow(single_use_lifetimes)] + #[allow(unreachable_pub)] + #[allow(clippy::unknown_clippy_lints)] + #[allow(clippy::pattern_type_mismatch)] + #[allow(clippy::redundant_pub_crate)] + #[allow(dead_code)] + #[allow(clippy::ref_option_ref)] + #[allow(clippy::type_repetition_in_bounds)] + pub(crate) struct __StructProjectionRef<'pin, T, U> + where + Struct: 'pin, + { + pub pinned: ::pin_project::__private::Pin<&'pin (T)>, + pub unpinned: &'pin (U), + } + impl Struct { + pub(crate) fn project<'pin>( + self: ::pin_project::__private::Pin<&'pin mut Self>, + ) -> __StructProjection<'pin, T, U> { + unsafe { + let Self { pinned, unpinned } = self.get_unchecked_mut(); + __StructProjection { + pinned: ::pin_project::__private::Pin::new_unchecked(pinned), + unpinned, + } + } + } + #[allow(clippy::missing_const_for_fn)] + pub(crate) fn project_ref<'pin>( + self: ::pin_project::__private::Pin<&'pin Self>, + ) -> __StructProjectionRef<'pin, T, U> { + unsafe { + let Self { pinned, unpinned } = self.get_ref(); + __StructProjectionRef { + pinned: ::pin_project::__private::Pin::new_unchecked(pinned), + unpinned, + } + } + } + } + #[forbid(safe_packed_borrows)] + fn __assert_not_repr_packed(this: &Struct) { + let _ = &this.pinned; + let _ = &this.unpinned; + } + #[allow(missing_debug_implementations)] + pub struct __Struct<'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 Struct where + __Struct<'pin, T, U>: ::pin_project::__private::Unpin + { + } + #[doc(hidden)] + unsafe impl<'pin, T, U> ::pin_project::UnsafeUnpin for Struct where + __Struct<'pin, T, U>: ::pin_project::__private::Unpin + { + } + trait StructMustNotImplDrop {} + #[allow(clippy::drop_bounds, drop_bounds)] + impl StructMustNotImplDrop for T {} + impl StructMustNotImplDrop for Struct {} + #[doc(hidden)] + impl ::pin_project::__private::PinnedDrop for Struct { + unsafe fn drop(self: ::pin_project::__private::Pin<&mut Self>) {} + } +}; +fn main() {} diff --git a/tests/expand/pub/struct.rs b/tests/expand/pub/struct.rs new file mode 100644 index 0000000..f50d1e9 --- /dev/null +++ b/tests/expand/pub/struct.rs @@ -0,0 +1,10 @@ +use pin_project::pin_project; + +#[pin_project] +pub struct Struct { + #[pin] + pub pinned: T, + pub unpinned: U, +} + +fn main() {} diff --git a/tests/expand/pub/tuple_struct.expanded.rs b/tests/expand/pub/tuple_struct.expanded.rs new file mode 100644 index 0000000..8dbcf91 --- /dev/null +++ b/tests/expand/pub/tuple_struct.expanded.rs @@ -0,0 +1,101 @@ +use pin_project::pin_project; +#[pin(__private())] +pub struct TupleStruct(#[pin] pub T, pub U); +#[allow(box_pointers)] +#[allow(deprecated)] +#[allow(explicit_outlives_requirements)] +#[allow(single_use_lifetimes)] +#[allow(unreachable_pub)] +#[allow(clippy::unknown_clippy_lints)] +#[allow(clippy::pattern_type_mismatch)] +#[allow(clippy::redundant_pub_crate)] +#[allow(clippy::used_underscore_binding)] +const _: () = { + #[allow(box_pointers)] + #[allow(deprecated)] + #[allow(explicit_outlives_requirements)] + #[allow(single_use_lifetimes)] + #[allow(unreachable_pub)] + #[allow(clippy::unknown_clippy_lints)] + #[allow(clippy::pattern_type_mismatch)] + #[allow(clippy::redundant_pub_crate)] + #[allow(dead_code)] + #[allow(clippy::mut_mut)] + #[allow(clippy::type_repetition_in_bounds)] + pub(crate) struct __TupleStructProjection<'pin, T, U>( + pub ::pin_project::__private::Pin<&'pin mut (T)>, + pub &'pin mut (U), + ) + where + TupleStruct: 'pin; + #[allow(box_pointers)] + #[allow(deprecated)] + #[allow(explicit_outlives_requirements)] + #[allow(single_use_lifetimes)] + #[allow(unreachable_pub)] + #[allow(clippy::unknown_clippy_lints)] + #[allow(clippy::pattern_type_mismatch)] + #[allow(clippy::redundant_pub_crate)] + #[allow(dead_code)] + #[allow(clippy::ref_option_ref)] + #[allow(clippy::type_repetition_in_bounds)] + pub(crate) struct __TupleStructProjectionRef<'pin, T, U>( + pub ::pin_project::__private::Pin<&'pin (T)>, + pub &'pin (U), + ) + where + TupleStruct: 'pin; + impl TupleStruct { + pub(crate) fn project<'pin>( + self: ::pin_project::__private::Pin<&'pin mut Self>, + ) -> __TupleStructProjection<'pin, T, U> { + unsafe { + let Self(_0, _1) = self.get_unchecked_mut(); + __TupleStructProjection(::pin_project::__private::Pin::new_unchecked(_0), _1) + } + } + #[allow(clippy::missing_const_for_fn)] + pub(crate) fn project_ref<'pin>( + self: ::pin_project::__private::Pin<&'pin Self>, + ) -> __TupleStructProjectionRef<'pin, T, U> { + unsafe { + let Self(_0, _1) = self.get_ref(); + __TupleStructProjectionRef(::pin_project::__private::Pin::new_unchecked(_0), _1) + } + } + } + #[forbid(safe_packed_borrows)] + fn __assert_not_repr_packed(this: &TupleStruct) { + let _ = &this.0; + let _ = &this.1; + } + #[allow(missing_debug_implementations)] + pub struct __TupleStruct<'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 TupleStruct where + __TupleStruct<'pin, T, U>: ::pin_project::__private::Unpin + { + } + #[doc(hidden)] + unsafe impl<'pin, T, U> ::pin_project::UnsafeUnpin for TupleStruct where + __TupleStruct<'pin, T, U>: ::pin_project::__private::Unpin + { + } + trait TupleStructMustNotImplDrop {} + #[allow(clippy::drop_bounds, drop_bounds)] + impl TupleStructMustNotImplDrop for T {} + impl TupleStructMustNotImplDrop for TupleStruct {} + #[doc(hidden)] + impl ::pin_project::__private::PinnedDrop for TupleStruct { + unsafe fn drop(self: ::pin_project::__private::Pin<&mut Self>) {} + } +}; +fn main() {} diff --git a/tests/expand/pub/tuple_struct.rs b/tests/expand/pub/tuple_struct.rs new file mode 100644 index 0000000..5756aaf --- /dev/null +++ b/tests/expand/pub/tuple_struct.rs @@ -0,0 +1,6 @@ +use pin_project::pin_project; + +#[pin_project] +pub struct TupleStruct(#[pin] pub T, pub U); + +fn main() {} diff --git a/tests/expand/unsafe_unpin/enum.expanded.rs b/tests/expand/unsafe_unpin/enum.expanded.rs new file mode 100644 index 0000000..faf87fc --- /dev/null +++ b/tests/expand/unsafe_unpin/enum.expanded.rs @@ -0,0 +1,115 @@ +use pin_project::{pin_project, UnsafeUnpin}; +# [pin (__private (UnsafeUnpin , project = EnumProj , project_ref = EnumProjRef))] +enum Enum { + Struct { + #[pin] + pinned: T, + unpinned: U, + }, + Tuple(#[pin] T, U), + Unit, +} +#[allow(box_pointers)] +#[allow(deprecated)] +#[allow(explicit_outlives_requirements)] +#[allow(single_use_lifetimes)] +#[allow(unreachable_pub)] +#[allow(clippy::unknown_clippy_lints)] +#[allow(clippy::pattern_type_mismatch)] +#[allow(clippy::redundant_pub_crate)] +#[allow(dead_code)] +#[allow(clippy::mut_mut)] +#[allow(clippy::type_repetition_in_bounds)] +enum EnumProj<'pin, T, U> +where + Enum: 'pin, +{ + Struct { + pinned: ::pin_project::__private::Pin<&'pin mut (T)>, + unpinned: &'pin mut (U), + }, + Tuple(::pin_project::__private::Pin<&'pin mut (T)>, &'pin mut (U)), + Unit, +} +#[allow(box_pointers)] +#[allow(deprecated)] +#[allow(explicit_outlives_requirements)] +#[allow(single_use_lifetimes)] +#[allow(unreachable_pub)] +#[allow(clippy::unknown_clippy_lints)] +#[allow(clippy::pattern_type_mismatch)] +#[allow(clippy::redundant_pub_crate)] +#[allow(dead_code)] +#[allow(clippy::ref_option_ref)] +#[allow(clippy::type_repetition_in_bounds)] +enum EnumProjRef<'pin, T, U> +where + Enum: 'pin, +{ + Struct { + pinned: ::pin_project::__private::Pin<&'pin (T)>, + unpinned: &'pin (U), + }, + Tuple(::pin_project::__private::Pin<&'pin (T)>, &'pin (U)), + Unit, +} +#[allow(box_pointers)] +#[allow(deprecated)] +#[allow(explicit_outlives_requirements)] +#[allow(single_use_lifetimes)] +#[allow(unreachable_pub)] +#[allow(clippy::unknown_clippy_lints)] +#[allow(clippy::pattern_type_mismatch)] +#[allow(clippy::redundant_pub_crate)] +#[allow(clippy::used_underscore_binding)] +const _: () = { + impl Enum { + fn project<'pin>( + self: ::pin_project::__private::Pin<&'pin mut Self>, + ) -> EnumProj<'pin, T, U> { + unsafe { + match self.get_unchecked_mut() { + Self::Struct { pinned, unpinned } => EnumProj::Struct { + pinned: ::pin_project::__private::Pin::new_unchecked(pinned), + unpinned, + }, + Self::Tuple(_0, _1) => { + EnumProj::Tuple(::pin_project::__private::Pin::new_unchecked(_0), _1) + } + Self::Unit => EnumProj::Unit, + } + } + } + #[allow(clippy::missing_const_for_fn)] + fn project_ref<'pin>( + self: ::pin_project::__private::Pin<&'pin Self>, + ) -> EnumProjRef<'pin, T, U> { + unsafe { + match self.get_ref() { + Self::Struct { pinned, unpinned } => EnumProjRef::Struct { + pinned: ::pin_project::__private::Pin::new_unchecked(pinned), + unpinned, + }, + Self::Tuple(_0, _1) => { + EnumProjRef::Tuple(::pin_project::__private::Pin::new_unchecked(_0), _1) + } + Self::Unit => EnumProjRef::Unit, + } + } + } + } + impl<'pin, T, U> ::pin_project::__private::Unpin for Enum where + ::pin_project::__private::Wrapper<'pin, Self>: ::pin_project::UnsafeUnpin + { + } + trait EnumMustNotImplDrop {} + #[allow(clippy::drop_bounds, drop_bounds)] + impl EnumMustNotImplDrop for T {} + impl EnumMustNotImplDrop for Enum {} + #[doc(hidden)] + impl ::pin_project::__private::PinnedDrop for Enum { + unsafe fn drop(self: ::pin_project::__private::Pin<&mut Self>) {} + } +}; +unsafe impl UnsafeUnpin for Enum {} +fn main() {} diff --git a/tests/expand/unsafe_unpin/enum.rs b/tests/expand/unsafe_unpin/enum.rs new file mode 100644 index 0000000..d368d71 --- /dev/null +++ b/tests/expand/unsafe_unpin/enum.rs @@ -0,0 +1,16 @@ +use pin_project::{pin_project, UnsafeUnpin}; + +#[pin_project(UnsafeUnpin, project = EnumProj, project_ref = EnumProjRef)] +enum Enum { + Struct { + #[pin] + pinned: T, + unpinned: U, + }, + Tuple(#[pin] T, U), + Unit, +} + +unsafe impl UnsafeUnpin for Enum {} + +fn main() {} diff --git a/tests/expand/unsafe_unpin/struct.expanded.rs b/tests/expand/unsafe_unpin/struct.expanded.rs new file mode 100644 index 0000000..c01668e --- /dev/null +++ b/tests/expand/unsafe_unpin/struct.expanded.rs @@ -0,0 +1,98 @@ +use pin_project::{pin_project, UnsafeUnpin}; +#[pin(__private(UnsafeUnpin))] +struct Struct { + #[pin] + pinned: T, + unpinned: U, +} +#[allow(box_pointers)] +#[allow(deprecated)] +#[allow(explicit_outlives_requirements)] +#[allow(single_use_lifetimes)] +#[allow(unreachable_pub)] +#[allow(clippy::unknown_clippy_lints)] +#[allow(clippy::pattern_type_mismatch)] +#[allow(clippy::redundant_pub_crate)] +#[allow(clippy::used_underscore_binding)] +const _: () = { + #[allow(box_pointers)] + #[allow(deprecated)] + #[allow(explicit_outlives_requirements)] + #[allow(single_use_lifetimes)] + #[allow(unreachable_pub)] + #[allow(clippy::unknown_clippy_lints)] + #[allow(clippy::pattern_type_mismatch)] + #[allow(clippy::redundant_pub_crate)] + #[allow(dead_code)] + #[allow(clippy::mut_mut)] + #[allow(clippy::type_repetition_in_bounds)] + struct __StructProjection<'pin, T, U> + where + Struct: 'pin, + { + pinned: ::pin_project::__private::Pin<&'pin mut (T)>, + unpinned: &'pin mut (U), + } + #[allow(box_pointers)] + #[allow(deprecated)] + #[allow(explicit_outlives_requirements)] + #[allow(single_use_lifetimes)] + #[allow(unreachable_pub)] + #[allow(clippy::unknown_clippy_lints)] + #[allow(clippy::pattern_type_mismatch)] + #[allow(clippy::redundant_pub_crate)] + #[allow(dead_code)] + #[allow(clippy::ref_option_ref)] + #[allow(clippy::type_repetition_in_bounds)] + struct __StructProjectionRef<'pin, T, U> + where + Struct: 'pin, + { + pinned: ::pin_project::__private::Pin<&'pin (T)>, + unpinned: &'pin (U), + } + impl Struct { + fn project<'pin>( + self: ::pin_project::__private::Pin<&'pin mut Self>, + ) -> __StructProjection<'pin, T, U> { + unsafe { + let Self { pinned, unpinned } = self.get_unchecked_mut(); + __StructProjection { + pinned: ::pin_project::__private::Pin::new_unchecked(pinned), + unpinned, + } + } + } + #[allow(clippy::missing_const_for_fn)] + fn project_ref<'pin>( + self: ::pin_project::__private::Pin<&'pin Self>, + ) -> __StructProjectionRef<'pin, T, U> { + unsafe { + let Self { pinned, unpinned } = self.get_ref(); + __StructProjectionRef { + pinned: ::pin_project::__private::Pin::new_unchecked(pinned), + unpinned, + } + } + } + } + #[forbid(safe_packed_borrows)] + fn __assert_not_repr_packed(this: &Struct) { + let _ = &this.pinned; + let _ = &this.unpinned; + } + impl<'pin, T, U> ::pin_project::__private::Unpin for Struct where + ::pin_project::__private::Wrapper<'pin, Self>: ::pin_project::UnsafeUnpin + { + } + trait StructMustNotImplDrop {} + #[allow(clippy::drop_bounds, drop_bounds)] + impl StructMustNotImplDrop for T {} + impl StructMustNotImplDrop for Struct {} + #[doc(hidden)] + impl ::pin_project::__private::PinnedDrop for Struct { + unsafe fn drop(self: ::pin_project::__private::Pin<&mut Self>) {} + } +}; +unsafe impl UnsafeUnpin for Struct {} +fn main() {} diff --git a/tests/expand/unsafe_unpin/struct.rs b/tests/expand/unsafe_unpin/struct.rs new file mode 100644 index 0000000..b0851b1 --- /dev/null +++ b/tests/expand/unsafe_unpin/struct.rs @@ -0,0 +1,12 @@ +use pin_project::{pin_project, UnsafeUnpin}; + +#[pin_project(UnsafeUnpin)] +struct Struct { + #[pin] + pinned: T, + unpinned: U, +} + +unsafe impl UnsafeUnpin for Struct {} + +fn main() {} diff --git a/tests/expand/unsafe_unpin/tuple_struct.expanded.rs b/tests/expand/unsafe_unpin/tuple_struct.expanded.rs new file mode 100644 index 0000000..3c9afb8 --- /dev/null +++ b/tests/expand/unsafe_unpin/tuple_struct.expanded.rs @@ -0,0 +1,86 @@ +use pin_project::{pin_project, UnsafeUnpin}; +#[pin(__private(UnsafeUnpin))] +struct TupleStruct(#[pin] T, U); +#[allow(box_pointers)] +#[allow(deprecated)] +#[allow(explicit_outlives_requirements)] +#[allow(single_use_lifetimes)] +#[allow(unreachable_pub)] +#[allow(clippy::unknown_clippy_lints)] +#[allow(clippy::pattern_type_mismatch)] +#[allow(clippy::redundant_pub_crate)] +#[allow(clippy::used_underscore_binding)] +const _: () = { + #[allow(box_pointers)] + #[allow(deprecated)] + #[allow(explicit_outlives_requirements)] + #[allow(single_use_lifetimes)] + #[allow(unreachable_pub)] + #[allow(clippy::unknown_clippy_lints)] + #[allow(clippy::pattern_type_mismatch)] + #[allow(clippy::redundant_pub_crate)] + #[allow(dead_code)] + #[allow(clippy::mut_mut)] + #[allow(clippy::type_repetition_in_bounds)] + struct __TupleStructProjection<'pin, T, U>( + ::pin_project::__private::Pin<&'pin mut (T)>, + &'pin mut (U), + ) + where + TupleStruct: 'pin; + #[allow(box_pointers)] + #[allow(deprecated)] + #[allow(explicit_outlives_requirements)] + #[allow(single_use_lifetimes)] + #[allow(unreachable_pub)] + #[allow(clippy::unknown_clippy_lints)] + #[allow(clippy::pattern_type_mismatch)] + #[allow(clippy::redundant_pub_crate)] + #[allow(dead_code)] + #[allow(clippy::ref_option_ref)] + #[allow(clippy::type_repetition_in_bounds)] + struct __TupleStructProjectionRef<'pin, T, U>( + ::pin_project::__private::Pin<&'pin (T)>, + &'pin (U), + ) + where + TupleStruct: 'pin; + impl TupleStruct { + fn project<'pin>( + self: ::pin_project::__private::Pin<&'pin mut Self>, + ) -> __TupleStructProjection<'pin, T, U> { + unsafe { + let Self(_0, _1) = self.get_unchecked_mut(); + __TupleStructProjection(::pin_project::__private::Pin::new_unchecked(_0), _1) + } + } + #[allow(clippy::missing_const_for_fn)] + fn project_ref<'pin>( + self: ::pin_project::__private::Pin<&'pin Self>, + ) -> __TupleStructProjectionRef<'pin, T, U> { + unsafe { + let Self(_0, _1) = self.get_ref(); + __TupleStructProjectionRef(::pin_project::__private::Pin::new_unchecked(_0), _1) + } + } + } + #[forbid(safe_packed_borrows)] + fn __assert_not_repr_packed(this: &TupleStruct) { + let _ = &this.0; + let _ = &this.1; + } + impl<'pin, T, U> ::pin_project::__private::Unpin for TupleStruct where + ::pin_project::__private::Wrapper<'pin, Self>: ::pin_project::UnsafeUnpin + { + } + trait TupleStructMustNotImplDrop {} + #[allow(clippy::drop_bounds, drop_bounds)] + impl TupleStructMustNotImplDrop for T {} + impl TupleStructMustNotImplDrop for TupleStruct {} + #[doc(hidden)] + impl ::pin_project::__private::PinnedDrop for TupleStruct { + unsafe fn drop(self: ::pin_project::__private::Pin<&mut Self>) {} + } +}; +unsafe impl UnsafeUnpin for Struct {} +fn main() {} diff --git a/tests/expand/unsafe_unpin/tuple_struct.rs b/tests/expand/unsafe_unpin/tuple_struct.rs new file mode 100644 index 0000000..964617a --- /dev/null +++ b/tests/expand/unsafe_unpin/tuple_struct.rs @@ -0,0 +1,8 @@ +use pin_project::{pin_project, UnsafeUnpin}; + +#[pin_project(UnsafeUnpin)] +struct TupleStruct(#[pin] T, U); + +unsafe impl UnsafeUnpin for Struct {} + +fn main() {} diff --git a/tests/expandtest.rs b/tests/expandtest.rs new file mode 100644 index 0000000..adf8dde --- /dev/null +++ b/tests/expandtest.rs @@ -0,0 +1,41 @@ +#![cfg(not(miri))] +#![warn(rust_2018_idioms, single_use_lifetimes)] + +use std::{ + env, + process::{Command, ExitStatus, Stdio}, +}; + +#[rustversion::attr(not(nightly), ignore)] +#[test] +fn expandtest() { + let is_ci = env::var_os("CI").is_some(); + let cargo = &*env::var("CARGO").unwrap_or_else(|_| "cargo".into()); + if !has_command(&[cargo, "expand"]) || !has_command(&[cargo, "fmt"]) { + if is_ci { + panic!("expandtest requires rustfmt and cargo-expand") + } + return; + } + + let path = "tests/expand/*/*.rs"; + if is_ci { + macrotest::expand_without_refresh(path); + } else { + env::set_var("MACROTEST", "overwrite"); + macrotest::expand(path); + } +} + +fn has_command(command: &[&str]) -> bool { + Command::new(command[0]) + .args(&command[1..]) + .arg("--version") + .stdin(Stdio::null()) + .stdout(Stdio::null()) + .stderr(Stdio::null()) + .status() + .as_ref() + .map(ExitStatus::success) + .unwrap_or(false) +} diff --git a/tests/lint.rs b/tests/lint.rs index b577e0e..527c533 100644 --- a/tests/lint.rs +++ b/tests/lint.rs @@ -10,6 +10,7 @@ explicit_outlives_requirements, macro_use_extern_crate, meta_variable_misuse, + missing_abi, missing_copy_implementations, missing_crate_level_docs, missing_debug_implementations, @@ -27,7 +28,7 @@ unused_results, variant_size_differences )] -// absolute_paths_not_starting_with_crate, anonymous_parameters, keyword_idents, pointer_structural_match: forbidden as a part of future_incompatible +// absolute_paths_not_starting_with_crate, anonymous_parameters, keyword_idents, pointer_structural_match, semicolon_in_expressions_from_macros: forbidden as a part of future_incompatible // missing_doc_code_examples, private_doc_tests, invalid_html_tags: warned as a part of rustdoc // unsafe_block_in_unsafe_fn: unstable // unsafe_code: checked in forbid_unsafe module @@ -36,11 +37,10 @@ #![warn(clippy::all, clippy::pedantic, clippy::nursery)] #![warn(clippy::restriction)] #![allow(clippy::blanket_clippy_restriction_lints)] // this is a test, so enable all restriction lints intentionally. +#![allow(clippy::exhaustive_structs, clippy::exhaustive_enums)] // TODO // Check interoperability with rustc and clippy lints. -mod auxiliary; - pub mod basic { include!("include/basic.rs"); @@ -543,6 +543,123 @@ pub mod box_pointers { } } +pub mod deprecated { + use pin_project::pin_project; + + #[allow(deprecated)] // for the type itself + #[pin_project(project_replace)] + #[derive(Debug, Clone, Copy)] + #[deprecated] + pub struct Struct { + #[deprecated] + #[pin] + pub p: (), + #[deprecated] + pub u: (), + } + + #[allow(deprecated)] // for the type itself + #[pin_project(project_replace)] + #[derive(Debug, Clone, Copy)] + #[deprecated] + pub struct TupleStruct( + #[deprecated] + #[pin] + pub (), + #[deprecated] pub (), + ); + + #[allow(deprecated)] // for the type itself + #[pin_project( + project = EnumProj, + project_ref = EnumProjRef, + project_replace = EnumProjOwn, + )] + #[derive(Debug, Clone, Copy)] + #[deprecated] + pub enum Enum { + #[deprecated] + Struct { + #[deprecated] + #[pin] + p: (), + #[deprecated] + u: (), + }, + #[deprecated] + Tuple( + #[deprecated] + #[pin] + (), + #[deprecated] (), + ), + #[deprecated] + Unit, + } + + pub mod inside_macro { + use pin_project::pin_project; + + #[rustfmt::skip] + macro_rules! mac { + () => { + #[allow(deprecated)] // for the type itself + #[pin_project(project_replace)] + #[derive(Debug, Clone, Copy)] + #[deprecated] + pub struct Struct { + #[deprecated] + #[pin] + pub p: (), + #[deprecated] + pub u: (), + } + + #[allow(deprecated)] // for the type itself + #[pin_project(project_replace)] + #[derive(Debug, Clone, Copy)] + #[deprecated] + pub struct TupleStruct( + #[deprecated] + #[pin] + pub (), + #[deprecated] pub (), + ); + + #[allow(deprecated)] // for the type itself + #[pin_project( + project = EnumProj, + project_ref = EnumProjRef, + project_replace = EnumProjOwn, + )] + #[derive(Debug, Clone, Copy)] + #[deprecated] + pub enum Enum { + #[deprecated] + Struct { + #[deprecated] + #[pin] + p: (), + #[deprecated] + u: (), + }, + #[deprecated] + Tuple( + #[deprecated] + #[pin] + (), + #[deprecated] (), + ), + #[deprecated] + Unit, + } + }; + } + + mac!(); + } +} + pub mod explicit_outlives_requirements { use pin_project::pin_project; @@ -652,7 +769,7 @@ pub mod single_use_lifetimes { #[allow(single_use_lifetimes)] // for the type itself: https://github.com/rust-lang/rust/issues/55058 #[pin_project(project_replace)] #[derive(Debug)] - pub struct HRTB<'pin___, T> + pub struct Hrtb<'pin___, T> where for<'pin> &'pin T: Unpin, T: for<'pin> Trait<'pin>, @@ -675,7 +792,7 @@ pub mod single_use_lifetimes { #[allow(single_use_lifetimes)] // for the type itself: https://github.com/rust-lang/rust/issues/55058 #[pin_project(project_replace)] #[derive(Debug)] - pub struct HRTB<'pin___, T> + pub struct Hrtb<'pin___, T> where for<'pin> &'pin T: Unpin, T: for<'pin> Trait<'pin>, @@ -1023,17 +1140,24 @@ pub mod clippy_used_underscore_binding { } } -// Run `./dev.sh +$toolchain test --test lint` to update this. -#[cfg(not(miri))] -#[allow(clippy::restriction)] -#[rustversion::attr(before(2020-12-25), ignore)] // Note: This date is commit-date and the day before the toolchain date. -#[test] -fn check_lint_list() { - use auxiliary::assert_diff; - use std::{env, process::Command, str}; - - let rustc = env::var_os("RUSTC").unwrap_or_else(|| "rustc".into()); - let output = Command::new(rustc).args(&["-W", "help"]).output().unwrap(); - let new = str::from_utf8(&output.stdout).unwrap(); - assert_diff("tests/lint.txt", new); +pub mod clippy_ref_option_ref { + use pin_project::pin_project; + + #[pin_project] + #[derive(Debug)] + pub struct Struct<'a> { + #[pin] + pub _pinned: Option<&'a ()>, + pub _unpinned: Option<&'a ()>, + } + + #[pin_project(project = EnumProj, project_ref = EnumProjRef)] + #[derive(Debug)] + pub enum Enum<'a> { + Struct { + #[pin] + _pinned: Option<&'a ()>, + _unpinned: Option<&'a ()>, + }, + } } diff --git a/tests/lint.txt b/tests/lint.txt deleted file mode 100644 index 8983ad7..0000000 --- a/tests/lint.txt +++ /dev/null @@ -1,157 +0,0 @@ - -Available lint options: - -W Warn about - -A Allow - -D Deny - -F Forbid (deny and all attempts to override) - - -Lint checks provided by rustc: - - name default meaning - ---- ------- ------- - absolute-paths-not-starting-with-crate allow fully qualified paths that start with a module name instead of `crate`, `self`, or an extern crate name - anonymous-parameters allow detects anonymous parameters - box-pointers allow use of owned (Box type) heap memory - deprecated-in-future allow detects use of items that will be deprecated in a future version - elided-lifetimes-in-paths allow hidden lifetime parameters in types are deprecated - explicit-outlives-requirements allow outlives requirements can be inferred - invalid-html-tags allow detects invalid HTML tags in doc comments - keyword-idents allow detects edition keywords being used as an identifier - macro-use-extern-crate allow the `#[macro_use]` attribute is now deprecated in favor of using macros via the module system - meta-variable-misuse allow possible meta-variable misuse at macro definition - missing-copy-implementations allow detects potentially-forgotten implementations of `Copy` - missing-crate-level-docs allow detects crates with no crate-level documentation - missing-debug-implementations allow detects missing implementations of Debug - missing-docs allow detects missing documentation for public members - missing-doc-code-examples allow detects publicly-exported items without code samples in their documentation - non-ascii-idents allow detects non-ASCII identifiers - pointer-structural-match allow pointers are not structural-match - private-doc-tests allow detects code samples in docs of private items not documented by rustdoc - single-use-lifetimes allow detects lifetime parameters that are only used once - trivial-casts allow detects trivial casts which could be removed - trivial-numeric-casts allow detects trivial casts of numeric types which could be removed - unaligned-references allow detects unaligned references to fields of packed structs - unreachable-pub allow `pub` items not reachable from crate root - unsafe-code allow usage of `unsafe` code - unsafe-op-in-unsafe-fn allow unsafe operations in unsafe functions without an explicit unsafe block are deprecated - unstable-features allow enabling unstable features (deprecated. do not use) - unused-crate-dependencies allow crate dependencies that are never used - unused-extern-crates allow extern crates that are never used - unused-import-braces allow unnecessary braces around an imported item - unused-lifetimes allow detects lifetime parameters that are never used - unused-qualifications allow detects unnecessarily qualified names - unused-results allow unused result of an expression in a statement - variant-size-differences allow detects enums with widely varying variant sizes - array-into-iter warn detects calling `into_iter` on arrays - asm-sub-register warn using only a subset of a register for inline asm inputs - bare-trait-objects warn suggest using `dyn Trait` for trait objects - bindings-with-variant-name warn detects pattern bindings with the same name as one of the matched variants - broken-intra-doc-links warn failures in resolving intra-doc link targets - cenum-impl-drop-cast warn a C-like enum implementing Drop is cast - clashing-extern-declarations warn detects when an extern fn has been declared with the same name but different types - coherence-leak-check warn distinct impls distinguished only by the leak-check code - confusable-idents warn detects visually confusable pairs between identifiers - const-evaluatable-unchecked warn detects a generic constant is used in a type without a emitting a warning - const-item-mutation warn detects attempts to mutate a `const` item - dead-code warn detect unused, unexported items - deprecated warn detects use of deprecated items - drop-bounds warn bounds of the form `T: Drop` are useless - ellipsis-inclusive-range-patterns warn `...` range patterns are deprecated - exported-private-dependencies warn public interface leaks type from a private dependency - function-item-references warn suggest casting to a function pointer when attempting to take references to function items - illegal-floating-point-literal-pattern warn floating-point literals cannot be used in patterns - improper-ctypes warn proper use of libc types in foreign modules - improper-ctypes-definitions warn proper use of libc types in foreign item definitions - incomplete-features warn incomplete features that may function improperly in some or all cases - indirect-structural-match warn constant used in pattern contains value of non-structural-match type in a field or a variant - inline-no-sanitize warn detects incompatible use of `#[inline(always)]` and `#[no_sanitize(...)]` - invalid-codeblock-attributes warn codeblock attribute looks a lot like a known one - invalid-value warn an invalid value is being created (such as a NULL reference) - irrefutable-let-patterns warn detects irrefutable patterns in if-let and while-let statements - late-bound-lifetime-arguments warn detects generic lifetime arguments in path segments with late bound lifetime parameters - mixed-script-confusables warn detects Unicode scripts whose mixed script confusables codepoints are solely used - mutable-borrow-reservation-conflict warn reservation of a two-phased borrow conflicts with other shared borrows - nontrivial-structural-match warn constant used in pattern of non-structural-match type and the constant's initializer expression contains values of non-structural-match types - non-autolinks warn detects URLs that could be written using only angle brackets - non-camel-case-types warn types, variants, traits and type parameters should have camel case names - non-shorthand-field-patterns warn using `Struct { x: x }` instead of `Struct { x }` in a pattern - non-snake-case warn variables, methods, functions, lifetime parameters and modules should have snake case names - non-upper-case-globals warn static constants should have uppercase identifiers - no-mangle-generic-items warn generic items must be mangled - overlapping-range-endpoints warn detects range patterns with overlapping endpoints - panic-fmt warn detect braces in single-argument panic!() invocations - path-statements warn path statements with no effect - private-intra-doc-links warn linking from a public item to a private one - private-in-public warn detect private items in public interfaces not caught by the old implementation - proc-macro-derive-resolution-fallback warn detects proc macro derives using inaccessible names from parent modules - redundant-semicolons warn detects unnecessary trailing semicolons - renamed-and-removed-lints warn lints that have been renamed or removed - safe-packed-borrows warn safe borrows of fields of packed structs were erroneously allowed - stable-features warn stable features found in `#[feature]` directive - temporary-cstring-as-ptr warn detects getting the inner pointer of a temporary `CString` - trivial-bounds warn these bounds don't depend on an type parameters - type-alias-bounds warn bounds in type aliases are not enforced - tyvar-behind-raw-pointer warn raw pointer to an inference variable - uncommon-codepoints warn detects uncommon Unicode codepoints in identifiers - unconditional-recursion warn functions that cannot return without calling themselves - uninhabited-static warn uninhabited static - unknown-lints warn unrecognized lint attribute - unnameable-test-items warn detects an item that cannot be named being marked as `#[test_case]` - unreachable-code warn detects unreachable code paths - unreachable-patterns warn detects unreachable patterns - unstable-name-collisions warn detects name collision with an existing but unstable method - unsupported-naked-functions warn unsupported naked function definitions - unused-allocation warn detects unnecessary allocations that can be eliminated - unused-assignments warn detect assignments that will never be read - unused-attributes warn detects attributes that were not used by the compiler - unused-braces warn unnecessary braces around an expression - unused-comparisons warn comparisons made useless by limits of the types involved - unused-doc-comments warn detects doc comments that aren't used by rustdoc - unused-features warn unused features found in crate-level `#[feature]` directives - unused-imports warn imports that are never used - unused-labels warn detects labels that are never used - unused-macros warn detects macros that were not used - unused-must-use warn unused result of a type flagged as `#[must_use]` - unused-mut warn detect mut variables which don't need to be mutable - unused-parens warn `if`, `match`, `while` and `return` do not need parentheses - unused-unsafe warn unnecessary use of an `unsafe` block - unused-variables warn detect variables which are not used in any way - warnings warn mass-change the level for lints which produce warnings - where-clauses-object-safety warn checks the object safety of where clauses - while-true warn suggest using `loop { }` instead of `while true { }` - ambiguous-associated-items deny ambiguous associated items - arithmetic-overflow deny arithmetic operation overflows - conflicting-repr-hints deny conflicts between `#[repr(..)]` hints that were previously accepted and used in practice - const-err deny constant evaluation detected erroneous expression - ill-formed-attribute-input deny ill-formed attribute inputs that were previously accepted and used in practice - incomplete-include deny trailing content in included file - invalid-type-param-default deny type parameter default erroneously allowed in invalid location - macro-expanded-macro-exports-accessed-by-absolute-paths deny macro-expanded `macro_export` macros from the current crate cannot be referred to by absolute paths - missing-fragment-specifier deny detects missing fragment specifiers in unused `macro_rules!` patterns - mutable-transmutes deny mutating transmuted &mut T from &T may cause undefined behavior - no-mangle-const-items deny const items will not have their symbols exported - order-dependent-trait-objects deny trait-object types were treated as different depending on marker-trait order - overflowing-literals deny literal out of range for its type - patterns-in-fns-without-body deny patterns in functions without body were erroneously allowed - pub-use-of-private-extern-crate deny detect public re-exports of private extern crates - soft-unstable deny a feature gate that doesn't break dependent crates - unconditional-panic deny operation will cause a panic at runtime - unknown-crate-types deny unknown crate type found in `#[crate_type]` directive - useless-deprecated deny detects deprecation attributes with no effect - - -Lint groups provided by rustc: - - name sub-lints - ---- --------- - warnings all lints that are set to issue warnings - future-incompatible keyword-idents, anonymous-parameters, illegal-floating-point-literal-pattern, private-in-public, pub-use-of-private-extern-crate, invalid-type-param-default, safe-packed-borrows, patterns-in-fns-without-body, missing-fragment-specifier, late-bound-lifetime-arguments, order-dependent-trait-objects, coherence-leak-check, tyvar-behind-raw-pointer, absolute-paths-not-starting-with-crate, unstable-name-collisions, where-clauses-object-safety, proc-macro-derive-resolution-fallback, macro-expanded-macro-exports-accessed-by-absolute-paths, ill-formed-attribute-input, conflicting-repr-hints, ambiguous-associated-items, mutable-borrow-reservation-conflict, indirect-structural-match, pointer-structural-match, nontrivial-structural-match, soft-unstable, cenum-impl-drop-cast, const-evaluatable-unchecked, uninhabited-static, unsupported-naked-functions, array-into-iter - nonstandard-style non-camel-case-types, non-snake-case, non-upper-case-globals - rust-2018-compatibility keyword-idents, anonymous-parameters, tyvar-behind-raw-pointer, absolute-paths-not-starting-with-crate - rust-2018-idioms bare-trait-objects, unused-extern-crates, ellipsis-inclusive-range-patterns, elided-lifetimes-in-paths, explicit-outlives-requirements - rustdoc non-autolinks, broken-intra-doc-links, private-intra-doc-links, invalid-codeblock-attributes, missing-doc-code-examples, private-doc-tests, invalid-html-tags - unused unused-imports, unused-variables, unused-assignments, dead-code, unused-mut, unreachable-code, unreachable-patterns, unused-must-use, unused-unsafe, path-statements, unused-attributes, unused-macros, unused-allocation, unused-doc-comments, unused-extern-crates, unused-features, unused-labels, unused-parens, unused-braces, redundant-semicolons - - -Lint tools like Clippy can provide additional lints and lint groups. diff --git a/tests/pin_project.rs b/tests/pin_project.rs index 17dbd2a..c6aaf94 100644 --- a/tests/pin_project.rs +++ b/tests/pin_project.rs @@ -4,13 +4,14 @@ #[macro_use] mod auxiliary; -use pin_project::{pin_project, pinned_drop, UnsafeUnpin}; use std::{ marker::{PhantomData, PhantomPinned}, panic, pin::Pin, }; +use pin_project::{pin_project, pinned_drop, UnsafeUnpin}; + #[test] fn projection() { #[pin_project( @@ -336,7 +337,7 @@ fn overlapping_lifetime_names() { #[allow(single_use_lifetimes)] // https://github.com/rust-lang/rust/issues/55058 #[pin_project(project_replace)] - pub struct HRTB<'pin___, T> + pub struct Hrtb<'pin___, T> where for<'pin> &'pin T: Unpin, T: for<'pin> Trait<'pin>, diff --git a/tests/pinned_drop.rs b/tests/pinned_drop.rs index 78b73dc..9e7287d 100644 --- a/tests/pinned_drop.rs +++ b/tests/pinned_drop.rs @@ -1,8 +1,9 @@ #![warn(rust_2018_idioms, single_use_lifetimes)] -use pin_project::{pin_project, pinned_drop}; use std::pin::Pin; +use pin_project::{pin_project, pinned_drop}; + #[test] fn safe_project() { #[pin_project(PinnedDrop)] diff --git a/tests/proper_unpin.rs b/tests/proper_unpin.rs index 8873572..0ba3ce3 100644 --- a/tests/proper_unpin.rs +++ b/tests/proper_unpin.rs @@ -5,9 +5,10 @@ mod auxiliary; pub mod default { - use pin_project::pin_project; use std::marker::PhantomPinned; + use pin_project::pin_project; + struct Inner { f: T, } @@ -60,9 +61,10 @@ pub mod default { } pub mod cfg { - use pin_project::pin_project; use std::marker::PhantomPinned; + use pin_project::pin_project; + #[pin_project] struct Foo { #[cfg(any())] @@ -88,9 +90,10 @@ pub mod cfg { } pub mod cfg_attr { - use pin_project::pin_project; use std::marker::PhantomPinned; + use pin_project::pin_project; + #[cfg_attr(any(), pin_project)] struct Foo { f: T, @@ -111,9 +114,10 @@ pub mod cfg_attr { // pin_project(!Unpin) pub mod not_unpin { - use pin_project::pin_project; use std::marker::PhantomPinned; + use pin_project::pin_project; + struct Inner { f: T, } diff --git a/tests/ui/cfg/packed_sneaky-span-issue-1.rs b/tests/ui/cfg/packed_sneaky-span-issue-1.rs index 8455d07..42f57b5 100644 --- a/tests/ui/cfg/packed_sneaky-span-issue-1.rs +++ b/tests/ui/cfg/packed_sneaky-span-issue-1.rs @@ -1,12 +1,10 @@ use auxiliary_macro::hidden_repr; use pin_project::pin_project; -//~ ERROR may not be used on #[repr(packed)] types -// span is lost. -// Refs: https://github.com/rust-lang/rust/issues/43081 #[pin_project] #[hidden_repr(packed)] struct S { + //~^ ERROR may not be used on #[repr(packed)] types #[cfg(not(any()))] #[pin] f: u32, diff --git a/tests/ui/cfg/packed_sneaky-span-issue-1.stderr b/tests/ui/cfg/packed_sneaky-span-issue-1.stderr index f4d7dee..abe3ecd 100644 --- a/tests/ui/cfg/packed_sneaky-span-issue-1.stderr +++ b/tests/ui/cfg/packed_sneaky-span-issue-1.stderr @@ -1 +1,11 @@ error: #[pin_project] attribute may not be used on #[repr(packed)] types + --> $DIR/packed_sneaky-span-issue-1.rs:6:1 + | +6 | / struct S { +7 | | //~^ ERROR may not be used on #[repr(packed)] types +8 | | #[cfg(not(any()))] +9 | | #[pin] +... | +13 | | f: u8, +14 | | } + | |_^ diff --git a/tests/ui/cfg/packed_sneaky-span-issue-2.rs b/tests/ui/cfg/packed_sneaky-span-issue-2.rs index 01706ee..948d72c 100644 --- a/tests/ui/cfg/packed_sneaky-span-issue-2.rs +++ b/tests/ui/cfg/packed_sneaky-span-issue-2.rs @@ -1,12 +1,10 @@ use auxiliary_macro::hidden_repr; use pin_project::pin_project; -//~ ERROR may not be used on #[repr(packed)] types -// span is lost. -// Refs: https://github.com/rust-lang/rust/issues/43081 #[pin_project] #[hidden_repr(packed)] struct S { + //~^ ERROR may not be used on #[repr(packed)] types #[cfg(any())] #[pin] f: u32, diff --git a/tests/ui/cfg/packed_sneaky-span-issue-2.stderr b/tests/ui/cfg/packed_sneaky-span-issue-2.stderr index f4d7dee..a957ceb 100644 --- a/tests/ui/cfg/packed_sneaky-span-issue-2.stderr +++ b/tests/ui/cfg/packed_sneaky-span-issue-2.stderr @@ -1 +1,11 @@ error: #[pin_project] attribute may not be used on #[repr(packed)] types + --> $DIR/packed_sneaky-span-issue-2.rs:6:1 + | +6 | / struct S { +7 | | //~^ ERROR may not be used on #[repr(packed)] types +8 | | #[cfg(any())] +9 | | #[pin] +... | +13 | | f: u8, +14 | | } + | |_^ diff --git a/tests/ui/cfg/unsupported.rs b/tests/ui/cfg/unsupported.rs index c450f6f..b950d4b 100644 --- a/tests/ui/cfg/unsupported.rs +++ b/tests/ui/cfg/unsupported.rs @@ -1,10 +1,8 @@ use pin_project::pin_project; -//~ ERROR may not be used on structs with zero fields -// span is lost. -// Refs: https://github.com/rust-lang/rust/issues/43081 #[pin_project] struct S { + //~^ ERROR may not be used on structs with zero fields #[cfg(any())] #[pin] f: u8, diff --git a/tests/ui/cfg/unsupported.stderr b/tests/ui/cfg/unsupported.stderr index 0ee8676..b3bd1ae 100644 --- a/tests/ui/cfg/unsupported.stderr +++ b/tests/ui/cfg/unsupported.stderr @@ -1 +1,10 @@ error: #[pin_project] attribute may not be used on structs with zero fields + --> $DIR/unsupported.rs:4:1 + | +4 | / struct S { +5 | | //~^ ERROR may not be used on structs with zero fields +6 | | #[cfg(any())] +7 | | #[pin] +8 | | f: u8, +9 | | } + | |_^ diff --git a/tests/ui/pin_project/project_replace_unsized.stderr b/tests/ui/pin_project/project_replace_unsized.stderr index e40db5f..26e416a 100644 --- a/tests/ui/pin_project/project_replace_unsized.stderr +++ b/tests/ui/pin_project/project_replace_unsized.stderr @@ -13,14 +13,6 @@ help: function arguments must have a statically known size, borrowed types alway 3 | #[pin_project(&project_replace)] //~ ERROR E0277 | ^ -error[E0277]: the size for values of type `T` cannot be known at compilation time - --> $DIR/project_replace_unsized.rs:5:5 - | -4 | struct Struct { - | - this type parameter needs to be `Sized` -5 | f: T, - | ^ doesn't have a size known at compile-time - error[E0277]: the size for values of type `T` cannot be known at compilation time --> $DIR/project_replace_unsized.rs:3:1 | @@ -29,10 +21,18 @@ error[E0277]: the size for values of type `T` cannot be known at compilation tim 4 | struct Struct { | - this type parameter needs to be `Sized` | - = note: required because it appears within the type `__StructProjectionOwned` - = note: structs must have a statically known size to be initialized + = note: required because it appears within the type `Struct` + = note: required by `UnsafeOverwriteGuard` = note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info) +error[E0277]: the size for values of type `T` cannot be known at compilation time + --> $DIR/project_replace_unsized.rs:5:5 + | +4 | struct Struct { + | - this type parameter needs to be `Sized` +5 | f: T, + | ^ doesn't have a size known at compile-time + error[E0277]: the size for values of type `T` cannot be known at compilation time --> $DIR/project_replace_unsized.rs:8:15 | @@ -49,14 +49,16 @@ help: function arguments must have a statically known size, borrowed types alway | ^ error[E0277]: the size for values of type `T` cannot be known at compilation time - --> $DIR/project_replace_unsized.rs:8:1 - | -8 | #[pin_project(project_replace)] //~ ERROR E0277 - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time -9 | struct TupleStruct(T); - | - this type parameter needs to be `Sized` - | - = note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info) + --> $DIR/project_replace_unsized.rs:8:1 + | +8 | #[pin_project(project_replace)] //~ ERROR E0277 + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time +9 | struct TupleStruct(T); + | - this type parameter needs to be `Sized` + | + = note: required because it appears within the type `TupleStruct` + = note: required by `UnsafeOverwriteGuard` + = note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info) error[E0277]: the size for values of type `T` cannot be known at compilation time --> $DIR/project_replace_unsized.rs:9:8 diff --git a/tests/ui/pin_project/project_replace_unsized_fn_params.stderr b/tests/ui/pin_project/project_replace_unsized_fn_params.stderr index 622d12f..f0f9573 100644 --- a/tests/ui/pin_project/project_replace_unsized_fn_params.stderr +++ b/tests/ui/pin_project/project_replace_unsized_fn_params.stderr @@ -10,14 +10,6 @@ error[E0277]: the size for values of type `T` cannot be known at compilation tim = note: required because it appears within the type `__StructProjectionOwned` = note: the return type of a function must have a statically known size -error[E0277]: the size for values of type `T` cannot be known at compilation time - --> $DIR/project_replace_unsized_fn_params.rs:7:5 - | -6 | struct Struct { - | - this type parameter needs to be `Sized` -7 | f: T, - | ^ doesn't have a size known at compile-time - error[E0277]: the size for values of type `T` cannot be known at compilation time --> $DIR/project_replace_unsized_fn_params.rs:5:1 | @@ -26,10 +18,18 @@ error[E0277]: the size for values of type `T` cannot be known at compilation tim 6 | struct Struct { | - this type parameter needs to be `Sized` | - = note: required because it appears within the type `__StructProjectionOwned` - = note: structs must have a statically known size to be initialized + = note: required because it appears within the type `Struct` + = note: required by `UnsafeOverwriteGuard` = note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info) +error[E0277]: the size for values of type `T` cannot be known at compilation time + --> $DIR/project_replace_unsized_fn_params.rs:7:5 + | +6 | struct Struct { + | - this type parameter needs to be `Sized` +7 | f: T, + | ^ doesn't have a size known at compile-time + error[E0277]: the size for values of type `T` cannot be known at compilation time --> $DIR/project_replace_unsized_fn_params.rs:11:8 | @@ -43,11 +43,13 @@ error[E0277]: the size for values of type `T` cannot be known at compilation tim = note: the return type of a function must have a statically known size error[E0277]: the size for values of type `T` cannot be known at compilation time - --> $DIR/project_replace_unsized_fn_params.rs:10:1 - | -10 | #[pin_project(project_replace)] //~ ERROR E0277 - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time -11 | struct TupleStruct(T); - | - this type parameter needs to be `Sized` - | - = note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info) + --> $DIR/project_replace_unsized_fn_params.rs:10:1 + | +10 | #[pin_project(project_replace)] //~ ERROR E0277 + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time +11 | struct TupleStruct(T); + | - this type parameter needs to be `Sized` + | + = note: required because it appears within the type `TupleStruct` + = note: required by `UnsafeOverwriteGuard` + = note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui/unstable-features/marker_trait_attr-feature-gate.rs b/tests/ui/unstable-features/marker_trait_attr-feature-gate.rs index 8860f4f..127cd1a 100644 --- a/tests/ui/unstable-features/marker_trait_attr-feature-gate.rs +++ b/tests/ui/unstable-features/marker_trait_attr-feature-gate.rs @@ -1,4 +1,4 @@ -// NB: If you change this test, change 'marker_trait_attr.rs' at the same time. +// Note: If you change this test, change 'marker_trait_attr.rs' at the same time. use pin_project::pin_project; use std::marker::PhantomPinned; diff --git a/tests/ui/unstable-features/marker_trait_attr.rs b/tests/ui/unstable-features/marker_trait_attr.rs index a6ca357..d6eab21 100644 --- a/tests/ui/unstable-features/marker_trait_attr.rs +++ b/tests/ui/unstable-features/marker_trait_attr.rs @@ -1,4 +1,4 @@ -// NB: If you change this test, change 'marker_trait_attr-feature-gate.rs' at the same time. +// Note: If you change this test, change 'marker_trait_attr-feature-gate.rs' at the same time. // marker_trait_attr // Tracking issue: https://github.com/rust-lang/rust/issues/29864 diff --git a/tests/ui/unstable-features/overlapping_marker_traits-feature-gate.rs b/tests/ui/unstable-features/overlapping_marker_traits-feature-gate.rs index 3af3cf0..9d1b8b8 100644 --- a/tests/ui/unstable-features/overlapping_marker_traits-feature-gate.rs +++ b/tests/ui/unstable-features/overlapping_marker_traits-feature-gate.rs @@ -1,4 +1,4 @@ -// NB: If you change this test, change 'overlapping_marker_traits.rs' at the same time. +// Note: If you change this test, change 'overlapping_marker_traits.rs' at the same time. use pin_project::pin_project; use std::marker::PhantomPinned; diff --git a/tests/ui/unstable-features/overlapping_marker_traits.rs b/tests/ui/unstable-features/overlapping_marker_traits.rs index c897d1c..0e0cddd 100644 --- a/tests/ui/unstable-features/overlapping_marker_traits.rs +++ b/tests/ui/unstable-features/overlapping_marker_traits.rs @@ -1,4 +1,4 @@ -// NB: If you change this test, change 'overlapping_marker_traits-feature-gate.rs' at the same time. +// Note: If you change this test, change 'overlapping_marker_traits-feature-gate.rs' at the same time. // This feature could break the guarantee for Unpin provided by pin-project, // but was removed in https://github.com/rust-lang/rust/pull/68544 (nightly-2020-02-06). diff --git a/tests/ui/unstable-features/trivial_bounds-bug.rs b/tests/ui/unstable-features/trivial_bounds-bug.rs index 2ec4960..5e821c4 100644 --- a/tests/ui/unstable-features/trivial_bounds-bug.rs +++ b/tests/ui/unstable-features/trivial_bounds-bug.rs @@ -1,4 +1,4 @@ -// NB: If you change this test, change 'trivial_bounds-feature-gate.rs' at the same time. +// Note: If you change this test, change 'trivial_bounds-feature-gate.rs' at the same time. // trivial_bounds // Tracking issue: https://github.com/rust-lang/rust/issues/48214 diff --git a/tests/ui/unstable-features/trivial_bounds-feature-gate.rs b/tests/ui/unstable-features/trivial_bounds-feature-gate.rs index ccdb182..f8467b0 100644 --- a/tests/ui/unstable-features/trivial_bounds-feature-gate.rs +++ b/tests/ui/unstable-features/trivial_bounds-feature-gate.rs @@ -1,4 +1,4 @@ -// NB: If you change this test, change 'trivial_bounds.rs' at the same time. +// Note: If you change this test, change 'trivial_bounds.rs' at the same time. mod phantom_pinned { use std::marker::{PhantomData, PhantomPinned}; diff --git a/tests/ui/unstable-features/trivial_bounds.rs b/tests/ui/unstable-features/trivial_bounds.rs index 680effe..2323bab 100644 --- a/tests/ui/unstable-features/trivial_bounds.rs +++ b/tests/ui/unstable-features/trivial_bounds.rs @@ -1,4 +1,4 @@ -// NB: If you change this test, change 'trivial_bounds-feature-gate.rs' at the same time. +// Note: If you change this test, change 'trivial_bounds-feature-gate.rs' at the same time. // trivial_bounds // Tracking issue: https://github.com/rust-lang/rust/issues/48214 diff --git a/tests/unsafe_unpin.rs b/tests/unsafe_unpin.rs index 1bd6c0b..8b6411c 100644 --- a/tests/unsafe_unpin.rs +++ b/tests/unsafe_unpin.rs @@ -4,9 +4,10 @@ #[macro_use] mod auxiliary; -use pin_project::{pin_project, UnsafeUnpin}; use std::marker::PhantomPinned; +use pin_project::{pin_project, UnsafeUnpin}; + #[pin_project(UnsafeUnpin)] pub struct Blah { f1: U, -- cgit v1.2.3