diff options
author | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2022-06-15 21:44:55 +0000 |
---|---|---|
committer | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2022-06-15 21:44:55 +0000 |
commit | c3beb173c0c1c5278c5f16c4dc44fa59e2e25581 (patch) | |
tree | d6a3b347e26f065a3b2bdd0d9c2627e287f35fba | |
parent | 4c58a090bda7b8a8f889d4d02cb9cb0249717d16 (diff) | |
parent | 73d5d1b098e3449ff2b6bd7fce807217aba158d5 (diff) | |
download | pin-project-lite-android12-mainline-tzdata3-release.tar.gz |
Snap for 8730993 from 73d5d1b098e3449ff2b6bd7fce807217aba158d5 to mainline-tzdata3-releaseaml_tz3_314012070aml_tz3_314012050aml_tz3_314012010aml_tz3_313110000aml_tz3_312511020aml_tz3_312511010aml_tz3_312410020aml_tz3_312410010android12-mainline-tzdata3-releaseaml_tz3_314012010
Change-Id: I71e964d1b432b1a75efeb9b5d6307517f8b1b09e
83 files changed, 2959 insertions, 3120 deletions
diff --git a/.cargo_vcs_info.json b/.cargo_vcs_info.json index 5b410f1..32ae14a 100644 --- a/.cargo_vcs_info.json +++ b/.cargo_vcs_info.json @@ -1,6 +1,5 @@ { "git": { - "sha1": "f405b4b063ec2a2cdc9e456aa737882ee4915ddd" - }, - "path_in_vcs": "" -}
\ No newline at end of file + "sha1": "416be96f7777862c68b567c92a91887f69a8c2b3" + } +} diff --git a/.clippy.toml b/.clippy.toml new file mode 100644 index 0000000..983eb57 --- /dev/null +++ b/.clippy.toml @@ -0,0 +1 @@ +msrv = "1.37" diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..a73a88d --- /dev/null +++ b/.editorconfig @@ -0,0 +1,20 @@ +# EditorConfig configuration +# https://editorconfig.org + +root = true + +[*] +charset = utf-8 +end_of_line = lf +indent_size = 4 +indent_style = space +insert_final_newline = true +trim_trailing_whitespace = true + +[*.{json,yml,md}] +indent_size = 2 + +[*.sh] +indent_size = 2 +binary_next_line = true +switch_case_indent = true diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..6313b56 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +* text=auto eol=lf diff --git a/.rustfmt.toml b/.rustfmt.toml new file mode 100644 index 0000000..6604f5c --- /dev/null +++ b/.rustfmt.toml @@ -0,0 +1,34 @@ +# Rustfmt configuration +# https://github.com/rust-lang/rustfmt/blob/HEAD/Configurations.md + +# This is required for bug-fixes, which technically can't be made to the stable +# first version. +# This is unstable (tracking issue: https://github.com/rust-lang/rustfmt/issues/3383). +version = "Two" +# Rustfmt cannot format long lines inside macros, but this option detects this. +# This is unstable (tracking issue: https://github.com/rust-lang/rustfmt/issues/3391) +error_on_line_overflow = true + +# Override the default formatting style. +# See https://internals.rust-lang.org/t/running-rustfmt-on-rust-lang-rust-and-other-rust-lang-repositories/8732/81. +use_small_heuristics = "Max" +# See https://github.com/rust-dev-tools/fmt-rfcs/issues/149. +# This is unstable (tracking issue: https://github.com/rust-lang/rustfmt/issues/3370) +overflow_delimited_expr = true + +# Apply rustfmt to more places. +# This is unstable (tracking issue: https://github.com/rust-lang/rustfmt/issues/3362). +merge_imports = true +# This is unstable (tracking issue: https://github.com/rust-lang/rustfmt/issues/3348). +format_code_in_doc_comments = true + +# Automatically fix deprecated style. +use_field_init_shorthand = true +use_try_shorthand = true + +# Set the default settings again to always apply the proper formatting without +# being affected by the editor settings. +edition = "2018" +hard_tabs = false +newline_style = "Unix" +tab_spaces = 4 @@ -43,17 +43,12 @@ rust_library { name: "libpin_project_lite", host_supported: true, crate_name: "pin_project_lite", - cargo_env_compat: true, - cargo_pkg_version: "0.2.8", srcs: ["src/lib.rs"], edition: "2018", apex_available: [ "//apex_available:platform", - "com.android.bluetooth", "com.android.resolv", - "com.android.uwb", "com.android.virt", ], - vendor_available: true, min_sdk_version: "29", } diff --git a/CHANGELOG.md b/CHANGELOG.md index 8e4d653..e9d1276 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,50 +10,24 @@ Note: In this file, do not use the hard wrap in the middle of a sentence for com ## [Unreleased] -## [0.2.8] - 2021-12-31 - -- Fix handling of trailing commas in `PinnedDrop` impl. ([#64](https://github.com/taiki-e/pin-project-lite/pull/64), thanks @Michael-J-Ward) - -## [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. ([#57](https://github.com/taiki-e/pin-project-lite/pull/57), thanks @SabrinaJewson) - -## [0.2.5] - 2021-03-02 - -- [Prepare for removal of `safe_packed_borrows` lint.](https://github.com/taiki-e/pin-project-lite/pull/55) See [#55](https://github.com/taiki-e/pin-project-lite/pull/55) for details. - ## [0.2.4] - 2021-01-11 -**NOTE:** This release has been yanked. See [#55](https://github.com/taiki-e/pin-project-lite/pull/55) for details. - -- Add `project_replace`. ([#43](https://github.com/taiki-e/pin-project-lite/pull/43), thanks @Marwes) +- [Add `project_replace`.](https://github.com/taiki-e/pin-project-lite/pull/43) ## [0.2.3] - 2021-01-09 -**NOTE:** This release has been yanked. See [#55](https://github.com/taiki-e/pin-project-lite/pull/55) for details. - - [Suppress `clippy::unknown_clippy_lints` lint in generated code.](https://github.com/taiki-e/pin-project-lite/pull/47) ## [0.2.2] - 2021-01-09 -**NOTE:** This release has been yanked.** See [#55](https://github.com/taiki-e/pin-project-lite/pull/55) for details. - - [Suppress `clippy::ref_option_ref` lint in generated code.](https://github.com/taiki-e/pin-project-lite/pull/45) ## [0.2.1] - 2021-01-05 -**NOTE:** This release has been yanked. See [#55](https://github.com/taiki-e/pin-project-lite/pull/55) for details. - - Exclude unneeded files from crates.io. ## [0.2.0] - 2020-11-13 -**NOTE:** This release has been yanked. See [#55](https://github.com/taiki-e/pin-project-lite/pull/55) for details. - - [`pin_project!` macro now supports enums.](https://github.com/taiki-e/pin-project-lite/pull/28) To use `pin_project!` on enums, you need to name the projection type returned from the method. @@ -103,34 +77,22 @@ Note: In this file, do not use the hard wrap in the middle of a sentence for com } ``` -## [0.1.12] - 2021-03-02 - -- [Prepare for removal of `safe_packed_borrows` lint.](https://github.com/taiki-e/pin-project-lite/pull/55) See [#55](https://github.com/taiki-e/pin-project-lite/pull/55) for details. - ## [0.1.11] - 2020-10-20 -**NOTE:** This release has been yanked. See [#55](https://github.com/taiki-e/pin-project-lite/pull/55) for details. - - Suppress `clippy::redundant_pub_crate` lint in generated code. - Documentation improvements. ## [0.1.10] - 2020-10-01 -**NOTE:** This release has been yanked. See [#55](https://github.com/taiki-e/pin-project-lite/pull/55) for details. - - Suppress `drop_bounds` lint, which will be added to rustc in the future. See [taiki-e/pin-project#272](https://github.com/taiki-e/pin-project/issues/272) for more details. ## [0.1.9] - 2020-09-29 -**NOTE:** This release has been yanked. See [#55](https://github.com/taiki-e/pin-project-lite/pull/55) for details. - - [Fix trailing comma support in generics.](https://github.com/taiki-e/pin-project-lite/pull/32) ## [0.1.8] - 2020-09-26 -**NOTE:** This release has been yanked. See [#55](https://github.com/taiki-e/pin-project-lite/pull/55) for details. - - [Fix compatibility of generated code with `forbid(future_incompatible)`.](https://github.com/taiki-e/pin-project-lite/pull/30) Note: This does not guarantee compatibility with `forbid(future_incompatible)` in the future. @@ -138,8 +100,6 @@ Note: In this file, do not use the hard wrap in the middle of a sentence for com ## [0.1.7] - 2020-06-04 -**NOTE:** This release has been yanked. See [#55](https://github.com/taiki-e/pin-project-lite/pull/55) for details. - - [Support `?Sized` bounds in where clauses.](https://github.com/taiki-e/pin-project-lite/pull/22) - [Fix lifetime inference error when an associated type is used in fields.](https://github.com/taiki-e/pin-project-lite/pull/20) @@ -150,59 +110,40 @@ Note: In this file, do not use the hard wrap in the middle of a sentence for com ## [0.1.6] - 2020-05-31 -**NOTE:** This release has been yanked. See [#55](https://github.com/taiki-e/pin-project-lite/pull/55) for details. - - [Support lifetime bounds in where clauses.](https://github.com/taiki-e/pin-project-lite/pull/18) - Documentation improvements. ## [0.1.5] - 2020-05-07 -**NOTE:** This release has been yanked. See [#55](https://github.com/taiki-e/pin-project-lite/pull/55) for details. - - [Support overwriting the name of `core` crate.](https://github.com/taiki-e/pin-project-lite/pull/14) ## [0.1.4] - 2020-01-20 -**NOTE:** This release has been yanked. See [#55](https://github.com/taiki-e/pin-project-lite/pull/55) for details. - - [Support ?Sized bounds in generic parameters.](https://github.com/taiki-e/pin-project-lite/pull/9) ## [0.1.3] - 2020-01-20 -**NOTE:** This release has been yanked. See [#55](https://github.com/taiki-e/pin-project-lite/pull/55) for details. - - [Support lifetime bounds in generic parameters.](https://github.com/taiki-e/pin-project-lite/pull/7) ## [0.1.2] - 2020-01-05 -**NOTE:** This release has been yanked. See [#55](https://github.com/taiki-e/pin-project-lite/pull/55) for details. - -- Support recognizing default generic parameters. ([#6](https://github.com/taiki-e/pin-project-lite/pull/6), thanks @kennytm) +- [Support recognizing default generic parameters.](https://github.com/taiki-e/pin-project-lite/pull/6) ## [0.1.1] - 2019-11-15 -**NOTE:** This release has been yanked. See [#55](https://github.com/taiki-e/pin-project-lite/pull/55) for details. - - [`pin_project!` macro now determines the visibility of the projection type/method is based on the original type.](https://github.com/taiki-e/pin-project-lite/pull/5) ## [0.1.0] - 2019-10-22 -**NOTE:** This release has been yanked. See [#55](https://github.com/taiki-e/pin-project-lite/pull/55) for details. - Initial release -[Unreleased]: https://github.com/taiki-e/pin-project-lite/compare/v0.2.8...HEAD -[0.2.8]: https://github.com/taiki-e/pin-project-lite/compare/v0.2.7...v0.2.8 -[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 +[Unreleased]: https://github.com/taiki-e/pin-project-lite/compare/v0.2.4...HEAD [0.2.4]: https://github.com/taiki-e/pin-project-lite/compare/v0.2.3...v0.2.4 [0.2.3]: https://github.com/taiki-e/pin-project-lite/compare/v0.2.2...v0.2.3 [0.2.2]: https://github.com/taiki-e/pin-project-lite/compare/v0.2.1...v0.2.2 [0.2.1]: https://github.com/taiki-e/pin-project-lite/compare/v0.2.0...v0.2.1 [0.2.0]: https://github.com/taiki-e/pin-project-lite/compare/v0.1.11...v0.2.0 -[0.1.12]: https://github.com/taiki-e/pin-project-lite/compare/v0.1.11...v0.1.12 [0.1.11]: https://github.com/taiki-e/pin-project-lite/compare/v0.1.10...v0.1.11 [0.1.10]: https://github.com/taiki-e/pin-project-lite/compare/v0.1.9...v0.1.10 [0.1.9]: https://github.com/taiki-e/pin-project-lite/compare/v0.1.8...v0.1.9 @@ -3,28 +3,28 @@ # When uploading crates to the registry Cargo will automatically # "normalize" Cargo.toml files for maximal compatibility # with all versions of Cargo and also rewrite `path` dependencies -# to registry (e.g., crates.io) dependencies. +# to registry (e.g., crates.io) dependencies # -# If you are reading this file be aware that the original Cargo.toml -# will likely look very different (and much more reasonable). -# See Cargo.toml.orig for the original contents. +# If you believe there's an error in this file please file an +# issue against the rust-lang/cargo repository. If you're +# editing this file be aware that the upstream Cargo.toml +# will likely look very different (and much more reasonable) [package] edition = "2018" -rust-version = "1.37" name = "pin-project-lite" -version = "0.2.8" -exclude = ["/.*", "/tools"] +version = "0.2.4" +authors = ["Taiki Endo <te316e89@gmail.com>"] +exclude = ["/.github", "/scripts"] description = "A lightweight version of pin-project written with declarative macros.\n" +documentation = "https://docs.rs/pin-project-lite" +readme = "README.md" keywords = ["pin", "macros"] categories = ["no-std", "rust-patterns"] license = "Apache-2.0 OR MIT" repository = "https://github.com/taiki-e/pin-project-lite" [package.metadata.docs.rs] targets = ["x86_64-unknown-linux-gnu"] -[dev-dependencies.macrotest] -version = "1.0.8" - [dev-dependencies.rustversion] version = "1" @@ -32,4 +32,4 @@ version = "1" version = "1" [dev-dependencies.trybuild] -version = "1.0.49" +version = "1" diff --git a/Cargo.toml.orig b/Cargo.toml.orig index e60195d..a909043 100644 --- a/Cargo.toml.orig +++ b/Cargo.toml.orig @@ -1,13 +1,15 @@ [package] name = "pin-project-lite" -version = "0.2.8" +version = "0.2.4" +authors = ["Taiki Endo <te316e89@gmail.com>"] edition = "2018" -rust-version = "1.37" license = "Apache-2.0 OR MIT" 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 = ["/.*", "/tools"] +readme = "README.md" +exclude = ["/.github", "/scripts"] description = """ A lightweight version of pin-project written with declarative macros. """ @@ -18,12 +20,12 @@ targets = ["x86_64-unknown-linux-gnu"] [workspace] members = [ "tests/doc", + "tests/expand", "tests/no-core", "tests/no-std", ] [dev-dependencies] -macrotest = "1.0.8" rustversion = "1" static_assertions = "1" -trybuild = "1.0.49" +trybuild = "1" @@ -7,13 +7,13 @@ third_party { } url { type: ARCHIVE - value: "https://static.crates.io/crates/pin-project-lite/pin-project-lite-0.2.8.crate" + value: "https://static.crates.io/crates/pin-project-lite/pin-project-lite-0.2.4.crate" } - version: "0.2.8" + version: "0.2.4" license_type: NOTICE last_upgrade_date { - year: 2022 - month: 3 - day: 1 + year: 2021 + month: 1 + day: 11 } } @@ -1,10 +1,10 @@ # pin-project-lite -[![crates.io](https://img.shields.io/crates/v/pin-project-lite?style=flat-square&logo=rust)](https://crates.io/crates/pin-project-lite) +[![crates.io](https://img.shields.io/crates/v/pin-project-lite.svg?style=flat-square&logo=rust)](https://crates.io/crates/pin-project-lite) [![docs.rs](https://img.shields.io/badge/docs.rs-pin--project--lite-blue?style=flat-square)](https://docs.rs/pin-project-lite) -[![license](https://img.shields.io/badge/license-Apache--2.0_OR_MIT-blue?style=flat-square)](#license) -[![rustc](https://img.shields.io/badge/rustc-1.37+-blue?style=flat-square&logo=rust)](https://www.rust-lang.org) -[![build status](https://img.shields.io/github/workflow/status/taiki-e/pin-project-lite/CI/main?style=flat-square&logo=github)](https://github.com/taiki-e/pin-project-lite/actions) +[![license](https://img.shields.io/badge/license-Apache--2.0_OR_MIT-blue.svg?style=flat-square)](#license) +[![rustc](https://img.shields.io/badge/rustc-1.37+-blue.svg?style=flat-square)](https://www.rust-lang.org) +[![build status](https://img.shields.io/github/workflow/status/taiki-e/pin-project-lite/CI/master?style=flat-square)](https://github.com/taiki-e/pin-project-lite/actions?query=workflow%3ACI+branch%3Amaster) A lightweight version of [pin-project] written with declarative macros. @@ -100,6 +100,10 @@ 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]. @@ -111,6 +115,7 @@ 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 diff --git a/TEST_MAPPING b/TEST_MAPPING deleted file mode 100644 index 5688278..0000000 --- a/TEST_MAPPING +++ /dev/null @@ -1,51 +0,0 @@ -// Generated by update_crate_tests.py for tests that depend on this crate. -{ - "imports": [ - { - "path": "external/rust/crates/anyhow" - }, - { - "path": "external/rust/crates/futures-util" - }, - { - "path": "external/rust/crates/tokio" - }, - { - "path": "external/rust/crates/tokio-test" - } - ], - "presubmit": [ - { - "name": "ZipFuseTest" - }, - { - "name": "authfs_device_test_src_lib" - }, - { - "name": "doh_unit_test" - }, - { - "name": "rustBinderTest" - }, - { - "name": "virtualizationservice_device_test" - } - ], - "presubmit-rust": [ - { - "name": "ZipFuseTest" - }, - { - "name": "authfs_device_test_src_lib" - }, - { - "name": "doh_unit_test" - }, - { - "name": "rustBinderTest" - }, - { - "name": "virtualizationservice_device_test" - } - ] -} diff --git a/cargo2android.json b/cargo2android.json index e136311..01465d0 100644 --- a/cargo2android.json +++ b/cargo2android.json @@ -1,14 +1,11 @@ { "apex-available": [ "//apex_available:platform", - "com.android.bluetooth", "com.android.resolv", - "com.android.uwb", "com.android.virt" ], + "min_sdk_version": "29", "dependencies": true, "device": true, - "min-sdk-version": "29", - "run": true, - "vendor-available": true -} + "run": true +}
\ No newline at end of file @@ -5,9 +5,8 @@ //! [`pin_project!`] macro creates a projection type covering all the fields of struct. //! //! ```rust -//! use std::pin::Pin; -//! //! use pin_project_lite::pin_project; +//! use std::pin::Pin; //! //! pin_project! { //! struct Struct<T, U> { @@ -30,15 +29,14 @@ //! returned from the method. //! //! ```rust -//! use std::pin::Pin; -//! //! use pin_project_lite::pin_project; +//! use std::pin::Pin; //! //! pin_project! { //! #[project = EnumProj] //! enum Enum<T, U> { //! Variant { #[pin] pinned: T, unpinned: U }, -//! } +//! } //! } //! //! impl<T, U> Enum<T, U> { @@ -82,6 +80,10 @@ //! 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]. @@ -92,6 +94,7 @@ //! //! [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] @@ -102,8 +105,8 @@ allow(dead_code, unused_variables) ) ))] -#![warn(rust_2018_idioms, single_use_lifetimes, unreachable_pub)] -#![warn(clippy::default_trait_access, clippy::wildcard_imports)] +#![warn(future_incompatible, rust_2018_idioms, single_use_lifetimes, unreachable_pub)] +#![warn(clippy::all, clippy::default_trait_access)] // ANDROID: Use std to allow building as a dylib. extern crate std; @@ -112,8 +115,8 @@ extern crate std; /// /// This macro creates a projection type according to the following rules: /// -/// - For the field that uses `#[pin]` attribute, makes the pinned reference to the field. -/// - For the other fields, makes the unpinned reference to the field. +/// * For the field that uses `#[pin]` attribute, makes the pinned reference to the field. +/// * For the other fields, makes the unpinned reference to the field. /// /// And the following methods are implemented on the original type: /// @@ -165,6 +168,23 @@ extern crate std; /// # } /// ``` /// +/// The `#[project]` (and `#[project_ref]`) attribute must precede the other +/// attributes except for `#[doc]`. For example, the following code will not be compiled: +/// +/// ```rust,compile_fail +/// # use pin_project_lite::pin_project; +/// # use std::pin::Pin; +/// pin_project! { +/// /// documents (`#[doc]`) can be placed before `#[project]`. +/// #[derive(Clone)] // <--- ERROR +/// #[project = EnumProj] +/// #[derive(Debug)] // <--- Ok +/// enum Enum<T> { +/// Variant { #[pin] field: T }, +/// } +/// } +/// ``` +/// /// Also, note that the projection types returned by `project` and `project_ref` have /// an additional lifetime at the beginning of generics. /// @@ -188,9 +208,8 @@ extern crate std; /// # Examples /// /// ```rust -/// use std::pin::Pin; -/// /// use pin_project_lite::pin_project; +/// use std::pin::Pin; /// /// pin_project! { /// struct Struct<T, U> { @@ -213,9 +232,8 @@ extern crate std; /// returned from the method. /// /// ```rust -/// use std::pin::Pin; -/// /// use pin_project_lite::pin_project; +/// use std::pin::Pin; /// /// pin_project! { /// #[project = EnumProj] @@ -245,9 +263,8 @@ extern crate std; /// consuming the [`Pin`]. /// /// ```rust -/// use std::pin::Pin; -/// /// use pin_project_lite::pin_project; +/// use std::pin::Pin; /// /// pin_project! { /// struct Struct<T> { @@ -271,9 +288,8 @@ extern crate std; /// attribute for a [`PhantomPinned`] field. /// /// ```rust -/// use std::marker::PhantomPinned; -/// /// use pin_project_lite::pin_project; +/// use std::marker::PhantomPinned; /// /// pin_project! { /// struct Struct<T> { @@ -292,124 +308,178 @@ extern crate std; /// [pin-project]: https://github.com/taiki-e/pin-project #[macro_export] macro_rules! pin_project { - ($($tt:tt)*) => { + // Parses options + ( + $(#[doc $($doc:tt)*])* + #[project = $proj_mut_ident:ident] + #[project_ref = $proj_ref_ident:ident] + #[project_replace = $proj_replace_ident:ident] + $($tt:tt)* + ) => { + $crate::__pin_project_internal! { + [$proj_mut_ident][$proj_ref_ident][$proj_replace_ident] + $(#[doc $($doc)*])* + $($tt)* + } + }; + ( + $(#[doc $($doc:tt)*])* + #[project = $proj_mut_ident:ident] + #[project_ref = $proj_ref_ident:ident] + $($tt:tt)* + ) => { $crate::__pin_project_internal! { - [][][][] + [$proj_mut_ident][$proj_ref_ident][] + $(#[doc $($doc)*])* + $($tt)* + } + }; + ( + $(#[doc $($doc:tt)*])* + #[project = $proj_mut_ident:ident] + #[project_replace = $proj_replace_ident:ident] + $($tt:tt)* + ) => { + $crate::__pin_project_internal! { + [$proj_mut_ident][][$proj_replace_ident] + $(#[doc $($doc)*])* + $($tt)* + } + }; + ( + $(#[doc $($doc:tt)*])* + #[project_ref = $proj_ref_ident:ident] + #[project_replace = $proj_replace_ident:ident] + $($tt:tt)* + ) => { + $crate::__pin_project_internal! { + [][$proj_ref_ident][$proj_replace_ident] + $(#[doc $($doc)*])* + $($tt)* + } + }; + ( + $(#[doc $($doc:tt)*])* + #[project = $proj_mut_ident:ident] + $($tt:tt)* + ) => { + $crate::__pin_project_internal! { + [$proj_mut_ident][][] + $(#[doc $($doc)*])* + $($tt)* + } + }; + ( + $(#[doc $($doc:tt)*])* + #[project_ref = $proj_ref_ident:ident] + $($tt:tt)* + ) => { + $crate::__pin_project_internal! { + [][$proj_ref_ident][] + $(#[doc $($doc)*])* + $($tt)* + } + }; + ( + $(#[doc $($doc:tt)*])* + #[project_replace = $proj_replace_ident:ident] + $($tt:tt)* + ) => { + $crate::__pin_project_internal! { + [][][$proj_replace_ident] + $(#[doc $($doc)*])* + $($tt)* + } + }; + ( + $($tt:tt)* + ) => { + $crate::__pin_project_internal! { + [][][] $($tt)* } }; } // limitations: -// - no support for tuple structs and tuple variant (wontfix). -// - no support for multiple trait/lifetime bounds. -// - no support for `Self` in where clauses. (wontfix) -// - no support for overlapping lifetime names. (wontfix) -// - no interoperability with other field attributes. -// - no useful error messages. (wontfix) +// * no support for tuple structs and tuple variant (wontfix). +// * no support for multiple trait/lifetime bounds. +// * no support for `Self` in where clauses. (wontfix) +// * no support for overlapping lifetime names. (wontfix) +// * no interoperability with other field attributes. +// * no useful error messages. (wontfix) // etc... // Not public API. #[doc(hidden)] #[macro_export] macro_rules! __pin_project_internal { - // macro helpers - // ignores any projection without a projection identity - (@make_proj_ty; - [] // no identity given, so we ignore the projection - $($field:tt)* - ) => {}; - // ignores make_proj_replace_ty without a projection identity - (@make_proj_replace_ty; - [] // no identity given, so we ignore the projection - $($field:tt)* - ) => {}; - (@$struct_ty_ident:ident=>make_proj_method; - [] - $($variant:tt)* - ) => {}; - (@$struct_ty_ident:ident=>make_proj_replace_method; - [] - $($field:tt)* - ) => {}; // ============================================================================================= // struct:main - (@expand; + (@struct=>internal; [$($proj_mut_ident:ident)?] [$($proj_ref_ident:ident)?] [$($proj_replace_ident:ident)?] [$proj_vis:vis] - [$(#[$attrs:meta])* $vis:vis $struct_ty_ident:ident $ident:ident] + [$(#[$attrs:meta])* $vis:vis struct $ident:ident] [$($def_generics:tt)*] [$($impl_generics:tt)*] [$($ty_generics:tt)*] [$(where $($where_clause:tt)*)?] { - $($body_data:tt)* + $( + $(#[$pin:ident])? + $field_vis:vis $field:ident: $field_ty:ty + ),+ } - $(impl $($pinned_drop:tt)*)? ) => { - $crate::__pin_project_internal! { @reconstruct; - [$(#[$attrs])* $vis $struct_ty_ident $ident] - [$($def_generics)*] [$($impl_generics)*] - [$($ty_generics)*] [$(where $($where_clause)*)?] - { - $($body_data)* - } + $(#[$attrs])* + $vis struct $ident $($def_generics)* + $(where + $($where_clause)*)? + { + $( + $field_vis $field: $field_ty + ),+ } - $crate::__pin_project_internal! { @make_proj_ty; + $crate::__pin_project_internal! { @struct=>make_proj_ty=>named; + [$proj_vis] [$($proj_mut_ident)?] - [$proj_vis $struct_ty_ident $ident] [make_proj_field_mut] + [$ident] [$($impl_generics)*] [$($ty_generics)*] [$(where $($where_clause)*)?] { - $($body_data)* + $( + $(#[$pin])? + $field_vis $field: $field_ty + ),+ } } - $crate::__pin_project_internal! { @make_proj_ty; + $crate::__pin_project_internal! { @struct=>make_proj_ty=>named; + [$proj_vis] [$($proj_ref_ident)?] - [$proj_vis $struct_ty_ident $ident] [make_proj_field_ref] + [$ident] [$($impl_generics)*] [$($ty_generics)*] [$(where $($where_clause)*)?] { - $($body_data)* + $( + $(#[$pin])? + $field_vis $field: $field_ty + ),+ } } - $crate::__pin_project_internal! { @make_proj_replace_ty; + $crate::__pin_project_internal! { @struct=>make_proj_replace_ty=>named; + [$proj_vis] [$($proj_replace_ident)?] - [$proj_vis $struct_ty_ident] [make_proj_field_replace] + [$ident] [$($impl_generics)*] [$($ty_generics)*] [$(where $($where_clause)*)?] { - $($body_data)* - } - } - - $crate::__pin_project_internal! { @constant; - [$(#[$attrs])* $vis $struct_ty_ident $ident] - [$($proj_mut_ident)?] [$($proj_ref_ident)?] [$($proj_replace_ident)?] - [$proj_vis] - [$($def_generics)*] [$($impl_generics)*] - [$($ty_generics)*] [$(where $($where_clause)*)?] - { - $($body_data)* + $( + $(#[$pin])? + $field_vis $field: $field_ty + ),+ } - $(impl $($pinned_drop)*)? - } - }; - (@constant; - [$(#[$attrs:meta])* $vis:vis struct $ident:ident] - [$($proj_mut_ident:ident)?] [$($proj_ref_ident:ident)?] [$($proj_replace_ident:ident)?] - [$proj_vis:vis] - [$($def_generics:tt)*] - [$($impl_generics:tt)*] [$($ty_generics:tt)*] [$(where $($where_clause:tt)*)?] - { - $( - $(#[$pin:ident])? - $field_vis:vis $field:ident: $field_ty:ty - ),+ $(,)? } - $(impl $($pinned_drop:tt)*)? - ) => { #[allow(explicit_outlives_requirements)] // https://github.com/rust-lang/rust/issues/60993 #[allow(single_use_lifetimes)] // https://github.com/rust-lang/rust/issues/55058 @@ -419,10 +489,11 @@ macro_rules! __pin_project_internal { #[allow(clippy::redundant_pub_crate)] // This lint warns `pub(crate)` field in private struct. #[allow(clippy::used_underscore_binding)] const _: () = { - $crate::__pin_project_internal! { @make_proj_ty; - [$($proj_mut_ident)? Projection] - [$proj_vis struct $ident] + $crate::__pin_project_internal! { @struct=>make_proj_ty=>unnamed; + [$proj_vis] + [$($proj_mut_ident)?][Projection] [make_proj_field_mut] + [$ident] [$($impl_generics)*] [$($ty_generics)*] [$(where $($where_clause)*)?] { $( @@ -431,10 +502,24 @@ macro_rules! __pin_project_internal { ),+ } } - $crate::__pin_project_internal! { @make_proj_ty; - [$($proj_ref_ident)? ProjectionRef] - [$proj_vis struct $ident] + $crate::__pin_project_internal! { @struct=>make_proj_ty=>unnamed; + [$proj_vis] + [$($proj_ref_ident)?][ProjectionRef] [make_proj_field_ref] + [$ident] + [$($impl_generics)*] [$($ty_generics)*] [$(where $($where_clause)*)?] + { + $( + $(#[$pin])? + $field_vis $field: $field_ty + ),+ + } + } + $crate::__pin_project_internal! { @struct=>make_proj_replace_ty=>unnamed; + [$proj_vis] + [$($proj_replace_ident)?][ProjectionReplace] + [make_proj_field_replace] + [$ident] [$($impl_generics)*] [$($ty_generics)*] [$(where $($where_clause)*)?] { $( @@ -449,8 +534,8 @@ macro_rules! __pin_project_internal { $($where_clause)*)? { $crate::__pin_project_internal! { @struct=>make_proj_method; - [$($proj_mut_ident)? Projection] [$proj_vis] + [$($proj_mut_ident)?][Projection] [project get_unchecked_mut mut] [$($ty_generics)*] { @@ -461,8 +546,8 @@ macro_rules! __pin_project_internal { } } $crate::__pin_project_internal! { @struct=>make_proj_method; - [$($proj_ref_ident)? ProjectionRef] [$proj_vis] + [$($proj_ref_ident)?][ProjectionRef] [project_ref get_ref] [$($ty_generics)*] { @@ -473,9 +558,8 @@ macro_rules! __pin_project_internal { } } $crate::__pin_project_internal! { @struct=>make_proj_replace_method; - [$($proj_replace_ident)?] [$proj_vis] - [ProjectionReplace] + [$($proj_replace_ident)?][ProjectionReplace] [$($ty_generics)*] { $( @@ -499,13 +583,14 @@ 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. // - // Taking a reference to a packed field is UB, and applying - // `#[forbid(unaligned_references)]` makes sure that doing this is a hard error. + // Taking a reference to a packed field is unsafe, amd appplying + // #[forbid(safe_packed_borrows)] makes sure that doing this without + // an 'unsafe' block (which we deliberately do not generate) + // is a hard error. // // If the struct ends up having #[repr(packed)] applied somehow, // this will generate an (unfriendly) error message. Under all reasonable @@ -513,16 +598,7 @@ macro_rules! __pin_project_internal { // a much nicer error above. // // See https://github.com/taiki-e/pin-project/pull/34 for more details. - // - // Note: - // - Lint-based tricks aren't perfect, but they're much better than nothing: - // https://github.com/taiki-e/pin-project-lite/issues/26 - // - // - Enable both unaligned_references and safe_packed_borrows lints - // because unaligned_references lint does not exist in older compilers: - // https://github.com/taiki-e/pin-project-lite/pull/55 - // https://github.com/rust-lang/rust/pull/82525 - #[forbid(unaligned_references, safe_packed_borrows)] + #[forbid(safe_packed_borrows)] fn __assert_not_repr_packed <$($impl_generics)*> (this: &$ident <$($ty_generics)*>) $(where $($where_clause)*)? @@ -535,10 +611,12 @@ macro_rules! __pin_project_internal { }; // ============================================================================================= // enum:main - (@constant; - [$(#[$attrs:meta])* $vis:vis enum $ident:ident] - [$($proj_mut_ident:ident)?] [$($proj_ref_ident:ident)?] [$($proj_replace_ident:ident)?] + (@enum=>internal; + [$($proj_mut_ident:ident)?] + [$($proj_ref_ident:ident)?] + [$($proj_replace_ident:ident)?] [$proj_vis:vis] + [$(#[$attrs:meta])* $vis:vis enum $ident:ident] [$($def_generics:tt)*] [$($impl_generics:tt)*] [$($ty_generics:tt)*] [$(where $($where_clause:tt)*)?] { @@ -548,12 +626,77 @@ macro_rules! __pin_project_internal { $( $(#[$pin:ident])? $field:ident: $field_ty:ty - ),+ $(,)? + ),+ })? - ),+ $(,)? + ),+ } - $(impl $($pinned_drop:tt)*)? ) => { + $(#[$attrs])* + $vis enum $ident $($def_generics)* + $(where + $($where_clause)*)? + { + $( + $(#[$variant_attrs])* + $variant $({ + $( + $field: $field_ty + ),+ + })? + ),+ + } + + $crate::__pin_project_internal! { @enum=>make_proj_ty; + [$proj_vis] + [$($proj_mut_ident)?] + [make_proj_field_mut] + [$ident] + [$($impl_generics)*] [$($ty_generics)*] [$(where $($where_clause)*)?] + { + $( + $variant $({ + $( + $(#[$pin])? + $field: $field_ty + ),+ + })? + ),+ + } + } + $crate::__pin_project_internal! { @enum=>make_proj_ty; + [$proj_vis] + [$($proj_ref_ident)?] + [make_proj_field_ref] + [$ident] + [$($impl_generics)*] [$($ty_generics)*] [$(where $($where_clause)*)?] + { + $( + $variant $({ + $( + $(#[$pin])? + $field: $field_ty + ),+ + })? + ),+ + } + } + $crate::__pin_project_internal! { @enum=>make_proj_replace_ty; + [$proj_vis] + [$($proj_replace_ident)?] + [make_proj_field_replace] + [$ident] + [$($impl_generics)*] [$($ty_generics)*] [$(where $($where_clause)*)?] + { + $( + $variant $({ + $( + $(#[$pin])? + $field: $field_ty + ),+ + })? + ),+ + } + } #[allow(single_use_lifetimes)] // https://github.com/rust-lang/rust/issues/55058 // This lint warns of `clippy::*` generated by external macros. @@ -566,8 +709,8 @@ macro_rules! __pin_project_internal { $($where_clause)*)? { $crate::__pin_project_internal! { @enum=>make_proj_method; - [$($proj_mut_ident)?] [$proj_vis] + [$($proj_mut_ident)?] [project get_unchecked_mut mut] [$($ty_generics)*] { @@ -582,8 +725,8 @@ macro_rules! __pin_project_internal { } } $crate::__pin_project_internal! { @enum=>make_proj_method; - [$($proj_ref_ident)?] [$proj_vis] + [$($proj_ref_ident)?] [project_ref get_ref] [$($ty_generics)*] { @@ -598,8 +741,8 @@ macro_rules! __pin_project_internal { } } $crate::__pin_project_internal! { @enum=>make_proj_replace_method; - [$($proj_replace_ident)?] [$proj_vis] + [$($proj_replace_ident)?] [$($ty_generics)*] { $( @@ -631,7 +774,6 @@ 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)]', @@ -639,66 +781,45 @@ macro_rules! __pin_project_internal { }; }; - (@reconstruct; - [$(#[$attrs:meta])* $vis:vis struct $ident:ident] - [$($def_generics:tt)*] [$($impl_generics:tt)*] - [$($ty_generics:tt)*] [$(where $($where_clause:tt)*)?] - { - $( - $(#[$pin:ident])? - $field_vis:vis $field:ident: $field_ty:ty - ),+ $(,)? - } + // ============================================================================================= + // struct:make_proj_ty + (@struct=>make_proj_ty=>unnamed; + [$proj_vis:vis] + [$_proj_ty_ident:ident][$proj_ty_ident:ident] + [$make_proj_field:ident] + [$ident:ident] + [$($impl_generics:tt)*] [$($ty_generics:tt)*] [$(where $($where_clause:tt)* )?] + $($field:tt)* + ) => {}; + (@struct=>make_proj_ty=>unnamed; + [$proj_vis:vis] + [][$proj_ty_ident:ident] + [$make_proj_field:ident] + [$ident:ident] + [$($impl_generics:tt)*] [$($ty_generics:tt)*] [$(where $($where_clause:tt)* )?] + $($field:tt)* ) => { - $(#[$attrs])* - $vis struct $ident $($def_generics)* - $(where - $($where_clause)*)? - { - $( - $field_vis $field: $field_ty - ),+ + $crate::__pin_project_internal! { @struct=>make_proj_ty=>named; + [$proj_vis] + [$proj_ty_ident] + [$make_proj_field] + [$ident] + [$($impl_generics)*] [$($ty_generics)*] [$(where $($where_clause)*)?] + $($field)* } }; - - // reconstruct original enum type - (@reconstruct; - [$(#[$attrs:meta])* $vis:vis enum $ident:ident] - [$($def_generics:tt)*] [$($impl_generics:tt)*] - [$($ty_generics:tt)*] [$(where $($where_clause:tt)*)?] - { - $( - $(#[$variant_attrs:meta])* - $variant:ident $({ - $( - $(#[$pin:ident])? - $field:ident: $field_ty:ty - ),+ $(,)? - })? - ),+ $(,)? - } - ) => { - $(#[$attrs])* - $vis enum $ident $($def_generics)* - $(where - $($where_clause)*)? + (@struct=>make_proj_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)* )?] { $( - $(#[$variant_attrs])* - $variant $({ - $( - $field: $field_ty - ),+ - })? + $(#[$pin:ident])? + $field_vis:vis $field:ident: $field_ty:ty ),+ } - }; - // construct a projected type - (@make_proj_ty; - [$proj_ty_ident:ident] - [$proj_vis:vis $struct_ty_ident:ident $ident:ident] - [$($impl_generics:tt)*] [$($ty_generics:tt)*] [$(where $($where_clause:tt)* )?] - [$($body_data:tt)+] ) => { #[allow(dead_code)] // This lint warns unused fields/variants. #[allow(single_use_lifetimes)] // https://github.com/rust-lang/rust/issues/55058 @@ -709,161 +830,180 @@ macro_rules! __pin_project_internal { #[allow(clippy::redundant_pub_crate)] // This lint warns `pub(crate)` field in private struct. #[allow(clippy::ref_option_ref)] // This lint warns `&Option<&<ty>>`. (only needed for project_ref) #[allow(clippy::type_repetition_in_bounds)] // https://github.com/rust-lang/rust-clippy/issues/4326 - $proj_vis $struct_ty_ident $proj_ty_ident <'__pin, $($impl_generics)*> + $proj_vis struct $proj_ty_ident <'__pin, $($impl_generics)*> where $ident <$($ty_generics)*>: '__pin $(, $($where_clause)*)? { - $($body_data)+ + $( + $field_vis $field: $crate::__pin_project_internal!(@$make_proj_field; + $(#[$pin])? $field_ty + ) + ),+ } }; - // construct a project_replace type - (@make_proj_replace_ty; - [$proj_ty_ident:ident] - [$proj_vis:vis $struct_ty_ident:ident] + (@struct=>make_proj_ty=>named; + [$proj_vis:vis] + [] + [$make_proj_field:ident] + [$ident:ident] [$($impl_generics:tt)*] [$($ty_generics:tt)*] [$(where $($where_clause:tt)* )?] - [$($body_data:tt)+] - ) => { - #[allow(dead_code)] // This lint warns unused fields/variants. - #[allow(single_use_lifetimes)] // https://github.com/rust-lang/rust/issues/55058 - #[allow(clippy::mut_mut)] // This lint warns `&mut &mut <ty>`. (only needed for project) - #[allow(clippy::redundant_pub_crate)] // This lint warns `pub(crate)` field in private struct. - #[allow(clippy::type_repetition_in_bounds)] // https://github.com/rust-lang/rust-clippy/issues/4326 - $proj_vis $struct_ty_ident $proj_ty_ident <$($impl_generics)*> - where - $($($where_clause)*)? - { - $($body_data)+ - } - }; - // ============================================================================================= - // struct:make_proj_ty - // if a proj_ty_ident was given, we do *not* create one with the default - (@make_proj_ty; - [$proj_ty_ident:ident $default_ident:ident] - [$proj_vis:vis struct $ident:ident] $($field:tt)* ) => {}; - (@make_proj_ty; - [$proj_ty_ident:ident] - [$proj_vis:vis struct $ident:ident] + + (@struct=>make_proj_replace_ty=>unnamed; + [$proj_vis:vis] + [$_proj_ty_ident:ident][$proj_ty_ident:ident] [$make_proj_field:ident] + [$ident:ident] [$($impl_generics:tt)*] [$($ty_generics:tt)*] [$(where $($where_clause:tt)* )?] - { - $( - $(#[$pin:ident])? - $field_vis:vis $field:ident: $field_ty:ty - ),+ $(,)? - } + $($field:tt)* + ) => {}; + (@struct=>make_proj_replace_ty=>unnamed; + [$proj_vis:vis] + [][$proj_ty_ident:ident] + [$make_proj_field:ident] + [$ident:ident] + [$($impl_generics:tt)*] [$($ty_generics:tt)*] [$(where $($where_clause:tt)* )?] + $($field:tt)* ) => { - $crate::__pin_project_internal!{@make_proj_ty; - [$proj_ty_ident] - [$proj_vis struct $ident] - [$($impl_generics)*] [$($ty_generics)*] [$(where $($where_clause)* )?] - [ - $( - $field_vis $field: $crate::__pin_project_internal!(@$make_proj_field; - $(#[$pin])? $field_ty - ) - ),+ - ] - } }; - (@make_proj_replace_ty; + (@struct=>make_proj_replace_ty=>named; + [$proj_vis:vis] [$proj_ty_ident:ident] - [$proj_vis:vis struct] [$make_proj_field:ident] + [$ident:ident] [$($impl_generics:tt)*] [$($ty_generics:tt)*] [$(where $($where_clause:tt)* )?] { $( $(#[$pin:ident])? $field_vis:vis $field:ident: $field_ty:ty - ),+ $(,)? + ),+ } ) => { - $crate::__pin_project_internal!{@make_proj_replace_ty; - [$proj_ty_ident] - [$proj_vis struct] - [$($impl_generics)*] [$($ty_generics)*] [$(where $($where_clause)* )?] - [ - $( - $field_vis $field: $crate::__pin_project_internal!(@$make_proj_field; - $(#[$pin])? $field_ty - ) - ),+ - ] + #[allow(dead_code)] // This lint warns unused fields/variants. + #[allow(single_use_lifetimes)] // https://github.com/rust-lang/rust/issues/55058 + #[allow(clippy::mut_mut)] // This lint warns `&mut &mut <ty>`. (only needed for project) + #[allow(clippy::redundant_pub_crate)] // This lint warns `pub(crate)` field in private struct. + #[allow(clippy::type_repetition_in_bounds)] // https://github.com/rust-lang/rust-clippy/issues/4326 + $proj_vis struct $proj_ty_ident <$($impl_generics)*> + where + $($($where_clause)*)? + { + $( + $field_vis $field: $crate::__pin_project_internal!(@$make_proj_field; + $(#[$pin])? $field_ty + ) + ),+ } }; + (@struct=>make_proj_replace_ty=>named; + [$proj_vis:vis] + [] + [$make_proj_field:ident] + [$ident:ident] + [$($impl_generics:tt)*] [$($ty_generics:tt)*] [$(where $($where_clause:tt)* )?] + $($field:tt)* + ) => {}; // ============================================================================================= // enum:make_proj_ty - (@make_proj_ty; + (@enum=>make_proj_ty; + [$proj_vis:vis] [$proj_ty_ident:ident] - [$proj_vis:vis enum $ident:ident] [$make_proj_field:ident] + [$ident:ident] [$($impl_generics:tt)*] [$($ty_generics:tt)*] [$(where $($where_clause:tt)* )?] { $( - $(#[$variant_attrs:meta])* $variant:ident $({ $( $(#[$pin:ident])? $field:ident: $field_ty:ty - ),+ $(,)? + ),+ })? - ),+ $(,)? + ),+ } ) => { - $crate::__pin_project_internal!{@make_proj_ty; - [$proj_ty_ident] - [$proj_vis enum $ident] - [$($impl_generics)*] [$($ty_generics)*] [$(where $($where_clause)* )?] - [ - $( - $variant $({ - $( - $field: $crate::__pin_project_internal!(@$make_proj_field; - $(#[$pin])? $field_ty - ) - ),+ - })? - ),+ - ] + #[allow(dead_code)] // This lint warns unused fields/variants. + #[allow(single_use_lifetimes)] // https://github.com/rust-lang/rust/issues/55058 + // This lint warns of `clippy::*` generated by external macros. + // We allow this lint for compatibility with older compilers. + #[allow(clippy::unknown_clippy_lints)] + #[allow(clippy::mut_mut)] // This lint warns `&mut &mut <ty>`. (only needed for project) + #[allow(clippy::redundant_pub_crate)] // This lint warns `pub(crate)` field in private struct. + #[allow(clippy::ref_option_ref)] // This lint warns `&Option<&<ty>>`. (only needed for project_ref) + #[allow(clippy::type_repetition_in_bounds)] // https://github.com/rust-lang/rust-clippy/issues/4326 + $proj_vis enum $proj_ty_ident <'__pin, $($impl_generics)*> + where + $ident <$($ty_generics)*>: '__pin + $(, $($where_clause)*)? + { + $( + $variant $({ + $( + $field: $crate::__pin_project_internal!(@$make_proj_field; + $(#[$pin])? $field_ty + ) + ),+ + })? + ),+ } }; - (@make_proj_replace_ty; + (@enum=>make_proj_ty; + [$proj_vis:vis] + [] + [$make_proj_field:ident] + [$ident:ident] + [$($impl_generics:tt)*] [$($ty_generics:tt)*] [$(where $($where_clause:tt)* )?] + $($variant:tt)* + ) => {}; + + (@enum=>make_proj_replace_ty; + [$proj_vis:vis] [$proj_ty_ident:ident] - [$proj_vis:vis enum] [$make_proj_field:ident] + [$ident:ident] [$($impl_generics:tt)*] [$($ty_generics:tt)*] [$(where $($where_clause:tt)* )?] { $( - $(#[$variant_attrs:meta])* $variant:ident $({ $( $(#[$pin:ident])? $field:ident: $field_ty:ty - ),+ $(,)? + ),+ })? - ),+ $(,)? + ),+ } ) => { - $crate::__pin_project_internal!{@make_proj_replace_ty; - [$proj_ty_ident] - [$proj_vis enum] - [$($impl_generics)*] [$($ty_generics)*] [$(where $($where_clause)* )?] - [ - $( - $variant $({ - $( - $field: $crate::__pin_project_internal!(@$make_proj_field; - $(#[$pin])? $field_ty - ) - ),+ - })? - ),+ - ] + #[allow(dead_code)] // This lint warns unused fields/variants. + #[allow(single_use_lifetimes)] // https://github.com/rust-lang/rust/issues/55058 + #[allow(clippy::mut_mut)] // This lint warns `&mut &mut <ty>`. (only needed for project) + #[allow(clippy::redundant_pub_crate)] // This lint warns `pub(crate)` field in private struct. + #[allow(clippy::type_repetition_in_bounds)] // https://github.com/rust-lang/rust-clippy/issues/4326 + $proj_vis enum $proj_ty_ident <$($impl_generics)*> + where + $($($where_clause)*)? + { + $( + $variant $({ + $( + $field: $crate::__pin_project_internal!(@$make_proj_field; + $(#[$pin])? $field_ty + ) + ),+ + })? + ),+ } }; + (@enum=>make_proj_replace_ty; + [$proj_vis:vis] + [] + [$make_proj_field:ident] + [$ident:ident] + [$($impl_generics:tt)*] [$($ty_generics:tt)*] [$(where $($where_clause:tt)* )?] + $($variant:tt)* + ) => {}; + // ============================================================================================= (@make_proj_replace_block; [$($proj_path: tt)+] @@ -900,25 +1040,9 @@ macro_rules! __pin_project_internal { // ============================================================================================= // struct:make_proj_method - // this employs an ignored default strategy that ensures the identity used matches the one used in `struct=>make_proj_ty` - (@struct=>make_proj_method; - [$proj_ty_ident:ident $_ignored_default_arg:ident] - [$proj_vis:vis] - [$method_ident:ident $get_method:ident $($mut:ident)?] - [$($ty_generics:tt)*] - $($variant:tt)* - ) => { - $crate::__pin_project_internal! { @struct=>make_proj_method; - [$proj_ty_ident] - [$proj_vis] - [$method_ident $get_method $($mut)?] - [$($ty_generics)*] - $($variant)* - } - }; (@struct=>make_proj_method; - [$proj_ty_ident:ident] [$proj_vis:vis] + [$proj_ty_ident:ident][$_proj_ty_ident:ident] [$method_ident:ident $get_method:ident $($mut:ident)?] [$($ty_generics:tt)*] { @@ -943,11 +1067,25 @@ macro_rules! __pin_project_internal { } } }; + (@struct=>make_proj_method; + [$proj_vis:vis] + [][$proj_ty_ident:ident] + [$method_ident:ident $get_method:ident $($mut:ident)?] + [$($ty_generics:tt)*] + $($variant:tt)* + ) => { + $crate::__pin_project_internal! { @struct=>make_proj_method; + [$proj_vis] + [$proj_ty_ident][$proj_ty_ident] + [$method_ident $get_method $($mut)?] + [$($ty_generics)*] + $($variant)* + } + }; (@struct=>make_proj_replace_method; - [$proj_ty_ident:ident] [$proj_vis:vis] - [$_proj_ty_ident:ident] + [$proj_ty_ident:ident][$_proj_ty_ident:ident] [$($ty_generics:tt)*] { $( @@ -965,7 +1103,10 @@ macro_rules! __pin_project_internal { // Destructors will run in reverse order, so next create a guard to overwrite // `self` with the replacement value without calling destructors. - let __guard = $crate::__private::UnsafeOverwriteGuard::new(__self_ptr, replacement); + let __guard = $crate::__private::UnsafeOverwriteGuard { + target: __self_ptr, + value: $crate::__private::ManuallyDrop::new(replacement), + }; let Self { $($field),* } = &mut *__self_ptr; @@ -981,11 +1122,19 @@ macro_rules! __pin_project_internal { } } }; + (@struct=>make_proj_replace_method; + [$proj_vis:vis] + [][$proj_ty_ident:ident] + [$($ty_generics:tt)*] + $($variant:tt)* + ) => { + }; + // ============================================================================================= // enum:make_proj_method (@enum=>make_proj_method; - [$proj_ty_ident:ident] [$proj_vis:vis] + [$proj_ty_ident:ident] [$method_ident:ident $get_method:ident $($mut:ident)?] [$($ty_generics:tt)*] { @@ -1022,9 +1171,17 @@ macro_rules! __pin_project_internal { } } }; + (@enum=>make_proj_method; + [$proj_vis:vis] + [] + [$method_ident:ident $get_method:ident $($mut:ident)?] + [$($ty_generics:tt)*] + $($variant:tt)* + ) => {}; + (@enum=>make_proj_replace_method; - [$proj_ty_ident:ident] [$proj_vis:vis] + [$proj_ty_ident:ident] [$($ty_generics:tt)*] { $( @@ -1046,7 +1203,10 @@ macro_rules! __pin_project_internal { // Destructors will run in reverse order, so next create a guard to overwrite // `self` with the replacement value without calling destructors. - let __guard = $crate::__private::UnsafeOverwriteGuard::new(__self_ptr, replacement); + let __guard = $crate::__private::UnsafeOverwriteGuard { + target: __self_ptr, + value: $crate::__private::ManuallyDrop::new(replacement), + }; match &mut *__self_ptr { $( @@ -1068,6 +1228,13 @@ macro_rules! __pin_project_internal { } } }; + (@enum=>make_proj_replace_method; + [$proj_vis:vis] + [] + [$($ty_generics:tt)*] + $($variant:tt)* + ) => {}; + // ============================================================================================= // make_unpin_impl (@make_unpin_impl; @@ -1089,11 +1256,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 declared within + // fields from our #[pin_project] type. This struct is delcared within // a function, which makes it impossible to be named by user code. - // This guarantees that it will use the default auto-trait impl for Unpin - + // This guarnatees 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', satisfying the privacy + // This type can be safely declared as 'public', satisfiying the privacy // checker without actually allowing user code to access it. // // This allows users to apply the #[pin_project] attribute to types @@ -1119,90 +1286,6 @@ 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)* )?] ) => { @@ -1213,7 +1296,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 conflict with the explicit MustNotImplDrop impl below. + // which will then comflict 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)] @@ -1274,7 +1357,7 @@ macro_rules! __pin_project_internal { #[pin] $field:ident ) => { - $crate::__private::UnsafeDropInPlaceGuard::new($field) + $crate::__private::UnsafeDropInPlaceGuard($field) }; (@make_unsafe_drop_in_place_guard; $field:ident @@ -1320,128 +1403,224 @@ macro_rules! __pin_project_internal { }; // ============================================================================================= - // Parses attributes and determines visibility - // parsing proj_mut_ident + // Parses input and determines visibility + // struct ( - [] - [$($proj_ref_ident:ident)?] - [$($proj_replace_ident:ident)?] - [$($attrs:tt)*] - - #[project = $proj_mut_ident:ident] - $($tt:tt)* - ) => { - $crate::__pin_project_internal! { - [$proj_mut_ident] - [$($proj_ref_ident)?] - [$($proj_replace_ident)?] - [$($attrs)*] - $($tt)* - } - }; - - // parsing proj_ref_ident - { [$($proj_mut_ident:ident)?] - [] + [$($proj_ref_ident:ident)?] [$($proj_replace_ident:ident)?] - [$($attrs:tt)*] - #[project_ref = $proj_ref_ident:ident] - $($tt:tt)* - } => { - $crate::__pin_project_internal! { - [$($proj_mut_ident)?] - [$proj_ref_ident] - [$($proj_replace_ident)?] - [$($attrs)*] - $($tt)* + $(#[$attrs:meta])* + pub struct $ident:ident $(< + $( $lifetime:lifetime $(: $lifetime_bound:lifetime)? ),* $(,)? + $( $generics:ident + $(: $generics_bound:path)? + $(: ?$generics_unsized_bound:path)? + $(: $generics_lifetime_bound:lifetime)? + $(= $generics_default:ty)? + ),* $(,)? + >)? + $(where + $( $where_clause_ty:ty + $(: $where_clause_bound:path)? + $(: ?$where_clause_unsized_bound:path)? + $(: $where_clause_lifetime_bound:lifetime)? + ),* $(,)? + )? + { + $( + $(#[$pin:ident])? + $field_vis:vis $field:ident: $field_ty:ty + ),+ $(,)? } - }; - - // parsing proj_replace_ident - { - [$($proj_mut_ident:ident)?] - [$($proj_ref_ident:ident)?] - [] - [$($attrs:tt)*] - - #[project_replace = $proj_replace_ident:ident] - $($tt:tt)* - } => { - $crate::__pin_project_internal! { + ) => { + $crate::__pin_project_internal! { @struct=>internal; [$($proj_mut_ident)?] [$($proj_ref_ident)?] - [$proj_replace_ident] - [$($attrs)*] - $($tt)* + [$($proj_replace_ident)?] + [pub(crate)] + [$(#[$attrs])* pub struct $ident] + [$(< + $( $lifetime $(: $lifetime_bound)? ,)* + $( $generics + $(: $generics_bound)? + $(: ?$generics_unsized_bound)? + $(: $generics_lifetime_bound)? + $(= $generics_default)? + ),* + >)?] + [$( + $( $lifetime $(: $lifetime_bound)? ,)* + $( $generics + $(: $generics_bound)? + $(: ?$generics_unsized_bound)? + $(: $generics_lifetime_bound)? + ),* + )?] + [$( $( $lifetime ,)* $( $generics ),* )?] + [$(where $( $where_clause_ty + $(: $where_clause_bound)? + $(: ?$where_clause_unsized_bound)? + $(: $where_clause_lifetime_bound)? + ),* )?] + { + $( + $(#[$pin])? + $field_vis $field: $field_ty + ),+ + } } }; - - // this is actually part of a recursive step that picks off a single non-`pin_project_lite` attribute - // there could be more to parse - { + ( [$($proj_mut_ident:ident)?] [$($proj_ref_ident:ident)?] [$($proj_replace_ident:ident)?] - [$($attrs:tt)*] - #[$($attr:tt)*] - $($tt:tt)* - } => { - $crate::__pin_project_internal! { - [$($proj_mut_ident)?] - [$($proj_ref_ident)?] - [$($proj_replace_ident)?] - [$($attrs)* #[$($attr)*]] - $($tt)* + $(#[$attrs:meta])* + $vis:vis struct $ident:ident $(< + $( $lifetime:lifetime $(: $lifetime_bound:lifetime)? ),* $(,)? + $( $generics:ident + $(: $generics_bound:path)? + $(: ?$generics_unsized_bound:path)? + $(: $generics_lifetime_bound:lifetime)? + $(= $generics_default:ty)? + ),* $(,)? + >)? + $(where + $( $where_clause_ty:ty + $(: $where_clause_bound:path)? + $(: ?$where_clause_unsized_bound:path)? + $(: $where_clause_lifetime_bound:lifetime)? + ),* $(,)? + )? + { + $( + $(#[$pin:ident])? + $field_vis:vis $field:ident: $field_ty:ty + ),+ $(,)? } - }; - - // now determine visibility - // if public, downgrade - { - [$($proj_mut_ident:ident)?] - [$($proj_ref_ident:ident)?] - [$($proj_replace_ident:ident)?] - [$($attrs:tt)*] - pub $struct_ty_ident:ident $ident:ident - $($tt:tt)* - } => { - $crate::__pin_project_internal! { + ) => { + $crate::__pin_project_internal! { @struct=>internal; [$($proj_mut_ident)?] [$($proj_ref_ident)?] [$($proj_replace_ident)?] - [$($attrs)*] - [pub $struct_ty_ident $ident pub(crate)] - $($tt)* + [$vis] + [$(#[$attrs])* $vis struct $ident] + [$(< + $( $lifetime $(: $lifetime_bound)? ,)* + $( $generics + $(: $generics_bound)? + $(: ?$generics_unsized_bound)? + $(: $generics_lifetime_bound)? + $(= $generics_default)? + ),* + >)?] + [$( + $( $lifetime $(: $lifetime_bound)? ,)* + $( $generics + $(: $generics_bound)? + $(: ?$generics_unsized_bound)? + $(: $generics_lifetime_bound)? + ),* + )?] + [$( $( $lifetime ,)* $( $generics ),* )?] + [$(where $( $where_clause_ty + $(: $where_clause_bound)? + $(: ?$where_clause_unsized_bound)? + $(: $where_clause_lifetime_bound)? + ),* )?] + { + $( + $(#[$pin])? + $field_vis $field: $field_ty + ),+ + } } }; - { + // enum + ( [$($proj_mut_ident:ident)?] [$($proj_ref_ident:ident)?] [$($proj_replace_ident:ident)?] - [$($attrs:tt)*] - $vis:vis $struct_ty_ident:ident $ident:ident - $($tt:tt)* - } => { - $crate::__pin_project_internal! { + + $(#[$attrs:meta])* + pub enum $ident:ident $(< + $( $lifetime:lifetime $(: $lifetime_bound:lifetime)? ),* $(,)? + $( $generics:ident + $(: $generics_bound:path)? + $(: ?$generics_unsized_bound:path)? + $(: $generics_lifetime_bound:lifetime)? + $(= $generics_default:ty)? + ),* $(,)? + >)? + $(where + $( $where_clause_ty:ty + $(: $where_clause_bound:path)? + $(: ?$where_clause_unsized_bound:path)? + $(: $where_clause_lifetime_bound:lifetime)? + ),* $(,)? + )? + { + $( + $(#[$variant_attrs:meta])* + $variant:ident $({ + $( + $(#[$pin:ident])? + $field:ident: $field_ty:ty + ),+ $(,)? + })? + ),+ $(,)? + } + ) => { + $crate::__pin_project_internal! { @enum=>internal; [$($proj_mut_ident)?] [$($proj_ref_ident)?] [$($proj_replace_ident)?] - [$($attrs)*] - [$vis $struct_ty_ident $ident $vis] - $($tt)* + [pub(crate)] + [$(#[$attrs])* pub enum $ident] + [$(< + $( $lifetime $(: $lifetime_bound)? ,)* + $( $generics + $(: $generics_bound)? + $(: ?$generics_unsized_bound)? + $(: $generics_lifetime_bound)? + $(= $generics_default)? + ),* + >)?] + [$( + $( $lifetime $(: $lifetime_bound)? ,)* + $( $generics + $(: $generics_bound)? + $(: ?$generics_unsized_bound)? + $(: $generics_lifetime_bound)? + ),* + )?] + [$( $( $lifetime ,)* $( $generics ),* )?] + [$(where $( $where_clause_ty + $(: $where_clause_bound)? + $(: ?$where_clause_unsized_bound)? + $(: $where_clause_lifetime_bound)? + ),* )?] + { + $( + $(#[$variant_attrs])* + $variant $({ + $( + $(#[$pin])? + $field: $field_ty + ),+ + })? + ),+ + } } }; - // parse generics ( [$($proj_mut_ident:ident)?] [$($proj_ref_ident:ident)?] [$($proj_replace_ident:ident)?] - [$($attrs:tt)*] - [$vis:vis $struct_ty_ident:ident $ident:ident $proj_ty_vis:vis] - $(< + + $(#[$attrs:meta])* + $vis:vis enum $ident:ident $(< $( $lifetime:lifetime $(: $lifetime_bound:lifetime)? ),* $(,)? $( $generics:ident $(: $generics_bound:path)? @@ -1458,16 +1637,23 @@ macro_rules! __pin_project_internal { ),* $(,)? )? { - $($body_data:tt)* + $( + $(#[$variant_attrs:meta])* + $variant:ident $({ + $( + $(#[$pin:ident])? + $field:ident: $field_ty:ty + ),+ $(,)? + })? + ),+ $(,)? } - $(impl $($pinned_drop:tt)*)? ) => { - $crate::__pin_project_internal! { @expand; + $crate::__pin_project_internal! { @enum=>internal; [$($proj_mut_ident)?] [$($proj_ref_ident)?] [$($proj_replace_ident)?] - [$proj_ty_vis] - [$($attrs)* $vis $struct_ty_ident $ident] + [$vis] + [$(#[$attrs])* $vis enum $ident] [$(< $( $lifetime $(: $lifetime_bound)? ,)* $( $generics @@ -1492,9 +1678,16 @@ macro_rules! __pin_project_internal { $(: $where_clause_lifetime_bound)? ),* )?] { - $($body_data)* + $( + $(#[$variant_attrs])* + $variant $({ + $( + $(#[$pin])? + $field: $field_ty + ),+ + })? + ),+ } - $(impl $($pinned_drop)*)? } }; } @@ -1502,10 +1695,10 @@ macro_rules! __pin_project_internal { // Not public API. #[doc(hidden)] pub mod __private { - use core::mem::ManuallyDrop; #[doc(hidden)] pub use core::{ marker::{PhantomData, Unpin}, + mem::ManuallyDrop, ops::Drop, pin::Pin, ptr, @@ -1519,14 +1712,7 @@ pub mod __private { // This is an internal helper used to ensure a value is dropped. #[doc(hidden)] - pub struct UnsafeDropInPlaceGuard<T: ?Sized>(*mut T); - - impl<T: ?Sized> UnsafeDropInPlaceGuard<T> { - #[doc(hidden)] - pub unsafe fn new(ptr: *mut T) -> Self { - Self(ptr) - } - } + pub struct UnsafeDropInPlaceGuard<T: ?Sized>(pub *mut T); impl<T: ?Sized> Drop for UnsafeDropInPlaceGuard<T> { fn drop(&mut self) { @@ -1540,15 +1726,8 @@ pub mod __private { // its destructor being called. #[doc(hidden)] pub struct UnsafeOverwriteGuard<T> { - target: *mut T, - value: ManuallyDrop<T>, - } - - impl<T> UnsafeOverwriteGuard<T> { - #[doc(hidden)] - pub unsafe fn new(target: *mut T, value: T) -> Self { - Self { target, value: ManuallyDrop::new(value) } - } + pub value: ManuallyDrop<T>, + pub target: *mut T, } impl<T> Drop for UnsafeOverwriteGuard<T> { diff --git a/src/lib.rs.orig b/src/lib.rs.orig new file mode 100644 index 0000000..ff1e3bf --- /dev/null +++ b/src/lib.rs.orig @@ -0,0 +1,1737 @@ +//! A lightweight version of [pin-project] written with declarative macros. +//! +//! # Examples +//! +//! [`pin_project!`] macro creates a projection type covering all the fields of struct. +//! +//! ```rust +//! use pin_project_lite::pin_project; +//! use std::pin::Pin; +//! +//! pin_project! { +//! struct Struct<T, U> { +//! #[pin] +//! pinned: T, +//! unpinned: U, +//! } +//! } +//! +//! impl<T, U> Struct<T, U> { +//! fn method(self: Pin<&mut Self>) { +//! let this = self.project(); +//! let _: Pin<&mut T> = this.pinned; // Pinned reference to the field +//! let _: &mut U = this.unpinned; // Normal reference to the field +//! } +//! } +//! ``` +//! +//! To use [`pin_project!`] on enums, you need to name the projection type +//! returned from the method. +//! +//! ```rust +//! use pin_project_lite::pin_project; +//! use std::pin::Pin; +//! +//! pin_project! { +//! #[project = EnumProj] +//! enum Enum<T, U> { +//! Variant { #[pin] pinned: T, unpinned: U }, +//! } +//! } +//! +//! impl<T, U> Enum<T, U> { +//! fn method(self: Pin<&mut Self>) { +//! match self.project() { +//! EnumProj::Variant { pinned, unpinned } => { +//! let _: Pin<&mut T> = pinned; +//! let _: &mut U = unpinned; +//! } +//! } +//! } +//! } +//! ``` +//! +//! # [pin-project] vs pin-project-lite +//! +//! Here are some similarities and differences compared to [pin-project]. +//! +//! ## Similar: Safety +//! +//! pin-project-lite guarantees safety in much the same way as [pin-project]. +//! Both are completely safe unless you write other unsafe code. +//! +//! ## Different: Minimal design +//! +//! This library does not tackle as expansive of a range of use cases as +//! [pin-project] does. If your use case is not already covered, please use +//! [pin-project]. +//! +//! ## Different: No proc-macro related dependencies +//! +//! This is the **only** reason to use this crate. However, **if you already +//! have proc-macro related dependencies in your crate's dependency graph, there +//! is no benefit from using this crate.** (Note: There is almost no difference +//! in the amount of code generated between [pin-project] and pin-project-lite.) +//! +//! ## Different: No useful error messages +//! +//! This macro does not handle any invalid input. So error messages are not to +//! 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]. +//! +//! ## Different: No support for tuple structs and tuple variants +//! +//! pin-project supports this. +//! +//! [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] +#![doc(test( + no_crate_inject, + attr( + deny(warnings, rust_2018_idioms, single_use_lifetimes), + allow(dead_code, unused_variables) + ) +))] +#![warn(future_incompatible, rust_2018_idioms, single_use_lifetimes, unreachable_pub)] +#![warn(clippy::all, clippy::default_trait_access)] + +/// A macro that creates a projection type covering all the fields of struct. +/// +/// This macro creates a projection type according to the following rules: +/// +/// * For the field that uses `#[pin]` attribute, makes the pinned reference to the field. +/// * For the other fields, makes the unpinned reference to the field. +/// +/// And the following methods are implemented on the original type: +/// +/// ```rust +/// # use std::pin::Pin; +/// # type Projection<'a> = &'a (); +/// # type ProjectionRef<'a> = &'a (); +/// # trait Dox { +/// fn project(self: Pin<&mut Self>) -> Projection<'_>; +/// fn project_ref(self: Pin<&Self>) -> ProjectionRef<'_>; +/// # } +/// ``` +/// +/// By passing an attribute with the same name as the method to the macro, +/// you can name the projection type returned from the method. This allows you +/// to use pattern matching on the projected types. +/// +/// ```rust +/// # use pin_project_lite::pin_project; +/// # use std::pin::Pin; +/// pin_project! { +/// #[project = EnumProj] +/// enum Enum<T> { +/// Variant { #[pin] field: T }, +/// } +/// } +/// +/// impl<T> Enum<T> { +/// fn method(self: Pin<&mut Self>) { +/// let this: EnumProj<'_, T> = self.project(); +/// match this { +/// EnumProj::Variant { field } => { +/// let _: Pin<&mut T> = field; +/// } +/// } +/// } +/// } +/// ``` +/// +/// By passing the `#[project_replace = MyProjReplace]` attribute you may create an additional +/// method which allows the contents of `Pin<&mut Self>` to be replaced while simultaneously moving +/// out all unpinned fields in `Self`. +/// +/// ```rust +/// # use std::pin::Pin; +/// # type MyProjReplace = (); +/// # trait Dox { +/// fn project_replace(self: Pin<&mut Self>, replacement: Self) -> MyProjReplace; +/// # } +/// ``` +/// +/// The `#[project]` (and `#[project_ref]`) attribute must precede the other +/// attributes except for `#[doc]`. For example, the following code will not be compiled: +/// +/// ```rust,compile_fail +/// # use pin_project_lite::pin_project; +/// # use std::pin::Pin; +/// pin_project! { +/// /// documents (`#[doc]`) can be placed before `#[project]`. +/// #[derive(Clone)] // <--- ERROR +/// #[project = EnumProj] +/// #[derive(Debug)] // <--- Ok +/// enum Enum<T> { +/// Variant { #[pin] field: T }, +/// } +/// } +/// ``` +/// +/// Also, note that the projection types returned by `project` and `project_ref` have +/// an additional lifetime at the beginning of generics. +/// +/// ```text +/// let this: EnumProj<'_, T> = self.project(); +/// ^^ +/// ``` +/// +/// The visibility of the projected types and projection methods is based on the +/// original type. However, if the visibility of the original type is `pub`, the +/// visibility of the projected types and the projection methods is downgraded +/// to `pub(crate)`. +/// +/// # Safety +/// +/// `pin_project!` macro guarantees safety in much the same way as [pin-project] crate. +/// Both are completely safe unless you write other unsafe code. +/// +/// See [pin-project] crate for more details. +/// +/// # Examples +/// +/// ```rust +/// use pin_project_lite::pin_project; +/// use std::pin::Pin; +/// +/// pin_project! { +/// struct Struct<T, U> { +/// #[pin] +/// pinned: T, +/// unpinned: U, +/// } +/// } +/// +/// impl<T, U> Struct<T, U> { +/// fn method(self: Pin<&mut Self>) { +/// let this = self.project(); +/// let _: Pin<&mut T> = this.pinned; // Pinned reference to the field +/// let _: &mut U = this.unpinned; // Normal reference to the field +/// } +/// } +/// ``` +/// +/// To use `pin_project!` on enums, you need to name the projection type +/// returned from the method. +/// +/// ```rust +/// use pin_project_lite::pin_project; +/// use std::pin::Pin; +/// +/// pin_project! { +/// #[project = EnumProj] +/// enum Enum<T> { +/// Struct { +/// #[pin] +/// field: T, +/// }, +/// Unit, +/// } +/// } +/// +/// impl<T> Enum<T> { +/// fn method(self: Pin<&mut Self>) { +/// match self.project() { +/// EnumProj::Struct { field } => { +/// let _: Pin<&mut T> = field; +/// } +/// EnumProj::Unit => {} +/// } +/// } +/// } +/// ``` +/// +/// If you want to call the `project()` method multiple times or later use the +/// original [`Pin`] type, it needs to use [`.as_mut()`][`Pin::as_mut`] to avoid +/// consuming the [`Pin`]. +/// +/// ```rust +/// use pin_project_lite::pin_project; +/// use std::pin::Pin; +/// +/// pin_project! { +/// struct Struct<T> { +/// #[pin] +/// field: T, +/// } +/// } +/// +/// impl<T> Struct<T> { +/// fn call_project_twice(mut self: Pin<&mut Self>) { +/// // `project` consumes `self`, so reborrow the `Pin<&mut Self>` via `as_mut`. +/// self.as_mut().project(); +/// self.as_mut().project(); +/// } +/// } +/// ``` +/// +/// # `!Unpin` +/// +/// If you want to ensure that [`Unpin`] is not implemented, use `#[pin]` +/// attribute for a [`PhantomPinned`] field. +/// +/// ```rust +/// use pin_project_lite::pin_project; +/// use std::marker::PhantomPinned; +/// +/// pin_project! { +/// struct Struct<T> { +/// field: T, +/// #[pin] // <------ This `#[pin]` is required to make `Struct` to `!Unpin`. +/// _pin: PhantomPinned, +/// } +/// } +/// ``` +/// +/// Note that using [`PhantomPinned`] without `#[pin]` attribute has no effect. +/// +/// [`PhantomPinned`]: core::marker::PhantomPinned +/// [`Pin::as_mut`]: core::pin::Pin::as_mut +/// [`Pin`]: core::pin::Pin +/// [pin-project]: https://github.com/taiki-e/pin-project +#[macro_export] +macro_rules! pin_project { + // Parses options + ( + $(#[doc $($doc:tt)*])* + #[project = $proj_mut_ident:ident] + #[project_ref = $proj_ref_ident:ident] + #[project_replace = $proj_replace_ident:ident] + $($tt:tt)* + ) => { + $crate::__pin_project_internal! { + [$proj_mut_ident][$proj_ref_ident][$proj_replace_ident] + $(#[doc $($doc)*])* + $($tt)* + } + }; + ( + $(#[doc $($doc:tt)*])* + #[project = $proj_mut_ident:ident] + #[project_ref = $proj_ref_ident:ident] + $($tt:tt)* + ) => { + $crate::__pin_project_internal! { + [$proj_mut_ident][$proj_ref_ident][] + $(#[doc $($doc)*])* + $($tt)* + } + }; + ( + $(#[doc $($doc:tt)*])* + #[project = $proj_mut_ident:ident] + #[project_replace = $proj_replace_ident:ident] + $($tt:tt)* + ) => { + $crate::__pin_project_internal! { + [$proj_mut_ident][][$proj_replace_ident] + $(#[doc $($doc)*])* + $($tt)* + } + }; + ( + $(#[doc $($doc:tt)*])* + #[project_ref = $proj_ref_ident:ident] + #[project_replace = $proj_replace_ident:ident] + $($tt:tt)* + ) => { + $crate::__pin_project_internal! { + [][$proj_ref_ident][$proj_replace_ident] + $(#[doc $($doc)*])* + $($tt)* + } + }; + ( + $(#[doc $($doc:tt)*])* + #[project = $proj_mut_ident:ident] + $($tt:tt)* + ) => { + $crate::__pin_project_internal! { + [$proj_mut_ident][][] + $(#[doc $($doc)*])* + $($tt)* + } + }; + ( + $(#[doc $($doc:tt)*])* + #[project_ref = $proj_ref_ident:ident] + $($tt:tt)* + ) => { + $crate::__pin_project_internal! { + [][$proj_ref_ident][] + $(#[doc $($doc)*])* + $($tt)* + } + }; + ( + $(#[doc $($doc:tt)*])* + #[project_replace = $proj_replace_ident:ident] + $($tt:tt)* + ) => { + $crate::__pin_project_internal! { + [][][$proj_replace_ident] + $(#[doc $($doc)*])* + $($tt)* + } + }; + ( + $($tt:tt)* + ) => { + $crate::__pin_project_internal! { + [][][] + $($tt)* + } + }; +} + +// limitations: +// * no support for tuple structs and tuple variant (wontfix). +// * no support for multiple trait/lifetime bounds. +// * no support for `Self` in where clauses. (wontfix) +// * no support for overlapping lifetime names. (wontfix) +// * no interoperability with other field attributes. +// * no useful error messages. (wontfix) +// etc... + +// Not public API. +#[doc(hidden)] +#[macro_export] +macro_rules! __pin_project_internal { + // ============================================================================================= + // struct:main + (@struct=>internal; + [$($proj_mut_ident:ident)?] + [$($proj_ref_ident:ident)?] + [$($proj_replace_ident:ident)?] + [$proj_vis:vis] + [$(#[$attrs:meta])* $vis:vis struct $ident:ident] + [$($def_generics:tt)*] + [$($impl_generics:tt)*] [$($ty_generics:tt)*] [$(where $($where_clause:tt)*)?] + { + $( + $(#[$pin:ident])? + $field_vis:vis $field:ident: $field_ty:ty + ),+ + } + ) => { + $(#[$attrs])* + $vis struct $ident $($def_generics)* + $(where + $($where_clause)*)? + { + $( + $field_vis $field: $field_ty + ),+ + } + + $crate::__pin_project_internal! { @struct=>make_proj_ty=>named; + [$proj_vis] + [$($proj_mut_ident)?] + [make_proj_field_mut] + [$ident] + [$($impl_generics)*] [$($ty_generics)*] [$(where $($where_clause)*)?] + { + $( + $(#[$pin])? + $field_vis $field: $field_ty + ),+ + } + } + $crate::__pin_project_internal! { @struct=>make_proj_ty=>named; + [$proj_vis] + [$($proj_ref_ident)?] + [make_proj_field_ref] + [$ident] + [$($impl_generics)*] [$($ty_generics)*] [$(where $($where_clause)*)?] + { + $( + $(#[$pin])? + $field_vis $field: $field_ty + ),+ + } + } + $crate::__pin_project_internal! { @struct=>make_proj_replace_ty=>named; + [$proj_vis] + [$($proj_replace_ident)?] + [make_proj_field_replace] + [$ident] + [$($impl_generics)*] [$($ty_generics)*] [$(where $($where_clause)*)?] + { + $( + $(#[$pin])? + $field_vis $field: $field_ty + ),+ + } + } + + #[allow(explicit_outlives_requirements)] // https://github.com/rust-lang/rust/issues/60993 + #[allow(single_use_lifetimes)] // https://github.com/rust-lang/rust/issues/55058 + // This lint warns of `clippy::*` generated by external macros. + // We allow this lint for compatibility with older compilers. + #[allow(clippy::unknown_clippy_lints)] + #[allow(clippy::redundant_pub_crate)] // This lint warns `pub(crate)` field in private struct. + #[allow(clippy::used_underscore_binding)] + const _: () = { + $crate::__pin_project_internal! { @struct=>make_proj_ty=>unnamed; + [$proj_vis] + [$($proj_mut_ident)?][Projection] + [make_proj_field_mut] + [$ident] + [$($impl_generics)*] [$($ty_generics)*] [$(where $($where_clause)*)?] + { + $( + $(#[$pin])? + $field_vis $field: $field_ty + ),+ + } + } + $crate::__pin_project_internal! { @struct=>make_proj_ty=>unnamed; + [$proj_vis] + [$($proj_ref_ident)?][ProjectionRef] + [make_proj_field_ref] + [$ident] + [$($impl_generics)*] [$($ty_generics)*] [$(where $($where_clause)*)?] + { + $( + $(#[$pin])? + $field_vis $field: $field_ty + ),+ + } + } + $crate::__pin_project_internal! { @struct=>make_proj_replace_ty=>unnamed; + [$proj_vis] + [$($proj_replace_ident)?][ProjectionReplace] + [make_proj_field_replace] + [$ident] + [$($impl_generics)*] [$($ty_generics)*] [$(where $($where_clause)*)?] + { + $( + $(#[$pin])? + $field_vis $field: $field_ty + ),+ + } + } + + impl <$($impl_generics)*> $ident <$($ty_generics)*> + $(where + $($where_clause)*)? + { + $crate::__pin_project_internal! { @struct=>make_proj_method; + [$proj_vis] + [$($proj_mut_ident)?][Projection] + [project get_unchecked_mut mut] + [$($ty_generics)*] + { + $( + $(#[$pin])? + $field_vis $field + ),+ + } + } + $crate::__pin_project_internal! { @struct=>make_proj_method; + [$proj_vis] + [$($proj_ref_ident)?][ProjectionRef] + [project_ref get_ref] + [$($ty_generics)*] + { + $( + $(#[$pin])? + $field_vis $field + ),+ + } + } + $crate::__pin_project_internal! { @struct=>make_proj_replace_method; + [$proj_vis] + [$($proj_replace_ident)?][ProjectionReplace] + [$($ty_generics)*] + { + $( + $(#[$pin])? + $field_vis $field + ),+ + } + } + } + + $crate::__pin_project_internal! { @make_unpin_impl; + [$vis $ident] + [$($impl_generics)*] [$($ty_generics)*] [$(where $($where_clause)*)?] + $( + $field: $crate::__pin_project_internal!(@make_unpin_bound; + $(#[$pin])? $field_ty + ) + ),+ + } + + $crate::__pin_project_internal! { @make_drop_impl; + [$ident] + [$($impl_generics)*] [$($ty_generics)*] [$(where $($where_clause)*)?] + } + + // Ensure that it's impossible to use pin projections on a #[repr(packed)] struct. + // + // Taking a reference to a packed field is unsafe, amd appplying + // #[forbid(safe_packed_borrows)] makes sure that doing this without + // an 'unsafe' block (which we deliberately do not generate) + // is a hard error. + // + // If the struct ends up having #[repr(packed)] applied somehow, + // this will generate an (unfriendly) error message. Under all reasonable + // circumstances, we'll detect the #[repr(packed)] attribute, and generate + // a much nicer error above. + // + // See https://github.com/taiki-e/pin-project/pull/34 for more details. + #[forbid(safe_packed_borrows)] + fn __assert_not_repr_packed <$($impl_generics)*> (this: &$ident <$($ty_generics)*>) + $(where + $($where_clause)*)? + { + $( + let _ = &this.$field; + )+ + } + }; + }; + // ============================================================================================= + // enum:main + (@enum=>internal; + [$($proj_mut_ident:ident)?] + [$($proj_ref_ident:ident)?] + [$($proj_replace_ident:ident)?] + [$proj_vis:vis] + [$(#[$attrs:meta])* $vis:vis enum $ident:ident] + [$($def_generics:tt)*] + [$($impl_generics:tt)*] [$($ty_generics:tt)*] [$(where $($where_clause:tt)*)?] + { + $( + $(#[$variant_attrs:meta])* + $variant:ident $({ + $( + $(#[$pin:ident])? + $field:ident: $field_ty:ty + ),+ + })? + ),+ + } + ) => { + $(#[$attrs])* + $vis enum $ident $($def_generics)* + $(where + $($where_clause)*)? + { + $( + $(#[$variant_attrs])* + $variant $({ + $( + $field: $field_ty + ),+ + })? + ),+ + } + + $crate::__pin_project_internal! { @enum=>make_proj_ty; + [$proj_vis] + [$($proj_mut_ident)?] + [make_proj_field_mut] + [$ident] + [$($impl_generics)*] [$($ty_generics)*] [$(where $($where_clause)*)?] + { + $( + $variant $({ + $( + $(#[$pin])? + $field: $field_ty + ),+ + })? + ),+ + } + } + $crate::__pin_project_internal! { @enum=>make_proj_ty; + [$proj_vis] + [$($proj_ref_ident)?] + [make_proj_field_ref] + [$ident] + [$($impl_generics)*] [$($ty_generics)*] [$(where $($where_clause)*)?] + { + $( + $variant $({ + $( + $(#[$pin])? + $field: $field_ty + ),+ + })? + ),+ + } + } + $crate::__pin_project_internal! { @enum=>make_proj_replace_ty; + [$proj_vis] + [$($proj_replace_ident)?] + [make_proj_field_replace] + [$ident] + [$($impl_generics)*] [$($ty_generics)*] [$(where $($where_clause)*)?] + { + $( + $variant $({ + $( + $(#[$pin])? + $field: $field_ty + ),+ + })? + ),+ + } + } + + #[allow(single_use_lifetimes)] // https://github.com/rust-lang/rust/issues/55058 + // This lint warns of `clippy::*` generated by external macros. + // We allow this lint for compatibility with older compilers. + #[allow(clippy::unknown_clippy_lints)] + #[allow(clippy::used_underscore_binding)] + const _: () = { + impl <$($impl_generics)*> $ident <$($ty_generics)*> + $(where + $($where_clause)*)? + { + $crate::__pin_project_internal! { @enum=>make_proj_method; + [$proj_vis] + [$($proj_mut_ident)?] + [project get_unchecked_mut mut] + [$($ty_generics)*] + { + $( + $variant $({ + $( + $(#[$pin])? + $field + ),+ + })? + ),+ + } + } + $crate::__pin_project_internal! { @enum=>make_proj_method; + [$proj_vis] + [$($proj_ref_ident)?] + [project_ref get_ref] + [$($ty_generics)*] + { + $( + $variant $({ + $( + $(#[$pin])? + $field + ),+ + })? + ),+ + } + } + $crate::__pin_project_internal! { @enum=>make_proj_replace_method; + [$proj_vis] + [$($proj_replace_ident)?] + [$($ty_generics)*] + { + $( + $variant $({ + $( + $(#[$pin])? + $field + ),+ + })? + ),+ + } + } + } + + $crate::__pin_project_internal! { @make_unpin_impl; + [$vis $ident] + [$($impl_generics)*] [$($ty_generics)*] [$(where $($where_clause)*)?] + $( + $variant: ($( + $( + $crate::__pin_project_internal!(@make_unpin_bound; + $(#[$pin])? $field_ty + ) + ),+ + )?) + ),+ + } + + $crate::__pin_project_internal! { @make_drop_impl; + [$ident] + [$($impl_generics)*] [$($ty_generics)*] [$(where $($where_clause)*)?] + } + + // We don't need to check for '#[repr(packed)]', + // since it does not apply to enums. + }; + }; + + // ============================================================================================= + // struct:make_proj_ty + (@struct=>make_proj_ty=>unnamed; + [$proj_vis:vis] + [$_proj_ty_ident:ident][$proj_ty_ident:ident] + [$make_proj_field:ident] + [$ident:ident] + [$($impl_generics:tt)*] [$($ty_generics:tt)*] [$(where $($where_clause:tt)* )?] + $($field:tt)* + ) => {}; + (@struct=>make_proj_ty=>unnamed; + [$proj_vis:vis] + [][$proj_ty_ident:ident] + [$make_proj_field:ident] + [$ident:ident] + [$($impl_generics:tt)*] [$($ty_generics:tt)*] [$(where $($where_clause:tt)* )?] + $($field:tt)* + ) => { + $crate::__pin_project_internal! { @struct=>make_proj_ty=>named; + [$proj_vis] + [$proj_ty_ident] + [$make_proj_field] + [$ident] + [$($impl_generics)*] [$($ty_generics)*] [$(where $($where_clause)*)?] + $($field)* + } + }; + (@struct=>make_proj_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])? + $field_vis:vis $field:ident: $field_ty:ty + ),+ + } + ) => { + #[allow(dead_code)] // This lint warns unused fields/variants. + #[allow(single_use_lifetimes)] // https://github.com/rust-lang/rust/issues/55058 + // This lint warns of `clippy::*` generated by external macros. + // We allow this lint for compatibility with older compilers. + #[allow(clippy::unknown_clippy_lints)] + #[allow(clippy::mut_mut)] // This lint warns `&mut &mut <ty>`. (only needed for project) + #[allow(clippy::redundant_pub_crate)] // This lint warns `pub(crate)` field in private struct. + #[allow(clippy::ref_option_ref)] // This lint warns `&Option<&<ty>>`. (only needed for project_ref) + #[allow(clippy::type_repetition_in_bounds)] // https://github.com/rust-lang/rust-clippy/issues/4326 + $proj_vis struct $proj_ty_ident <'__pin, $($impl_generics)*> + where + $ident <$($ty_generics)*>: '__pin + $(, $($where_clause)*)? + { + $( + $field_vis $field: $crate::__pin_project_internal!(@$make_proj_field; + $(#[$pin])? $field_ty + ) + ),+ + } + }; + (@struct=>make_proj_ty=>named; + [$proj_vis:vis] + [] + [$make_proj_field:ident] + [$ident:ident] + [$($impl_generics:tt)*] [$($ty_generics:tt)*] [$(where $($where_clause:tt)* )?] + $($field:tt)* + ) => {}; + + (@struct=>make_proj_replace_ty=>unnamed; + [$proj_vis:vis] + [$_proj_ty_ident:ident][$proj_ty_ident:ident] + [$make_proj_field:ident] + [$ident:ident] + [$($impl_generics:tt)*] [$($ty_generics:tt)*] [$(where $($where_clause:tt)* )?] + $($field:tt)* + ) => {}; + (@struct=>make_proj_replace_ty=>unnamed; + [$proj_vis:vis] + [][$proj_ty_ident:ident] + [$make_proj_field:ident] + [$ident:ident] + [$($impl_generics:tt)*] [$($ty_generics:tt)*] [$(where $($where_clause: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])? + $field_vis:vis $field:ident: $field_ty:ty + ),+ + } + ) => { + #[allow(dead_code)] // This lint warns unused fields/variants. + #[allow(single_use_lifetimes)] // https://github.com/rust-lang/rust/issues/55058 + #[allow(clippy::mut_mut)] // This lint warns `&mut &mut <ty>`. (only needed for project) + #[allow(clippy::redundant_pub_crate)] // This lint warns `pub(crate)` field in private struct. + #[allow(clippy::type_repetition_in_bounds)] // https://github.com/rust-lang/rust-clippy/issues/4326 + $proj_vis struct $proj_ty_ident <$($impl_generics)*> + where + $($($where_clause)*)? + { + $( + $field_vis $field: $crate::__pin_project_internal!(@$make_proj_field; + $(#[$pin])? $field_ty + ) + ),+ + } + }; + (@struct=>make_proj_replace_ty=>named; + [$proj_vis:vis] + [] + [$make_proj_field:ident] + [$ident:ident] + [$($impl_generics:tt)*] [$($ty_generics:tt)*] [$(where $($where_clause:tt)* )?] + $($field:tt)* + ) => {}; + // ============================================================================================= + // enum:make_proj_ty + (@enum=>make_proj_ty; + [$proj_vis:vis] + [$proj_ty_ident:ident] + [$make_proj_field:ident] + [$ident:ident] + [$($impl_generics:tt)*] [$($ty_generics:tt)*] [$(where $($where_clause:tt)* )?] + { + $( + $variant:ident $({ + $( + $(#[$pin:ident])? + $field:ident: $field_ty:ty + ),+ + })? + ),+ + } + ) => { + #[allow(dead_code)] // This lint warns unused fields/variants. + #[allow(single_use_lifetimes)] // https://github.com/rust-lang/rust/issues/55058 + // This lint warns of `clippy::*` generated by external macros. + // We allow this lint for compatibility with older compilers. + #[allow(clippy::unknown_clippy_lints)] + #[allow(clippy::mut_mut)] // This lint warns `&mut &mut <ty>`. (only needed for project) + #[allow(clippy::redundant_pub_crate)] // This lint warns `pub(crate)` field in private struct. + #[allow(clippy::ref_option_ref)] // This lint warns `&Option<&<ty>>`. (only needed for project_ref) + #[allow(clippy::type_repetition_in_bounds)] // https://github.com/rust-lang/rust-clippy/issues/4326 + $proj_vis enum $proj_ty_ident <'__pin, $($impl_generics)*> + where + $ident <$($ty_generics)*>: '__pin + $(, $($where_clause)*)? + { + $( + $variant $({ + $( + $field: $crate::__pin_project_internal!(@$make_proj_field; + $(#[$pin])? $field_ty + ) + ),+ + })? + ),+ + } + }; + (@enum=>make_proj_ty; + [$proj_vis:vis] + [] + [$make_proj_field:ident] + [$ident:ident] + [$($impl_generics:tt)*] [$($ty_generics:tt)*] [$(where $($where_clause:tt)* )?] + $($variant:tt)* + ) => {}; + + (@enum=>make_proj_replace_ty; + [$proj_vis:vis] + [$proj_ty_ident:ident] + [$make_proj_field:ident] + [$ident:ident] + [$($impl_generics:tt)*] [$($ty_generics:tt)*] [$(where $($where_clause:tt)* )?] + { + $( + $variant:ident $({ + $( + $(#[$pin:ident])? + $field:ident: $field_ty:ty + ),+ + })? + ),+ + } + ) => { + #[allow(dead_code)] // This lint warns unused fields/variants. + #[allow(single_use_lifetimes)] // https://github.com/rust-lang/rust/issues/55058 + #[allow(clippy::mut_mut)] // This lint warns `&mut &mut <ty>`. (only needed for project) + #[allow(clippy::redundant_pub_crate)] // This lint warns `pub(crate)` field in private struct. + #[allow(clippy::type_repetition_in_bounds)] // https://github.com/rust-lang/rust-clippy/issues/4326 + $proj_vis enum $proj_ty_ident <$($impl_generics)*> + where + $($($where_clause)*)? + { + $( + $variant $({ + $( + $field: $crate::__pin_project_internal!(@$make_proj_field; + $(#[$pin])? $field_ty + ) + ),+ + })? + ),+ + } + }; + (@enum=>make_proj_replace_ty; + [$proj_vis:vis] + [] + [$make_proj_field:ident] + [$ident:ident] + [$($impl_generics:tt)*] [$($ty_generics:tt)*] [$(where $($where_clause:tt)* )?] + $($variant:tt)* + ) => {}; + + // ============================================================================================= + (@make_proj_replace_block; + [$($proj_path: tt)+] + { + $( + $(#[$pin:ident])? + $field_vis:vis $field:ident + ),+ + } + ) => { + let result = $($proj_path)* { + $( + $field: $crate::__pin_project_internal!(@make_replace_field_proj; + $(#[$pin])? $field + ) + ),+ + }; + + { + ( $( + $crate::__pin_project_internal!(@make_unsafe_drop_in_place_guard; + $(#[$pin])? $field + ), + )* ); + } + + result + }; + (@make_proj_replace_block; + [$($proj_path: tt)+] + ) => { + $($proj_path)* + }; + + // ============================================================================================= + // struct:make_proj_method + (@struct=>make_proj_method; + [$proj_vis:vis] + [$proj_ty_ident:ident][$_proj_ty_ident:ident] + [$method_ident:ident $get_method:ident $($mut:ident)?] + [$($ty_generics:tt)*] + { + $( + $(#[$pin:ident])? + $field_vis:vis $field:ident + ),+ + } + ) => { + $proj_vis fn $method_ident<'__pin>( + self: $crate::__private::Pin<&'__pin $($mut)? Self>, + ) -> $proj_ty_ident <'__pin, $($ty_generics)*> { + unsafe { + let Self { $($field),* } = self.$get_method(); + $proj_ty_ident { + $( + $field: $crate::__pin_project_internal!(@make_unsafe_field_proj; + $(#[$pin])? $field + ) + ),+ + } + } + } + }; + (@struct=>make_proj_method; + [$proj_vis:vis] + [][$proj_ty_ident:ident] + [$method_ident:ident $get_method:ident $($mut:ident)?] + [$($ty_generics:tt)*] + $($variant:tt)* + ) => { + $crate::__pin_project_internal! { @struct=>make_proj_method; + [$proj_vis] + [$proj_ty_ident][$proj_ty_ident] + [$method_ident $get_method $($mut)?] + [$($ty_generics)*] + $($variant)* + } + }; + + (@struct=>make_proj_replace_method; + [$proj_vis:vis] + [$proj_ty_ident:ident][$_proj_ty_ident:ident] + [$($ty_generics:tt)*] + { + $( + $(#[$pin:ident])? + $field_vis:vis $field:ident + ),+ + } + ) => { + $proj_vis fn project_replace( + self: $crate::__private::Pin<&mut Self>, + replacement: Self, + ) -> $proj_ty_ident <$($ty_generics)*> { + unsafe { + let __self_ptr: *mut Self = self.get_unchecked_mut(); + + // Destructors will run in reverse order, so next create a guard to overwrite + // `self` with the replacement value without calling destructors. + let __guard = $crate::__private::UnsafeOverwriteGuard { + target: __self_ptr, + value: $crate::__private::ManuallyDrop::new(replacement), + }; + + let Self { $($field),* } = &mut *__self_ptr; + + $crate::__pin_project_internal!{@make_proj_replace_block; + [$proj_ty_ident] + { + $( + $(#[$pin])? + $field + ),+ + } + } + } + } + }; + (@struct=>make_proj_replace_method; + [$proj_vis:vis] + [][$proj_ty_ident:ident] + [$($ty_generics:tt)*] + $($variant:tt)* + ) => { + }; + + // ============================================================================================= + // enum:make_proj_method + (@enum=>make_proj_method; + [$proj_vis:vis] + [$proj_ty_ident:ident] + [$method_ident:ident $get_method:ident $($mut:ident)?] + [$($ty_generics:tt)*] + { + $( + $variant:ident $({ + $( + $(#[$pin:ident])? + $field:ident + ),+ + })? + ),+ + } + ) => { + $proj_vis fn $method_ident<'__pin>( + self: $crate::__private::Pin<&'__pin $($mut)? Self>, + ) -> $proj_ty_ident <'__pin, $($ty_generics)*> { + unsafe { + match self.$get_method() { + $( + Self::$variant $({ + $($field),+ + })? => { + $proj_ty_ident::$variant $({ + $( + $field: $crate::__pin_project_internal!( + @make_unsafe_field_proj; + $(#[$pin])? $field + ) + ),+ + })? + } + ),+ + } + } + } + }; + (@enum=>make_proj_method; + [$proj_vis:vis] + [] + [$method_ident:ident $get_method:ident $($mut:ident)?] + [$($ty_generics:tt)*] + $($variant:tt)* + ) => {}; + + (@enum=>make_proj_replace_method; + [$proj_vis:vis] + [$proj_ty_ident:ident] + [$($ty_generics:tt)*] + { + $( + $variant:ident $({ + $( + $(#[$pin:ident])? + $field:ident + ),+ + })? + ),+ + } + ) => { + $proj_vis fn project_replace( + self: $crate::__private::Pin<&mut Self>, + replacement: Self, + ) -> $proj_ty_ident <$($ty_generics)*> { + unsafe { + let __self_ptr: *mut Self = self.get_unchecked_mut(); + + // Destructors will run in reverse order, so next create a guard to overwrite + // `self` with the replacement value without calling destructors. + let __guard = $crate::__private::UnsafeOverwriteGuard { + target: __self_ptr, + value: $crate::__private::ManuallyDrop::new(replacement), + }; + + match &mut *__self_ptr { + $( + Self::$variant $({ + $($field),+ + })? => { + $crate::__pin_project_internal!{@make_proj_replace_block; + [$proj_ty_ident :: $variant] + $({ + $( + $(#[$pin])? + $field + ),+ + })? + } + } + ),+ + } + } + } + }; + (@enum=>make_proj_replace_method; + [$proj_vis:vis] + [] + [$($ty_generics:tt)*] + $($variant:tt)* + ) => {}; + + // ============================================================================================= + // make_unpin_impl + (@make_unpin_impl; + [$vis:vis $ident:ident] + [$($impl_generics:tt)*] [$($ty_generics:tt)*] [$(where $($where_clause:tt)* )?] + $($field:tt)* + ) => { + // Automatically create the appropriate conditional `Unpin` implementation. + // + // Basically this is equivalent to the following code: + // ```rust + // impl<T, U> Unpin for Struct<T, U> where T: Unpin {} + // ``` + // + // However, if struct is public and there is a private type field, + // this would cause an E0446 (private type in public interface). + // + // When RFC 2145 is implemented (rust-lang/rust#48054), + // 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 + // 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 - + // that is, it will implement Unpin iff all of its fields implement Unpin. + // This type can be safely declared as 'public', satisfiying the privacy + // checker without actually allowing user code to access it. + // + // This allows users to apply the #[pin_project] attribute to types + // regardless of the privacy of the types of their fields. + // + // See also https://github.com/taiki-e/pin-project/pull/53. + #[allow(non_snake_case)] + $vis struct __Origin <'__pin, $($impl_generics)*> + $(where + $($where_clause)*)? + { + __dummy_lifetime: $crate::__private::PhantomData<&'__pin ()>, + $($field)* + } + impl <'__pin, $($impl_generics)*> $crate::__private::Unpin for $ident <$($ty_generics)*> + where + __Origin <'__pin, $($ty_generics)*>: $crate::__private::Unpin + $(, $($where_clause)*)? + { + } + }; + + // ============================================================================================= + // make_drop_impl + (@make_drop_impl; + [$ident:ident] + [$($impl_generics:tt)*] [$($ty_generics:tt)*] [$(where $($where_clause:tt)* )?] + ) => { + // Ensure that struct does not implement `Drop`. + // + // There are two possible cases: + // 1. The user type does not implement Drop. In this case, + // 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. + // This will result in a compilation error, which is exactly what we want. + trait MustNotImplDrop {} + #[allow(clippy::drop_bounds, drop_bounds)] + impl<T: $crate::__private::Drop> MustNotImplDrop for T {} + impl <$($impl_generics)*> MustNotImplDrop for $ident <$($ty_generics)*> + $(where + $($where_clause)*)? + { + } + }; + + // ============================================================================================= + // make_unpin_bound + (@make_unpin_bound; + #[pin] + $field_ty:ty + ) => { + $field_ty + }; + (@make_unpin_bound; + $field_ty:ty + ) => { + $crate::__private::AlwaysUnpin<$field_ty> + }; + + // ============================================================================================= + // make_unsafe_field_proj + (@make_unsafe_field_proj; + #[pin] + $field:ident + ) => { + $crate::__private::Pin::new_unchecked($field) + }; + (@make_unsafe_field_proj; + $field:ident + ) => { + $field + }; + + // ============================================================================================= + // make_replace_field_proj + (@make_replace_field_proj; + #[pin] + $field:ident + ) => { + $crate::__private::PhantomData + }; + (@make_replace_field_proj; + $field:ident + ) => { + $crate::__private::ptr::read($field) + }; + + + // ============================================================================================= + // make_unsafe_drop_in_place_guard + (@make_unsafe_drop_in_place_guard; + #[pin] + $field:ident + ) => { + $crate::__private::UnsafeDropInPlaceGuard($field) + }; + (@make_unsafe_drop_in_place_guard; + $field:ident + ) => { + () + }; + + // ============================================================================================= + // make_proj_field + (@make_proj_field_mut; + #[pin] + $field_ty:ty + ) => { + $crate::__private::Pin<&'__pin mut ($field_ty)> + }; + (@make_proj_field_mut; + $field_ty:ty + ) => { + &'__pin mut ($field_ty) + }; + (@make_proj_field_ref; + #[pin] + $field_ty:ty + ) => { + $crate::__private::Pin<&'__pin ($field_ty)> + }; + (@make_proj_field_ref; + $field_ty:ty + ) => { + &'__pin ($field_ty) + }; + + (@make_proj_field_replace; + #[pin] + $field_ty:ty + ) => { + $crate::__private::PhantomData<$field_ty> + }; + (@make_proj_field_replace; + $field_ty:ty + ) => { + $field_ty + }; + + // ============================================================================================= + // Parses input and determines visibility + // struct + ( + [$($proj_mut_ident:ident)?] + [$($proj_ref_ident:ident)?] + [$($proj_replace_ident:ident)?] + + $(#[$attrs:meta])* + pub struct $ident:ident $(< + $( $lifetime:lifetime $(: $lifetime_bound:lifetime)? ),* $(,)? + $( $generics:ident + $(: $generics_bound:path)? + $(: ?$generics_unsized_bound:path)? + $(: $generics_lifetime_bound:lifetime)? + $(= $generics_default:ty)? + ),* $(,)? + >)? + $(where + $( $where_clause_ty:ty + $(: $where_clause_bound:path)? + $(: ?$where_clause_unsized_bound:path)? + $(: $where_clause_lifetime_bound:lifetime)? + ),* $(,)? + )? + { + $( + $(#[$pin:ident])? + $field_vis:vis $field:ident: $field_ty:ty + ),+ $(,)? + } + ) => { + $crate::__pin_project_internal! { @struct=>internal; + [$($proj_mut_ident)?] + [$($proj_ref_ident)?] + [$($proj_replace_ident)?] + [pub(crate)] + [$(#[$attrs])* pub struct $ident] + [$(< + $( $lifetime $(: $lifetime_bound)? ,)* + $( $generics + $(: $generics_bound)? + $(: ?$generics_unsized_bound)? + $(: $generics_lifetime_bound)? + $(= $generics_default)? + ),* + >)?] + [$( + $( $lifetime $(: $lifetime_bound)? ,)* + $( $generics + $(: $generics_bound)? + $(: ?$generics_unsized_bound)? + $(: $generics_lifetime_bound)? + ),* + )?] + [$( $( $lifetime ,)* $( $generics ),* )?] + [$(where $( $where_clause_ty + $(: $where_clause_bound)? + $(: ?$where_clause_unsized_bound)? + $(: $where_clause_lifetime_bound)? + ),* )?] + { + $( + $(#[$pin])? + $field_vis $field: $field_ty + ),+ + } + } + }; + ( + [$($proj_mut_ident:ident)?] + [$($proj_ref_ident:ident)?] + [$($proj_replace_ident:ident)?] + + $(#[$attrs:meta])* + $vis:vis struct $ident:ident $(< + $( $lifetime:lifetime $(: $lifetime_bound:lifetime)? ),* $(,)? + $( $generics:ident + $(: $generics_bound:path)? + $(: ?$generics_unsized_bound:path)? + $(: $generics_lifetime_bound:lifetime)? + $(= $generics_default:ty)? + ),* $(,)? + >)? + $(where + $( $where_clause_ty:ty + $(: $where_clause_bound:path)? + $(: ?$where_clause_unsized_bound:path)? + $(: $where_clause_lifetime_bound:lifetime)? + ),* $(,)? + )? + { + $( + $(#[$pin:ident])? + $field_vis:vis $field:ident: $field_ty:ty + ),+ $(,)? + } + ) => { + $crate::__pin_project_internal! { @struct=>internal; + [$($proj_mut_ident)?] + [$($proj_ref_ident)?] + [$($proj_replace_ident)?] + [$vis] + [$(#[$attrs])* $vis struct $ident] + [$(< + $( $lifetime $(: $lifetime_bound)? ,)* + $( $generics + $(: $generics_bound)? + $(: ?$generics_unsized_bound)? + $(: $generics_lifetime_bound)? + $(= $generics_default)? + ),* + >)?] + [$( + $( $lifetime $(: $lifetime_bound)? ,)* + $( $generics + $(: $generics_bound)? + $(: ?$generics_unsized_bound)? + $(: $generics_lifetime_bound)? + ),* + )?] + [$( $( $lifetime ,)* $( $generics ),* )?] + [$(where $( $where_clause_ty + $(: $where_clause_bound)? + $(: ?$where_clause_unsized_bound)? + $(: $where_clause_lifetime_bound)? + ),* )?] + { + $( + $(#[$pin])? + $field_vis $field: $field_ty + ),+ + } + } + }; + // enum + ( + [$($proj_mut_ident:ident)?] + [$($proj_ref_ident:ident)?] + [$($proj_replace_ident:ident)?] + + $(#[$attrs:meta])* + pub enum $ident:ident $(< + $( $lifetime:lifetime $(: $lifetime_bound:lifetime)? ),* $(,)? + $( $generics:ident + $(: $generics_bound:path)? + $(: ?$generics_unsized_bound:path)? + $(: $generics_lifetime_bound:lifetime)? + $(= $generics_default:ty)? + ),* $(,)? + >)? + $(where + $( $where_clause_ty:ty + $(: $where_clause_bound:path)? + $(: ?$where_clause_unsized_bound:path)? + $(: $where_clause_lifetime_bound:lifetime)? + ),* $(,)? + )? + { + $( + $(#[$variant_attrs:meta])* + $variant:ident $({ + $( + $(#[$pin:ident])? + $field:ident: $field_ty:ty + ),+ $(,)? + })? + ),+ $(,)? + } + ) => { + $crate::__pin_project_internal! { @enum=>internal; + [$($proj_mut_ident)?] + [$($proj_ref_ident)?] + [$($proj_replace_ident)?] + [pub(crate)] + [$(#[$attrs])* pub enum $ident] + [$(< + $( $lifetime $(: $lifetime_bound)? ,)* + $( $generics + $(: $generics_bound)? + $(: ?$generics_unsized_bound)? + $(: $generics_lifetime_bound)? + $(= $generics_default)? + ),* + >)?] + [$( + $( $lifetime $(: $lifetime_bound)? ,)* + $( $generics + $(: $generics_bound)? + $(: ?$generics_unsized_bound)? + $(: $generics_lifetime_bound)? + ),* + )?] + [$( $( $lifetime ,)* $( $generics ),* )?] + [$(where $( $where_clause_ty + $(: $where_clause_bound)? + $(: ?$where_clause_unsized_bound)? + $(: $where_clause_lifetime_bound)? + ),* )?] + { + $( + $(#[$variant_attrs])* + $variant $({ + $( + $(#[$pin])? + $field: $field_ty + ),+ + })? + ),+ + } + } + }; + ( + [$($proj_mut_ident:ident)?] + [$($proj_ref_ident:ident)?] + [$($proj_replace_ident:ident)?] + + $(#[$attrs:meta])* + $vis:vis enum $ident:ident $(< + $( $lifetime:lifetime $(: $lifetime_bound:lifetime)? ),* $(,)? + $( $generics:ident + $(: $generics_bound:path)? + $(: ?$generics_unsized_bound:path)? + $(: $generics_lifetime_bound:lifetime)? + $(= $generics_default:ty)? + ),* $(,)? + >)? + $(where + $( $where_clause_ty:ty + $(: $where_clause_bound:path)? + $(: ?$where_clause_unsized_bound:path)? + $(: $where_clause_lifetime_bound:lifetime)? + ),* $(,)? + )? + { + $( + $(#[$variant_attrs:meta])* + $variant:ident $({ + $( + $(#[$pin:ident])? + $field:ident: $field_ty:ty + ),+ $(,)? + })? + ),+ $(,)? + } + ) => { + $crate::__pin_project_internal! { @enum=>internal; + [$($proj_mut_ident)?] + [$($proj_ref_ident)?] + [$($proj_replace_ident)?] + [$vis] + [$(#[$attrs])* $vis enum $ident] + [$(< + $( $lifetime $(: $lifetime_bound)? ,)* + $( $generics + $(: $generics_bound)? + $(: ?$generics_unsized_bound)? + $(: $generics_lifetime_bound)? + $(= $generics_default)? + ),* + >)?] + [$( + $( $lifetime $(: $lifetime_bound)? ,)* + $( $generics + $(: $generics_bound)? + $(: ?$generics_unsized_bound)? + $(: $generics_lifetime_bound)? + ),* + )?] + [$( $( $lifetime ,)* $( $generics ),* )?] + [$(where $( $where_clause_ty + $(: $where_clause_bound)? + $(: ?$where_clause_unsized_bound)? + $(: $where_clause_lifetime_bound)? + ),* )?] + { + $( + $(#[$variant_attrs])* + $variant $({ + $( + $(#[$pin])? + $field: $field_ty + ),+ + })? + ),+ + } + } + }; +} + +// Not public API. +#[doc(hidden)] +pub mod __private { + #[doc(hidden)] + pub use core::{ + marker::{PhantomData, Unpin}, + mem::ManuallyDrop, + ops::Drop, + pin::Pin, + ptr, + }; + + // This is an internal helper struct used by `pin_project!`. + #[doc(hidden)] + pub struct AlwaysUnpin<T: ?Sized>(PhantomData<T>); + + impl<T: ?Sized> Unpin for AlwaysUnpin<T> {} + + // This is an internal helper used to ensure a value is dropped. + #[doc(hidden)] + pub struct UnsafeDropInPlaceGuard<T: ?Sized>(pub *mut T); + + impl<T: ?Sized> Drop for UnsafeDropInPlaceGuard<T> { + fn drop(&mut self) { + unsafe { + ptr::drop_in_place(self.0); + } + } + } + + // This is an internal helper used to ensure a value is overwritten without + // its destructor being called. + #[doc(hidden)] + pub struct UnsafeOverwriteGuard<T> { + pub value: ManuallyDrop<T>, + pub target: *mut T, + } + + impl<T> Drop for UnsafeOverwriteGuard<T> { + fn drop(&mut self) { + unsafe { + ptr::write(self.target, ptr::read(&*self.value)); + } + } + } +} diff --git a/tests/README.md b/tests/README.md deleted file mode 100644 index 4721616..0000000 --- a/tests/README.md +++ /dev/null @@ -1,46 +0,0 @@ -# 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 1457099..e39037c 100644 --- a/tests/auxiliary/mod.rs +++ b/tests/auxiliary/mod.rs @@ -1,4 +1,6 @@ #![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 70d2358..5a91b20 100644 --- a/tests/compiletest.rs +++ b/tests/compiletest.rs @@ -3,7 +3,7 @@ use std::env; -#[rustversion::attr(not(nightly), ignore)] +#[rustversion::attr(before(2020-12-03), ignore)] // Note: This date is commit-date and the day before the toolchain date. #[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 6e5deaf..d84c324 100644 --- a/tests/drop_order.rs +++ b/tests/drop_order.rs @@ -2,9 +2,8 @@ // Refs: https://doc.rust-lang.org/reference/destructors.html -use std::{cell::Cell, panic, pin::Pin, thread}; - use pin_project_lite::pin_project; +use std::{cell::Cell, panic, pin::Pin, thread}; struct D<'a>(&'a Cell<usize>, usize); @@ -129,7 +128,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 deleted file mode 100644 index eae0aac..0000000 --- a/tests/expand/default/enum.expanded.rs +++ /dev/null @@ -1,127 +0,0 @@ -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 deleted file mode 100644 index 90d6860..0000000 --- a/tests/expand/default/enum.rs +++ /dev/null @@ -1,17 +0,0 @@ -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 deleted file mode 100644 index 8ab318c..0000000 --- a/tests/expand/default/struct.expanded.rs +++ /dev/null @@ -1,84 +0,0 @@ -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 deleted file mode 100644 index e5447c7..0000000 --- a/tests/expand/default/struct.rs +++ /dev/null @@ -1,11 +0,0 @@ -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 deleted file mode 100644 index fca0feb..0000000 --- a/tests/expand/multifields/enum.expanded.rs +++ /dev/null @@ -1,88 +0,0 @@ -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 deleted file mode 100644 index c713362..0000000 --- a/tests/expand/multifields/enum.rs +++ /dev/null @@ -1,18 +0,0 @@ -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 deleted file mode 100644 index 4320f68..0000000 --- a/tests/expand/multifields/struct.expanded.rs +++ /dev/null @@ -1,152 +0,0 @@ -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 deleted file mode 100644 index a1d45d1..0000000 --- a/tests/expand/multifields/struct.rs +++ /dev/null @@ -1,15 +0,0 @@ -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 deleted file mode 100644 index eae0aac..0000000 --- a/tests/expand/naming/enum-all.expanded.rs +++ /dev/null @@ -1,127 +0,0 @@ -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 deleted file mode 100644 index 90d6860..0000000 --- a/tests/expand/naming/enum-all.rs +++ /dev/null @@ -1,17 +0,0 @@ -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 deleted file mode 100644 index 7c4d6af..0000000 --- a/tests/expand/naming/enum-mut.expanded.rs +++ /dev/null @@ -1,57 +0,0 @@ -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 deleted file mode 100644 index 69beecd..0000000 --- a/tests/expand/naming/enum-mut.rs +++ /dev/null @@ -1,15 +0,0 @@ -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 deleted file mode 100644 index 28ce97d..0000000 --- a/tests/expand/naming/enum-none.expanded.rs +++ /dev/null @@ -1,26 +0,0 @@ -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 deleted file mode 100644 index b2e3f9d..0000000 --- a/tests/expand/naming/enum-none.rs +++ /dev/null @@ -1,14 +0,0 @@ -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 deleted file mode 100644 index a1a013b..0000000 --- a/tests/expand/naming/enum-ref.expanded.rs +++ /dev/null @@ -1,57 +0,0 @@ -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 deleted file mode 100644 index 480d592..0000000 --- a/tests/expand/naming/enum-ref.rs +++ /dev/null @@ -1,15 +0,0 @@ -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 deleted file mode 100644 index b91c24e..0000000 --- a/tests/expand/naming/struct-all.expanded.rs +++ /dev/null @@ -1,117 +0,0 @@ -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 deleted file mode 100644 index cb08753..0000000 --- a/tests/expand/naming/struct-all.rs +++ /dev/null @@ -1,14 +0,0 @@ -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 deleted file mode 100644 index aaa41cd..0000000 --- a/tests/expand/naming/struct-mut.expanded.rs +++ /dev/null @@ -1,84 +0,0 @@ -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 deleted file mode 100644 index 59db445..0000000 --- a/tests/expand/naming/struct-mut.rs +++ /dev/null @@ -1,12 +0,0 @@ -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 deleted file mode 100644 index 8ab318c..0000000 --- a/tests/expand/naming/struct-none.expanded.rs +++ /dev/null @@ -1,84 +0,0 @@ -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 deleted file mode 100644 index e5447c7..0000000 --- a/tests/expand/naming/struct-none.rs +++ /dev/null @@ -1,11 +0,0 @@ -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 deleted file mode 100644 index 3d97ab8..0000000 --- a/tests/expand/naming/struct-ref.expanded.rs +++ /dev/null @@ -1,84 +0,0 @@ -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 deleted file mode 100644 index 6821af8..0000000 --- a/tests/expand/naming/struct-ref.rs +++ /dev/null @@ -1,12 +0,0 @@ -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 deleted file mode 100644 index 665ff63..0000000 --- a/tests/expand/pinned_drop/enum.expanded.rs +++ /dev/null @@ -1,95 +0,0 @@ -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 deleted file mode 100644 index 1855cb7..0000000 --- a/tests/expand/pinned_drop/enum.rs +++ /dev/null @@ -1,22 +0,0 @@ -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 deleted file mode 100644 index 5b82b7a..0000000 --- a/tests/expand/pinned_drop/struct.expanded.rs +++ /dev/null @@ -1,92 +0,0 @@ -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 deleted file mode 100644 index 0cc7567..0000000 --- a/tests/expand/pinned_drop/struct.rs +++ /dev/null @@ -1,17 +0,0 @@ -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 deleted file mode 100644 index 6f190cb..0000000 --- a/tests/expand/pub/enum.expanded.rs +++ /dev/null @@ -1,87 +0,0 @@ -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 deleted file mode 100644 index d3968af..0000000 --- a/tests/expand/pub/enum.rs +++ /dev/null @@ -1,16 +0,0 @@ -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 deleted file mode 100644 index 7b5826d..0000000 --- a/tests/expand/pub/struct.expanded.rs +++ /dev/null @@ -1,84 +0,0 @@ -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 deleted file mode 100644 index 6659096..0000000 --- a/tests/expand/pub/struct.rs +++ /dev/null @@ -1,11 +0,0 @@ -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 deleted file mode 100644 index 3f0d5c1..0000000 --- a/tests/expandtest.rs +++ /dev/null @@ -1,43 +0,0 @@ -#![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 792adce..46ec1df 100644 --- a/tests/lint.rs +++ b/tests/lint.rs @@ -1,43 +1,44 @@ -// Check interoperability with rustc and clippy lints. - #![forbid(unsafe_code)] -// for old compilers -#![allow(unknown_lints)] -#![warn(nonstandard_style, rust_2018_idioms, unused)] +#![warn(nonstandard_style, rust_2018_idioms, rustdoc, 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, 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 +#![forbid(future_incompatible, rust_2018_compatibility)] +#![allow(unknown_lints)] // for old compilers #![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 )] -#![warn(clippy::all, clippy::pedantic, clippy::nursery, clippy::restriction)] +// 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)] #![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"); @@ -161,6 +162,7 @@ mod clippy_redundant_pub_crate { } } + #[allow(dead_code)] pin_project! { #[project = EnumProj] #[project_ref = EnumProjRef] @@ -176,7 +178,6 @@ 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 668e975..b1c72c1 100644 --- a/tests/proper_unpin.rs +++ b/tests/proper_unpin.rs @@ -5,9 +5,8 @@ mod auxiliary; pub mod default { - use std::marker::PhantomPinned; - use pin_project_lite::pin_project; + use std::marker::PhantomPinned; struct Inner<T> { f: T, diff --git a/tests/test.rs b/tests/test.rs index ed9b75c..f4c29ee 100644 --- a/tests/test.rs +++ b/tests/test.rs @@ -8,7 +8,6 @@ use core::{ marker::{PhantomData, PhantomPinned}, pin::Pin, }; - use pin_project_lite::pin_project; #[test] @@ -52,7 +51,7 @@ fn projection() { { let StructProjReplace { f1: PhantomData, f2 } = - s.as_mut().project_replace(Struct::default()); + s.as_mut().project_replace(Default::default()); assert_eq!(f2, 2); let StructProj { f1, f2 } = s.project(); assert_eq!(*f1, 0); @@ -588,21 +587,6 @@ 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 { @@ -615,7 +599,6 @@ fn attrs() { pin_project! { /// dox1 - #[derive(Clone)] #[project = Enum2Proj] #[project_ref = Enum2ProjRef] /// dox2 @@ -633,63 +616,3 @@ 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/pin_project/conflict-drop.rs b/tests/ui/conflict-drop.rs index 870059d..870059d 100644 --- a/tests/ui/pin_project/conflict-drop.rs +++ b/tests/ui/conflict-drop.rs diff --git a/tests/ui/pin_project/conflict-drop.stderr b/tests/ui/conflict-drop.stderr index 8531d08..f97c92b 100644 --- a/tests/ui/pin_project/conflict-drop.stderr +++ b/tests/ui/conflict-drop.stderr @@ -1,5 +1,5 @@ -error[E0119]: conflicting implementations of trait `_::MustNotImplDrop` for type `Foo<_, _>` - --> tests/ui/pin_project/conflict-drop.rs:3:1 +error[E0119]: conflicting implementations of trait `_::MustNotImplDrop` for type `Foo<_, _>`: + --> $DIR/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 the macro `$crate::__pin_project_internal` (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui/pin_project/conflict-unpin.rs b/tests/ui/conflict-unpin.rs index f702f06..f702f06 100644 --- a/tests/ui/pin_project/conflict-unpin.rs +++ b/tests/ui/conflict-unpin.rs diff --git a/tests/ui/pin_project/conflict-unpin.stderr b/tests/ui/conflict-unpin.stderr index 0c3141c..546dafd 100644 --- a/tests/ui/pin_project/conflict-unpin.stderr +++ b/tests/ui/conflict-unpin.stderr @@ -1,5 +1,5 @@ -error[E0119]: conflicting implementations of trait `std::marker::Unpin` for type `Foo<_, _>` - --> tests/ui/pin_project/conflict-unpin.rs:5:1 +error[E0119]: conflicting implementations of trait `std::marker::Unpin` for type `Foo<_, _>`: + --> $DIR/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 the macro `$crate::__pin_project_internal` (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) -error[E0119]: conflicting implementations of trait `std::marker::Unpin` for type `Bar<_, _>` - --> tests/ui/pin_project/conflict-unpin.rs:18:1 +error[E0119]: conflicting implementations of trait `std::marker::Unpin` for type `Bar<_, _>`: + --> $DIR/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 the macro `$crate::__pin_project_internal` (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) -error[E0119]: conflicting implementations of trait `std::marker::Unpin` for type `Baz<_, _>` - --> tests/ui/pin_project/conflict-unpin.rs:29:1 +error[E0119]: conflicting implementations of trait `std::marker::Unpin` for type `Baz<_, _>`: + --> $DIR/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 the macro `$crate::__pin_project_internal` (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui/pin_project/invalid-bounds.rs b/tests/ui/invalid-bounds.rs index 64b397a..64b397a 100644 --- a/tests/ui/pin_project/invalid-bounds.rs +++ b/tests/ui/invalid-bounds.rs diff --git a/tests/ui/invalid-bounds.stderr b/tests/ui/invalid-bounds.stderr new file mode 100644 index 0000000..a565cce --- /dev/null +++ b/tests/ui/invalid-bounds.stderr @@ -0,0 +1,176 @@ +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/pin_project/invalid.rs b/tests/ui/invalid.rs index e0ea61d..e0ea61d 100644 --- a/tests/ui/pin_project/invalid.rs +++ b/tests/ui/invalid.rs diff --git a/tests/ui/pin_project/invalid.stderr b/tests/ui/invalid.stderr index 1e363d7..06f2d79 100644 --- a/tests/ui/pin_project/invalid.stderr +++ b/tests/ui/invalid.stderr @@ -1,5 +1,5 @@ -error: no rules expected the token `struct` - --> tests/ui/pin_project/invalid.rs:3:1 +error: no rules expected the token `[` + --> $DIR/invalid.rs:3:1 | 3 | / pin_project! { 4 | | struct A<T> { @@ -9,10 +9,10 @@ error: no rules expected the token `struct` 8 | | } | |_^ 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) + = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) -error: no rules expected the token `struct` - --> tests/ui/pin_project/invalid.rs:17:1 +error: no rules expected the token `[` + --> $DIR/invalid.rs:17:1 | 17 | / pin_project! { 18 | | struct C<T> { @@ -23,10 +23,10 @@ error: no rules expected the token `struct` 23 | | } | |_^ 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) + = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) error: cannot find attribute `pin` in this scope - --> tests/ui/pin_project/invalid.rs:11:7 + --> $DIR/invalid.rs:11:7 | 11 | #[pin] //~ ERROR cannot find attribute `pin` in this scope | ^^^ diff --git a/tests/ui/pin_project/overlapping_lifetime_names.rs b/tests/ui/overlapping_lifetime_names.rs index 117c18d..87a737e 100644 --- a/tests/ui/pin_project/overlapping_lifetime_names.rs +++ b/tests/ui/overlapping_lifetime_names.rs @@ -1,7 +1,7 @@ use pin_project_lite::pin_project; -pin_project! { //~ ERROR E0263,E0496 - pub struct Foo<'__pin, T> { +pin_project! { //~ ERROR E0496 + pub struct Foo<'__pin, T> { //~ ERROR E0263 #[pin] field: &'__pin mut T, } diff --git a/tests/ui/overlapping_lifetime_names.stderr b/tests/ui/overlapping_lifetime_names.stderr new file mode 100644 index 0000000..8a9bb4f --- /dev/null +++ b/tests/ui/overlapping_lifetime_names.stderr @@ -0,0 +1,75 @@ +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/pin_project/overlapping_unpin_struct.rs b/tests/ui/overlapping_unpin_struct.rs index 25131d1..1338524 100644 --- a/tests/ui/pin_project/overlapping_unpin_struct.rs +++ b/tests/ui/overlapping_unpin_struct.rs @@ -1,6 +1,5 @@ -use std::marker::PhantomPinned; - use pin_project_lite::pin_project; +use std::marker::PhantomPinned; pin_project! { struct Foo<T> { diff --git a/tests/ui/overlapping_unpin_struct.stderr b/tests/ui/overlapping_unpin_struct.stderr new file mode 100644 index 0000000..ab76f81 --- /dev/null +++ b/tests/ui/overlapping_unpin_struct.stderr @@ -0,0 +1,11 @@ +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 new file mode 100644 index 0000000..0bccc1f --- /dev/null +++ b/tests/ui/packed.rs @@ -0,0 +1,19 @@ +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 new file mode 100644 index 0000000..a976163 --- /dev/null +++ b/tests/ui/packed.stderr @@ -0,0 +1,55 @@ +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/pin_project/invalid-bounds.stderr b/tests/ui/pin_project/invalid-bounds.stderr deleted file mode 100644 index e179565..0000000 --- a/tests/ui/pin_project/invalid-bounds.stderr +++ /dev/null @@ -1,272 +0,0 @@ -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/pin_project/overlapping_lifetime_names.stderr b/tests/ui/pin_project/overlapping_lifetime_names.stderr deleted file mode 100644 index dfd4235..0000000 --- a/tests/ui/pin_project/overlapping_lifetime_names.stderr +++ /dev/null @@ -1,25 +0,0 @@ -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/pin_project/overlapping_unpin_struct.stderr b/tests/ui/pin_project/overlapping_unpin_struct.stderr deleted file mode 100644 index 1049879..0000000 --- a/tests/ui/pin_project/overlapping_unpin_struct.stderr +++ /dev/null @@ -1,33 +0,0 @@ -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 deleted file mode 100644 index 50afb11..0000000 --- a/tests/ui/pin_project/packed.rs +++ /dev/null @@ -1,21 +0,0 @@ -#![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 deleted file mode 100644 index 40a955e..0000000 --- a/tests/ui/pin_project/packed.stderr +++ /dev/null @@ -1,57 +0,0 @@ -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/pin_project/unsupported.stderr b/tests/ui/pin_project/unsupported.stderr deleted file mode 100644 index d95f455..0000000 --- a/tests/ui/pin_project/unsupported.stderr +++ /dev/null @@ -1,53 +0,0 @@ -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 deleted file mode 100644 index 609b3be..0000000 --- a/tests/ui/pinned_drop/call-drop-inner.rs +++ /dev/null @@ -1,17 +0,0 @@ -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 deleted file mode 100644 index 5bcb728..0000000 --- a/tests/ui/pinned_drop/call-drop-inner.stderr +++ /dev/null @@ -1,20 +0,0 @@ -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 deleted file mode 100644 index 68b01b2..0000000 --- a/tests/ui/pinned_drop/conditional-drop-impl.rs +++ /dev/null @@ -1,26 +0,0 @@ -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 deleted file mode 100644 index f6c2075..0000000 --- a/tests/ui/pinned_drop/conditional-drop-impl.stderr +++ /dev/null @@ -1,38 +0,0 @@ -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/pin_project/unpin_sneaky.rs b/tests/ui/unpin_sneaky.rs index 984cc2a..984cc2a 100644 --- a/tests/ui/pin_project/unpin_sneaky.rs +++ b/tests/ui/unpin_sneaky.rs diff --git a/tests/ui/pin_project/unpin_sneaky.stderr b/tests/ui/unpin_sneaky.stderr index 4eb6eff..39a7745 100644 --- a/tests/ui/pin_project/unpin_sneaky.stderr +++ b/tests/ui/unpin_sneaky.stderr @@ -1,11 +1,11 @@ error[E0412]: cannot find type `__Origin` in this scope - --> tests/ui/pin_project/unpin_sneaky.rs:10:16 + --> $DIR/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]` - --> tests/ui/pin_project/unpin_sneaky.rs:10:1 + --> $DIR/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/pin_project/unsupported.rs b/tests/ui/unsupported.rs index 2f80836..2f80836 100644 --- a/tests/ui/pin_project/unsupported.rs +++ b/tests/ui/unsupported.rs diff --git a/tests/ui/unsupported.stderr b/tests/ui/unsupported.stderr new file mode 100644 index 0000000..2cd17df --- /dev/null +++ b/tests/ui/unsupported.stderr @@ -0,0 +1,53 @@ +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) |