diff options
author | Joel Galenson <jgalenson@google.com> | 2021-08-13 06:33:23 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2021-08-13 06:33:23 +0000 |
commit | 666a7a774c9ca03ec7eb5f19ccb4d29d1fdac902 (patch) | |
tree | a58f29691de054af851d5539f7dbc3c266c69101 | |
parent | 6ae1652dcaf9433073ed88b45e7da97eff18e03d (diff) | |
parent | b35a9ae3d93449ebd266997bc32fe43390c5239e (diff) | |
download | pin-project-lite-666a7a774c9ca03ec7eb5f19ccb4d29d1fdac902.tar.gz |
Upgrade rust/crates/pin-project-lite to 0.2.7 am: ac3724814a am: 08debfdddd am: 03291e422c am: b35a9ae3d9
Original change: https://android-review.googlesource.com/c/platform/external/rust/crates/pin-project-lite/+/1791070
Change-Id: Ib43bd4c572bd92018c448eaa728f3c52af94f344
31 files changed, 630 insertions, 215 deletions
diff --git a/.cargo_vcs_info.json b/.cargo_vcs_info.json index d25aa1d..2ad3c7d 100644 --- a/.cargo_vcs_info.json +++ b/.cargo_vcs_info.json @@ -1,5 +1,5 @@ { "git": { - "sha1": "bd5adc2edab1d9d2d8ff2010bec8fc4e80eff49a" + "sha1": "d21bbea70a60718cc2ff67dc0e6a4049126ff9e6" } } diff --git a/CHANGELOG.md b/CHANGELOG.md index 666dd6b..aaa107b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,10 @@ Note: In this file, do not use the hard wrap in the middle of a sentence for com ## [Unreleased] +## [0.2.7] - 2021-06-26 + +- [Support custom Drop implementation.](https://github.com/taiki-e/pin-project-lite/pull/25) See [#25](https://github.com/taiki-e/pin-project-lite/pull/25) for details. + ## [0.2.6] - 2021-03-04 - [Support item attributes in any order.](https://github.com/taiki-e/pin-project-lite/pull/57) @@ -184,7 +188,8 @@ Note: In this file, do not use the hard wrap in the middle of a sentence for com Initial release -[Unreleased]: https://github.com/taiki-e/pin-project-lite/compare/v0.2.6...HEAD +[Unreleased]: https://github.com/taiki-e/pin-project-lite/compare/v0.2.7...HEAD +[0.2.7]: https://github.com/taiki-e/pin-project-lite/compare/v0.2.6...v0.2.7 [0.2.6]: https://github.com/taiki-e/pin-project-lite/compare/v0.2.5...v0.2.6 [0.2.5]: https://github.com/taiki-e/pin-project-lite/compare/v0.2.4...v0.2.5 [0.2.4]: https://github.com/taiki-e/pin-project-lite/compare/v0.2.3...v0.2.4 @@ -13,9 +13,9 @@ [package] edition = "2018" name = "pin-project-lite" -version = "0.2.6" +version = "0.2.7" authors = ["Taiki Endo <te316e89@gmail.com>"] -exclude = ["/.*", "/scripts"] +exclude = ["/.*", "/tools"] description = "A lightweight version of pin-project written with declarative macros.\n" documentation = "https://docs.rs/pin-project-lite" keywords = ["pin", "macros"] diff --git a/Cargo.toml.orig b/Cargo.toml.orig index 2146247..c22afad 100644 --- a/Cargo.toml.orig +++ b/Cargo.toml.orig @@ -1,6 +1,6 @@ [package] name = "pin-project-lite" -version = "0.2.6" +version = "0.2.7" authors = ["Taiki Endo <te316e89@gmail.com>"] edition = "2018" license = "Apache-2.0 OR MIT" @@ -8,23 +8,19 @@ repository = "https://github.com/taiki-e/pin-project-lite" documentation = "https://docs.rs/pin-project-lite" keywords = ["pin", "macros"] categories = ["no-std", "rust-patterns"] -exclude = ["/.*", "/scripts"] +exclude = ["/.*", "/tools"] description = """ A lightweight version of pin-project written with declarative macros. """ -[package.metadata.docs.rs] -targets = ["x86_64-unknown-linux-gnu"] - [workspace] -members = [ - "tests/doc", - "tests/no-core", - "tests/no-std", -] +members = ["tests/doc", "tests/no-core", "tests/no-std"] [dev-dependencies] macrotest = "1.0.8" rustversion = "1" static_assertions = "1" trybuild = "1" + +[package.metadata.docs.rs] +targets = ["x86_64-unknown-linux-gnu"] @@ -7,13 +7,13 @@ third_party { } url { type: ARCHIVE - value: "https://static.crates.io/crates/pin-project-lite/pin-project-lite-0.2.6.crate" + value: "https://static.crates.io/crates/pin-project-lite/pin-project-lite-0.2.7.crate" } - version: "0.2.6" + version: "0.2.7" license_type: NOTICE last_upgrade_date { year: 2021 - month: 5 - day: 19 + month: 8 + day: 9 } } @@ -100,10 +100,6 @@ be useful in most cases. If you do need useful error messages, then upon error you can pass the same input to [pin-project] to receive a helpful description of the compile error. -### Different: No support for custom Drop implementation - -pin-project supports this by [`#[pinned_drop]`][pinned-drop]. - ### Different: No support for custom Unpin implementation pin-project supports this by [`UnsafeUnpin`][unsafe-unpin] and [`!Unpin`][not-unpin]. @@ -115,7 +111,6 @@ pin-project supports this. [`pin_project!`]: https://docs.rs/pin-project-lite/0.2/pin_project_lite/macro.pin_project.html [not-unpin]: https://docs.rs/pin-project/1/pin_project/attr.pin_project.html#unpin [pin-project]: https://github.com/taiki-e/pin-project -[pinned-drop]: https://docs.rs/pin-project/1/pin_project/attr.pin_project.html#pinned_drop [unsafe-unpin]: https://docs.rs/pin-project/1/pin_project/attr.pin_project.html#unsafeunpin ## License @@ -82,10 +82,6 @@ //! error you can pass the same input to [pin-project] to receive a helpful //! description of the compile error. //! -//! ## Different: No support for custom Drop implementation -//! -//! pin-project supports this by [`#[pinned_drop]`][pinned-drop]. -//! //! ## Different: No support for custom Unpin implementation //! //! pin-project supports this by [`UnsafeUnpin`][unsafe-unpin] and [`!Unpin`][not-unpin]. @@ -96,7 +92,6 @@ //! //! [not-unpin]: https://docs.rs/pin-project/1/pin_project/attr.pin_project.html#unpin //! [pin-project]: https://github.com/taiki-e/pin-project -//! [pinned-drop]: https://docs.rs/pin-project/1/pin_project/attr.pin_project.html#pinned_drop //! [unsafe-unpin]: https://docs.rs/pin-project/1/pin_project/attr.pin_project.html#unsafeunpin #![no_std] @@ -108,7 +103,7 @@ ) ))] #![warn(future_incompatible, rust_2018_idioms, single_use_lifetimes, unreachable_pub)] -#![warn(clippy::all, clippy::default_trait_access)] +#![warn(clippy::default_trait_access, clippy::wildcard_imports)] // ANDROID: Use std to allow building as a dylib. extern crate std; @@ -334,6 +329,7 @@ macro_rules! __pin_project_internal { $field_vis:vis $field:ident: $field_ty:ty ),+ } + $(impl $($pinned_drop:tt)*)? ) => { $(#[$attrs])* $vis struct $ident $($def_generics)* @@ -377,6 +373,7 @@ macro_rules! __pin_project_internal { [make_proj_field_replace] [$ident] [$($impl_generics)*] [$($ty_generics)*] [$(where $($where_clause)*)?] + [$(impl $($pinned_drop)*)?] { $( $(#[$pin])? @@ -425,6 +422,7 @@ macro_rules! __pin_project_internal { [make_proj_field_replace] [$ident] [$($impl_generics)*] [$($ty_generics)*] [$(where $($where_clause)*)?] + [$(impl $($pinned_drop)*)?] { $( $(#[$pin])? @@ -487,6 +485,7 @@ macro_rules! __pin_project_internal { $crate::__pin_project_internal! { @make_drop_impl; [$ident] [$($impl_generics)*] [$($ty_generics)*] [$(where $($where_clause)*)?] + $(impl $($pinned_drop)*)? } // Ensure that it's impossible to use pin projections on a #[repr(packed)] struct. @@ -541,6 +540,7 @@ macro_rules! __pin_project_internal { })? ),+ } + $(impl $($pinned_drop:tt)*)? ) => { $(#[$attrs])* $vis enum $ident $($def_generics)* @@ -597,6 +597,7 @@ macro_rules! __pin_project_internal { [make_proj_field_replace] [$ident] [$($impl_generics)*] [$($ty_generics)*] [$(where $($where_clause)*)?] + [$(impl $($pinned_drop)*)?] { $( $variant $({ @@ -685,6 +686,7 @@ macro_rules! __pin_project_internal { $crate::__pin_project_internal! { @make_drop_impl; [$ident] [$($impl_generics)*] [$($ty_generics)*] [$(where $($where_clause)*)?] + $(impl $($pinned_drop)*)? } // We don't need to check for '#[repr(packed)]', @@ -768,6 +770,7 @@ macro_rules! __pin_project_internal { [$make_proj_field:ident] [$ident:ident] [$($impl_generics:tt)*] [$($ty_generics:tt)*] [$(where $($where_clause:tt)* )?] + [$(impl $($pinned_drop:tt)*)?] $($field:tt)* ) => {}; (@struct=>make_proj_replace_ty=>unnamed; @@ -776,15 +779,16 @@ macro_rules! __pin_project_internal { [$make_proj_field:ident] [$ident:ident] [$($impl_generics:tt)*] [$($ty_generics:tt)*] [$(where $($where_clause:tt)* )?] + [$(impl $($pinned_drop:tt)*)?] $($field:tt)* - ) => { - }; + ) => {}; (@struct=>make_proj_replace_ty=>named; [$proj_vis:vis] [$proj_ty_ident:ident] [$make_proj_field:ident] [$ident:ident] [$($impl_generics:tt)*] [$($ty_generics:tt)*] [$(where $($where_clause:tt)* )?] + [] { $( $(#[$pin:ident])? @@ -814,6 +818,7 @@ macro_rules! __pin_project_internal { [$make_proj_field:ident] [$ident:ident] [$($impl_generics:tt)*] [$($ty_generics:tt)*] [$(where $($where_clause:tt)* )?] + [$(impl $($pinned_drop:tt)*)?] $($field:tt)* ) => {}; // ============================================================================================= @@ -875,6 +880,7 @@ macro_rules! __pin_project_internal { [$make_proj_field:ident] [$ident:ident] [$($impl_generics:tt)*] [$($ty_generics:tt)*] [$(where $($where_clause:tt)* )?] + [] { $( $variant:ident $({ @@ -912,6 +918,7 @@ macro_rules! __pin_project_internal { [$make_proj_field:ident] [$ident:ident] [$($impl_generics:tt)*] [$($ty_generics:tt)*] [$(where $($where_clause:tt)* )?] + [$(impl $($pinned_drop:tt)*)?] $($variant:tt)* ) => {}; @@ -1167,11 +1174,11 @@ macro_rules! __pin_project_internal { // this will become a lint, rather then a hard error. // // As a workaround for this, we generate a new struct, containing all of the pinned - // fields from our #[pin_project] type. This struct is delcared within + // fields from our #[pin_project] type. This struct is declared within // a function, which makes it impossible to be named by user code. - // This guarnatees that it will use the default auto-trait impl for Unpin - + // This guarantees that it will use the default auto-trait impl for Unpin - // that is, it will implement Unpin iff all of its fields implement Unpin. - // This type can be safely declared as 'public', satisfiying the privacy + // This type can be safely declared as 'public', satisfying the privacy // checker without actually allowing user code to access it. // // This allows users to apply the #[pin_project] attribute to types @@ -1197,6 +1204,90 @@ macro_rules! __pin_project_internal { // ============================================================================================= // make_drop_impl (@make_drop_impl; + [$_ident:ident] + [$($_impl_generics:tt)*] [$($_ty_generics:tt)*] [$(where $($_where_clause:tt)* )?] + impl $(< + $( $lifetime:lifetime $(: $lifetime_bound:lifetime)? ),* $(,)? + $( $generics:ident + $(: $generics_bound:path)? + $(: ?$generics_unsized_bound:path)? + $(: $generics_lifetime_bound:lifetime)? + ),* + >)? PinnedDrop for $self_ty:ty + $(where + $( $where_clause_ty:ty + $(: $where_clause_bound:path)? + $(: ?$where_clause_unsized_bound:path)? + $(: $where_clause_lifetime_bound:lifetime)? + ),* + )? + { + fn drop($($arg:ident)+: Pin<&mut Self>) { + $($tt:tt)* + } + } + ) => { + impl $(< + $( $lifetime $(: $lifetime_bound)? ,)* + $( $generics + $(: $generics_bound)? + $(: ?$generics_unsized_bound)? + $(: $generics_lifetime_bound)? + ),* + >)? $crate::__private::Drop for $self_ty + $(where + $( $where_clause_ty + $(: $where_clause_bound)? + $(: ?$where_clause_unsized_bound)? + $(: $where_clause_lifetime_bound)? + ),* + )? + { + fn drop(&mut self) { + // Implementing `__DropInner::__drop_inner` is safe, but calling it is not safe. + // This is because destructors can be called multiple times in safe code and + // [double dropping is unsound](https://github.com/rust-lang/rust/pull/62360). + // + // `__drop_inner` is defined as a safe method, but this is fine since + // `__drop_inner` is not accessible by the users and we call `__drop_inner` only + // once. + // + // Users can implement [`Drop`] safely using `pin_project!` and can drop a + // type that implements `PinnedDrop` using the [`drop`] function safely. + fn __drop_inner $(< + $( $lifetime $(: $lifetime_bound)? ,)* + $( $generics + $(: $generics_bound)? + $(: ?$generics_unsized_bound)? + $(: $generics_lifetime_bound)? + ),* + >)? ( + $($arg)+: $crate::__private::Pin<&mut $self_ty>, + ) + $(where + $( $where_clause_ty + $(: $where_clause_bound)? + $(: ?$where_clause_unsized_bound)? + $(: $where_clause_lifetime_bound)? + ),* + )? + { + // A dummy `__drop_inner` function to prevent users call outer `__drop_inner`. + fn __drop_inner() {} + $($tt)* + } + + // Safety - we're in 'drop', so we know that 'self' will + // never move again. + let pinned_self: $crate::__private::Pin<&mut Self> + = unsafe { $crate::__private::Pin::new_unchecked(self) }; + // We call `__drop_inner` only once. Since `__DropInner::__drop_inner` + // is not accessible by the users, it is never called again. + __drop_inner(pinned_self); + } + } + }; + (@make_drop_impl; [$ident:ident] [$($impl_generics:tt)*] [$($ty_generics:tt)*] [$(where $($where_clause:tt)* )?] ) => { @@ -1207,7 +1298,7 @@ macro_rules! __pin_project_internal { // the first blanked impl will not apply to it. This code // will compile, as there is only one impl of MustNotImplDrop for the user type // 2. The user type does impl Drop. This will make the blanket impl applicable, - // which will then comflict with the explicit MustNotImplDrop impl below. + // which will then conflict with the explicit MustNotImplDrop impl below. // This will result in a compilation error, which is exactly what we want. trait MustNotImplDrop {} #[allow(clippy::drop_bounds, drop_bounds)] @@ -1417,6 +1508,7 @@ macro_rules! __pin_project_internal { $field_vis:vis $field:ident: $field_ty:ty ),+ $(,)? } + $(impl $($pinned_drop:tt)*)? ) => { $crate::__pin_project_internal! { @struct=>internal; [$($proj_mut_ident)?] @@ -1453,6 +1545,7 @@ macro_rules! __pin_project_internal { $field_vis $field: $field_ty ),+ } + $(impl $($pinned_drop)*)? } }; ( @@ -1483,6 +1576,7 @@ macro_rules! __pin_project_internal { $field_vis:vis $field:ident: $field_ty:ty ),+ $(,)? } + $(impl $($pinned_drop:tt)*)? ) => { $crate::__pin_project_internal! { @struct=>internal; [$($proj_mut_ident)?] @@ -1519,6 +1613,7 @@ macro_rules! __pin_project_internal { $field_vis $field: $field_ty ),+ } + $(impl $($pinned_drop)*)? } }; // enum @@ -1555,6 +1650,7 @@ macro_rules! __pin_project_internal { })? ),+ $(,)? } + $(impl $($pinned_drop:tt)*)? ) => { $crate::__pin_project_internal! { @enum=>internal; [$($proj_mut_ident)?] @@ -1596,6 +1692,7 @@ macro_rules! __pin_project_internal { })? ),+ } + $(impl $($pinned_drop)*)? } }; ( @@ -1631,6 +1728,7 @@ macro_rules! __pin_project_internal { })? ),+ $(,)? } + $(impl $($pinned_drop:tt)*)? ) => { $crate::__pin_project_internal! { @enum=>internal; [$($proj_mut_ident)?] @@ -1672,6 +1770,7 @@ macro_rules! __pin_project_internal { })? ),+ } + $(impl $($pinned_drop)*)? } }; } diff --git a/tests/compiletest.rs b/tests/compiletest.rs index 77e913b..8970215 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(before(2021-05-15), ignore)] // Note: This date is commit-date and the day before the toolchain date. #[test] fn ui() { if env::var_os("CI").is_none() { diff --git a/tests/drop_order.rs b/tests/drop_order.rs index 07120cc..6e5deaf 100644 --- a/tests/drop_order.rs +++ b/tests/drop_order.rs @@ -129,7 +129,7 @@ fn project_replace_panic() { fn drop(&mut self) { *self.0 = true; if self.1 { - panic!() + panic!(); } } } 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/expandtest.rs b/tests/expandtest.rs index adf8dde..3f0d5c1 100644 --- a/tests/expandtest.rs +++ b/tests/expandtest.rs @@ -6,6 +6,8 @@ use std::{ process::{Command, ExitStatus, Stdio}, }; +const PATH: &str = "tests/expand/**/*.rs"; + #[rustversion::attr(not(nightly), ignore)] #[test] fn expandtest() { @@ -13,17 +15,17 @@ fn expandtest() { 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") + panic!("expandtest requires rustfmt and cargo-expand"); } return; } - let path = "tests/expand/*/*.rs"; + let args = &["--all-features"]; if is_ci { - macrotest::expand_without_refresh(path); + macrotest::expand_without_refresh_args(PATH, args); } else { env::set_var("MACROTEST", "overwrite"); - macrotest::expand(path); + macrotest::expand_args(PATH, args); } } diff --git a/tests/lint.rs b/tests/lint.rs index 381bb18..2324cd5 100644 --- a/tests/lint.rs +++ b/tests/lint.rs @@ -1,48 +1,44 @@ -#![forbid(unsafe_code)] -#![warn(nonstandard_style, rust_2018_idioms, rustdoc, unused)] +// Check interoperability with rustc and clippy 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)] +#![forbid(future_incompatible)] #![allow(unknown_lints)] // for old compilers +#![forbid(unsafe_code)] #![warn( box_pointers, deprecated_in_future, - disjoint_capture_drop_reorder, - elided_lifetimes_in_paths, - explicit_outlives_requirements, + disjoint_capture_migration, 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, semicolon_in_expressions_from_macros: forbidden as a part of future_incompatible -// missing_doc_code_examples, private_doc_tests, invalid_html_tags: warned as a part of rustdoc -// unsafe_block_in_unsafe_fn: unstable -// unsafe_code: forbidden -// unstable_features: deprecated: https://doc.rust-lang.org/beta/rustc/lints/listing/allowed-by-default.html#unstable-features +// rust_2018_compatibility, rust_2021_compatibility, absolute_paths_not_starting_with_crate, etc.: forbidden as a part of future_incompatible +// elided_lifetimes_in_paths, explicit_outlives_requirements, unused_extern_crates: warned as a part of rust_2018_idioms +// unsafe_block_in_unsafe_fn: unsafe_block_in_unsafe_fn: requires Rust 1.52. and, we don't generate unsafe fn. +// 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: forbidden #![warn(clippy::all, clippy::pedantic, clippy::nursery)] #![warn(clippy::restriction)] #![allow(clippy::blanket_clippy_restriction_lints)] // this is a test, so enable all restriction lints intentionally. #![allow(clippy::exhaustive_structs, clippy::exhaustive_enums)] // TODO -// Check interoperability with rustc and clippy lints. - pub mod basic { include!("include/basic.rs"); } diff --git a/tests/test.rs b/tests/test.rs index d792bab..162fc20 100644 --- a/tests/test.rs +++ b/tests/test.rs @@ -52,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); @@ -633,3 +633,36 @@ 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; + } + } + } +} diff --git a/tests/ui/pin_project/conflict-drop.stderr b/tests/ui/pin_project/conflict-drop.stderr index f97c92b..bbfc910 100644 --- a/tests/ui/pin_project/conflict-drop.stderr +++ b/tests/ui/pin_project/conflict-drop.stderr @@ -1,4 +1,4 @@ -error[E0119]: conflicting implementations of trait `_::MustNotImplDrop` for type `Foo<_, _>`: +error[E0119]: conflicting implementations of trait `_::MustNotImplDrop` for type `Foo<_, _>` --> $DIR/conflict-drop.rs:3:1 | 3 | / pin_project! { //~ ERROR E0119 @@ -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/pin_project/conflict-unpin.stderr b/tests/ui/pin_project/conflict-unpin.stderr index 546dafd..18bdd92 100644 --- a/tests/ui/pin_project/conflict-unpin.stderr +++ b/tests/ui/pin_project/conflict-unpin.stderr @@ -1,4 +1,4 @@ -error[E0119]: conflicting implementations of trait `std::marker::Unpin` for type `Foo<_, _>`: +error[E0119]: conflicting implementations of trait `std::marker::Unpin` for type `Foo<_, _>` --> $DIR/conflict-unpin.rs:5:1 | 5 | / pin_project! { //~ ERROR E0119 @@ -13,9 +13,9 @@ 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<_, _>`: +error[E0119]: conflicting implementations of trait `std::marker::Unpin` for type `Bar<_, _>` --> $DIR/conflict-unpin.rs:18:1 | 18 | / pin_project! { //~ ERROR E0119 @@ -30,9 +30,9 @@ 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<_, _>`: +error[E0119]: conflicting implementations of trait `std::marker::Unpin` for type `Baz<_, _>` --> $DIR/conflict-unpin.rs:29:1 | 29 | / pin_project! { //~ ERROR E0119 @@ -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/pin_project/invalid-bounds.stderr b/tests/ui/pin_project/invalid-bounds.stderr index a565cce..b276989 100644 --- a/tests/ui/pin_project/invalid-bounds.stderr +++ b/tests/ui/pin_project/invalid-bounds.stderr @@ -8,7 +8,7 @@ error: no rules expected the token `[` 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) + = note: this error originates in the macro `pin_project` (in Nightly builds, run with -Z macro-backtrace for more info) error: no rules expected the token `[` --> $DIR/invalid-bounds.rs:9:1 @@ -20,7 +20,7 @@ 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) + = note: this error originates in the macro `pin_project` (in Nightly builds, run with -Z macro-backtrace for more info) error: expected one of `+`, `,`, `=`, or `>`, found `:` --> $DIR/invalid-bounds.rs:15:1 @@ -36,7 +36,7 @@ error: expected one of `+`, `,`, `=`, or `>`, found `:` | |_unexpected token | in this macro invocation | - = 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: expected one of `+`, `,`, `=`, or `>`, found `:` --> $DIR/invalid-bounds.rs:21:1 @@ -52,7 +52,7 @@ error: expected one of `+`, `,`, `=`, or `>`, found `:` | |_unexpected token | in this macro invocation | - = 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: expected one of `+`, `,`, `=`, or `>`, found `:` --> $DIR/invalid-bounds.rs:27:1 @@ -68,7 +68,7 @@ error: expected one of `+`, `,`, `=`, or `>`, found `:` | |_unexpected token | in this macro invocation | - = 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-bounds.rs:33:1 @@ -80,7 +80,7 @@ error: no rules expected the token `[` 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) + = note: this error originates in the macro `pin_project` (in Nightly builds, run with -Z macro-backtrace for more info) error: no rules expected the token `[` --> $DIR/invalid-bounds.rs:39:1 @@ -94,7 +94,7 @@ error: no rules expected the token `[` 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) + = note: this error originates in the macro `pin_project` (in Nightly builds, run with -Z macro-backtrace for more info) error: no rules expected the token `[` --> $DIR/invalid-bounds.rs:48:1 @@ -108,7 +108,7 @@ error: no rules expected the token `[` 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) + = note: this error originates in the macro `pin_project` (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 @@ -125,7 +125,7 @@ error: expected `where`, or `{` after struct name, found `:` | |_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) + = 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 `:` --> $DIR/invalid-bounds.rs:66:1 @@ -142,7 +142,7 @@ error: expected `where`, or `{` after struct name, found `:` | |_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) + = 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 `:` --> $DIR/invalid-bounds.rs:75:1 @@ -159,7 +159,7 @@ error: expected `where`, or `{` after struct name, found `:` | |_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) + = 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-bounds.rs:84:1 @@ -173,4 +173,4 @@ error: no rules expected the token `[` 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) + = note: this error originates in the macro `pin_project` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui/pin_project/invalid.stderr b/tests/ui/pin_project/invalid.stderr index 06f2d79..38df517 100644 --- a/tests/ui/pin_project/invalid.stderr +++ b/tests/ui/pin_project/invalid.stderr @@ -9,7 +9,7 @@ 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 `pin_project` (in Nightly builds, run with -Z macro-backtrace for more info) error: no rules expected the token `[` --> $DIR/invalid.rs:17:1 @@ -23,7 +23,7 @@ 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 `pin_project` (in Nightly builds, run with -Z macro-backtrace for more info) error: cannot find attribute `pin` in this scope --> $DIR/invalid.rs:11:7 diff --git a/tests/ui/pin_project/overlapping_lifetime_names.rs b/tests/ui/pin_project/overlapping_lifetime_names.rs index 87a737e..117c18d 100644 --- a/tests/ui/pin_project/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 index 8a9bb4f..f87875d 100644 --- a/tests/ui/pin_project/overlapping_lifetime_names.stderr +++ b/tests/ui/pin_project/overlapping_lifetime_names.stderr @@ -1,36 +1,32 @@ -error[E0496]: lifetime name `'__pin` shadows a lifetime name that is already in scope - --> $DIR/overlapping_lifetime_names.rs:3:1 +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 - | | ------ first declared here +3 | / pin_project! { //~ ERROR E0263,E0496 +4 | | pub struct Foo<'__pin, T> { + | | ^^^^^^ declared twice 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) + | |_- previous declaration here -error[E0496]: lifetime name `'__pin` shadows a lifetime name that is already in scope - --> $DIR/overlapping_lifetime_names.rs:3:1 +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 - | | ------ first declared here +3 | / pin_project! { //~ ERROR E0263,E0496 +4 | | pub struct Foo<'__pin, T> { + | | ^^^^^^ declared twice 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) + | |_- 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 +3 | / pin_project! { //~ ERROR E0263,E0496 +4 | | pub struct Foo<'__pin, T> { | | ^^^^^^ declared twice 5 | | #[pin] 6 | | field: &'__pin mut T, @@ -38,35 +34,39 @@ error[E0263]: lifetime name `'__pin` declared twice in the same scope 8 | | } | |_- previous declaration here -error[E0263]: lifetime name `'__pin` declared twice in the same scope - --> $DIR/overlapping_lifetime_names.rs:4:20 +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 - | | ^^^^^^ declared twice +3 | / pin_project! { //~ ERROR E0263,E0496 +4 | | pub struct Foo<'__pin, T> { + | | ------ first declared here 5 | | #[pin] 6 | | field: &'__pin mut T, 7 | | } 8 | | } - | |_- previous declaration here + | |_^ 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) -error[E0263]: lifetime name `'__pin` declared twice in the same scope - --> $DIR/overlapping_lifetime_names.rs:4:20 +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 - | | ^^^^^^ declared twice +3 | / pin_project! { //~ ERROR E0263,E0496 +4 | | pub struct Foo<'__pin, T> { + | | ------ first declared here 5 | | #[pin] 6 | | field: &'__pin mut T, 7 | | } 8 | | } - | |_- previous declaration here + | |_^ 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) 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 +3 | / pin_project! { //~ ERROR E0263,E0496 +4 | | pub struct Foo<'__pin, T> { | | ^^^^^^ declared twice 5 | | #[pin] 6 | | field: &'__pin mut T, diff --git a/tests/ui/pin_project/overlapping_unpin_struct.rs b/tests/ui/pin_project/overlapping_unpin_struct.rs index 1338524..25131d1 100644 --- a/tests/ui/pin_project/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 index ab76f81..9486f9d 100644 --- a/tests/ui/pin_project/overlapping_unpin_struct.stderr +++ b/tests/ui/pin_project/overlapping_unpin_struct.stderr @@ -1,11 +1,22 @@ error[E0277]: `PhantomPinned` cannot be unpinned - --> $DIR/overlapping_unpin_struct.rs:18:5 + --> $DIR/overlapping_unpin_struct.rs:19:5 | -15 | fn is_unpin<T: Unpin>() {} +16 | fn is_unpin<T: Unpin>() {} | ----- required by this bound in `is_unpin` ... -18 | is_unpin::<Foo<PhantomPinned>>(); //~ ERROR E0277 +19 | 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: consider using `Box::pin` +note: required because it appears within the type `_::__Origin<'_, PhantomPinned>` + --> $DIR/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>` + = 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 index 507a038..50afb11 100644 --- a/tests/ui/pin_project/packed.rs +++ b/tests/ui/pin_project/packed.rs @@ -1,3 +1,5 @@ +#![allow(unaligned_references)] + use pin_project_lite::pin_project; pin_project! { //~ ERROR reference to packed field is unaligned diff --git a/tests/ui/pin_project/packed.stderr b/tests/ui/pin_project/packed.stderr index 14ffc86..85f84c2 100644 --- a/tests/ui/pin_project/packed.stderr +++ b/tests/ui/pin_project/packed.stderr @@ -1,107 +1,55 @@ error: reference to packed field is unaligned - --> $DIR/packed.rs:3:1 - | -3 | / pin_project! { //~ ERROR reference to packed field is unaligned -4 | | #[repr(packed, C)] -5 | | struct Packed { -6 | | #[pin] -7 | | field: u16, -8 | | } -9 | | } - | |_^ - | -note: the lint level is defined here - --> $DIR/packed.rs:3:1 - | -3 | / pin_project! { //~ ERROR reference to packed field is unaligned -4 | | #[repr(packed, C)] -5 | | struct Packed { -6 | | #[pin] -7 | | field: u16, -8 | | } -9 | | } - | |_^ - = note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced) - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) - -error: reference to packed field is unaligned - --> $DIR/packed.rs:11:1 + --> $DIR/packed.rs:5:1 | -11 | / pin_project! { //~ ERROR reference to packed field is unaligned -12 | | #[repr(packed(2))] -13 | | struct PackedN { -14 | | #[pin] -15 | | field: u32, -16 | | } -17 | | } +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 - --> $DIR/packed.rs:11:1 + --> $DIR/packed.rs:5:1 | -11 | / pin_project! { //~ ERROR reference to packed field is unaligned -12 | | #[repr(packed(2))] -13 | | struct PackedN { -14 | | #[pin] -15 | | field: u32, -16 | | } -17 | | } +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) - = 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: borrow of packed field is unsafe and requires unsafe function or block (error E0133) - --> $DIR/packed.rs:3:1 - | -3 | / pin_project! { //~ ERROR reference to packed field is unaligned -4 | | #[repr(packed, C)] -5 | | struct Packed { -6 | | #[pin] -7 | | field: u16, -8 | | } -9 | | } - | |_^ - | -note: the lint level is defined here - --> $DIR/packed.rs:3:1 - | -3 | / pin_project! { //~ ERROR reference to packed field is unaligned -4 | | #[repr(packed, C)] -5 | | struct Packed { -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 +error: reference to packed field is unaligned + --> $DIR/packed.rs:13:1 | -11 | / pin_project! { //~ ERROR reference to packed field is unaligned -12 | | #[repr(packed(2))] -13 | | struct PackedN { -14 | | #[pin] -15 | | field: u32, -16 | | } -17 | | } +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 - --> $DIR/packed.rs:11:1 + --> $DIR/packed.rs:13:1 | -11 | / pin_project! { //~ ERROR reference to packed field is unaligned -12 | | #[repr(packed(2))] -13 | | struct PackedN { -14 | | #[pin] -15 | | field: u32, -16 | | } -17 | | } +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 #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) + = 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) + = 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/unsupported.stderr b/tests/ui/pin_project/unsupported.stderr index 2cd17df..892e57c 100644 --- a/tests/ui/pin_project/unsupported.stderr +++ b/tests/ui/pin_project/unsupported.stderr @@ -6,7 +6,7 @@ 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) + = note: this error originates in the macro `pin_project` (in Nightly builds, run with -Z macro-backtrace for more info) error: no rules expected the token `[` --> $DIR/unsupported.rs:7:1 @@ -16,7 +16,7 @@ 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) + = note: this error originates in the macro `pin_project` (in Nightly builds, run with -Z macro-backtrace for more info) error: no rules expected the token `[` --> $DIR/unsupported.rs:11:1 @@ -26,7 +26,7 @@ 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) + = note: this error originates in the macro `pin_project` (in Nightly builds, run with -Z macro-backtrace for more info) error: no rules expected the token `[` --> $DIR/unsupported.rs:15:1 @@ -38,7 +38,7 @@ error: no rules expected the token `[` 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) + = note: this error originates in the macro `pin_project` (in Nightly builds, run with -Z macro-backtrace for more info) error: no rules expected the token `[` --> $DIR/unsupported.rs:21:1 @@ -50,4 +50,4 @@ error: no rules expected the token `[` 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) + = note: this error originates in the macro `pin_project` (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..576e417 --- /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 + --> $DIR/call-drop-inner.rs:10:13 + | +10 | __drop_inner(this); + | ^^^^^^^^^^^^ ---- supplied 1 argument + | | + | expected 0 arguments + | +note: function defined here + --> $DIR/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..a67bc8d --- /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 + --> $DIR/conditional-drop-impl.rs:9:9 + | +9 | impl<T: Unpin> Drop for DropImpl<T> { + | ^^^^^ + | +note: the implementor must specify the same requirement + --> $DIR/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 + --> $DIR/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 + --> $DIR/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) |