diff options
Diffstat (limited to 'tests')
68 files changed, 2461 insertions, 440 deletions
diff --git a/tests/README.md b/tests/README.md new file mode 100644 index 0000000..4721616 --- /dev/null +++ b/tests/README.md @@ -0,0 +1,46 @@ +# Tests + +Many of the tests in this repository are based on [pin-project's tests](https://github.com/taiki-e/pin-project/tree/HEAD/tests). + +To run all tests, run the following command: + +```sh +cargo +nightly test --all +``` + +## UI tests (`ui`, `compiletest.rs`) + +This checks errors detected by the macro or the Rust compiler in the resulting +expanded code. + +To run this test, run the following command: + +```sh +cargo +nightly test --test compiletest +``` + +Locally, this test updates the files in the `ui` directory if there are +changes to the generated code. If there are any changes to the files in the +`ui` directory after running the test, please commit them. + +See also [`trybuild` documentation](https://docs.rs/trybuild). + +## Expansion tests (`expand`, `expandtest.rs`) + +Similar to ui tests, but instead of checking the compiler output, this checks +the code generated by macros. + +See pin-project's [examples](https://github.com/taiki-e/pin-project/tree/HEAD/examples) +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. + +See also [`macrotest` documentation](https://docs.rs/macrotest). diff --git a/tests/auxiliary/mod.rs b/tests/auxiliary/mod.rs index e39037c..1457099 100644 --- a/tests/auxiliary/mod.rs +++ b/tests/auxiliary/mod.rs @@ -1,6 +1,4 @@ #![allow(dead_code, unused_macros)] -#![allow(box_pointers, unreachable_pub)] -#![allow(clippy::restriction)] macro_rules! assert_unpin { ($ty:ty) => { diff --git a/tests/compiletest.rs b/tests/compiletest.rs index 5a91b20..70d2358 100644 --- a/tests/compiletest.rs +++ b/tests/compiletest.rs @@ -3,7 +3,7 @@ use std::env; -#[rustversion::attr(before(2020-12-03), ignore)] // Note: This date is commit-date and the day before the toolchain date. +#[rustversion::attr(not(nightly), ignore)] #[test] fn ui() { if env::var_os("CI").is_none() { @@ -11,5 +11,5 @@ fn ui() { } let t = trybuild::TestCases::new(); - t.compile_fail("tests/ui/*.rs"); + t.compile_fail("tests/ui/**/*.rs"); } diff --git a/tests/drop_order.rs b/tests/drop_order.rs index d84c324..6e5deaf 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_lite::pin_project; use std::{cell::Cell, panic, pin::Pin, thread}; +use pin_project_lite::pin_project; + struct D<'a>(&'a Cell<usize>, usize); impl Drop for D<'_> { @@ -128,7 +129,7 @@ fn project_replace_panic() { fn drop(&mut self) { *self.0 = true; if self.1 { - panic!() + panic!(); } } } diff --git a/tests/expand/default/enum.expanded.rs b/tests/expand/default/enum.expanded.rs new file mode 100644 index 0000000..eae0aac --- /dev/null +++ b/tests/expand/default/enum.expanded.rs @@ -0,0 +1,127 @@ +use pin_project_lite::pin_project; +enum Enum<T, U> { + Struct { pinned: T, unpinned: U }, + Unit, +} +#[allow(dead_code)] +#[allow(single_use_lifetimes)] +#[allow(clippy::unknown_clippy_lints)] +#[allow(clippy::mut_mut)] +#[allow(clippy::redundant_pub_crate)] +#[allow(clippy::ref_option_ref)] +#[allow(clippy::type_repetition_in_bounds)] +enum EnumProj<'__pin, T, U> +where + Enum<T, U>: '__pin, +{ + Struct { + pinned: ::pin_project_lite::__private::Pin<&'__pin mut (T)>, + unpinned: &'__pin mut (U), + }, + Unit, +} +#[allow(dead_code)] +#[allow(single_use_lifetimes)] +#[allow(clippy::unknown_clippy_lints)] +#[allow(clippy::mut_mut)] +#[allow(clippy::redundant_pub_crate)] +#[allow(clippy::ref_option_ref)] +#[allow(clippy::type_repetition_in_bounds)] +enum EnumProjRef<'__pin, T, U> +where + Enum<T, U>: '__pin, +{ + Struct { + pinned: ::pin_project_lite::__private::Pin<&'__pin (T)>, + unpinned: &'__pin (U), + }, + Unit, +} +#[allow(dead_code)] +#[allow(single_use_lifetimes)] +#[allow(clippy::mut_mut)] +#[allow(clippy::redundant_pub_crate)] +#[allow(clippy::type_repetition_in_bounds)] +enum EnumProjReplace<T, U> { + Struct { + pinned: ::pin_project_lite::__private::PhantomData<T>, + unpinned: U, + }, + Unit, +} +#[allow(single_use_lifetimes)] +#[allow(clippy::unknown_clippy_lints)] +#[allow(clippy::used_underscore_binding)] +const _: () = { + impl<T, U> Enum<T, U> { + fn project<'__pin>( + self: ::pin_project_lite::__private::Pin<&'__pin mut Self>, + ) -> EnumProj<'__pin, T, U> { + unsafe { + match self.get_unchecked_mut() { + Self::Struct { pinned, unpinned } => EnumProj::Struct { + pinned: ::pin_project_lite::__private::Pin::new_unchecked(pinned), + unpinned: unpinned, + }, + Self::Unit => EnumProj::Unit, + } + } + } + fn project_ref<'__pin>( + self: ::pin_project_lite::__private::Pin<&'__pin Self>, + ) -> EnumProjRef<'__pin, T, U> { + unsafe { + match self.get_ref() { + Self::Struct { pinned, unpinned } => EnumProjRef::Struct { + pinned: ::pin_project_lite::__private::Pin::new_unchecked(pinned), + unpinned: unpinned, + }, + Self::Unit => EnumProjRef::Unit, + } + } + } + fn project_replace( + self: ::pin_project_lite::__private::Pin<&mut Self>, + replacement: Self, + ) -> EnumProjReplace<T, U> { + unsafe { + let __self_ptr: *mut Self = self.get_unchecked_mut(); + let __guard = ::pin_project_lite::__private::UnsafeOverwriteGuard::new( + __self_ptr, + replacement, + ); + match &mut *__self_ptr { + Self::Struct { pinned, unpinned } => { + let result = EnumProjReplace::Struct { + pinned: ::pin_project_lite::__private::PhantomData, + unpinned: ::pin_project_lite::__private::ptr::read(unpinned), + }; + { + ( + ::pin_project_lite::__private::UnsafeDropInPlaceGuard::new(pinned), + (), + ); + } + result + } + Self::Unit => EnumProjReplace::Unit, + } + } + } + } + #[allow(non_snake_case)] + struct __Origin<'__pin, T, U> { + __dummy_lifetime: ::pin_project_lite::__private::PhantomData<&'__pin ()>, + Struct: (T, ::pin_project_lite::__private::AlwaysUnpin<U>), + Unit: (), + } + impl<'__pin, T, U> ::pin_project_lite::__private::Unpin for Enum<T, U> where + __Origin<'__pin, T, U>: ::pin_project_lite::__private::Unpin + { + } + trait MustNotImplDrop {} + #[allow(clippy::drop_bounds, drop_bounds)] + impl<T: ::pin_project_lite::__private::Drop> MustNotImplDrop for T {} + impl<T, U> MustNotImplDrop for Enum<T, U> {} +}; +fn main() {} diff --git a/tests/expand/default/enum.rs b/tests/expand/default/enum.rs new file mode 100644 index 0000000..90d6860 --- /dev/null +++ b/tests/expand/default/enum.rs @@ -0,0 +1,17 @@ +use pin_project_lite::pin_project; + +pin_project! { + #[project = EnumProj] + #[project_ref = EnumProjRef] + #[project_replace = EnumProjReplace] + enum Enum<T, U> { + Struct { + #[pin] + pinned: T, + unpinned: 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..8ab318c --- /dev/null +++ b/tests/expand/default/struct.expanded.rs @@ -0,0 +1,84 @@ +use pin_project_lite::pin_project; +struct Struct<T, U> { + pinned: T, + unpinned: U, +} +#[allow(explicit_outlives_requirements)] +#[allow(single_use_lifetimes)] +#[allow(clippy::unknown_clippy_lints)] +#[allow(clippy::redundant_pub_crate)] +#[allow(clippy::used_underscore_binding)] +const _: () = { + #[allow(dead_code)] + #[allow(single_use_lifetimes)] + #[allow(clippy::unknown_clippy_lints)] + #[allow(clippy::mut_mut)] + #[allow(clippy::redundant_pub_crate)] + #[allow(clippy::ref_option_ref)] + #[allow(clippy::type_repetition_in_bounds)] + struct Projection<'__pin, T, U> + where + Struct<T, U>: '__pin, + { + pinned: ::pin_project_lite::__private::Pin<&'__pin mut (T)>, + unpinned: &'__pin mut (U), + } + #[allow(dead_code)] + #[allow(single_use_lifetimes)] + #[allow(clippy::unknown_clippy_lints)] + #[allow(clippy::mut_mut)] + #[allow(clippy::redundant_pub_crate)] + #[allow(clippy::ref_option_ref)] + #[allow(clippy::type_repetition_in_bounds)] + struct ProjectionRef<'__pin, T, U> + where + Struct<T, U>: '__pin, + { + pinned: ::pin_project_lite::__private::Pin<&'__pin (T)>, + unpinned: &'__pin (U), + } + impl<T, U> Struct<T, U> { + fn project<'__pin>( + self: ::pin_project_lite::__private::Pin<&'__pin mut Self>, + ) -> Projection<'__pin, T, U> { + unsafe { + let Self { pinned, unpinned } = self.get_unchecked_mut(); + Projection { + pinned: ::pin_project_lite::__private::Pin::new_unchecked(pinned), + unpinned: unpinned, + } + } + } + fn project_ref<'__pin>( + self: ::pin_project_lite::__private::Pin<&'__pin Self>, + ) -> ProjectionRef<'__pin, T, U> { + unsafe { + let Self { pinned, unpinned } = self.get_ref(); + ProjectionRef { + pinned: ::pin_project_lite::__private::Pin::new_unchecked(pinned), + unpinned: unpinned, + } + } + } + } + #[allow(non_snake_case)] + struct __Origin<'__pin, T, U> { + __dummy_lifetime: ::pin_project_lite::__private::PhantomData<&'__pin ()>, + pinned: T, + unpinned: ::pin_project_lite::__private::AlwaysUnpin<U>, + } + impl<'__pin, T, U> ::pin_project_lite::__private::Unpin for Struct<T, U> where + __Origin<'__pin, T, U>: ::pin_project_lite::__private::Unpin + { + } + trait MustNotImplDrop {} + #[allow(clippy::drop_bounds, drop_bounds)] + impl<T: ::pin_project_lite::__private::Drop> MustNotImplDrop for T {} + impl<T, U> MustNotImplDrop for Struct<T, U> {} + #[forbid(unaligned_references, safe_packed_borrows)] + fn __assert_not_repr_packed<T, U>(this: &Struct<T, U>) { + let _ = &this.pinned; + let _ = &this.unpinned; + } +}; +fn main() {} diff --git a/tests/expand/default/struct.rs b/tests/expand/default/struct.rs new file mode 100644 index 0000000..e5447c7 --- /dev/null +++ b/tests/expand/default/struct.rs @@ -0,0 +1,11 @@ +use pin_project_lite::pin_project; + +pin_project! { + struct Struct<T, U> { + #[pin] + pinned: T, + unpinned: 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..fca0feb --- /dev/null +++ b/tests/expand/multifields/enum.expanded.rs @@ -0,0 +1,88 @@ +use pin_project_lite::pin_project; +enum Enum<T, U> { + Struct { + pinned1: T, + pinned2: T, + unpinned1: U, + unpinned2: U, + }, + Unit, +} +#[allow(dead_code)] +#[allow(single_use_lifetimes)] +#[allow(clippy::mut_mut)] +#[allow(clippy::redundant_pub_crate)] +#[allow(clippy::type_repetition_in_bounds)] +enum EnumProjReplace<T, U> { + Struct { + pinned1: ::pin_project_lite::__private::PhantomData<T>, + pinned2: ::pin_project_lite::__private::PhantomData<T>, + unpinned1: U, + unpinned2: U, + }, + Unit, +} +#[allow(single_use_lifetimes)] +#[allow(clippy::unknown_clippy_lints)] +#[allow(clippy::used_underscore_binding)] +const _: () = { + impl<T, U> Enum<T, U> { + fn project_replace( + self: ::pin_project_lite::__private::Pin<&mut Self>, + replacement: Self, + ) -> EnumProjReplace<T, U> { + unsafe { + let __self_ptr: *mut Self = self.get_unchecked_mut(); + let __guard = ::pin_project_lite::__private::UnsafeOverwriteGuard::new( + __self_ptr, + replacement, + ); + match &mut *__self_ptr { + Self::Struct { + pinned1, + pinned2, + unpinned1, + unpinned2, + } => { + let result = EnumProjReplace::Struct { + pinned1: ::pin_project_lite::__private::PhantomData, + pinned2: ::pin_project_lite::__private::PhantomData, + unpinned1: ::pin_project_lite::__private::ptr::read(unpinned1), + unpinned2: ::pin_project_lite::__private::ptr::read(unpinned2), + }; + { + ( + ::pin_project_lite::__private::UnsafeDropInPlaceGuard::new(pinned1), + ::pin_project_lite::__private::UnsafeDropInPlaceGuard::new(pinned2), + (), + (), + ); + } + result + } + Self::Unit => EnumProjReplace::Unit, + } + } + } + } + #[allow(non_snake_case)] + struct __Origin<'__pin, T, U> { + __dummy_lifetime: ::pin_project_lite::__private::PhantomData<&'__pin ()>, + Struct: ( + T, + T, + ::pin_project_lite::__private::AlwaysUnpin<U>, + ::pin_project_lite::__private::AlwaysUnpin<U>, + ), + Unit: (), + } + impl<'__pin, T, U> ::pin_project_lite::__private::Unpin for Enum<T, U> where + __Origin<'__pin, T, U>: ::pin_project_lite::__private::Unpin + { + } + trait MustNotImplDrop {} + #[allow(clippy::drop_bounds, drop_bounds)] + impl<T: ::pin_project_lite::__private::Drop> MustNotImplDrop for T {} + impl<T, U> MustNotImplDrop for Enum<T, U> {} +}; +fn main() {} diff --git a/tests/expand/multifields/enum.rs b/tests/expand/multifields/enum.rs new file mode 100644 index 0000000..c713362 --- /dev/null +++ b/tests/expand/multifields/enum.rs @@ -0,0 +1,18 @@ +use pin_project_lite::pin_project; + +pin_project! { +#[project_replace = EnumProjReplace] +enum Enum<T, U> { + Struct { + #[pin] + pinned1: T, + #[pin] + pinned2: T, + unpinned1: U, + unpinned2: 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..4320f68 --- /dev/null +++ b/tests/expand/multifields/struct.expanded.rs @@ -0,0 +1,152 @@ +use pin_project_lite::pin_project; +struct Struct<T, U> { + pinned1: T, + pinned2: T, + unpinned1: U, + unpinned2: U, +} +#[allow(dead_code)] +#[allow(single_use_lifetimes)] +#[allow(clippy::mut_mut)] +#[allow(clippy::redundant_pub_crate)] +#[allow(clippy::type_repetition_in_bounds)] +struct StructProjReplace<T, U> { + pinned1: ::pin_project_lite::__private::PhantomData<T>, + pinned2: ::pin_project_lite::__private::PhantomData<T>, + unpinned1: U, + unpinned2: U, +} +#[allow(explicit_outlives_requirements)] +#[allow(single_use_lifetimes)] +#[allow(clippy::unknown_clippy_lints)] +#[allow(clippy::redundant_pub_crate)] +#[allow(clippy::used_underscore_binding)] +const _: () = { + #[allow(dead_code)] + #[allow(single_use_lifetimes)] + #[allow(clippy::unknown_clippy_lints)] + #[allow(clippy::mut_mut)] + #[allow(clippy::redundant_pub_crate)] + #[allow(clippy::ref_option_ref)] + #[allow(clippy::type_repetition_in_bounds)] + struct Projection<'__pin, T, U> + where + Struct<T, U>: '__pin, + { + pinned1: ::pin_project_lite::__private::Pin<&'__pin mut (T)>, + pinned2: ::pin_project_lite::__private::Pin<&'__pin mut (T)>, + unpinned1: &'__pin mut (U), + unpinned2: &'__pin mut (U), + } + #[allow(dead_code)] + #[allow(single_use_lifetimes)] + #[allow(clippy::unknown_clippy_lints)] + #[allow(clippy::mut_mut)] + #[allow(clippy::redundant_pub_crate)] + #[allow(clippy::ref_option_ref)] + #[allow(clippy::type_repetition_in_bounds)] + struct ProjectionRef<'__pin, T, U> + where + Struct<T, U>: '__pin, + { + pinned1: ::pin_project_lite::__private::Pin<&'__pin (T)>, + pinned2: ::pin_project_lite::__private::Pin<&'__pin (T)>, + unpinned1: &'__pin (U), + unpinned2: &'__pin (U), + } + impl<T, U> Struct<T, U> { + fn project<'__pin>( + self: ::pin_project_lite::__private::Pin<&'__pin mut Self>, + ) -> Projection<'__pin, T, U> { + unsafe { + let Self { + pinned1, + pinned2, + unpinned1, + unpinned2, + } = self.get_unchecked_mut(); + Projection { + pinned1: ::pin_project_lite::__private::Pin::new_unchecked(pinned1), + pinned2: ::pin_project_lite::__private::Pin::new_unchecked(pinned2), + unpinned1: unpinned1, + unpinned2: unpinned2, + } + } + } + fn project_ref<'__pin>( + self: ::pin_project_lite::__private::Pin<&'__pin Self>, + ) -> ProjectionRef<'__pin, T, U> { + unsafe { + let Self { + pinned1, + pinned2, + unpinned1, + unpinned2, + } = self.get_ref(); + ProjectionRef { + pinned1: ::pin_project_lite::__private::Pin::new_unchecked(pinned1), + pinned2: ::pin_project_lite::__private::Pin::new_unchecked(pinned2), + unpinned1: unpinned1, + unpinned2: unpinned2, + } + } + } + fn project_replace( + self: ::pin_project_lite::__private::Pin<&mut Self>, + replacement: Self, + ) -> StructProjReplace<T, U> { + unsafe { + let __self_ptr: *mut Self = self.get_unchecked_mut(); + let __guard = ::pin_project_lite::__private::UnsafeOverwriteGuard::new( + __self_ptr, + replacement, + ); + let Self { + pinned1, + pinned2, + unpinned1, + unpinned2, + } = &mut *__self_ptr; + let result = StructProjReplace { + pinned1: ::pin_project_lite::__private::PhantomData, + pinned2: ::pin_project_lite::__private::PhantomData, + unpinned1: ::pin_project_lite::__private::ptr::read(unpinned1), + unpinned2: ::pin_project_lite::__private::ptr::read(unpinned2), + }; + { + ( + ::pin_project_lite::__private::UnsafeDropInPlaceGuard::new(pinned1), + ::pin_project_lite::__private::UnsafeDropInPlaceGuard::new(pinned2), + (), + (), + ); + } + result + } + } + } + #[allow(non_snake_case)] + struct __Origin<'__pin, T, U> { + __dummy_lifetime: ::pin_project_lite::__private::PhantomData<&'__pin ()>, + pinned1: T, + pinned2: T, + unpinned1: ::pin_project_lite::__private::AlwaysUnpin<U>, + unpinned2: ::pin_project_lite::__private::AlwaysUnpin<U>, + } + impl<'__pin, T, U> ::pin_project_lite::__private::Unpin for Struct<T, U> where + __Origin<'__pin, T, U>: ::pin_project_lite::__private::Unpin + { + } + trait MustNotImplDrop {} + #[allow(clippy::drop_bounds, drop_bounds)] + impl<T: ::pin_project_lite::__private::Drop> MustNotImplDrop for T {} + impl<T, U> MustNotImplDrop for Struct<T, U> {} + #[forbid(unaligned_references, safe_packed_borrows)] + fn __assert_not_repr_packed<T, U>(this: &Struct<T, U>) { + let _ = &this.pinned1; + let _ = &this.pinned2; + let _ = &this.unpinned1; + let _ = &this.unpinned2; + } +}; +fn main() {} diff --git a/tests/expand/multifields/struct.rs b/tests/expand/multifields/struct.rs new file mode 100644 index 0000000..a1d45d1 --- /dev/null +++ b/tests/expand/multifields/struct.rs @@ -0,0 +1,15 @@ +use pin_project_lite::pin_project; + +pin_project! { +#[project_replace = StructProjReplace] +struct Struct<T, U> { + #[pin] + pinned1: T, + #[pin] + pinned2: T, + unpinned1: U, + unpinned2: 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..eae0aac --- /dev/null +++ b/tests/expand/naming/enum-all.expanded.rs @@ -0,0 +1,127 @@ +use pin_project_lite::pin_project; +enum Enum<T, U> { + Struct { pinned: T, unpinned: U }, + Unit, +} +#[allow(dead_code)] +#[allow(single_use_lifetimes)] +#[allow(clippy::unknown_clippy_lints)] +#[allow(clippy::mut_mut)] +#[allow(clippy::redundant_pub_crate)] +#[allow(clippy::ref_option_ref)] +#[allow(clippy::type_repetition_in_bounds)] +enum EnumProj<'__pin, T, U> +where + Enum<T, U>: '__pin, +{ + Struct { + pinned: ::pin_project_lite::__private::Pin<&'__pin mut (T)>, + unpinned: &'__pin mut (U), + }, + Unit, +} +#[allow(dead_code)] +#[allow(single_use_lifetimes)] +#[allow(clippy::unknown_clippy_lints)] +#[allow(clippy::mut_mut)] +#[allow(clippy::redundant_pub_crate)] +#[allow(clippy::ref_option_ref)] +#[allow(clippy::type_repetition_in_bounds)] +enum EnumProjRef<'__pin, T, U> +where + Enum<T, U>: '__pin, +{ + Struct { + pinned: ::pin_project_lite::__private::Pin<&'__pin (T)>, + unpinned: &'__pin (U), + }, + Unit, +} +#[allow(dead_code)] +#[allow(single_use_lifetimes)] +#[allow(clippy::mut_mut)] +#[allow(clippy::redundant_pub_crate)] +#[allow(clippy::type_repetition_in_bounds)] +enum EnumProjReplace<T, U> { + Struct { + pinned: ::pin_project_lite::__private::PhantomData<T>, + unpinned: U, + }, + Unit, +} +#[allow(single_use_lifetimes)] +#[allow(clippy::unknown_clippy_lints)] +#[allow(clippy::used_underscore_binding)] +const _: () = { + impl<T, U> Enum<T, U> { + fn project<'__pin>( + self: ::pin_project_lite::__private::Pin<&'__pin mut Self>, + ) -> EnumProj<'__pin, T, U> { + unsafe { + match self.get_unchecked_mut() { + Self::Struct { pinned, unpinned } => EnumProj::Struct { + pinned: ::pin_project_lite::__private::Pin::new_unchecked(pinned), + unpinned: unpinned, + }, + Self::Unit => EnumProj::Unit, + } + } + } + fn project_ref<'__pin>( + self: ::pin_project_lite::__private::Pin<&'__pin Self>, + ) -> EnumProjRef<'__pin, T, U> { + unsafe { + match self.get_ref() { + Self::Struct { pinned, unpinned } => EnumProjRef::Struct { + pinned: ::pin_project_lite::__private::Pin::new_unchecked(pinned), + unpinned: unpinned, + }, + Self::Unit => EnumProjRef::Unit, + } + } + } + fn project_replace( + self: ::pin_project_lite::__private::Pin<&mut Self>, + replacement: Self, + ) -> EnumProjReplace<T, U> { + unsafe { + let __self_ptr: *mut Self = self.get_unchecked_mut(); + let __guard = ::pin_project_lite::__private::UnsafeOverwriteGuard::new( + __self_ptr, + replacement, + ); + match &mut *__self_ptr { + Self::Struct { pinned, unpinned } => { + let result = EnumProjReplace::Struct { + pinned: ::pin_project_lite::__private::PhantomData, + unpinned: ::pin_project_lite::__private::ptr::read(unpinned), + }; + { + ( + ::pin_project_lite::__private::UnsafeDropInPlaceGuard::new(pinned), + (), + ); + } + result + } + Self::Unit => EnumProjReplace::Unit, + } + } + } + } + #[allow(non_snake_case)] + struct __Origin<'__pin, T, U> { + __dummy_lifetime: ::pin_project_lite::__private::PhantomData<&'__pin ()>, + Struct: (T, ::pin_project_lite::__private::AlwaysUnpin<U>), + Unit: (), + } + impl<'__pin, T, U> ::pin_project_lite::__private::Unpin for Enum<T, U> where + __Origin<'__pin, T, U>: ::pin_project_lite::__private::Unpin + { + } + trait MustNotImplDrop {} + #[allow(clippy::drop_bounds, drop_bounds)] + impl<T: ::pin_project_lite::__private::Drop> MustNotImplDrop for T {} + impl<T, U> MustNotImplDrop for Enum<T, U> {} +}; +fn main() {} diff --git a/tests/expand/naming/enum-all.rs b/tests/expand/naming/enum-all.rs new file mode 100644 index 0000000..90d6860 --- /dev/null +++ b/tests/expand/naming/enum-all.rs @@ -0,0 +1,17 @@ +use pin_project_lite::pin_project; + +pin_project! { + #[project = EnumProj] + #[project_ref = EnumProjRef] + #[project_replace = EnumProjReplace] + enum Enum<T, U> { + Struct { + #[pin] + pinned: T, + unpinned: 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..7c4d6af --- /dev/null +++ b/tests/expand/naming/enum-mut.expanded.rs @@ -0,0 +1,57 @@ +use pin_project_lite::pin_project; +enum Enum<T, U> { + Struct { pinned: T, unpinned: U }, + Unit, +} +#[allow(dead_code)] +#[allow(single_use_lifetimes)] +#[allow(clippy::unknown_clippy_lints)] +#[allow(clippy::mut_mut)] +#[allow(clippy::redundant_pub_crate)] +#[allow(clippy::ref_option_ref)] +#[allow(clippy::type_repetition_in_bounds)] +enum EnumProj<'__pin, T, U> +where + Enum<T, U>: '__pin, +{ + Struct { + pinned: ::pin_project_lite::__private::Pin<&'__pin mut (T)>, + unpinned: &'__pin mut (U), + }, + Unit, +} +#[allow(single_use_lifetimes)] +#[allow(clippy::unknown_clippy_lints)] +#[allow(clippy::used_underscore_binding)] +const _: () = { + impl<T, U> Enum<T, U> { + fn project<'__pin>( + self: ::pin_project_lite::__private::Pin<&'__pin mut Self>, + ) -> EnumProj<'__pin, T, U> { + unsafe { + match self.get_unchecked_mut() { + Self::Struct { pinned, unpinned } => EnumProj::Struct { + pinned: ::pin_project_lite::__private::Pin::new_unchecked(pinned), + unpinned: unpinned, + }, + Self::Unit => EnumProj::Unit, + } + } + } + } + #[allow(non_snake_case)] + struct __Origin<'__pin, T, U> { + __dummy_lifetime: ::pin_project_lite::__private::PhantomData<&'__pin ()>, + Struct: (T, ::pin_project_lite::__private::AlwaysUnpin<U>), + Unit: (), + } + impl<'__pin, T, U> ::pin_project_lite::__private::Unpin for Enum<T, U> where + __Origin<'__pin, T, U>: ::pin_project_lite::__private::Unpin + { + } + trait MustNotImplDrop {} + #[allow(clippy::drop_bounds, drop_bounds)] + impl<T: ::pin_project_lite::__private::Drop> MustNotImplDrop for T {} + impl<T, U> MustNotImplDrop for Enum<T, U> {} +}; +fn main() {} diff --git a/tests/expand/naming/enum-mut.rs b/tests/expand/naming/enum-mut.rs new file mode 100644 index 0000000..69beecd --- /dev/null +++ b/tests/expand/naming/enum-mut.rs @@ -0,0 +1,15 @@ +use pin_project_lite::pin_project; + +pin_project! { + #[project = EnumProj] + enum Enum<T, U> { + Struct { + #[pin] + pinned: T, + unpinned: 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..28ce97d --- /dev/null +++ b/tests/expand/naming/enum-none.expanded.rs @@ -0,0 +1,26 @@ +use pin_project_lite::pin_project; +enum Enum<T, U> { + Struct { pinned: T, unpinned: U }, + Unit, +} +#[allow(single_use_lifetimes)] +#[allow(clippy::unknown_clippy_lints)] +#[allow(clippy::used_underscore_binding)] +const _: () = { + impl<T, U> Enum<T, U> {} + #[allow(non_snake_case)] + struct __Origin<'__pin, T, U> { + __dummy_lifetime: ::pin_project_lite::__private::PhantomData<&'__pin ()>, + Struct: (T, ::pin_project_lite::__private::AlwaysUnpin<U>), + Unit: (), + } + impl<'__pin, T, U> ::pin_project_lite::__private::Unpin for Enum<T, U> where + __Origin<'__pin, T, U>: ::pin_project_lite::__private::Unpin + { + } + trait MustNotImplDrop {} + #[allow(clippy::drop_bounds, drop_bounds)] + impl<T: ::pin_project_lite::__private::Drop> MustNotImplDrop for T {} + impl<T, U> MustNotImplDrop for Enum<T, U> {} +}; +fn main() {} diff --git a/tests/expand/naming/enum-none.rs b/tests/expand/naming/enum-none.rs new file mode 100644 index 0000000..b2e3f9d --- /dev/null +++ b/tests/expand/naming/enum-none.rs @@ -0,0 +1,14 @@ +use pin_project_lite::pin_project; + +pin_project! { + enum Enum<T, U> { + Struct { + #[pin] + pinned: T, + unpinned: 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..a1a013b --- /dev/null +++ b/tests/expand/naming/enum-ref.expanded.rs @@ -0,0 +1,57 @@ +use pin_project_lite::pin_project; +enum Enum<T, U> { + Struct { pinned: T, unpinned: U }, + Unit, +} +#[allow(dead_code)] +#[allow(single_use_lifetimes)] +#[allow(clippy::unknown_clippy_lints)] +#[allow(clippy::mut_mut)] +#[allow(clippy::redundant_pub_crate)] +#[allow(clippy::ref_option_ref)] +#[allow(clippy::type_repetition_in_bounds)] +enum EnumProjRef<'__pin, T, U> +where + Enum<T, U>: '__pin, +{ + Struct { + pinned: ::pin_project_lite::__private::Pin<&'__pin (T)>, + unpinned: &'__pin (U), + }, + Unit, +} +#[allow(single_use_lifetimes)] +#[allow(clippy::unknown_clippy_lints)] +#[allow(clippy::used_underscore_binding)] +const _: () = { + impl<T, U> Enum<T, U> { + fn project_ref<'__pin>( + self: ::pin_project_lite::__private::Pin<&'__pin Self>, + ) -> EnumProjRef<'__pin, T, U> { + unsafe { + match self.get_ref() { + Self::Struct { pinned, unpinned } => EnumProjRef::Struct { + pinned: ::pin_project_lite::__private::Pin::new_unchecked(pinned), + unpinned: unpinned, + }, + Self::Unit => EnumProjRef::Unit, + } + } + } + } + #[allow(non_snake_case)] + struct __Origin<'__pin, T, U> { + __dummy_lifetime: ::pin_project_lite::__private::PhantomData<&'__pin ()>, + Struct: (T, ::pin_project_lite::__private::AlwaysUnpin<U>), + Unit: (), + } + impl<'__pin, T, U> ::pin_project_lite::__private::Unpin for Enum<T, U> where + __Origin<'__pin, T, U>: ::pin_project_lite::__private::Unpin + { + } + trait MustNotImplDrop {} + #[allow(clippy::drop_bounds, drop_bounds)] + impl<T: ::pin_project_lite::__private::Drop> MustNotImplDrop for T {} + impl<T, U> MustNotImplDrop for Enum<T, U> {} +}; +fn main() {} diff --git a/tests/expand/naming/enum-ref.rs b/tests/expand/naming/enum-ref.rs new file mode 100644 index 0000000..480d592 --- /dev/null +++ b/tests/expand/naming/enum-ref.rs @@ -0,0 +1,15 @@ +use pin_project_lite::pin_project; + +pin_project! { + #[project_ref = EnumProjRef] + enum Enum<T, U> { + Struct { + #[pin] + pinned: T, + unpinned: 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..b91c24e --- /dev/null +++ b/tests/expand/naming/struct-all.expanded.rs @@ -0,0 +1,117 @@ +use pin_project_lite::pin_project; +struct Struct<T, U> { + pinned: T, + unpinned: U, +} +#[allow(dead_code)] +#[allow(single_use_lifetimes)] +#[allow(clippy::unknown_clippy_lints)] +#[allow(clippy::mut_mut)] +#[allow(clippy::redundant_pub_crate)] +#[allow(clippy::ref_option_ref)] +#[allow(clippy::type_repetition_in_bounds)] +struct StructProj<'__pin, T, U> +where + Struct<T, U>: '__pin, +{ + pinned: ::pin_project_lite::__private::Pin<&'__pin mut (T)>, + unpinned: &'__pin mut (U), +} +#[allow(dead_code)] +#[allow(single_use_lifetimes)] +#[allow(clippy::unknown_clippy_lints)] +#[allow(clippy::mut_mut)] +#[allow(clippy::redundant_pub_crate)] +#[allow(clippy::ref_option_ref)] +#[allow(clippy::type_repetition_in_bounds)] +struct StructProjRef<'__pin, T, U> +where + Struct<T, U>: '__pin, +{ + pinned: ::pin_project_lite::__private::Pin<&'__pin (T)>, + unpinned: &'__pin (U), +} +#[allow(dead_code)] +#[allow(single_use_lifetimes)] +#[allow(clippy::mut_mut)] +#[allow(clippy::redundant_pub_crate)] +#[allow(clippy::type_repetition_in_bounds)] +struct StructProjReplace<T, U> { + pinned: ::pin_project_lite::__private::PhantomData<T>, + unpinned: U, +} +#[allow(explicit_outlives_requirements)] +#[allow(single_use_lifetimes)] +#[allow(clippy::unknown_clippy_lints)] +#[allow(clippy::redundant_pub_crate)] +#[allow(clippy::used_underscore_binding)] +const _: () = { + impl<T, U> Struct<T, U> { + fn project<'__pin>( + self: ::pin_project_lite::__private::Pin<&'__pin mut Self>, + ) -> StructProj<'__pin, T, U> { + unsafe { + let Self { pinned, unpinned } = self.get_unchecked_mut(); + StructProj { + pinned: ::pin_project_lite::__private::Pin::new_unchecked(pinned), + unpinned: unpinned, + } + } + } + fn project_ref<'__pin>( + self: ::pin_project_lite::__private::Pin<&'__pin Self>, + ) -> StructProjRef<'__pin, T, U> { + unsafe { + let Self { pinned, unpinned } = self.get_ref(); + StructProjRef { + pinned: ::pin_project_lite::__private::Pin::new_unchecked(pinned), + unpinned: unpinned, + } + } + } + fn project_replace( + self: ::pin_project_lite::__private::Pin<&mut Self>, + replacement: Self, + ) -> StructProjReplace<T, U> { + unsafe { + let __self_ptr: *mut Self = self.get_unchecked_mut(); + let __guard = ::pin_project_lite::__private::UnsafeOverwriteGuard::new( + __self_ptr, + replacement, + ); + let Self { pinned, unpinned } = &mut *__self_ptr; + let result = StructProjReplace { + pinned: ::pin_project_lite::__private::PhantomData, + unpinned: ::pin_project_lite::__private::ptr::read(unpinned), + }; + { + ( + ::pin_project_lite::__private::UnsafeDropInPlaceGuard::new(pinned), + (), + ); + } + result + } + } + } + #[allow(non_snake_case)] + struct __Origin<'__pin, T, U> { + __dummy_lifetime: ::pin_project_lite::__private::PhantomData<&'__pin ()>, + pinned: T, + unpinned: ::pin_project_lite::__private::AlwaysUnpin<U>, + } + impl<'__pin, T, U> ::pin_project_lite::__private::Unpin for Struct<T, U> where + __Origin<'__pin, T, U>: ::pin_project_lite::__private::Unpin + { + } + trait MustNotImplDrop {} + #[allow(clippy::drop_bounds, drop_bounds)] + impl<T: ::pin_project_lite::__private::Drop> MustNotImplDrop for T {} + impl<T, U> MustNotImplDrop for Struct<T, U> {} + #[forbid(unaligned_references, safe_packed_borrows)] + fn __assert_not_repr_packed<T, U>(this: &Struct<T, U>) { + let _ = &this.pinned; + let _ = &this.unpinned; + } +}; +fn main() {} diff --git a/tests/expand/naming/struct-all.rs b/tests/expand/naming/struct-all.rs new file mode 100644 index 0000000..cb08753 --- /dev/null +++ b/tests/expand/naming/struct-all.rs @@ -0,0 +1,14 @@ +use pin_project_lite::pin_project; + +pin_project! { + #[project = StructProj] + #[project_ref = StructProjRef] + #[project_replace = StructProjReplace] + struct Struct<T, U> { + #[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..aaa41cd --- /dev/null +++ b/tests/expand/naming/struct-mut.expanded.rs @@ -0,0 +1,84 @@ +use pin_project_lite::pin_project; +struct Struct<T, U> { + pinned: T, + unpinned: U, +} +#[allow(dead_code)] +#[allow(single_use_lifetimes)] +#[allow(clippy::unknown_clippy_lints)] +#[allow(clippy::mut_mut)] +#[allow(clippy::redundant_pub_crate)] +#[allow(clippy::ref_option_ref)] +#[allow(clippy::type_repetition_in_bounds)] +struct StructProj<'__pin, T, U> +where + Struct<T, U>: '__pin, +{ + pinned: ::pin_project_lite::__private::Pin<&'__pin mut (T)>, + unpinned: &'__pin mut (U), +} +#[allow(explicit_outlives_requirements)] +#[allow(single_use_lifetimes)] +#[allow(clippy::unknown_clippy_lints)] +#[allow(clippy::redundant_pub_crate)] +#[allow(clippy::used_underscore_binding)] +const _: () = { + #[allow(dead_code)] + #[allow(single_use_lifetimes)] + #[allow(clippy::unknown_clippy_lints)] + #[allow(clippy::mut_mut)] + #[allow(clippy::redundant_pub_crate)] + #[allow(clippy::ref_option_ref)] + #[allow(clippy::type_repetition_in_bounds)] + struct ProjectionRef<'__pin, T, U> + where + Struct<T, U>: '__pin, + { + pinned: ::pin_project_lite::__private::Pin<&'__pin (T)>, + unpinned: &'__pin (U), + } + impl<T, U> Struct<T, U> { + fn project<'__pin>( + self: ::pin_project_lite::__private::Pin<&'__pin mut Self>, + ) -> StructProj<'__pin, T, U> { + unsafe { + let Self { pinned, unpinned } = self.get_unchecked_mut(); + StructProj { + pinned: ::pin_project_lite::__private::Pin::new_unchecked(pinned), + unpinned: unpinned, + } + } + } + fn project_ref<'__pin>( + self: ::pin_project_lite::__private::Pin<&'__pin Self>, + ) -> ProjectionRef<'__pin, T, U> { + unsafe { + let Self { pinned, unpinned } = self.get_ref(); + ProjectionRef { + pinned: ::pin_project_lite::__private::Pin::new_unchecked(pinned), + unpinned: unpinned, + } + } + } + } + #[allow(non_snake_case)] + struct __Origin<'__pin, T, U> { + __dummy_lifetime: ::pin_project_lite::__private::PhantomData<&'__pin ()>, + pinned: T, + unpinned: ::pin_project_lite::__private::AlwaysUnpin<U>, + } + impl<'__pin, T, U> ::pin_project_lite::__private::Unpin for Struct<T, U> where + __Origin<'__pin, T, U>: ::pin_project_lite::__private::Unpin + { + } + trait MustNotImplDrop {} + #[allow(clippy::drop_bounds, drop_bounds)] + impl<T: ::pin_project_lite::__private::Drop> MustNotImplDrop for T {} + impl<T, U> MustNotImplDrop for Struct<T, U> {} + #[forbid(unaligned_references, safe_packed_borrows)] + fn __assert_not_repr_packed<T, U>(this: &Struct<T, U>) { + let _ = &this.pinned; + let _ = &this.unpinned; + } +}; +fn main() {} diff --git a/tests/expand/naming/struct-mut.rs b/tests/expand/naming/struct-mut.rs new file mode 100644 index 0000000..59db445 --- /dev/null +++ b/tests/expand/naming/struct-mut.rs @@ -0,0 +1,12 @@ +use pin_project_lite::pin_project; + +pin_project! { + #[project = StructProj] + struct Struct<T, U> { + #[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..8ab318c --- /dev/null +++ b/tests/expand/naming/struct-none.expanded.rs @@ -0,0 +1,84 @@ +use pin_project_lite::pin_project; +struct Struct<T, U> { + pinned: T, + unpinned: U, +} +#[allow(explicit_outlives_requirements)] +#[allow(single_use_lifetimes)] +#[allow(clippy::unknown_clippy_lints)] +#[allow(clippy::redundant_pub_crate)] +#[allow(clippy::used_underscore_binding)] +const _: () = { + #[allow(dead_code)] + #[allow(single_use_lifetimes)] + #[allow(clippy::unknown_clippy_lints)] + #[allow(clippy::mut_mut)] + #[allow(clippy::redundant_pub_crate)] + #[allow(clippy::ref_option_ref)] + #[allow(clippy::type_repetition_in_bounds)] + struct Projection<'__pin, T, U> + where + Struct<T, U>: '__pin, + { + pinned: ::pin_project_lite::__private::Pin<&'__pin mut (T)>, + unpinned: &'__pin mut (U), + } + #[allow(dead_code)] + #[allow(single_use_lifetimes)] + #[allow(clippy::unknown_clippy_lints)] + #[allow(clippy::mut_mut)] + #[allow(clippy::redundant_pub_crate)] + #[allow(clippy::ref_option_ref)] + #[allow(clippy::type_repetition_in_bounds)] + struct ProjectionRef<'__pin, T, U> + where + Struct<T, U>: '__pin, + { + pinned: ::pin_project_lite::__private::Pin<&'__pin (T)>, + unpinned: &'__pin (U), + } + impl<T, U> Struct<T, U> { + fn project<'__pin>( + self: ::pin_project_lite::__private::Pin<&'__pin mut Self>, + ) -> Projection<'__pin, T, U> { + unsafe { + let Self { pinned, unpinned } = self.get_unchecked_mut(); + Projection { + pinned: ::pin_project_lite::__private::Pin::new_unchecked(pinned), + unpinned: unpinned, + } + } + } + fn project_ref<'__pin>( + self: ::pin_project_lite::__private::Pin<&'__pin Self>, + ) -> ProjectionRef<'__pin, T, U> { + unsafe { + let Self { pinned, unpinned } = self.get_ref(); + ProjectionRef { + pinned: ::pin_project_lite::__private::Pin::new_unchecked(pinned), + unpinned: unpinned, + } + } + } + } + #[allow(non_snake_case)] + struct __Origin<'__pin, T, U> { + __dummy_lifetime: ::pin_project_lite::__private::PhantomData<&'__pin ()>, + pinned: T, + unpinned: ::pin_project_lite::__private::AlwaysUnpin<U>, + } + impl<'__pin, T, U> ::pin_project_lite::__private::Unpin for Struct<T, U> where + __Origin<'__pin, T, U>: ::pin_project_lite::__private::Unpin + { + } + trait MustNotImplDrop {} + #[allow(clippy::drop_bounds, drop_bounds)] + impl<T: ::pin_project_lite::__private::Drop> MustNotImplDrop for T {} + impl<T, U> MustNotImplDrop for Struct<T, U> {} + #[forbid(unaligned_references, safe_packed_borrows)] + fn __assert_not_repr_packed<T, U>(this: &Struct<T, U>) { + let _ = &this.pinned; + let _ = &this.unpinned; + } +}; +fn main() {} diff --git a/tests/expand/naming/struct-none.rs b/tests/expand/naming/struct-none.rs new file mode 100644 index 0000000..e5447c7 --- /dev/null +++ b/tests/expand/naming/struct-none.rs @@ -0,0 +1,11 @@ +use pin_project_lite::pin_project; + +pin_project! { + struct Struct<T, U> { + #[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..3d97ab8 --- /dev/null +++ b/tests/expand/naming/struct-ref.expanded.rs @@ -0,0 +1,84 @@ +use pin_project_lite::pin_project; +struct Struct<T, U> { + pinned: T, + unpinned: U, +} +#[allow(dead_code)] +#[allow(single_use_lifetimes)] +#[allow(clippy::unknown_clippy_lints)] +#[allow(clippy::mut_mut)] +#[allow(clippy::redundant_pub_crate)] +#[allow(clippy::ref_option_ref)] +#[allow(clippy::type_repetition_in_bounds)] +struct StructProjRef<'__pin, T, U> +where + Struct<T, U>: '__pin, +{ + pinned: ::pin_project_lite::__private::Pin<&'__pin (T)>, + unpinned: &'__pin (U), +} +#[allow(explicit_outlives_requirements)] +#[allow(single_use_lifetimes)] +#[allow(clippy::unknown_clippy_lints)] +#[allow(clippy::redundant_pub_crate)] +#[allow(clippy::used_underscore_binding)] +const _: () = { + #[allow(dead_code)] + #[allow(single_use_lifetimes)] + #[allow(clippy::unknown_clippy_lints)] + #[allow(clippy::mut_mut)] + #[allow(clippy::redundant_pub_crate)] + #[allow(clippy::ref_option_ref)] + #[allow(clippy::type_repetition_in_bounds)] + struct Projection<'__pin, T, U> + where + Struct<T, U>: '__pin, + { + pinned: ::pin_project_lite::__private::Pin<&'__pin mut (T)>, + unpinned: &'__pin mut (U), + } + impl<T, U> Struct<T, U> { + fn project<'__pin>( + self: ::pin_project_lite::__private::Pin<&'__pin mut Self>, + ) -> Projection<'__pin, T, U> { + unsafe { + let Self { pinned, unpinned } = self.get_unchecked_mut(); + Projection { + pinned: ::pin_project_lite::__private::Pin::new_unchecked(pinned), + unpinned: unpinned, + } + } + } + fn project_ref<'__pin>( + self: ::pin_project_lite::__private::Pin<&'__pin Self>, + ) -> StructProjRef<'__pin, T, U> { + unsafe { + let Self { pinned, unpinned } = self.get_ref(); + StructProjRef { + pinned: ::pin_project_lite::__private::Pin::new_unchecked(pinned), + unpinned: unpinned, + } + } + } + } + #[allow(non_snake_case)] + struct __Origin<'__pin, T, U> { + __dummy_lifetime: ::pin_project_lite::__private::PhantomData<&'__pin ()>, + pinned: T, + unpinned: ::pin_project_lite::__private::AlwaysUnpin<U>, + } + impl<'__pin, T, U> ::pin_project_lite::__private::Unpin for Struct<T, U> where + __Origin<'__pin, T, U>: ::pin_project_lite::__private::Unpin + { + } + trait MustNotImplDrop {} + #[allow(clippy::drop_bounds, drop_bounds)] + impl<T: ::pin_project_lite::__private::Drop> MustNotImplDrop for T {} + impl<T, U> MustNotImplDrop for Struct<T, U> {} + #[forbid(unaligned_references, safe_packed_borrows)] + fn __assert_not_repr_packed<T, U>(this: &Struct<T, U>) { + let _ = &this.pinned; + let _ = &this.unpinned; + } +}; +fn main() {} diff --git a/tests/expand/naming/struct-ref.rs b/tests/expand/naming/struct-ref.rs new file mode 100644 index 0000000..6821af8 --- /dev/null +++ b/tests/expand/naming/struct-ref.rs @@ -0,0 +1,12 @@ +use pin_project_lite::pin_project; + +pin_project! { + #[project_ref = StructProjRef] + struct Struct<T, U> { + #[pin] + pinned: T, + unpinned: 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..665ff63 --- /dev/null +++ b/tests/expand/pinned_drop/enum.expanded.rs @@ -0,0 +1,95 @@ +use pin_project_lite::pin_project; +use std::pin::Pin; +enum Enum<T, U> { + Struct { pinned: T, unpinned: U }, + Unit, +} +#[allow(dead_code)] +#[allow(single_use_lifetimes)] +#[allow(clippy::unknown_clippy_lints)] +#[allow(clippy::mut_mut)] +#[allow(clippy::redundant_pub_crate)] +#[allow(clippy::ref_option_ref)] +#[allow(clippy::type_repetition_in_bounds)] +enum EnumProj<'__pin, T, U> +where + Enum<T, U>: '__pin, +{ + Struct { + pinned: ::pin_project_lite::__private::Pin<&'__pin mut (T)>, + unpinned: &'__pin mut (U), + }, + Unit, +} +#[allow(dead_code)] +#[allow(single_use_lifetimes)] +#[allow(clippy::unknown_clippy_lints)] +#[allow(clippy::mut_mut)] +#[allow(clippy::redundant_pub_crate)] +#[allow(clippy::ref_option_ref)] +#[allow(clippy::type_repetition_in_bounds)] +enum EnumProjRef<'__pin, T, U> +where + Enum<T, U>: '__pin, +{ + Struct { + pinned: ::pin_project_lite::__private::Pin<&'__pin (T)>, + unpinned: &'__pin (U), + }, + Unit, +} +#[allow(single_use_lifetimes)] +#[allow(clippy::unknown_clippy_lints)] +#[allow(clippy::used_underscore_binding)] +const _: () = { + impl<T, U> Enum<T, U> { + fn project<'__pin>( + self: ::pin_project_lite::__private::Pin<&'__pin mut Self>, + ) -> EnumProj<'__pin, T, U> { + unsafe { + match self.get_unchecked_mut() { + Self::Struct { pinned, unpinned } => EnumProj::Struct { + pinned: ::pin_project_lite::__private::Pin::new_unchecked(pinned), + unpinned: unpinned, + }, + Self::Unit => EnumProj::Unit, + } + } + } + fn project_ref<'__pin>( + self: ::pin_project_lite::__private::Pin<&'__pin Self>, + ) -> EnumProjRef<'__pin, T, U> { + unsafe { + match self.get_ref() { + Self::Struct { pinned, unpinned } => EnumProjRef::Struct { + pinned: ::pin_project_lite::__private::Pin::new_unchecked(pinned), + unpinned: unpinned, + }, + Self::Unit => EnumProjRef::Unit, + } + } + } + } + #[allow(non_snake_case)] + struct __Origin<'__pin, T, U> { + __dummy_lifetime: ::pin_project_lite::__private::PhantomData<&'__pin ()>, + Struct: (T, ::pin_project_lite::__private::AlwaysUnpin<U>), + Unit: (), + } + impl<'__pin, T, U> ::pin_project_lite::__private::Unpin for Enum<T, U> where + __Origin<'__pin, T, U>: ::pin_project_lite::__private::Unpin + { + } + impl<T, U> ::pin_project_lite::__private::Drop for Enum<T, U> { + fn drop(&mut self) { + fn __drop_inner<T, U>(this: ::pin_project_lite::__private::Pin<&mut Enum<T, U>>) { + fn __drop_inner() {} + let _ = this; + } + let pinned_self: ::pin_project_lite::__private::Pin<&mut Self> = + unsafe { ::pin_project_lite::__private::Pin::new_unchecked(self) }; + __drop_inner(pinned_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..1855cb7 --- /dev/null +++ b/tests/expand/pinned_drop/enum.rs @@ -0,0 +1,22 @@ +use pin_project_lite::pin_project; +use std::pin::Pin; + +pin_project! { + #[project = EnumProj] + #[project_ref = EnumProjRef] + enum Enum<T, U> { + Struct { + #[pin] + pinned: T, + unpinned: U, + }, + Unit, + } + impl<T, U> PinnedDrop for Enum<T, U> { + fn drop(this: Pin<&mut Self>) { + let _ = this; + } + } +} + +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..5b82b7a --- /dev/null +++ b/tests/expand/pinned_drop/struct.expanded.rs @@ -0,0 +1,92 @@ +use pin_project_lite::pin_project; +use std::pin::Pin; +struct Struct<T, U> { + pinned: T, + unpinned: U, +} +#[allow(explicit_outlives_requirements)] +#[allow(single_use_lifetimes)] +#[allow(clippy::unknown_clippy_lints)] +#[allow(clippy::redundant_pub_crate)] +#[allow(clippy::used_underscore_binding)] +const _: () = { + #[allow(dead_code)] + #[allow(single_use_lifetimes)] + #[allow(clippy::unknown_clippy_lints)] + #[allow(clippy::mut_mut)] + #[allow(clippy::redundant_pub_crate)] + #[allow(clippy::ref_option_ref)] + #[allow(clippy::type_repetition_in_bounds)] + struct Projection<'__pin, T, U> + where + Struct<T, U>: '__pin, + { + pinned: ::pin_project_lite::__private::Pin<&'__pin mut (T)>, + unpinned: &'__pin mut (U), + } + #[allow(dead_code)] + #[allow(single_use_lifetimes)] + #[allow(clippy::unknown_clippy_lints)] + #[allow(clippy::mut_mut)] + #[allow(clippy::redundant_pub_crate)] + #[allow(clippy::ref_option_ref)] + #[allow(clippy::type_repetition_in_bounds)] + struct ProjectionRef<'__pin, T, U> + where + Struct<T, U>: '__pin, + { + pinned: ::pin_project_lite::__private::Pin<&'__pin (T)>, + unpinned: &'__pin (U), + } + impl<T, U> Struct<T, U> { + fn project<'__pin>( + self: ::pin_project_lite::__private::Pin<&'__pin mut Self>, + ) -> Projection<'__pin, T, U> { + unsafe { + let Self { pinned, unpinned } = self.get_unchecked_mut(); + Projection { + pinned: ::pin_project_lite::__private::Pin::new_unchecked(pinned), + unpinned: unpinned, + } + } + } + fn project_ref<'__pin>( + self: ::pin_project_lite::__private::Pin<&'__pin Self>, + ) -> ProjectionRef<'__pin, T, U> { + unsafe { + let Self { pinned, unpinned } = self.get_ref(); + ProjectionRef { + pinned: ::pin_project_lite::__private::Pin::new_unchecked(pinned), + unpinned: unpinned, + } + } + } + } + #[allow(non_snake_case)] + struct __Origin<'__pin, T, U> { + __dummy_lifetime: ::pin_project_lite::__private::PhantomData<&'__pin ()>, + pinned: T, + unpinned: ::pin_project_lite::__private::AlwaysUnpin<U>, + } + impl<'__pin, T, U> ::pin_project_lite::__private::Unpin for Struct<T, U> where + __Origin<'__pin, T, U>: ::pin_project_lite::__private::Unpin + { + } + impl<T, U> ::pin_project_lite::__private::Drop for Struct<T, U> { + fn drop(&mut self) { + fn __drop_inner<T, U>(this: ::pin_project_lite::__private::Pin<&mut Struct<T, U>>) { + fn __drop_inner() {} + let _ = this; + } + let pinned_self: ::pin_project_lite::__private::Pin<&mut Self> = + unsafe { ::pin_project_lite::__private::Pin::new_unchecked(self) }; + __drop_inner(pinned_self); + } + } + #[forbid(unaligned_references, safe_packed_borrows)] + fn __assert_not_repr_packed<T, U>(this: &Struct<T, U>) { + let _ = &this.pinned; + let _ = &this.unpinned; + } +}; +fn main() {} diff --git a/tests/expand/pinned_drop/struct.rs b/tests/expand/pinned_drop/struct.rs new file mode 100644 index 0000000..0cc7567 --- /dev/null +++ b/tests/expand/pinned_drop/struct.rs @@ -0,0 +1,17 @@ +use pin_project_lite::pin_project; +use std::pin::Pin; + +pin_project! { + struct Struct<T, U> { + #[pin] + pinned: T, + unpinned: U, + } + impl<T, U> PinnedDrop for Struct<T, U> { + fn drop(this: Pin<&mut Self>) { + let _ = this; + } + } +} + +fn main() {} diff --git a/tests/expand/pub/enum.expanded.rs b/tests/expand/pub/enum.expanded.rs new file mode 100644 index 0000000..6f190cb --- /dev/null +++ b/tests/expand/pub/enum.expanded.rs @@ -0,0 +1,87 @@ +use pin_project_lite::pin_project; +pub enum Enum<T, U> { + Struct { pinned: T, unpinned: U }, + Unit, +} +#[allow(dead_code)] +#[allow(single_use_lifetimes)] +#[allow(clippy::unknown_clippy_lints)] +#[allow(clippy::mut_mut)] +#[allow(clippy::redundant_pub_crate)] +#[allow(clippy::ref_option_ref)] +#[allow(clippy::type_repetition_in_bounds)] +pub(crate) enum EnumProj<'__pin, T, U> +where + Enum<T, U>: '__pin, +{ + Struct { + pinned: ::pin_project_lite::__private::Pin<&'__pin mut (T)>, + unpinned: &'__pin mut (U), + }, + Unit, +} +#[allow(dead_code)] +#[allow(single_use_lifetimes)] +#[allow(clippy::unknown_clippy_lints)] +#[allow(clippy::mut_mut)] +#[allow(clippy::redundant_pub_crate)] +#[allow(clippy::ref_option_ref)] +#[allow(clippy::type_repetition_in_bounds)] +pub(crate) enum EnumProjRef<'__pin, T, U> +where + Enum<T, U>: '__pin, +{ + Struct { + pinned: ::pin_project_lite::__private::Pin<&'__pin (T)>, + unpinned: &'__pin (U), + }, + Unit, +} +#[allow(single_use_lifetimes)] +#[allow(clippy::unknown_clippy_lints)] +#[allow(clippy::used_underscore_binding)] +const _: () = { + impl<T, U> Enum<T, U> { + pub(crate) fn project<'__pin>( + self: ::pin_project_lite::__private::Pin<&'__pin mut Self>, + ) -> EnumProj<'__pin, T, U> { + unsafe { + match self.get_unchecked_mut() { + Self::Struct { pinned, unpinned } => EnumProj::Struct { + pinned: ::pin_project_lite::__private::Pin::new_unchecked(pinned), + unpinned: unpinned, + }, + Self::Unit => EnumProj::Unit, + } + } + } + pub(crate) fn project_ref<'__pin>( + self: ::pin_project_lite::__private::Pin<&'__pin Self>, + ) -> EnumProjRef<'__pin, T, U> { + unsafe { + match self.get_ref() { + Self::Struct { pinned, unpinned } => EnumProjRef::Struct { + pinned: ::pin_project_lite::__private::Pin::new_unchecked(pinned), + unpinned: unpinned, + }, + Self::Unit => EnumProjRef::Unit, + } + } + } + } + #[allow(non_snake_case)] + pub struct __Origin<'__pin, T, U> { + __dummy_lifetime: ::pin_project_lite::__private::PhantomData<&'__pin ()>, + Struct: (T, ::pin_project_lite::__private::AlwaysUnpin<U>), + Unit: (), + } + impl<'__pin, T, U> ::pin_project_lite::__private::Unpin for Enum<T, U> where + __Origin<'__pin, T, U>: ::pin_project_lite::__private::Unpin + { + } + trait MustNotImplDrop {} + #[allow(clippy::drop_bounds, drop_bounds)] + impl<T: ::pin_project_lite::__private::Drop> MustNotImplDrop for T {} + impl<T, U> MustNotImplDrop for Enum<T, U> {} +}; +fn main() {} diff --git a/tests/expand/pub/enum.rs b/tests/expand/pub/enum.rs new file mode 100644 index 0000000..d3968af --- /dev/null +++ b/tests/expand/pub/enum.rs @@ -0,0 +1,16 @@ +use pin_project_lite::pin_project; + +pin_project! { + #[project = EnumProj] + #[project_ref = EnumProjRef] + pub enum Enum<T, U> { + Struct { + #[pin] + pinned: T, + unpinned: 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..7b5826d --- /dev/null +++ b/tests/expand/pub/struct.expanded.rs @@ -0,0 +1,84 @@ +use pin_project_lite::pin_project; +pub struct Struct<T, U> { + pub pinned: T, + pub unpinned: U, +} +#[allow(explicit_outlives_requirements)] +#[allow(single_use_lifetimes)] +#[allow(clippy::unknown_clippy_lints)] +#[allow(clippy::redundant_pub_crate)] +#[allow(clippy::used_underscore_binding)] +const _: () = { + #[allow(dead_code)] + #[allow(single_use_lifetimes)] + #[allow(clippy::unknown_clippy_lints)] + #[allow(clippy::mut_mut)] + #[allow(clippy::redundant_pub_crate)] + #[allow(clippy::ref_option_ref)] + #[allow(clippy::type_repetition_in_bounds)] + pub(crate) struct Projection<'__pin, T, U> + where + Struct<T, U>: '__pin, + { + pub pinned: ::pin_project_lite::__private::Pin<&'__pin mut (T)>, + pub unpinned: &'__pin mut (U), + } + #[allow(dead_code)] + #[allow(single_use_lifetimes)] + #[allow(clippy::unknown_clippy_lints)] + #[allow(clippy::mut_mut)] + #[allow(clippy::redundant_pub_crate)] + #[allow(clippy::ref_option_ref)] + #[allow(clippy::type_repetition_in_bounds)] + pub(crate) struct ProjectionRef<'__pin, T, U> + where + Struct<T, U>: '__pin, + { + pub pinned: ::pin_project_lite::__private::Pin<&'__pin (T)>, + pub unpinned: &'__pin (U), + } + impl<T, U> Struct<T, U> { + pub(crate) fn project<'__pin>( + self: ::pin_project_lite::__private::Pin<&'__pin mut Self>, + ) -> Projection<'__pin, T, U> { + unsafe { + let Self { pinned, unpinned } = self.get_unchecked_mut(); + Projection { + pinned: ::pin_project_lite::__private::Pin::new_unchecked(pinned), + unpinned: unpinned, + } + } + } + pub(crate) fn project_ref<'__pin>( + self: ::pin_project_lite::__private::Pin<&'__pin Self>, + ) -> ProjectionRef<'__pin, T, U> { + unsafe { + let Self { pinned, unpinned } = self.get_ref(); + ProjectionRef { + pinned: ::pin_project_lite::__private::Pin::new_unchecked(pinned), + unpinned: unpinned, + } + } + } + } + #[allow(non_snake_case)] + pub struct __Origin<'__pin, T, U> { + __dummy_lifetime: ::pin_project_lite::__private::PhantomData<&'__pin ()>, + pinned: T, + unpinned: ::pin_project_lite::__private::AlwaysUnpin<U>, + } + impl<'__pin, T, U> ::pin_project_lite::__private::Unpin for Struct<T, U> where + __Origin<'__pin, T, U>: ::pin_project_lite::__private::Unpin + { + } + trait MustNotImplDrop {} + #[allow(clippy::drop_bounds, drop_bounds)] + impl<T: ::pin_project_lite::__private::Drop> MustNotImplDrop for T {} + impl<T, U> MustNotImplDrop for Struct<T, U> {} + #[forbid(unaligned_references, safe_packed_borrows)] + fn __assert_not_repr_packed<T, U>(this: &Struct<T, U>) { + let _ = &this.pinned; + let _ = &this.unpinned; + } +}; +fn main() {} diff --git a/tests/expand/pub/struct.rs b/tests/expand/pub/struct.rs new file mode 100644 index 0000000..6659096 --- /dev/null +++ b/tests/expand/pub/struct.rs @@ -0,0 +1,11 @@ +use pin_project_lite::pin_project; + +pin_project! { + pub struct Struct<T, U> { + #[pin] + pub pinned: T, + pub unpinned: U, + } +} + +fn main() {} diff --git a/tests/expandtest.rs b/tests/expandtest.rs new file mode 100644 index 0000000..3f0d5c1 --- /dev/null +++ b/tests/expandtest.rs @@ -0,0 +1,43 @@ +#![cfg(not(miri))] +#![warn(rust_2018_idioms, single_use_lifetimes)] + +use std::{ + env, + process::{Command, ExitStatus, Stdio}, +}; + +const PATH: &str = "tests/expand/**/*.rs"; + +#[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 args = &["--all-features"]; + if is_ci { + macrotest::expand_without_refresh_args(PATH, args); + } else { + env::set_var("MACROTEST", "overwrite"); + macrotest::expand_args(PATH, args); + } +} + +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 46ec1df..792adce 100644 --- a/tests/lint.rs +++ b/tests/lint.rs @@ -1,44 +1,43 @@ +// Check interoperability with rustc and clippy lints. + #![forbid(unsafe_code)] -#![warn(nonstandard_style, rust_2018_idioms, rustdoc, unused)] +// for old compilers +#![allow(unknown_lints)] +#![warn(nonstandard_style, rust_2018_idioms, unused)] // Note: This does not guarantee compatibility with forbidding these lints in the future. // If rustc adds a new lint, we may not be able to keep this. -#![forbid(future_incompatible, rust_2018_compatibility)] -#![allow(unknown_lints)] // for old compilers +#![forbid(future_incompatible, rust_2018_compatibility, rust_2021_compatibility)] +// lints forbidden as a part of future_incompatible, rust_2018_compatibility, and rust_2021_compatibility are not included in the list below. +// elided_lifetimes_in_paths, explicit_outlives_requirements, unused_extern_crates: as a part of rust_2018_idioms +// unsafe_block_in_unsafe_fn: requires Rust 1.52. and, we don't generate unsafe fn. +// non_exhaustive_omitted_patterns: unstable +// unstable_features: no way to generate #![feature(..)] by macros, expect for unstable inner attribute. and this lint is deprecated: https://doc.rust-lang.org/rustc/lints/listing/allowed-by-default.html#unstable-features +// unused_crate_dependencies: unrelated +// unsafe_code: checked in forbid_unsafe module #![warn( box_pointers, deprecated_in_future, - elided_lifetimes_in_paths, - explicit_outlives_requirements, macro_use_extern_crate, meta_variable_misuse, + missing_abi, missing_copy_implementations, - missing_crate_level_docs, missing_debug_implementations, missing_docs, non_ascii_idents, + noop_method_call, single_use_lifetimes, trivial_casts, trivial_numeric_casts, - unaligned_references, unreachable_pub, - unused_extern_crates, unused_import_braces, unused_lifetimes, unused_qualifications, 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 -// missing_doc_code_examples, private_doc_tests, invalid_html_tags: warned as a part of rustdoc -// unsafe_block_in_unsafe_fn: unstable -// unsafe_code: forbidden -// unstable_features: deprecated: https://doc.rust-lang.org/beta/rustc/lints/listing/allowed-by-default.html#unstable-features -// unused_crate_dependencies: unrelated -#![warn(clippy::all, clippy::pedantic, clippy::nursery)] -#![warn(clippy::restriction)] +#![warn(clippy::all, clippy::pedantic, clippy::nursery, clippy::restriction)] #![allow(clippy::blanket_clippy_restriction_lints)] // this is a test, so enable all restriction lints intentionally. - -// Check interoperability with rustc and clippy lints. +#![allow(clippy::exhaustive_structs, clippy::exhaustive_enums)] // TODO pub mod basic { include!("include/basic.rs"); @@ -162,7 +161,6 @@ mod clippy_redundant_pub_crate { } } - #[allow(dead_code)] pin_project! { #[project = EnumProj] #[project_ref = EnumProjRef] @@ -178,6 +176,7 @@ mod clippy_redundant_pub_crate { } } +#[allow(clippy::use_self)] pub mod clippy_type_repetition_in_bounds { use pin_project_lite::pin_project; diff --git a/tests/proper_unpin.rs b/tests/proper_unpin.rs index b1c72c1..668e975 100644 --- a/tests/proper_unpin.rs +++ b/tests/proper_unpin.rs @@ -5,9 +5,10 @@ mod auxiliary; pub mod default { - use pin_project_lite::pin_project; use std::marker::PhantomPinned; + use pin_project_lite::pin_project; + struct Inner<T> { f: T, } diff --git a/tests/test.rs b/tests/test.rs index f4c29ee..ed9b75c 100644 --- a/tests/test.rs +++ b/tests/test.rs @@ -8,6 +8,7 @@ use core::{ marker::{PhantomData, PhantomPinned}, pin::Pin, }; + use pin_project_lite::pin_project; #[test] @@ -51,7 +52,7 @@ fn projection() { { let StructProjReplace { f1: PhantomData, f2 } = - s.as_mut().project_replace(Default::default()); + s.as_mut().project_replace(Struct::default()); assert_eq!(f2, 2); let StructProj { f1, f2 } = s.project(); assert_eq!(*f1, 0); @@ -587,6 +588,21 @@ fn trailing_comma() { #[test] fn attrs() { pin_project! { + /// dox1 + #[derive(Clone)] + #[project = StructProj] + #[project_ref = StructProjRef] + /// dox2 + #[derive(Debug)] + /// dox3 + struct Struct { + // TODO + // /// dox4 + f: () + } + } + + pin_project! { #[project = Enum1Proj] #[project_ref = Enum1ProjRef] enum Enum1 { @@ -599,6 +615,7 @@ fn attrs() { pin_project! { /// dox1 + #[derive(Clone)] #[project = Enum2Proj] #[project_ref = Enum2ProjRef] /// dox2 @@ -616,3 +633,63 @@ fn attrs() { } } } + +#[test] +fn pinned_drop() { + pin_project! { + pub struct Struct1<'a> { + was_dropped: &'a mut bool, + #[pin] + field: u8, + } + impl PinnedDrop for Struct1<'_> { + fn drop(this: Pin<&mut Self>) { + **this.project().was_dropped = true; + } + } + } + + let mut was_dropped = false; + drop(Struct1 { was_dropped: &mut was_dropped, field: 42 }); + assert!(was_dropped); + + pin_project! { + pub struct Struct2<'a> { + was_dropped: &'a mut bool, + #[pin] + field: u8, + } + impl PinnedDrop for Struct2<'_> { + fn drop(mut this: Pin<&mut Self>) { + **this.as_mut().project().was_dropped = true; + } + } + } + + trait Service<Request> { + type Error; + } + + pin_project! { + struct Struct3<'a, T, Request> + where + T: Service<Request>, + T::Error: std::error::Error, + { + was_dropped: &'a mut bool, + #[pin] + field: T, + req: Request, + } + + impl<T, Request> PinnedDrop for Struct3<'_, T, Request> + where + T: Service<Request>, + T::Error: std::error::Error, + { + fn drop(mut this: Pin<&mut Self>) { + **this.as_mut().project().was_dropped = true; + } + } + } +} diff --git a/tests/ui/invalid-bounds.stderr b/tests/ui/invalid-bounds.stderr deleted file mode 100644 index a565cce..0000000 --- a/tests/ui/invalid-bounds.stderr +++ /dev/null @@ -1,176 +0,0 @@ -error: no rules expected the token `[` - --> $DIR/invalid-bounds.rs:3:1 - | -3 | / pin_project! { -4 | | struct Generics1<T: 'static : Sized> { //~ ERROR no rules expected the token `:` -5 | | field: T, -6 | | } -7 | | } - | |_^ no rules expected this token in macro call - | - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) - -error: no rules expected the token `[` - --> $DIR/invalid-bounds.rs:9:1 - | -9 | / pin_project! { -10 | | struct Generics2<T: 'static : ?Sized> { //~ ERROR no rules expected the token `:` -11 | | field: T, -12 | | } -13 | | } - | |_^ no rules expected this token in macro call - | - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) - -error: expected one of `+`, `,`, `=`, or `>`, found `:` - --> $DIR/invalid-bounds.rs:15:1 - | -15 | / pin_project! { -16 | | struct Generics3<T: Sized : 'static> { //~ ERROR expected one of `+`, `,`, `=`, or `>`, found `:` -17 | | field: T, -18 | | } -19 | | } - | | ^ - | | | - | | expected one of `+`, `,`, `=`, or `>` - | |_unexpected token - | in this macro invocation - | - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) - -error: expected one of `+`, `,`, `=`, or `>`, found `:` - --> $DIR/invalid-bounds.rs:21:1 - | -21 | / pin_project! { -22 | | struct Generics4<T: ?Sized : 'static> { //~ ERROR expected one of `+`, `,`, `=`, or `>`, found `:` -23 | | field: T, -24 | | } -25 | | } - | | ^ - | | | - | | expected one of `+`, `,`, `=`, or `>` - | |_unexpected token - | in this macro invocation - | - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) - -error: expected one of `+`, `,`, `=`, or `>`, found `:` - --> $DIR/invalid-bounds.rs:27:1 - | -27 | / pin_project! { -28 | | struct Generics5<T: Sized : ?Sized> { //~ ERROR expected one of `+`, `,`, `=`, or `>`, found `:` -29 | | field: T, -30 | | } -31 | | } - | | ^ - | | | - | | expected one of `+`, `,`, `=`, or `>` - | |_unexpected token - | in this macro invocation - | - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) - -error: no rules expected the token `[` - --> $DIR/invalid-bounds.rs:33:1 - | -33 | / pin_project! { -34 | | struct Generics6<T: ?Sized : Sized> { //~ ERROR no rules expected the token `Sized` -35 | | field: T, -36 | | } -37 | | } - | |_^ no rules expected this token in macro call - | - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) - -error: no rules expected the token `[` - --> $DIR/invalid-bounds.rs:39:1 - | -39 | / pin_project! { -40 | | struct WhereClause1<T> -41 | | where -42 | | T: 'static : Sized //~ ERROR no rules expected the token `:` -... | -45 | | } -46 | | } - | |_^ no rules expected this token in macro call - | - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) - -error: no rules expected the token `[` - --> $DIR/invalid-bounds.rs:48:1 - | -48 | / pin_project! { -49 | | struct WhereClause2<T> -50 | | where -51 | | T: 'static : ?Sized //~ ERROR no rules expected the token `:` -... | -54 | | } -55 | | } - | |_^ no rules expected this token in macro call - | - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) - -error: expected `where`, or `{` after struct name, found `:` - --> $DIR/invalid-bounds.rs:57:1 - | -57 | / pin_project! { -58 | | struct WhereClause3<T> -59 | | where -60 | | T: Sized : 'static //~ ERROR expected `where`, or `{` after struct name, found `:` -... | -63 | | } -64 | | } - | | ^ - | | | - | |_expected `where`, or `{` after struct name - | in this macro invocation - | - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) - -error: expected `where`, or `{` after struct name, found `:` - --> $DIR/invalid-bounds.rs:66:1 - | -66 | / pin_project! { -67 | | struct WhereClause4<T> -68 | | where -69 | | T: ?Sized : 'static //~ ERROR expected `where`, or `{` after struct name, found `:` -... | -72 | | } -73 | | } - | | ^ - | | | - | |_expected `where`, or `{` after struct name - | in this macro invocation - | - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) - -error: expected `where`, or `{` after struct name, found `:` - --> $DIR/invalid-bounds.rs:75:1 - | -75 | / pin_project! { -76 | | struct WhereClause5<T> -77 | | where -78 | | T: Sized : ?Sized //~ ERROR expected `where`, or `{` after struct name, found `:` -... | -81 | | } -82 | | } - | | ^ - | | | - | |_expected `where`, or `{` after struct name - | in this macro invocation - | - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) - -error: no rules expected the token `[` - --> $DIR/invalid-bounds.rs:84:1 - | -84 | / pin_project! { -85 | | struct WhereClause6<T> -86 | | where -87 | | T: ?Sized : Sized //~ ERROR no rules expected the token `Sized` -... | -90 | | } -91 | | } - | |_^ no rules expected this token in macro call - | - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui/overlapping_lifetime_names.stderr b/tests/ui/overlapping_lifetime_names.stderr deleted file mode 100644 index 8a9bb4f..0000000 --- a/tests/ui/overlapping_lifetime_names.stderr +++ /dev/null @@ -1,75 +0,0 @@ -error[E0496]: lifetime name `'__pin` shadows a lifetime name that is already in scope - --> $DIR/overlapping_lifetime_names.rs:3:1 - | -3 | / pin_project! { //~ ERROR E0496 -4 | | pub struct Foo<'__pin, T> { //~ ERROR E0263 - | | ------ first declared here -5 | | #[pin] -6 | | field: &'__pin mut T, -7 | | } -8 | | } - | |_^ lifetime `'__pin` already in scope - | - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0496]: lifetime name `'__pin` shadows a lifetime name that is already in scope - --> $DIR/overlapping_lifetime_names.rs:3:1 - | -3 | / pin_project! { //~ ERROR E0496 -4 | | pub struct Foo<'__pin, T> { //~ ERROR E0263 - | | ------ first declared here -5 | | #[pin] -6 | | field: &'__pin mut T, -7 | | } -8 | | } - | |_^ lifetime `'__pin` already in scope - | - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0263]: lifetime name `'__pin` declared twice in the same scope - --> $DIR/overlapping_lifetime_names.rs:4:20 - | -3 | / pin_project! { //~ ERROR E0496 -4 | | pub struct Foo<'__pin, T> { //~ ERROR E0263 - | | ^^^^^^ declared twice -5 | | #[pin] -6 | | field: &'__pin mut T, -7 | | } -8 | | } - | |_- previous declaration here - -error[E0263]: lifetime name `'__pin` declared twice in the same scope - --> $DIR/overlapping_lifetime_names.rs:4:20 - | -3 | / pin_project! { //~ ERROR E0496 -4 | | pub struct Foo<'__pin, T> { //~ ERROR E0263 - | | ^^^^^^ declared twice -5 | | #[pin] -6 | | field: &'__pin mut T, -7 | | } -8 | | } - | |_- previous declaration here - -error[E0263]: lifetime name `'__pin` declared twice in the same scope - --> $DIR/overlapping_lifetime_names.rs:4:20 - | -3 | / pin_project! { //~ ERROR E0496 -4 | | pub struct Foo<'__pin, T> { //~ ERROR E0263 - | | ^^^^^^ declared twice -5 | | #[pin] -6 | | field: &'__pin mut T, -7 | | } -8 | | } - | |_- previous declaration here - -error[E0263]: lifetime name `'__pin` declared twice in the same scope - --> $DIR/overlapping_lifetime_names.rs:4:20 - | -3 | / pin_project! { //~ ERROR E0496 -4 | | pub struct Foo<'__pin, T> { //~ ERROR E0263 - | | ^^^^^^ declared twice -5 | | #[pin] -6 | | field: &'__pin mut T, -7 | | } -8 | | } - | |_- previous declaration here diff --git a/tests/ui/overlapping_unpin_struct.stderr b/tests/ui/overlapping_unpin_struct.stderr deleted file mode 100644 index ab76f81..0000000 --- a/tests/ui/overlapping_unpin_struct.stderr +++ /dev/null @@ -1,11 +0,0 @@ -error[E0277]: `PhantomPinned` cannot be unpinned - --> $DIR/overlapping_unpin_struct.rs:18:5 - | -15 | fn is_unpin<T: Unpin>() {} - | ----- required by this bound in `is_unpin` -... -18 | is_unpin::<Foo<PhantomPinned>>(); //~ ERROR E0277 - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ within `_::__Origin<'_, PhantomPinned>`, the trait `Unpin` is not implemented for `PhantomPinned` - | - = note: required because it appears within the type `_::__Origin<'_, PhantomPinned>` - = note: required because of the requirements on the impl of `Unpin` for `Foo<PhantomPinned>` diff --git a/tests/ui/packed.rs b/tests/ui/packed.rs deleted file mode 100644 index 0bccc1f..0000000 --- a/tests/ui/packed.rs +++ /dev/null @@ -1,19 +0,0 @@ -use pin_project_lite::pin_project; - -pin_project! { //~ ERROR borrow of packed field is unsafe and requires unsafe function or block - #[repr(packed, C)] - struct A { - #[pin] - field: u16, - } -} - -pin_project! { //~ ERROR borrow of packed field is unsafe and requires unsafe function or block - #[repr(packed(2))] - struct C { - #[pin] - field: u32, - } -} - -fn main() {} diff --git a/tests/ui/packed.stderr b/tests/ui/packed.stderr deleted file mode 100644 index a976163..0000000 --- a/tests/ui/packed.stderr +++ /dev/null @@ -1,55 +0,0 @@ -error: borrow of packed field is unsafe and requires unsafe function or block (error E0133) - --> $DIR/packed.rs:3:1 - | -3 | / pin_project! { //~ ERROR borrow of packed field is unsafe and requires unsafe function or block -4 | | #[repr(packed, C)] -5 | | struct A { -6 | | #[pin] -7 | | field: u16, -8 | | } -9 | | } - | |_^ - | -note: the lint level is defined here - --> $DIR/packed.rs:3:1 - | -3 | / pin_project! { //~ ERROR borrow of packed field is unsafe and requires unsafe function or block -4 | | #[repr(packed, C)] -5 | | struct A { -6 | | #[pin] -7 | | field: u16, -8 | | } -9 | | } - | |_^ - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #46043 <https://github.com/rust-lang/rust/issues/46043> - = note: fields of packed structs might be misaligned: dereferencing a misaligned pointer or even just creating a misaligned reference is undefined behavior - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) - -error: borrow of packed field is unsafe and requires unsafe function or block (error E0133) - --> $DIR/packed.rs:11:1 - | -11 | / pin_project! { //~ ERROR borrow of packed field is unsafe and requires unsafe function or block -12 | | #[repr(packed(2))] -13 | | struct C { -14 | | #[pin] -15 | | field: u32, -16 | | } -17 | | } - | |_^ - | -note: the lint level is defined here - --> $DIR/packed.rs:11:1 - | -11 | / pin_project! { //~ ERROR borrow of packed field is unsafe and requires unsafe function or block -12 | | #[repr(packed(2))] -13 | | struct C { -14 | | #[pin] -15 | | field: u32, -16 | | } -17 | | } - | |_^ - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #46043 <https://github.com/rust-lang/rust/issues/46043> - = note: fields of packed structs might be misaligned: dereferencing a misaligned pointer or even just creating a misaligned reference is undefined behavior - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui/conflict-drop.rs b/tests/ui/pin_project/conflict-drop.rs index 870059d..870059d 100644 --- a/tests/ui/conflict-drop.rs +++ b/tests/ui/pin_project/conflict-drop.rs diff --git a/tests/ui/conflict-drop.stderr b/tests/ui/pin_project/conflict-drop.stderr index f97c92b..8531d08 100644 --- a/tests/ui/conflict-drop.stderr +++ b/tests/ui/pin_project/conflict-drop.stderr @@ -1,5 +1,5 @@ -error[E0119]: conflicting implementations of trait `_::MustNotImplDrop` for type `Foo<_, _>`: - --> $DIR/conflict-drop.rs:3:1 +error[E0119]: conflicting implementations of trait `_::MustNotImplDrop` for type `Foo<_, _>` + --> tests/ui/pin_project/conflict-drop.rs:3:1 | 3 | / pin_project! { //~ ERROR E0119 4 | | struct Foo<T, U> { @@ -13,4 +13,4 @@ error[E0119]: conflicting implementations of trait `_::MustNotImplDrop` for type | |_first implementation here | conflicting implementation for `Foo<_, _>` | - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the macro `$crate::__pin_project_internal` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui/conflict-unpin.rs b/tests/ui/pin_project/conflict-unpin.rs index f702f06..f702f06 100644 --- a/tests/ui/conflict-unpin.rs +++ b/tests/ui/pin_project/conflict-unpin.rs diff --git a/tests/ui/conflict-unpin.stderr b/tests/ui/pin_project/conflict-unpin.stderr index 546dafd..0c3141c 100644 --- a/tests/ui/conflict-unpin.stderr +++ b/tests/ui/pin_project/conflict-unpin.stderr @@ -1,5 +1,5 @@ -error[E0119]: conflicting implementations of trait `std::marker::Unpin` for type `Foo<_, _>`: - --> $DIR/conflict-unpin.rs:5:1 +error[E0119]: conflicting implementations of trait `std::marker::Unpin` for type `Foo<_, _>` + --> tests/ui/pin_project/conflict-unpin.rs:5:1 | 5 | / pin_project! { //~ ERROR E0119 6 | | struct Foo<T, U> { @@ -13,10 +13,10 @@ error[E0119]: conflicting implementations of trait `std::marker::Unpin` for type 14 | impl<T, U> Unpin for Foo<T, U> where T: Unpin {} // Conditional Unpin impl | --------------------------------------------- first implementation here | - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the macro `$crate::__pin_project_internal` (in Nightly builds, run with -Z macro-backtrace for more info) -error[E0119]: conflicting implementations of trait `std::marker::Unpin` for type `Bar<_, _>`: - --> $DIR/conflict-unpin.rs:18:1 +error[E0119]: conflicting implementations of trait `std::marker::Unpin` for type `Bar<_, _>` + --> tests/ui/pin_project/conflict-unpin.rs:18:1 | 18 | / pin_project! { //~ ERROR E0119 19 | | struct Bar<T, U> { @@ -30,10 +30,10 @@ error[E0119]: conflicting implementations of trait `std::marker::Unpin` for type 27 | impl<T, U> Unpin for Bar<T, U> {} // Non-conditional Unpin impl | ------------------------------ first implementation here | - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the macro `$crate::__pin_project_internal` (in Nightly builds, run with -Z macro-backtrace for more info) -error[E0119]: conflicting implementations of trait `std::marker::Unpin` for type `Baz<_, _>`: - --> $DIR/conflict-unpin.rs:29:1 +error[E0119]: conflicting implementations of trait `std::marker::Unpin` for type `Baz<_, _>` + --> tests/ui/pin_project/conflict-unpin.rs:29:1 | 29 | / pin_project! { //~ ERROR E0119 30 | | struct Baz<T, U> { @@ -47,4 +47,4 @@ error[E0119]: conflicting implementations of trait `std::marker::Unpin` for type 38 | impl<T: Unpin, U: Unpin> Unpin for Baz<T, U> {} // Conditional Unpin impl | -------------------------------------------- first implementation here | - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the macro `$crate::__pin_project_internal` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui/invalid-bounds.rs b/tests/ui/pin_project/invalid-bounds.rs index 64b397a..64b397a 100644 --- a/tests/ui/invalid-bounds.rs +++ b/tests/ui/pin_project/invalid-bounds.rs diff --git a/tests/ui/pin_project/invalid-bounds.stderr b/tests/ui/pin_project/invalid-bounds.stderr new file mode 100644 index 0000000..e179565 --- /dev/null +++ b/tests/ui/pin_project/invalid-bounds.stderr @@ -0,0 +1,272 @@ +error: no rules expected the token `[` + --> tests/ui/pin_project/invalid-bounds.rs:3:1 + | +3 | / pin_project! { +4 | | struct Generics1<T: 'static : Sized> { //~ ERROR no rules expected the token `:` +5 | | field: T, +6 | | } +7 | | } + | |_^ no rules expected this token in macro call + | + = note: this error originates in the macro `$crate::__pin_project_internal` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: no rules expected the token `[` + --> tests/ui/pin_project/invalid-bounds.rs:9:1 + | +9 | / pin_project! { +10 | | struct Generics2<T: 'static : ?Sized> { //~ ERROR no rules expected the token `:` +11 | | field: T, +12 | | } +13 | | } + | |_^ no rules expected this token in macro call + | + = note: this error originates in the macro `$crate::__pin_project_internal` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: expected one of `+`, `,`, `=`, or `>`, found `:` + --> tests/ui/pin_project/invalid-bounds.rs:15:1 + | +15 | / pin_project! { +16 | | struct Generics3<T: Sized : 'static> { //~ ERROR expected one of `+`, `,`, `=`, or `>`, found `:` +17 | | field: T, +18 | | } +19 | | } + | | ^ + | | | + | | expected one of `+`, `,`, `=`, or `>` + | |_unexpected token + | in this macro invocation + | + = note: this error originates in the macro `$crate::__pin_project_internal` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: expected one of `+`, `,`, `=`, or `>`, found `:` + --> tests/ui/pin_project/invalid-bounds.rs:15:1 + | +15 | / pin_project! { +16 | | struct Generics3<T: Sized : 'static> { //~ ERROR expected one of `+`, `,`, `=`, or `>`, found `:` +17 | | field: T, +18 | | } +19 | | } + | | ^ + | | | + | |_expected one of `+`, `,`, `=`, or `>` + | unexpected token + | + = note: this error originates in the macro `$crate::__pin_project_internal` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: expected one of `+`, `,`, `=`, or `>`, found `:` + --> tests/ui/pin_project/invalid-bounds.rs:21:1 + | +21 | / pin_project! { +22 | | struct Generics4<T: ?Sized : 'static> { //~ ERROR expected one of `+`, `,`, `=`, or `>`, found `:` +23 | | field: T, +24 | | } +25 | | } + | | ^ + | | | + | | expected one of `+`, `,`, `=`, or `>` + | |_unexpected token + | in this macro invocation + | + = note: this error originates in the macro `$crate::__pin_project_internal` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: expected one of `+`, `,`, `=`, or `>`, found `:` + --> tests/ui/pin_project/invalid-bounds.rs:21:1 + | +21 | / pin_project! { +22 | | struct Generics4<T: ?Sized : 'static> { //~ ERROR expected one of `+`, `,`, `=`, or `>`, found `:` +23 | | field: T, +24 | | } +25 | | } + | | ^ + | | | + | |_expected one of `+`, `,`, `=`, or `>` + | unexpected token + | + = note: this error originates in the macro `$crate::__pin_project_internal` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: expected one of `+`, `,`, `=`, or `>`, found `:` + --> tests/ui/pin_project/invalid-bounds.rs:27:1 + | +27 | / pin_project! { +28 | | struct Generics5<T: Sized : ?Sized> { //~ ERROR expected one of `+`, `,`, `=`, or `>`, found `:` +29 | | field: T, +30 | | } +31 | | } + | | ^ + | | | + | | expected one of `+`, `,`, `=`, or `>` + | |_unexpected token + | in this macro invocation + | + = note: this error originates in the macro `$crate::__pin_project_internal` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: expected one of `+`, `,`, `=`, or `>`, found `:` + --> tests/ui/pin_project/invalid-bounds.rs:27:1 + | +27 | / pin_project! { +28 | | struct Generics5<T: Sized : ?Sized> { //~ ERROR expected one of `+`, `,`, `=`, or `>`, found `:` +29 | | field: T, +30 | | } +31 | | } + | | ^ + | | | + | |_expected one of `+`, `,`, `=`, or `>` + | unexpected token + | + = note: this error originates in the macro `$crate::__pin_project_internal` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: no rules expected the token `[` + --> tests/ui/pin_project/invalid-bounds.rs:33:1 + | +33 | / pin_project! { +34 | | struct Generics6<T: ?Sized : Sized> { //~ ERROR no rules expected the token `Sized` +35 | | field: T, +36 | | } +37 | | } + | |_^ no rules expected this token in macro call + | + = note: this error originates in the macro `$crate::__pin_project_internal` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: no rules expected the token `[` + --> tests/ui/pin_project/invalid-bounds.rs:39:1 + | +39 | / pin_project! { +40 | | struct WhereClause1<T> +41 | | where +42 | | T: 'static : Sized //~ ERROR no rules expected the token `:` +... | +45 | | } +46 | | } + | |_^ no rules expected this token in macro call + | + = note: this error originates in the macro `$crate::__pin_project_internal` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: no rules expected the token `[` + --> tests/ui/pin_project/invalid-bounds.rs:48:1 + | +48 | / pin_project! { +49 | | struct WhereClause2<T> +50 | | where +51 | | T: 'static : ?Sized //~ ERROR no rules expected the token `:` +... | +54 | | } +55 | | } + | |_^ no rules expected this token in macro call + | + = note: this error originates in the macro `$crate::__pin_project_internal` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: expected `where`, or `{` after struct name, found `:` + --> tests/ui/pin_project/invalid-bounds.rs:57:1 + | +57 | / pin_project! { +58 | | struct WhereClause3<T> +59 | | where +60 | | T: Sized : 'static //~ ERROR expected `where`, or `{` after struct name, found `:` +... | +63 | | } +64 | | } + | | ^ + | | | + | |_expected `where`, or `{` after struct name + | in this macro invocation + | + = note: this error originates in the macro `$crate::__pin_project_internal` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: expected one of `+`, `,`, or `{`, found `:` + --> tests/ui/pin_project/invalid-bounds.rs:57:1 + | +57 | / pin_project! { +58 | | struct WhereClause3<T> +59 | | where +60 | | T: Sized : 'static //~ ERROR expected `where`, or `{` after struct name, found `:` +... | +63 | | } +64 | | } + | | ^ + | | | + | |_expected one of `+`, `,`, or `{` + | unexpected token + | + = note: this error originates in the macro `$crate::__pin_project_internal` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: expected `where`, or `{` after struct name, found `:` + --> tests/ui/pin_project/invalid-bounds.rs:66:1 + | +66 | / pin_project! { +67 | | struct WhereClause4<T> +68 | | where +69 | | T: ?Sized : 'static //~ ERROR expected `where`, or `{` after struct name, found `:` +... | +72 | | } +73 | | } + | | ^ + | | | + | |_expected `where`, or `{` after struct name + | in this macro invocation + | + = note: this error originates in the macro `$crate::__pin_project_internal` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: expected one of `+`, `,`, or `{`, found `:` + --> tests/ui/pin_project/invalid-bounds.rs:66:1 + | +66 | / pin_project! { +67 | | struct WhereClause4<T> +68 | | where +69 | | T: ?Sized : 'static //~ ERROR expected `where`, or `{` after struct name, found `:` +... | +72 | | } +73 | | } + | | ^ + | | | + | |_expected one of `+`, `,`, or `{` + | unexpected token + | + = note: this error originates in the macro `$crate::__pin_project_internal` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: expected `where`, or `{` after struct name, found `:` + --> tests/ui/pin_project/invalid-bounds.rs:75:1 + | +75 | / pin_project! { +76 | | struct WhereClause5<T> +77 | | where +78 | | T: Sized : ?Sized //~ ERROR expected `where`, or `{` after struct name, found `:` +... | +81 | | } +82 | | } + | | ^ + | | | + | |_expected `where`, or `{` after struct name + | in this macro invocation + | + = note: this error originates in the macro `$crate::__pin_project_internal` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: expected one of `+`, `,`, or `{`, found `:` + --> tests/ui/pin_project/invalid-bounds.rs:75:1 + | +75 | / pin_project! { +76 | | struct WhereClause5<T> +77 | | where +78 | | T: Sized : ?Sized //~ ERROR expected `where`, or `{` after struct name, found `:` +... | +81 | | } +82 | | } + | | ^ + | | | + | |_expected one of `+`, `,`, or `{` + | unexpected token + | + = note: this error originates in the macro `$crate::__pin_project_internal` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: no rules expected the token `[` + --> tests/ui/pin_project/invalid-bounds.rs:84:1 + | +84 | / pin_project! { +85 | | struct WhereClause6<T> +86 | | where +87 | | T: ?Sized : Sized //~ ERROR no rules expected the token `Sized` +... | +90 | | } +91 | | } + | |_^ no rules expected this token in macro call + | + = note: this error originates in the macro `$crate::__pin_project_internal` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui/invalid.rs b/tests/ui/pin_project/invalid.rs index e0ea61d..e0ea61d 100644 --- a/tests/ui/invalid.rs +++ b/tests/ui/pin_project/invalid.rs diff --git a/tests/ui/invalid.stderr b/tests/ui/pin_project/invalid.stderr index 06f2d79..1e363d7 100644 --- a/tests/ui/invalid.stderr +++ b/tests/ui/pin_project/invalid.stderr @@ -1,5 +1,5 @@ -error: no rules expected the token `[` - --> $DIR/invalid.rs:3:1 +error: no rules expected the token `struct` + --> tests/ui/pin_project/invalid.rs:3:1 | 3 | / pin_project! { 4 | | struct A<T> { @@ -9,10 +9,10 @@ error: no rules expected the token `[` 8 | | } | |_^ no rules expected this token in macro call | - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the macro `$crate::__pin_project_internal` (in Nightly builds, run with -Z macro-backtrace for more info) -error: no rules expected the token `[` - --> $DIR/invalid.rs:17:1 +error: no rules expected the token `struct` + --> tests/ui/pin_project/invalid.rs:17:1 | 17 | / pin_project! { 18 | | struct C<T> { @@ -23,10 +23,10 @@ error: no rules expected the token `[` 23 | | } | |_^ no rules expected this token in macro call | - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the macro `$crate::__pin_project_internal` (in Nightly builds, run with -Z macro-backtrace for more info) error: cannot find attribute `pin` in this scope - --> $DIR/invalid.rs:11:7 + --> tests/ui/pin_project/invalid.rs:11:7 | 11 | #[pin] //~ ERROR cannot find attribute `pin` in this scope | ^^^ diff --git a/tests/ui/overlapping_lifetime_names.rs b/tests/ui/pin_project/overlapping_lifetime_names.rs index 87a737e..117c18d 100644 --- a/tests/ui/overlapping_lifetime_names.rs +++ b/tests/ui/pin_project/overlapping_lifetime_names.rs @@ -1,7 +1,7 @@ use pin_project_lite::pin_project; -pin_project! { //~ ERROR E0496 - pub struct Foo<'__pin, T> { //~ ERROR E0263 +pin_project! { //~ ERROR E0263,E0496 + pub struct Foo<'__pin, T> { #[pin] field: &'__pin mut T, } diff --git a/tests/ui/pin_project/overlapping_lifetime_names.stderr b/tests/ui/pin_project/overlapping_lifetime_names.stderr new file mode 100644 index 0000000..dfd4235 --- /dev/null +++ b/tests/ui/pin_project/overlapping_lifetime_names.stderr @@ -0,0 +1,25 @@ +error[E0263]: lifetime name `'__pin` declared twice in the same scope + --> tests/ui/pin_project/overlapping_lifetime_names.rs:4:20 + | +3 | / pin_project! { //~ ERROR E0263,E0496 +4 | | pub struct Foo<'__pin, T> { + | | ^^^^^^ declared twice +5 | | #[pin] +6 | | field: &'__pin mut T, +7 | | } +8 | | } + | |_- previous declaration here + +error[E0496]: lifetime name `'__pin` shadows a lifetime name that is already in scope + --> tests/ui/pin_project/overlapping_lifetime_names.rs:3:1 + | +3 | / pin_project! { //~ ERROR E0263,E0496 +4 | | pub struct Foo<'__pin, T> { + | | ------ first declared here +5 | | #[pin] +6 | | field: &'__pin mut T, +7 | | } +8 | | } + | |_^ lifetime `'__pin` already in scope + | + = note: this error originates in the macro `$crate::__pin_project_internal` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui/overlapping_unpin_struct.rs b/tests/ui/pin_project/overlapping_unpin_struct.rs index 1338524..25131d1 100644 --- a/tests/ui/overlapping_unpin_struct.rs +++ b/tests/ui/pin_project/overlapping_unpin_struct.rs @@ -1,6 +1,7 @@ -use pin_project_lite::pin_project; use std::marker::PhantomPinned; +use pin_project_lite::pin_project; + pin_project! { struct Foo<T> { #[pin] diff --git a/tests/ui/pin_project/overlapping_unpin_struct.stderr b/tests/ui/pin_project/overlapping_unpin_struct.stderr new file mode 100644 index 0000000..1049879 --- /dev/null +++ b/tests/ui/pin_project/overlapping_unpin_struct.stderr @@ -0,0 +1,33 @@ +error[E0277]: `PhantomPinned` cannot be unpinned + --> tests/ui/pin_project/overlapping_unpin_struct.rs:19:5 + | +19 | is_unpin::<Foo<PhantomPinned>>(); //~ ERROR E0277 + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ within `_::__Origin<'_, PhantomPinned>`, the trait `Unpin` is not implemented for `PhantomPinned` + | + = note: consider using `Box::pin` +note: required because it appears within the type `_::__Origin<'_, PhantomPinned>` + --> tests/ui/pin_project/overlapping_unpin_struct.rs:5:1 + | +5 | / pin_project! { +6 | | struct Foo<T> { +7 | | #[pin] +8 | | inner: T, +9 | | } +10 | | } + | |_^ +note: required because of the requirements on the impl of `Unpin` for `Foo<PhantomPinned>` + --> tests/ui/pin_project/overlapping_unpin_struct.rs:5:1 + | +5 | / pin_project! { +6 | | struct Foo<T> { +7 | | #[pin] +8 | | inner: T, +9 | | } +10 | | } + | |_^ +note: required by a bound in `is_unpin` + --> tests/ui/pin_project/overlapping_unpin_struct.rs:16:16 + | +16 | fn is_unpin<T: Unpin>() {} + | ^^^^^ required by this bound in `is_unpin` + = note: this error originates in the macro `$crate::__pin_project_internal` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui/pin_project/packed.rs b/tests/ui/pin_project/packed.rs new file mode 100644 index 0000000..50afb11 --- /dev/null +++ b/tests/ui/pin_project/packed.rs @@ -0,0 +1,21 @@ +#![allow(unaligned_references)] + +use pin_project_lite::pin_project; + +pin_project! { //~ ERROR reference to packed field is unaligned + #[repr(packed, C)] + struct Packed { + #[pin] + field: u16, + } +} + +pin_project! { //~ ERROR reference to packed field is unaligned + #[repr(packed(2))] + struct PackedN { + #[pin] + field: u32, + } +} + +fn main() {} diff --git a/tests/ui/pin_project/packed.stderr b/tests/ui/pin_project/packed.stderr new file mode 100644 index 0000000..40a955e --- /dev/null +++ b/tests/ui/pin_project/packed.stderr @@ -0,0 +1,57 @@ +error: reference to packed field is unaligned + --> tests/ui/pin_project/packed.rs:5:1 + | +5 | / pin_project! { //~ ERROR reference to packed field is unaligned +6 | | #[repr(packed, C)] +7 | | struct Packed { +8 | | #[pin] +9 | | field: u16, +10 | | } +11 | | } + | |_^ + | +note: the lint level is defined here + --> tests/ui/pin_project/packed.rs:5:1 + | +5 | / pin_project! { //~ ERROR reference to packed field is unaligned +6 | | #[repr(packed, C)] +7 | | struct Packed { +8 | | #[pin] +9 | | field: u16, +10 | | } +11 | | } + | |_^ + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523> + = note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced) + = help: copy the field contents to a local variable, or replace the reference with a raw pointer and use `read_unaligned`/`write_unaligned` (loads and stores via `*p` must be properly aligned even when using raw pointers) + = note: this error originates in the macro `$crate::__pin_project_internal` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: reference to packed field is unaligned + --> tests/ui/pin_project/packed.rs:13:1 + | +13 | / pin_project! { //~ ERROR reference to packed field is unaligned +14 | | #[repr(packed(2))] +15 | | struct PackedN { +16 | | #[pin] +17 | | field: u32, +18 | | } +19 | | } + | |_^ + | +note: the lint level is defined here + --> tests/ui/pin_project/packed.rs:13:1 + | +13 | / pin_project! { //~ ERROR reference to packed field is unaligned +14 | | #[repr(packed(2))] +15 | | struct PackedN { +16 | | #[pin] +17 | | field: u32, +18 | | } +19 | | } + | |_^ + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523> + = note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced) + = help: copy the field contents to a local variable, or replace the reference with a raw pointer and use `read_unaligned`/`write_unaligned` (loads and stores via `*p` must be properly aligned even when using raw pointers) + = note: this error originates in the macro `$crate::__pin_project_internal` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui/unpin_sneaky.rs b/tests/ui/pin_project/unpin_sneaky.rs index 984cc2a..984cc2a 100644 --- a/tests/ui/unpin_sneaky.rs +++ b/tests/ui/pin_project/unpin_sneaky.rs diff --git a/tests/ui/unpin_sneaky.stderr b/tests/ui/pin_project/unpin_sneaky.stderr index 39a7745..4eb6eff 100644 --- a/tests/ui/unpin_sneaky.stderr +++ b/tests/ui/pin_project/unpin_sneaky.stderr @@ -1,11 +1,11 @@ error[E0412]: cannot find type `__Origin` in this scope - --> $DIR/unpin_sneaky.rs:10:16 + --> tests/ui/pin_project/unpin_sneaky.rs:10:16 | 10 | impl Unpin for __Origin {} //~ ERROR E0412,E0321 | ^^^^^^^^ not found in this scope error[E0321]: cross-crate traits with a default impl, like `Unpin`, can only be implemented for a struct/enum type, not `[type error]` - --> $DIR/unpin_sneaky.rs:10:1 + --> tests/ui/pin_project/unpin_sneaky.rs:10:1 | 10 | impl Unpin for __Origin {} //~ ERROR E0412,E0321 | ^^^^^^^^^^^^^^^^^^^^^^^ can't implement cross-crate trait with a default impl for non-struct/enum type diff --git a/tests/ui/unsupported.rs b/tests/ui/pin_project/unsupported.rs index 2f80836..2f80836 100644 --- a/tests/ui/unsupported.rs +++ b/tests/ui/pin_project/unsupported.rs diff --git a/tests/ui/pin_project/unsupported.stderr b/tests/ui/pin_project/unsupported.stderr new file mode 100644 index 0000000..d95f455 --- /dev/null +++ b/tests/ui/pin_project/unsupported.stderr @@ -0,0 +1,53 @@ +error: no rules expected the token `}` + --> tests/ui/pin_project/unsupported.rs:3:1 + | +3 | / pin_project! { +4 | | struct Struct1 {} //~ ERROR no rules expected the token `}` +5 | | } + | |_^ no rules expected this token in macro call + | + = note: this error originates in the macro `$crate::__pin_project_internal` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: no rules expected the token `[` + --> tests/ui/pin_project/unsupported.rs:7:1 + | +7 | / pin_project! { +8 | | struct Struct2(); //~ ERROR no rules expected the token `(` +9 | | } + | |_^ no rules expected this token in macro call + | + = note: this error originates in the macro `$crate::__pin_project_internal` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: no rules expected the token `[` + --> tests/ui/pin_project/unsupported.rs:11:1 + | +11 | / pin_project! { +12 | | struct Struct3; //~ ERROR no rules expected the token `;` +13 | | } + | |_^ no rules expected this token in macro call + | + = note: this error originates in the macro `$crate::__pin_project_internal` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: no rules expected the token `enum` + --> tests/ui/pin_project/unsupported.rs:15:1 + | +15 | / pin_project! { +16 | | enum Enum { //~ ERROR no rules expected the token `enum` +17 | | A(u8) +18 | | } +19 | | } + | |_^ no rules expected this token in macro call + | + = note: this error originates in the macro `$crate::__pin_project_internal` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: no rules expected the token `union` + --> tests/ui/pin_project/unsupported.rs:21:1 + | +21 | / pin_project! { +22 | | union Union { //~ ERROR no rules expected the token `union` +23 | | x: u8, +24 | | } +25 | | } + | |_^ no rules expected this token in macro call + | + = note: this error originates in the macro `$crate::__pin_project_internal` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui/pinned_drop/call-drop-inner.rs b/tests/ui/pinned_drop/call-drop-inner.rs new file mode 100644 index 0000000..609b3be --- /dev/null +++ b/tests/ui/pinned_drop/call-drop-inner.rs @@ -0,0 +1,17 @@ +use pin_project_lite::pin_project; + +pin_project! { + pub struct S { + #[pin] + field: u8, + } + impl PinnedDrop for S { + fn drop(this: Pin<&mut Self>) { + __drop_inner(this); + } + } +} + +fn main() { + let _x = S { field: 0 }; +} diff --git a/tests/ui/pinned_drop/call-drop-inner.stderr b/tests/ui/pinned_drop/call-drop-inner.stderr new file mode 100644 index 0000000..5bcb728 --- /dev/null +++ b/tests/ui/pinned_drop/call-drop-inner.stderr @@ -0,0 +1,20 @@ +error[E0061]: this function takes 0 arguments but 1 argument was supplied + --> tests/ui/pinned_drop/call-drop-inner.rs:10:13 + | +10 | __drop_inner(this); + | ^^^^^^^^^^^^ ---- supplied 1 argument + | | + | expected 0 arguments + | +note: function defined here + --> tests/ui/pinned_drop/call-drop-inner.rs:3:1 + | +3 | / pin_project! { +4 | | pub struct S { +5 | | #[pin] +6 | | field: u8, +... | +12 | | } +13 | | } + | |_^ + = note: this error originates in the macro `$crate::__pin_project_internal` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui/pinned_drop/conditional-drop-impl.rs b/tests/ui/pinned_drop/conditional-drop-impl.rs new file mode 100644 index 0000000..68b01b2 --- /dev/null +++ b/tests/ui/pinned_drop/conditional-drop-impl.rs @@ -0,0 +1,26 @@ +use pin_project_lite::pin_project; + +// In `Drop` impl, the implementor must specify the same requirement as type definition. + +struct DropImpl<T> { + f: T, +} + +impl<T: Unpin> Drop for DropImpl<T> { + //~^ ERROR E0367 + fn drop(&mut self) {} +} + +pin_project! { + //~^ ERROR E0367 + struct PinnedDropImpl<T> { + #[pin] + f: T, + } + + impl<T: Unpin> PinnedDrop for PinnedDropImpl<T> { + fn drop(_this: Pin<&mut Self>) {} + } +} + +fn main() {} diff --git a/tests/ui/pinned_drop/conditional-drop-impl.stderr b/tests/ui/pinned_drop/conditional-drop-impl.stderr new file mode 100644 index 0000000..f6c2075 --- /dev/null +++ b/tests/ui/pinned_drop/conditional-drop-impl.stderr @@ -0,0 +1,38 @@ +error[E0367]: `Drop` impl requires `T: Unpin` but the struct it is implemented for does not + --> tests/ui/pinned_drop/conditional-drop-impl.rs:9:9 + | +9 | impl<T: Unpin> Drop for DropImpl<T> { + | ^^^^^ + | +note: the implementor must specify the same requirement + --> tests/ui/pinned_drop/conditional-drop-impl.rs:5:1 + | +5 | / struct DropImpl<T> { +6 | | f: T, +7 | | } + | |_^ + +error[E0367]: `Drop` impl requires `T: Unpin` but the struct it is implemented for does not + --> tests/ui/pinned_drop/conditional-drop-impl.rs:14:1 + | +14 | / pin_project! { +15 | | //~^ ERROR E0367 +16 | | struct PinnedDropImpl<T> { +17 | | #[pin] +... | +23 | | } +24 | | } + | |_^ + | +note: the implementor must specify the same requirement + --> tests/ui/pinned_drop/conditional-drop-impl.rs:14:1 + | +14 | / pin_project! { +15 | | //~^ ERROR E0367 +16 | | struct PinnedDropImpl<T> { +17 | | #[pin] +... | +23 | | } +24 | | } + | |_^ + = note: this error originates in the macro `$crate::__pin_project_internal` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui/unsupported.stderr b/tests/ui/unsupported.stderr deleted file mode 100644 index 2cd17df..0000000 --- a/tests/ui/unsupported.stderr +++ /dev/null @@ -1,53 +0,0 @@ -error: no rules expected the token `[` - --> $DIR/unsupported.rs:3:1 - | -3 | / pin_project! { -4 | | struct Struct1 {} //~ ERROR no rules expected the token `}` -5 | | } - | |_^ no rules expected this token in macro call - | - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) - -error: no rules expected the token `[` - --> $DIR/unsupported.rs:7:1 - | -7 | / pin_project! { -8 | | struct Struct2(); //~ ERROR no rules expected the token `(` -9 | | } - | |_^ no rules expected this token in macro call - | - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) - -error: no rules expected the token `[` - --> $DIR/unsupported.rs:11:1 - | -11 | / pin_project! { -12 | | struct Struct3; //~ ERROR no rules expected the token `;` -13 | | } - | |_^ no rules expected this token in macro call - | - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) - -error: no rules expected the token `[` - --> $DIR/unsupported.rs:15:1 - | -15 | / pin_project! { -16 | | enum Enum { //~ ERROR no rules expected the token `enum` -17 | | A(u8) -18 | | } -19 | | } - | |_^ no rules expected this token in macro call - | - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) - -error: no rules expected the token `[` - --> $DIR/unsupported.rs:21:1 - | -21 | / pin_project! { -22 | | union Union { //~ ERROR no rules expected the token `union` -23 | | x: u8, -24 | | } -25 | | } - | |_^ no rules expected this token in macro call - | - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) |