pin-project-0.4.8/.editorconfig010064400007650000024000000007251356530425500146650ustar0000000000000000# EditorConfig configuration # https://editorconfig.org # Top-most EditorConfig file root = true # Unix-style newlines with a newline ending every file, utf-8 charset [*] end_of_line = lf insert_final_newline = true trim_trailing_whitespace = true charset = utf-8 # Match rust/toml, set 4 space indentation [*.{rs,toml}] indent_style = space indent_size = 4 # Match json/yaml/markdown, set 2 space indentation [*.{json,yml,md}] indent_style = space indent_size = 2 pin-project-0.4.8/.gitattributes010064400007650000024000000001501356530430100150630ustar0000000000000000[attr]rust text eol=lf whitespace=tab-in-indent,trailing-space,tabwidth=4 * text=auto eol=lf *.rs rust pin-project-0.4.8/.github/bors.toml010064400007650000024000000003531356530425500154070ustar0000000000000000status = [ "test (1.33.0)", "test (1.36.0)", "test (stable)", "test (beta)", "test (nightly)", "test (macos)", "style (clippy)", "style (rustfmt)", "style (rustdoc)", ] delete_merged_branches = true pin-project-0.4.8/.github/CODEOWNERS010064400007650000024000000000131356530430100151210ustar0000000000000000* @taiki-e pin-project-0.4.8/.github/workflows/ci.yml010064400007650000024000000062031361355222300167120ustar0000000000000000name: ci on: pull_request: push: branches: - master - staging - trying schedule: - cron: '00 01 * * *' env: RUSTFLAGS: -Dwarnings jobs: test: name: test runs-on: ${{ matrix.os }} strategy: matrix: build: # This is the minimum supported Rust version of this crate. # When updating this, the reminder to update the minimum supported # Rust version in README.md. - 1.33.0 - 1.36.0 - stable - beta - nightly # pin-project itself has no platform-dependent implementation. # macOS is only used to check that pin-project can interoperate # correctly with `#[cfg()]`. - macos # - windows include: - build: 1.33.0 os: ubuntu-latest rust: 1.33.0 - build: 1.36.0 os: ubuntu-latest rust: 1.36.0 - build: stable os: ubuntu-latest rust: stable - build: beta os: ubuntu-latest rust: beta - build: nightly os: ubuntu-latest rust: nightly - build: macos os: macos-latest rust: nightly # - build: windows # os: windows-latest # rust: nightly steps: - uses: actions/checkout@master - name: Install Rust shell: bash run: | . ./ci/install-rust.sh ${{ matrix.rust }} - name: Install cargo-hack if: matrix.rust == 'nightly' run: | cargo install cargo-hack - name: cargo test run: | cargo test --all - name: cargo test --cfg pin_project_show_unpin_struct if: matrix.rust == 'nightly' env: RUSTFLAGS: -Dwarnings --cfg pin_project_show_unpin_struct run: | cargo test --all --all-features -- -Zunstable-options --include-ignored # Refs: https://github.com/rust-lang/cargo/issues/5657 - name: cargo check -Zminimal-versions if: matrix.rust == 'nightly' run: | cargo update -Zminimal-versions cargo hack check --all --all-features --no-dev-deps --ignore-private style: name: style runs-on: ubuntu-latest strategy: fail-fast: false matrix: component: - clippy - rustfmt - rustdoc steps: - uses: actions/checkout@master - name: Install Rust shell: bash run: | . ./ci/install-rust.sh - name: Install component if: matrix.component != 'rustdoc' shell: bash run: | . ./ci/install-component.sh ${{ matrix.component }} - name: cargo clippy if: matrix.component == 'clippy' run: | cargo clippy --all --all-features - name: cargo fmt -- --check if: matrix.component == 'rustfmt' run: | cargo fmt --all -- --check - name: cargo doc if: matrix.component == 'rustdoc' env: RUSTDOCFLAGS: -Dwarnings run: | cargo doc --no-deps --all --all-features pin-project-0.4.8/.gitignore010064400007650000024000000003301356530430100141600ustar0000000000000000target **/*.rs.bk Cargo.lock # For platform and editor specific settings, it is recommended to add to # a global .gitignore file. # Refs: https://help.github.com/en/articles/ignoring-files#create-a-global-gitignore pin-project-0.4.8/.rustfmt.toml010064400007650000024000000015501356530430100146540ustar0000000000000000# Rustfmt configuration # https://github.com/rust-lang/rustfmt/blob/master/Configurations.md # This is required for bug-fixes, which technically can't be made to the stable # first version. version = "Two" # Tracking issue: https://github.com/rust-lang/rustfmt/issues/3383 # Refs: https://internals.rust-lang.org/t/running-rustfmt-on-rust-lang-rust-and-other-rust-lang-repositories/8732/72 use_small_heuristics = "Max" # Apply rustfmt to more places. merge_imports = true # Tracking issue: https://github.com/rust-lang/rustfmt/issues/3362 format_code_in_doc_comments = true # Tracking issue: https://github.com/rust-lang/rustfmt/issues/3348 # Set the default settings again to always apply the proper formatting without # being affected by the editor settings. # Refs: https://github.com/rust-lang/rls/issues/501#issuecomment-333717736 edition = "2018" tab_spaces = 4 pin-project-0.4.8/Cargo.toml.orig010064400007650000024000000012551361355302600150720ustar0000000000000000[package] name = "pin-project" version = "0.4.8" authors = ["Taiki Endo "] edition = "2018" license = "Apache-2.0 OR MIT" repository = "https://github.com/taiki-e/pin-project" homepage = "https://github.com/taiki-e/pin-project" documentation = "https://docs.rs/pin-project" keywords = ["pin", "macros", "attribute"] categories = ["no-std", "rust-patterns"] readme = "README.md" description = """ A crate for safe and ergonomic pin-projection. """ [workspace] members = [ "pin-project-internal", "tests/ui/auxiliary", "tests/doc", ] [dependencies] pin-project-internal = { version = "=0.4.8", path = "pin-project-internal", default-features = false } pin-project-0.4.8/Cargo.toml0000644000000020541361355310600113770ustar00# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO # # 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 # # 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" name = "pin-project" version = "0.4.8" authors = ["Taiki Endo "] description = "A crate for safe and ergonomic pin-projection.\n" homepage = "https://github.com/taiki-e/pin-project" documentation = "https://docs.rs/pin-project" readme = "README.md" keywords = ["pin", "macros", "attribute"] categories = ["no-std", "rust-patterns"] license = "Apache-2.0 OR MIT" repository = "https://github.com/taiki-e/pin-project" [dependencies.pin-project-internal] version = "=0.4.8" default-features = false pin-project-0.4.8/CHANGELOG.md010064400007650000024000000301661361355266100140230ustar0000000000000000# Changelog All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](https://semver.org). ## [Unreleased] ## [0.4.8] - 2020-01-27 * [Ensured that users cannot implement `PinnedDrop` without proper attribute argument.][180] [180]: https://github.com/taiki-e/pin-project/pull/180 ## [0.4.7] - 2020-01-20 * [Fixed support for lifetime bounds.][176] [176]: https://github.com/taiki-e/pin-project/pull/176 ## [0.4.6] - 2019-11-20 * [Fixed compile error when there is `Self` in the where clause.][169] [169]: https://github.com/taiki-e/pin-project/pull/169 ## [0.4.5] - 2019-10-21 * [Fixed compile error with `dyn` types.][158] [158]: https://github.com/taiki-e/pin-project/pull/158 ## [0.4.4] - 2019-10-17 * [Fixed an issue where `PinnedDrop` implementations can call unsafe code without an unsafe block.][149] [149]: https://github.com/taiki-e/pin-project/pull/149 ## [0.4.3] - 2019-10-15 - YANKED * [`#[pin_project]` can now interoperate with `#[cfg_attr()]`.][135] * [`#[pin_project]` can now interoperate with `#[cfg()]` on tuple structs and tuple variants.][135] * [Fixed support for DSTs(Dynamically Sized Types) on `#[pin_project(UnsafeUnpin)]`][120] [120]: https://github.com/taiki-e/pin-project/pull/120 [135]: https://github.com/taiki-e/pin-project/pull/135 ## [0.4.2] - 2019-09-29 - YANKED * [Fixed support for DSTs(Dynamically Sized Types).][113] [113]: https://github.com/taiki-e/pin-project/pull/113 ## [0.4.1] - 2019-09-26 - YANKED * [Fixed an issue that caused an error when using `#[pin_project]` on a type that has `#[pin]` + `!Unpin` field with no generics or lifetime.][111] [111]: https://github.com/taiki-e/pin-project/pull/111 ## [0.4.0] - 2019-09-25 - YANKED * [**Pin projection has become a safe operation.**][18] In the absence of other unsafe code that you write, it is impossible to cause undefined behavior. * `#[unsafe_project]` attribute has been replaced with `#[pin_project]` attribute. ([#18][18], [#33][33]) * [The `Unpin` argument has been removed - an `Unpin` impl is now generated by default.][18] * Drop impls must be specified with `#[pinned_drop]` instead of via a normal `Drop` impl. ([#18][18], [#33][33], [#86][86]) * [`Unpin` impls must be specified with an impl of `UnsafeUnpin`, instead of implementing the normal `Unpin` trait.][18] * [`#[pin_project]` attribute now determines the visibility of the projection type/method is based on the original type.][96] * [`#[pin_project]` can now be used for public type with private field types.][53] * [`#[pin_project]` can now interoperate with `#[cfg()]`.][77] * [Added `project_ref` method to `#[pin_project]` types.][93] * [Added `#[project_ref]` attribute.][93] * [Removed "project_attr" feature and always enable `#[project]` attribute.][94] * [`#[project]` attribute can now be used for `impl` blocks.][46] * [`#[project]` attribute can now be used for `use` statements.][85] * [`#[project]` attribute now supports `match` expressions at the position of the initializer expression of `let` expressions.][51] Changes since the 0.4.0-beta.1 release: * [Fixed an issue that caused an error when using `#[pin_project(UnsafeUnpin)]` and not providing a manual `UnsafeUnpin` implementation on a type with no generics or lifetime.][107] [18]: https://github.com/taiki-e/pin-project/pull/18 [33]: https://github.com/taiki-e/pin-project/pull/107 [107]: https://github.com/taiki-e/pin-project/pull/107 ## [0.4.0-beta.1] - 2019-09-21 * [Changed the argument type of project method back to `self: Pin<&mut Self>`.][90] * [Removed "project_attr" feature and always enable `#[project]` attribute.][94] * [Removed "renamed" feature.][100] * [`#[project]` attribute can now be used for `use` statements.][85] * [Added `project_ref` method and `#[project_ref]` attribute.][93] * [`#[pin_project]` attribute now determines the visibility of the projection type/method is based on the original type.][96] [85]: https://github.com/taiki-e/pin-project/pull/85 [90]: https://github.com/taiki-e/pin-project/pull/90 [93]: https://github.com/taiki-e/pin-project/pull/93 [94]: https://github.com/taiki-e/pin-project/pull/94 [96]: https://github.com/taiki-e/pin-project/pull/96 [100]: https://github.com/taiki-e/pin-project/pull/100 ## [0.4.0-alpha.11] - 2019-09-11 * [Changed #[pinned_drop] to trait implementation.][86] ```rust #[pinned_drop] impl PinnedDrop for Foo<'_, T> { fn drop(mut self: Pin<&mut Self>) { **self.project().was_dropped = true; } } ``` * Added some examples and generated code. * Improve error messages. [86]: https://github.com/taiki-e/pin-project/pull/86 ## [0.4.0-alpha.10] - 2019-09-07 * [`#[pin_project]` can now interoperate with `#[cfg()]`.][77] * Improved documentation. [77]: https://github.com/taiki-e/pin-project/pull/77 ## [0.4.0-alpha.9] - 2019-09-05 * [Added 'project_into' method to #[pin_project] types][69]. This can be useful when returning a pin projection from a method. ```rust fn get_pin_mut(self: Pin<&mut Self>) -> Pin<&mut T> { self.project_into().pinned } ``` * [Prevented UnpinStruct from appearing in the document by default.][71] See [taiki-e/pin-project#71][71] for more details. [69]: https://github.com/taiki-e/pin-project/pull/69 [71]: https://github.com/taiki-e/pin-project/pull/69 ## [0.4.0-alpha.8] - 2019-09-03 * [Improved document of generated code.][62]. Also added an option to control the document of generated code. See [taiki-e/pin-project#62][62] for more details. * [Improved error messages][61] [61]: https://github.com/taiki-e/pin-project/pull/61 [62]: https://github.com/taiki-e/pin-project/pull/62 ## [0.4.0-alpha.7] - 2019-09-02 * [Applied `#[allow(dead_code)]` to generated types.][57] [57]: https://github.com/taiki-e/pin-project/pull/57 ## [0.4.0-alpha.6] - 2019-09-01 * [Allowed using `#[pin_project]` type with private field types][53] [53]: https://github.com/taiki-e/pin-project/pull/53 ## [0.4.0-alpha.5] - 2019-08-24 * [`#[project]` attribute now supports `match` expressions at the position of the initializer expression of `let` expressions.][51] [51]: https://github.com/taiki-e/pin-project/pull/51 ## [0.4.0-alpha.4] - 2019-08-23 * Avoided clippy::drop_bounds lint in generated code. ## [0.4.0-alpha.3] - 2019-08-23 * [Changed `project` method generated by `#[pin_project]` attribute to take an `&mut Pin<&mut Self>` argument.][47] * [`#[project]` attribute can now be used for impl blocks.][46] * [`#[pin_project]` attribute can now detect that the type used does not have its own drop implementation without actually implementing drop.][48] This removed some restrictions. [46]: https://github.com/taiki-e/pin-project/pull/46 [47]: https://github.com/taiki-e/pin-project/pull/47 [48]: https://github.com/taiki-e/pin-project/pull/48 ## [0.4.0-alpha.2] - 2019-08-13 * Updated `proc-macro2`, `syn`, and `quote` to 1.0. ## [0.4.0-alpha.1] - 2019-08-11 * **Pin projection has become a safe operation.** * `#[unsafe_project]` has been replaced with `#[pin_project]`. * The `Unpin` argument has been removed - an `Unpin` impl is now generated by default. * Drop impls must be specified with `#[pinned_drop]` instead of via a normal `Drop` impl. * `Unpin` impls must be specified with an impl of `UnsafeUnpin`, instead of implementing the normal `Unpin` trait. * Made `#[project]` attribute disabled by default. See also [tracking issue for 0.4 release][21]. [21]: https://github.com/taiki-e/pin-project/issues/21 ## [0.3.5] - 2019-08-14 * Updated `proc-macro2`, `syn`, and `quote` to 1.0. ## [0.3.4] - 2019-07-21 * Improved error messages. ## [0.3.3] - 2019-07-15 - YANKED * Improved error messages. ## [0.3.2] - 2019-03-30 * Avoided suffixes on tuple index. ## [0.3.1] - 2019-03-02 * Improved documentation. * Updated minimum `syn` version to 0.15.22. ## [0.3.0] - 2019-02-20 * Removed `unsafe_fields` attribute. * Removed `unsafe_variants` attribute. ## [0.2.2] - 2019-02-20 * Fixed a bug that generates incorrect code for the some structures with trait bounds on type generics. ## [0.2.1] - 2019-02-20 * Fixed a bug that generates incorrect code for the structures with where clause and associated type fields. ## [0.2.0] - 2019-02-11 * Made `unsafe_fields` optional. * Improved documentation. ## [0.1.8] - 2019-02-02 * Added the feature to create projected enums to `unsafe_project`. * Added `project` attribute to support pattern matching. ## [0.1.7] - 2019-01-19 * Fixed documentation. ## [0.1.6] - 2019-01-19 * `unsafe_fields` can now opt-out. * Added `unsafe_variants` attribute. This attribute is available if pin-project is built with the "unsafe_variants" feature. ## [0.1.5] - 2019-01-17 * Added support for tuple struct to `unsafe_project`. ## [0.1.4] - 2019-01-12 * Added options for automatically implementing `Unpin` to both `unsafe_project` and `unsafe_fields`. ## [0.1.3] - 2019-01-11 * Fixed dependencies. * Added `unsafe_fields` attribute. ## [0.1.2] - 2019-01-09 * Improved documentation. ## [0.1.1] - 2019-01-08 * Renamed from `unsafe_pin_project` to `unsafe_project`. ## [0.1.0] - 2019-01-08 - YANKED Initial release [Unreleased]: https://github.com/taiki-e/pin-project/compare/v0.4.8...HEAD [0.4.8]: https://github.com/taiki-e/pin-project/compare/v0.4.7...v0.4.8 [0.4.7]: https://github.com/taiki-e/pin-project/compare/v0.4.6...v0.4.7 [0.4.6]: https://github.com/taiki-e/pin-project/compare/v0.4.5...v0.4.6 [0.4.5]: https://github.com/taiki-e/pin-project/compare/v0.4.4...v0.4.5 [0.4.4]: https://github.com/taiki-e/pin-project/compare/v0.4.3...v0.4.4 [0.4.3]: https://github.com/taiki-e/pin-project/compare/v0.4.2...v0.4.3 [0.4.2]: https://github.com/taiki-e/pin-project/compare/v0.4.1...v0.4.2 [0.4.1]: https://github.com/taiki-e/pin-project/compare/v0.4.0...v0.4.1 [0.4.0]: https://github.com/taiki-e/pin-project/compare/v0.4.0-beta.1...v0.4.0 [0.4.0-beta.1]: https://github.com/taiki-e/pin-project/compare/v0.4.0-alpha.11...v0.4.0-beta.1 [0.4.0-alpha.11]: https://github.com/taiki-e/pin-project/compare/v0.4.0-alpha.10...v0.4.0-alpha.11 [0.4.0-alpha.10]: https://github.com/taiki-e/pin-project/compare/v0.4.0-alpha.9...v0.4.0-alpha.10 [0.4.0-alpha.9]: https://github.com/taiki-e/pin-project/compare/v0.4.0-alpha.8...v0.4.0-alpha.9 [0.4.0-alpha.8]: https://github.com/taiki-e/pin-project/compare/v0.4.0-alpha.7...v0.4.0-alpha.8 [0.4.0-alpha.7]: https://github.com/taiki-e/pin-project/compare/v0.4.0-alpha.6...v0.4.0-alpha.7 [0.4.0-alpha.6]: https://github.com/taiki-e/pin-project/compare/v0.4.0-alpha.5...v0.4.0-alpha.6 [0.4.0-alpha.5]: https://github.com/taiki-e/pin-project/compare/v0.4.0-alpha.4...v0.4.0-alpha.5 [0.4.0-alpha.4]: https://github.com/taiki-e/pin-project/compare/v0.4.0-alpha.3...v0.4.0-alpha.4 [0.4.0-alpha.3]: https://github.com/taiki-e/pin-project/compare/v0.4.0-alpha.2...v0.4.0-alpha.3 [0.4.0-alpha.2]: https://github.com/taiki-e/pin-project/compare/v0.4.0-alpha.1...v0.4.0-alpha.2 [0.4.0-alpha.1]: https://github.com/taiki-e/pin-project/compare/v0.3.5...v0.4.0-alpha.1 [0.3.5]: https://github.com/taiki-e/pin-project/compare/v0.3.4...v0.3.5 [0.3.4]: https://github.com/taiki-e/pin-project/compare/v0.3.3...v0.3.4 [0.3.3]: https://github.com/taiki-e/pin-project/compare/v0.3.2...v0.3.3 [0.3.2]: https://github.com/taiki-e/pin-project/compare/v0.3.1...v0.3.2 [0.3.1]: https://github.com/taiki-e/pin-project/compare/v0.3.0...v0.3.1 [0.3.0]: https://github.com/taiki-e/pin-project/compare/v0.2.2...v0.3.0 [0.2.2]: https://github.com/taiki-e/pin-project/compare/v0.2.1...v0.2.2 [0.2.1]: https://github.com/taiki-e/pin-project/compare/v0.2.0...v0.2.1 [0.2.0]: https://github.com/taiki-e/pin-project/compare/v0.1.8...v0.2.0 [0.1.8]: https://github.com/taiki-e/pin-project/compare/v0.1.7...v0.1.8 [0.1.7]: https://github.com/taiki-e/pin-project/compare/v0.1.6...v0.1.7 [0.1.6]: https://github.com/taiki-e/pin-project/compare/v0.1.5...v0.1.6 [0.1.5]: https://github.com/taiki-e/pin-project/compare/v0.1.4...v0.1.5 [0.1.4]: https://github.com/taiki-e/pin-project/compare/v0.1.3...v0.1.4 [0.1.3]: https://github.com/taiki-e/pin-project/compare/v0.1.2...v0.1.3 [0.1.2]: https://github.com/taiki-e/pin-project/compare/v0.1.1...v0.1.2 [0.1.1]: https://github.com/taiki-e/pin-project/compare/v0.1.0...v0.1.1 [0.1.0]: https://github.com/taiki-e/pin-project/releases/tag/v0.1.0 pin-project-0.4.8/ci.sh010064400007650000024000000007161356530425500131370ustar0000000000000000#!/bin/bash # A script to run a simplified version of the checks done by CI. # # Usage # # ```sh # . ./ci.sh # ``` echo "Running 'cargo fmt -- --check'" cargo +nightly fmt --all -- --check echo "Running 'cargo clippy'" cargo +nightly clippy --all --all-features echo "Running 'cargo test'" cargo +nightly test --all --all-features echo "Running 'cargo doc'" cargo +nightly doc --no-deps --all --all-features echo "Running 'compiletest'" . ./compiletest.sh pin-project-0.4.8/ci/install-component.sh010064400007650000024000000016121356530430100165710ustar0000000000000000#!/bin/bash set -euo pipefail component="${1}" if ! rustup component add "${component}" 2>/dev/null; then # If the component is unavailable on the latest nightly, # use the latest toolchain with the component available. # Refs: https://github.com/rust-lang/rustup-components-history#the-web-part target=$(curl -sSf "https://rust-lang.github.io/rustup-components-history/x86_64-unknown-linux-gnu/${component}") echo "'${component}' is unavailable on the default toolchain, use the toolchain 'nightly-${target}' instead" rustup update "nightly-${target}" --no-self-update rustup default "nightly-${target}" echo "Query rust and cargo versions:" rustup -V rustc -V cargo -V rustup component add "${component}" fi echo "Query component versions:" case "${component}" in clippy | miri) cargo "${component}" -V ;; rustfmt) "${component}" -V ;; esac pin-project-0.4.8/ci/install-rust.sh010064400007650000024000000007231356530430100155660ustar0000000000000000#!/bin/bash set -euo pipefail toolchain="${1:-nightly}" if rustup -V 2>/dev/null; then rustup set profile minimal rustup update "${toolchain}" --no-self-update rustup default "${toolchain}" else curl -sSf https://sh.rustup.rs | sh -s -- -y --profile minimal --default-toolchain "${toolchain}" export PATH=${PATH}:${HOME}/.cargo/bin echo "##[add-path]${HOME}/.cargo/bin" fi echo "Query rust and cargo versions:" rustup -V rustc -V cargo -V pin-project-0.4.8/compiletest.sh010064400007650000024000000006501360756734600151020ustar0000000000000000#!/bin/bash # A script to run compile tests with the same condition of the checks done by CI. # # Usage # # ```sh # . ./compiletest.sh # ``` TRYBUILD=overwrite RUSTFLAGS='--cfg pin_project_show_unpin_struct' cargo +nightly test -p pin-project --all-features --test compiletest -- --ignored # RUSTFLAGS='--cfg pin_project_show_unpin_struct' cargo +nightly test -p pin-project --all-features --test compiletest -- --ignored pin-project-0.4.8/examples/enum-default-expanded.rs010064400007650000024000000046351356530430100205440ustar0000000000000000// Original code (./enum-default.rs): // // ```rust // #![allow(dead_code)] // // use pin_project::pin_project; // // #[pin_project] // enum Enum { // Pinned(#[pin] T), // Unpinned(U), // } // // fn main() {} // ``` #![allow(dead_code, unused_imports, unused_parens)] use pin_project::pin_project; enum Enum { Pinned(/* #[pin] */ T), Unpinned(U), } #[allow(clippy::mut_mut)] // This lint warns `&mut &mut `. #[allow(dead_code)] // This lint warns unused fields/variants. enum __EnumProjection<'pin, T, U> { Pinned(::core::pin::Pin<&'pin mut (T)>), Unpinned(&'pin mut (U)), } #[allow(dead_code)] // This lint warns unused fields/variants. enum __EnumProjectionRef<'pin, T, U> { Pinned(::core::pin::Pin<&'pin (T)>), Unpinned(&'pin (U)), } impl Enum { fn project<'pin>(self: ::core::pin::Pin<&'pin mut Self>) -> __EnumProjection<'pin, T, U> { unsafe { match self.get_unchecked_mut() { Enum::Pinned(_0) => __EnumProjection::Pinned(::core::pin::Pin::new_unchecked(_0)), Enum::Unpinned(_0) => __EnumProjection::Unpinned(_0), } } } fn project_ref<'pin>(self: ::core::pin::Pin<&'pin Self>) -> __EnumProjectionRef<'pin, T, U> { unsafe { match self.get_ref() { Enum::Pinned(_0) => { __EnumProjectionRef::Pinned(::core::pin::Pin::new_unchecked(_0)) } Enum::Unpinned(_0) => __EnumProjectionRef::Unpinned(_0), } } } } // Automatically create the appropriate conditional `Unpin` implementation. // // See ./struct-default-expanded.rs and https://github.com/taiki-e/pin-project/pull/53. // for details. #[allow(non_snake_case)] fn __unpin_scope_Enum() { struct __Enum<'pin, T, U> { __pin_project_use_generics: ::pin_project::__private::AlwaysUnpin<'pin, (T, U)>, __field0: T, } impl<'pin, T, U> ::core::marker::Unpin for Enum where __Enum<'pin, T, U>: ::core::marker::Unpin {} } // Ensure that enum does not implement `Drop`. // // See ./struct-default-expanded.rs for details. trait EnumMustNotImplDrop {} #[allow(clippy::drop_bounds)] impl EnumMustNotImplDrop for T {} #[allow(single_use_lifetimes)] impl EnumMustNotImplDrop for Enum {} // We don't need to check for '#[repr(packed)]', // since it does not apply to enums. fn main() {} pin-project-0.4.8/examples/enum-default.rs010064400007650000024000000003041356530430100167430ustar0000000000000000// See ./enum-default-expanded.rs for generated code. #![allow(dead_code)] use pin_project::pin_project; #[pin_project] enum Enum { Pinned(#[pin] T), Unpinned(U), } fn main() {} pin-project-0.4.8/examples/pinned_drop-expanded.rs010064400007650000024000000101441356530430100204470ustar0000000000000000// Original code (./pinned_drop.rs): // // ```rust // #![allow(dead_code)] // // use pin_project::{pin_project, pinned_drop}; // use std::pin::Pin; // // #[pin_project(PinnedDrop)] // pub struct Foo<'a, T> { // was_dropped: &'a mut bool, // #[pin] // field: T, // } // // #[pinned_drop] // fn drop_foo(mut this: Pin<&mut Foo<'_, T>>) { // **this.project().was_dropped = true; // } // // fn main() {} // ``` #![allow(dead_code, unused_imports, unused_parens)] use pin_project::{pin_project, pinned_drop}; use std::pin::Pin; pub struct Foo<'a, T> { was_dropped: &'a mut bool, // #[pin] field: T, } #[allow(clippy::mut_mut)] // This lint warns `&mut &mut `. #[allow(dead_code)] // This lint warns unused fields/variants. pub(crate) struct __FooProjection<'pin, 'a, T> { was_dropped: &'pin mut (&'a mut bool), field: ::core::pin::Pin<&'pin mut (T)>, } #[allow(dead_code)] // This lint warns unused fields/variants. pub(crate) struct __FooProjectionRef<'pin, 'a, T> { was_dropped: &'pin (&'a mut bool), field: ::core::pin::Pin<&'pin (T)>, } impl<'a, T> Foo<'a, T> { pub(crate) fn project<'pin>( self: ::core::pin::Pin<&'pin mut Self>, ) -> __FooProjection<'pin, 'a, T> { unsafe { let Foo { was_dropped, field } = self.get_unchecked_mut(); __FooProjection { was_dropped, field: ::core::pin::Pin::new_unchecked(field) } } } pub(crate) fn project_ref<'pin>( self: ::core::pin::Pin<&'pin Self>, ) -> __FooProjectionRef<'pin, 'a, T> { unsafe { let Foo { was_dropped, field } = self.get_ref(); __FooProjectionRef { was_dropped, field: ::core::pin::Pin::new_unchecked(field) } } } } #[allow(single_use_lifetimes)] impl<'a, T> ::core::ops::Drop for Foo<'a, T> { fn drop(&mut self) { // Safety - we're in 'drop', so we know that 'self' will // never move again. let pinned_self = unsafe { ::core::pin::Pin::new_unchecked(self) }; // We call `pinned_drop` only once. Since `PinnedDrop::drop` // is an unsafe function and a private API, it is never called again in safe // code *unless the user uses a maliciously crafted macro*. unsafe { ::pin_project::__private::PinnedDrop::drop(pinned_self); } } } // It is safe to implement PinnedDrop::drop, but it is not safe to call it. // This is because destructors can be called multiple times (double dropping // is unsound: rust-lang/rust#62360). // // Ideally, it would be desirable to be able to prohibit manual calls in the // same way as Drop::drop, but the library cannot. So, by using macros and // replacing them with private traits, we prevent users from calling // PinnedDrop::drop. // // Users can implement `Drop` safely using `#[pinned_drop]`. // **Do not call or implement this trait directly.** impl ::pin_project::__private::PinnedDrop for Foo<'_, T> { // Since calling it twice on the same object would be UB, // this method is unsafe. unsafe fn drop(self: Pin<&mut Self>) { fn __drop_inner(__self: Pin<&mut Foo<'_, T>>) { **__self.project().was_dropped = true; } __drop_inner(self); } } // Automatically create the appropriate conditional `Unpin` implementation. // // See ./struct-default-expanded.rs and https://github.com/taiki-e/pin-project/pull/53. // for details. #[allow(non_snake_case)] fn __unpin_scope_Foo() { pub struct __Foo<'pin, 'a, T> { __pin_project_use_generics: ::pin_project::__private::AlwaysUnpin<'pin, (T)>, __field0: T, __lifetime0: &'a (), } impl<'pin, 'a, T> ::core::marker::Unpin for Foo<'a, T> where __Foo<'pin, 'a, T>: ::core::marker::Unpin { } } // Ensure that it's impossible to use pin projections on a #[repr(packed)] struct. // // See ./struct-default-expanded.rs and https://github.com/taiki-e/pin-project/pull/34 // for details. #[allow(single_use_lifetimes)] #[allow(non_snake_case)] #[deny(safe_packed_borrows)] fn __pin_project_assert_not_repr_packed_Foo<'a, T>(val: &Foo<'a, T>) { &val.was_dropped; &val.field; } fn main() {} pin-project-0.4.8/examples/pinned_drop.rs010064400007650000024000000006251356530430100166640ustar0000000000000000// See ./pinned_drop-expanded.rs for generated code. #![allow(dead_code)] use pin_project::{pin_project, pinned_drop}; use std::pin::Pin; #[pin_project(PinnedDrop)] pub struct Foo<'a, T> { was_dropped: &'a mut bool, #[pin] field: T, } #[pinned_drop] impl PinnedDrop for Foo<'_, T> { fn drop(self: Pin<&mut Self>) { **self.project().was_dropped = true; } } fn main() {} pin-project-0.4.8/examples/README.md010064400007650000024000000010161356530420100152660ustar0000000000000000## Examples and generated code of each feature of pin-project * [Basic usage of `#[pin_project]` on structs.](struct-default.rs) -- [generated code](struct-default-expanded.rs) * [Basic usage of `#[pin_project]` on enums.](enum-default.rs) -- [generated code](enum-default-expanded.rs) * [Manual implementation of `Unpin` by `UnsafeUnpin`.](unsafe_unpin.rs) -- [generated code](unsafe_unpin-expanded.rs) * [Manual implementation of `Drop` by `#[pinned_drop]`.](pinned_drop.rs) -- [generated code](pinned_drop-expanded.rs) pin-project-0.4.8/examples/struct-default-expanded.rs010064400007650000024000000105661357107177400211400ustar0000000000000000// Original code (./struct-default.rs): // // ```rust // #![allow(dead_code)] // // use pin_project::pin_project; // // #[pin_project] // struct Struct { // #[pin] // pinned: T, // unpinned: U, // } // // fn main() {} // ``` #![allow(dead_code, unused_imports, unused_parens)] use pin_project::pin_project; struct Struct { // #[pin] pinned: T, unpinned: U, } #[allow(clippy::mut_mut)] // This lint warns `&mut &mut `. #[allow(dead_code)] // This lint warns unused fields/variants. struct __StructProjection<'pin, T, U> { pinned: ::core::pin::Pin<&'pin mut (T)>, unpinned: &'pin mut (U), } #[allow(dead_code)] // This lint warns unused fields/variants. struct __StructProjectionRef<'pin, T, U> { pinned: ::core::pin::Pin<&'pin (T)>, unpinned: &'pin (U), } impl Struct { fn project<'pin>(self: ::core::pin::Pin<&'pin mut Self>) -> __StructProjection<'pin, T, U> { unsafe { let Struct { pinned, unpinned } = self.get_unchecked_mut(); __StructProjection { pinned: ::core::pin::Pin::new_unchecked(pinned), unpinned } } } fn project_ref<'pin>(self: ::core::pin::Pin<&'pin Self>) -> __StructProjectionRef<'pin, T, U> { unsafe { let Struct { pinned, unpinned } = self.get_ref(); __StructProjectionRef { pinned: ::core::pin::Pin::new_unchecked(pinned), unpinned } } } } // Automatically create the appropriate conditional `Unpin` implementation. // // Basically this is equivalent to the following code: // ```rust // impl Unpin for Struct 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 declared 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 - // that is, it will implement Unpin iff all of its fields implement Unpin. // This type can be safely declared as 'public', satisfying the privacy // checker without actually allowing user code to access it. // // This allows users to apply the #[pin_project] attribute to types // 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)] fn __unpin_scope_Struct() { struct __Struct<'pin, T, U> { __pin_project_use_generics: ::pin_project::__private::AlwaysUnpin<'pin, (T, U)>, __field0: T, } impl<'pin, T, U> ::core::marker::Unpin for Struct where __Struct<'pin, T, U>: ::core::marker::Unpin { } } // 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 conflict with the explicit MustNotImplDrop impl below. // This will result in a compilation error, which is exactly what we want. trait StructMustNotImplDrop {} #[allow(clippy::drop_bounds)] impl StructMustNotImplDrop for T {} #[allow(single_use_lifetimes)] impl StructMustNotImplDrop for Struct {} // Ensure that it's impossible to use pin projections on a #[repr(packed)] struct. // // Taking a reference to a packed field is unsafe, and applying // #[deny(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. #[allow(single_use_lifetimes)] #[allow(non_snake_case)] #[deny(safe_packed_borrows)] fn __pin_project_assert_not_repr_packed_Struct(val: &Struct) { &val.pinned; &val.unpinned; } fn main() {} pin-project-0.4.8/examples/struct-default.rs010064400007650000024000000003161356530430100173260ustar0000000000000000// See ./struct-default-expanded.rs for generated code. #![allow(dead_code)] use pin_project::pin_project; #[pin_project] struct Struct { #[pin] pinned: T, unpinned: U, } fn main() {} pin-project-0.4.8/examples/unsafe_unpin-expanded.rs010064400007650000024000000047011356530430100206420ustar0000000000000000// Original code (./unsafe_unpin.rs): // // ```rust // #![allow(dead_code)] // // use pin_project::{pin_project, UnsafeUnpin}; // // #[pin_project(UnsafeUnpin)] // pub struct Foo { // #[pin] // pinned: T, // unpinned: U, // } // // unsafe impl UnsafeUnpin for Foo {} // // fn main() {} // ``` #![allow(dead_code, unused_imports, unused_parens)] use pin_project::{pin_project, UnsafeUnpin}; pub struct Foo { // #[pin] pinned: T, unpinned: U, } #[allow(clippy::mut_mut)] // This lint warns `&mut &mut `. #[allow(dead_code)] // This lint warns unused fields/variants. pub(crate) struct __FooProjection<'pin, T, U> { pinned: ::core::pin::Pin<&'pin mut (T)>, unpinned: &'pin mut (U), } #[allow(dead_code)] // This lint warns unused fields/variants. pub(crate) struct __FooProjectionRef<'pin, T, U> { pinned: ::core::pin::Pin<&'pin (T)>, unpinned: &'pin (U), } impl Foo { pub(crate) fn project<'pin>( self: ::core::pin::Pin<&'pin mut Self>, ) -> __FooProjection<'pin, T, U> { unsafe { let Foo { pinned, unpinned } = self.get_unchecked_mut(); __FooProjection { pinned: ::core::pin::Pin::new_unchecked(pinned), unpinned } } } pub(crate) fn project_ref<'pin>( self: ::core::pin::Pin<&'pin Self>, ) -> __FooProjectionRef<'pin, T, U> { unsafe { let Foo { pinned, unpinned } = self.get_ref(); __FooProjectionRef { pinned: ::core::pin::Pin::new_unchecked(pinned), unpinned } } } } unsafe impl UnsafeUnpin for Foo {} #[allow(single_use_lifetimes)] impl<'pin, T, U> ::core::marker::Unpin for Foo where ::pin_project::__private::Wrapper<'pin, Self>: ::pin_project::UnsafeUnpin { } // Ensure that struct does not implement `Drop`. // // See ./struct-default-expanded.rs for details. trait FooMustNotImplDrop {} #[allow(clippy::drop_bounds)] impl FooMustNotImplDrop for T {} #[allow(single_use_lifetimes)] impl FooMustNotImplDrop for Foo {} // Ensure that it's impossible to use pin projections on a #[repr(packed)] struct. // // See ./struct-default-expanded.rs and https://github.com/taiki-e/pin-project/pull/34 // for details. #[allow(single_use_lifetimes)] #[allow(non_snake_case)] #[deny(safe_packed_borrows)] fn __pin_project_assert_not_repr_packed_Foo(val: &Foo) { &val.pinned; &val.unpinned; } fn main() {} pin-project-0.4.8/examples/unsafe_unpin.rs010064400007650000024000000004371356530430100170560ustar0000000000000000// See ./pinned_drop-expanded.rs for generated code. #![allow(dead_code)] use pin_project::{pin_project, UnsafeUnpin}; #[pin_project(UnsafeUnpin)] pub struct Foo { #[pin] pinned: T, unpinned: U, } unsafe impl UnsafeUnpin for Foo {} fn main() {} pin-project-0.4.8/LICENSE-APACHE010060000007650000024000000261361340521270600141200ustar0000000000000000 Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright [yyyy] [name of copyright owner] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. pin-project-0.4.8/LICENSE-MIT010060000007650000024000000017771340521270600136340ustar0000000000000000Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. pin-project-0.4.8/README.md010064400007650000024000000041041356530430100134520ustar0000000000000000# pin-project [![crates-badge]][crates-url] [![docs-badge]][docs-url] [![license-badge]][license] [![rustc-badge]][rustc-url] [crates-badge]: https://img.shields.io/crates/v/pin-project.svg [crates-url]: https://crates.io/crates/pin-project [docs-badge]: https://docs.rs/pin-project/badge.svg [docs-url]: https://docs.rs/pin-project [license-badge]: https://img.shields.io/crates/l/pin-project.svg [license]: #license [rustc-badge]: https://img.shields.io/badge/rustc-1.33+-lightgray.svg [rustc-url]: https://blog.rust-lang.org/2019/02/28/Rust-1.33.0.html A crate for safe and ergonomic pin-projection. [Documentation][docs-url] [Examples](examples/README.md) ## Usage Add this to your `Cargo.toml`: ```toml [dependencies] pin-project = "0.4" ``` The current pin-project requires Rust 1.33 or later. ## Examples [`pin_project`] attribute creates a projection struct covering all the fields. ```rust use pin_project::pin_project; use std::pin::Pin; #[pin_project] struct Struct { #[pin] pinned: T, unpinned: U, } impl Struct { fn foo(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 } } ``` [Code like this will be generated](examples/struct-default-expanded.rs) See [API documentation][docs-url] for more details. Also, there are examples and generated code of each feature in [examples](examples/README.md) directory. [`pin_project`]: https://docs.rs/pin-project/0.4/pin_project/attr.pin_project.html ## License Licensed under either of * Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or ) * MIT license ([LICENSE-MIT](LICENSE-MIT) or ) at your option. ### Contribution Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions. pin-project-0.4.8/src/lib.rs010064400007650000024000000177431361355232600141210ustar0000000000000000//! A crate for safe and ergonomic pin-projection. //! //! ## Examples //! //! [`pin_project`] attribute creates a projection struct covering all the fields. //! //! ```rust //! use pin_project::pin_project; //! use std::pin::Pin; //! //! #[pin_project] //! struct Struct { //! #[pin] //! pinned: T, //! unpinned: U, //! } //! //! impl Struct { //! fn foo(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 //! } //! } //! ``` //! //! [Code like this will be generated](https://github.com/taiki-e/pin-project/blob/master/examples/struct-default-expanded.rs) //! //! See [`pin_project`] attribute for more details. //! //! Also, there are examples and generated code of each feature in [examples](https://github.com/taiki-e/pin-project/blob/master/examples/README.md) directory. //! //! [`pin_project`]: attr.pin_project.html #![no_std] #![recursion_limit = "256"] #![doc(html_root_url = "https://docs.rs/pin-project/0.4.8")] #![doc(test( no_crate_inject, attr(deny(warnings, rust_2018_idioms, single_use_lifetimes), allow(dead_code)) ))] #![warn(unsafe_code)] #![warn(missing_docs, rust_2018_idioms, single_use_lifetimes, unreachable_pub)] #![warn(clippy::all)] // mem::take requires Rust 1.40 #![allow(clippy::mem_replace_with_default)] #![allow(clippy::needless_doctest_main)] #[doc(inline)] pub use pin_project_internal::pin_project; #[doc(inline)] pub use pin_project_internal::pinned_drop; #[doc(inline)] pub use pin_project_internal::project; #[doc(inline)] pub use pin_project_internal::project_ref; /// A trait used for custom implementations of [`Unpin`]. /// This trait is used in conjunction with the `UnsafeUnpin` /// argument to [`pin_project`] /// /// The Rust [`Unpin`] trait is safe to implement - by itself, /// implementing it cannot lead to undefined behavior. Undefined /// behavior can only occur when other unsafe code is used. /// /// It turns out that using pin projections, which requires unsafe code, /// imposes additional requirements on an [`Unpin`] impl. Normally, all of this /// unsafety is contained within this crate, ensuring that it's impossible for /// you to violate any of the guarantees required by pin projection. /// /// However, things change if you want to provide a custom [`Unpin`] impl /// for your `#[pin_project]` type. As stated in [the Rust /// documentation](https://doc.rust-lang.org/nightly/std/pin/index.html#projections-and-structural-pinning), /// you must be sure to only implement [`Unpin`] when all of your `#[pin]` fields (i.e. structurally /// pinned fields) are also [`Unpin`]. /// /// To help highlight this unsafety, the `UnsafeUnpin` trait is provided. /// Implementing this trait is logically equivalent to implementing [`Unpin`] - /// this crate will generate an [`Unpin`] impl for your type that 'forwards' to /// your `UnsafeUnpin` impl. However, this trait is `unsafe` - since your type /// uses structural pinning (otherwise, you wouldn't be using this crate!), /// you must be sure that your `UnsafeUnpin` impls follows all of /// the requirements for an [`Unpin`] impl of a structurally-pinned type. /// /// Note that if you specify `#[pin_project(UnsafeUnpin)]`, but do *not* /// provide an impl of `UnsafeUnpin`, your type will never implement [`Unpin`]. /// This is effectively the same thing as adding a [`PhantomPinned`] to your type /// /// Since this trait is `unsafe`, impls of it will be detected by the `unsafe_code` lint, /// and by tools like `cargo geiger`. /// /// ## Examples /// /// An `UnsafeUnpin` impl which, in addition to requiring that structurally pinned /// fields be [`Unpin`], imposes an additional requirement: /// /// ```rust /// use pin_project::{pin_project, UnsafeUnpin}; /// /// #[pin_project(UnsafeUnpin)] /// struct Foo { /// #[pin] /// field_1: K, /// field_2: V, /// } /// /// unsafe impl UnsafeUnpin for Foo where K: Unpin + Clone {} /// ``` /// /// [`PhantomPinned`]: core::marker::PhantomPinned /// [`pin_project`]: attr.pin_project.html #[allow(unsafe_code)] pub unsafe trait UnsafeUnpin {} // Not public API. #[doc(hidden)] pub mod __private { use super::UnsafeUnpin; use core::{marker::PhantomData, pin::Pin}; #[doc(hidden)] pub use pin_project_internal::__PinProjectInternalDerive; // It is safe to implement PinnedDrop::drop, but it is not safe to call it. // This is because destructors can be called multiple times (double dropping // is unsound: rust-lang/rust#62360). // // Ideally, it would be desirable to be able to prohibit manual calls in the // same way as Drop::drop, but the library cannot. So, by using macros and // replacing them with private traits, we prevent users from calling // PinnedDrop::drop. // // Users can implement `Drop` safely using `#[pinned_drop]`. // **Do not call or implement this trait directly.** #[doc(hidden)] pub trait PinnedDrop { // Since calling it twice on the same object would be UB, // this method is unsafe. #[allow(unsafe_code)] #[doc(hidden)] unsafe fn drop(self: Pin<&mut Self>); } // This is an internal helper struct used by `pin-project-internal`. // This allows us to force an error if the user tries to provide // a regular `Unpin` impl when they specify the `UnsafeUnpin` argument. // This is why we need Wrapper: // // Supposed we have the following code: // // #[pin_project(UnsafeUnpin)] // struct MyStruct { // #[pin] field: T // } // // impl Unpin for MyStruct where MyStruct: UnsafeUnpin {} // generated by pin-project-internal // impl Unpin for MyStruct where T: Copy // written by the user // // We want this code to be rejected - the user is completely bypassing `UnsafeUnpin`, // and providing an unsound Unpin impl in safe code! // // Unfortunately, the Rust compiler will accept the above code. // Because MyStruct is declared in the same crate as the user-provided impl, // the compiler will notice that 'MyStruct: UnsafeUnpin' never holds. // // The solution is to introduce the 'Wrapper' struct, which is defined // in the 'pin-project' crate. // // We now have code that looks like this: // // impl Unpin for MyStruct where Wrapper>: UnsafeUnpin {} // generated by pin-project-internal // impl Unpin for MyStruct where T: Copy // written by the user // // We also have 'unsafe impl UnsafeUnpin for Wrapper where T: UnsafeUnpin {}' in the // 'pin-project' crate. // // Now, our generated impl has a bound involving a type defined in another crate - Wrapper. // This will cause rust to conservatively assume that 'Wrapper>: UnsafeUnpin' // holds, in the interest of preserving forwards compatibility (in case such an impl is added // for Wrapper in a new version of the crate). // // This will cause rust to reject any other Unpin impls for MyStruct, since it will // assume that our generated impl could potentially apply in any situation. // // This achieves the desired effect - when the user writes `#[pin_project(UnsafeUnpin)]`, // the user must either provide no impl of `UnsafeUnpin` (which is equivalent // to making the type never implement Unpin), or provide an impl of `UnsafeUnpin`. // It is impossible for them to provide an impl of `Unpin` #[doc(hidden)] pub struct Wrapper<'a, T: ?Sized>(PhantomData<&'a ()>, T); #[allow(unsafe_code)] unsafe impl UnsafeUnpin for Wrapper<'_, T> where T: UnsafeUnpin {} // This is an internal helper struct used by `pin-project-internal`. // // See https://github.com/taiki-e/pin-project/pull/53 for more details. #[doc(hidden)] pub struct AlwaysUnpin<'a, T: ?Sized>(PhantomData<&'a ()>, PhantomData); impl Unpin for AlwaysUnpin<'_, T> {} } pin-project-0.4.8/tests/cfg.rs010064400007650000024000000132651361127335300144560ustar0000000000000000#![warn(unsafe_code)] #![warn(rust_2018_idioms, single_use_lifetimes)] #![allow(dead_code)] // Refs: https://doc.rust-lang.org/nightly/reference/attributes.html use pin_project::pin_project; use std::{marker::PhantomPinned, pin::Pin}; fn is_unpin() {} #[cfg(target_os = "linux")] pub struct Linux; #[cfg(not(target_os = "linux"))] pub struct Other; // Use this type to check that `cfg(any())` is working properly. // If `cfg(any())` is not working properly, `is_unpin` will fail. pub struct Any(PhantomPinned); #[test] fn cfg() { // structs #[pin_project] pub struct SameName { #[cfg(target_os = "linux")] #[pin] inner: Linux, #[cfg(not(target_os = "linux"))] #[pin] inner: Other, #[cfg(any())] #[pin] any: Any, } is_unpin::(); #[cfg(target_os = "linux")] let _x = SameName { inner: Linux }; #[cfg(not(target_os = "linux"))] let _x = SameName { inner: Other }; #[pin_project] pub struct DifferentName { #[cfg(target_os = "linux")] #[pin] l: Linux, #[cfg(not(target_os = "linux"))] #[pin] o: Other, #[cfg(any())] #[pin] a: Any, } is_unpin::(); #[cfg(target_os = "linux")] let _x = DifferentName { l: Linux }; #[cfg(not(target_os = "linux"))] let _x = DifferentName { o: Other }; #[pin_project] pub struct TupleStruct( #[cfg(target_os = "linux")] #[pin] Linux, #[cfg(not(target_os = "linux"))] #[pin] Other, #[cfg(any())] #[pin] Any, ); is_unpin::(); #[cfg(target_os = "linux")] let _x = TupleStruct(Linux); #[cfg(not(target_os = "linux"))] let _x = TupleStruct(Other); // enums #[pin_project] pub enum Variant { #[cfg(target_os = "linux")] Inner(#[pin] Linux), #[cfg(not(target_os = "linux"))] Inner(#[pin] Other), #[cfg(target_os = "linux")] Linux(#[pin] Linux), #[cfg(not(target_os = "linux"))] Other(#[pin] Other), #[cfg(any())] Any(#[pin] Any), } is_unpin::(); #[cfg(target_os = "linux")] let _x = Variant::Inner(Linux); #[cfg(not(target_os = "linux"))] let _x = Variant::Inner(Other); #[cfg(target_os = "linux")] let _x = Variant::Linux(Linux); #[cfg(not(target_os = "linux"))] let _x = Variant::Other(Other); #[pin_project] pub enum Field { SameName { #[cfg(target_os = "linux")] #[pin] inner: Linux, #[cfg(not(target_os = "linux"))] #[pin] inner: Other, #[cfg(any())] #[pin] any: Any, }, DifferentName { #[cfg(target_os = "linux")] #[pin] l: Linux, #[cfg(not(target_os = "linux"))] #[pin] w: Other, #[cfg(any())] #[pin] any: Any, }, TupleVariant( #[cfg(target_os = "linux")] #[pin] Linux, #[cfg(not(target_os = "linux"))] #[pin] Other, #[cfg(any())] #[pin] Any, ), } is_unpin::(); #[cfg(target_os = "linux")] let _x = Field::SameName { inner: Linux }; #[cfg(not(target_os = "linux"))] let _x = Field::SameName { inner: Other }; #[cfg(target_os = "linux")] let _x = Field::DifferentName { l: Linux }; #[cfg(not(target_os = "linux"))] let _x = Field::DifferentName { w: Other }; #[cfg(target_os = "linux")] let _x = Field::TupleVariant(Linux); #[cfg(not(target_os = "linux"))] let _x = Field::TupleVariant(Other); } #[test] fn cfg_attr() { #[pin_project] pub struct SameCfg { #[cfg(target_os = "linux")] #[cfg_attr(target_os = "linux", pin)] inner: Linux, #[cfg(not(target_os = "linux"))] #[cfg_attr(not(target_os = "linux"), pin)] inner: Other, #[cfg(any())] #[cfg_attr(any(), pin)] any: Any, } is_unpin::(); #[cfg(target_os = "linux")] let mut x = SameCfg { inner: Linux }; #[cfg(not(target_os = "linux"))] let mut x = SameCfg { inner: Other }; let x = Pin::new(&mut x).project(); #[cfg(target_os = "linux")] let _: Pin<&mut Linux> = x.inner; #[cfg(not(target_os = "linux"))] let _: Pin<&mut Other> = x.inner; #[pin_project] pub struct DifferentCfg { #[cfg(target_os = "linux")] #[cfg_attr(target_os = "linux", pin)] inner: Linux, #[cfg(not(target_os = "linux"))] #[cfg_attr(target_os = "linux", pin)] inner: Other, #[cfg(any())] #[cfg_attr(any(), pin)] any: Any, } is_unpin::(); #[cfg(target_os = "linux")] let mut x = DifferentCfg { inner: Linux }; #[cfg(not(target_os = "linux"))] let mut x = DifferentCfg { inner: Other }; let x = Pin::new(&mut x).project(); #[cfg(target_os = "linux")] let _: Pin<&mut Linux> = x.inner; #[cfg(not(target_os = "linux"))] let _: &mut Other = x.inner; #[cfg_attr(not(any()), pin_project)] struct Foo { #[cfg_attr(not(any()), pin)] inner: T, } let mut x = Foo { inner: 0_u8 }; let x = Pin::new(&mut x).project(); let _: Pin<&mut u8> = x.inner; } #[test] fn cfg_attr_any_packed() { // Since `cfg(any())` can never be true, it is okay for this to pass. #[pin_project] #[cfg_attr(any(), repr(packed))] struct Struct { #[pin] field: u32, } } pin-project-0.4.8/tests/compiletest.rs010064400007650000024000000010161361127335300162360ustar0000000000000000#![cfg(pin_project_show_unpin_struct)] #![warn(unsafe_code)] #![warn(rust_2018_idioms, single_use_lifetimes)] #[ignore] #[test] fn ui() { let t = trybuild::TestCases::new(); t.compile_fail("tests/ui/cfg/*.rs"); t.compile_fail("tests/ui/pin_project/*.rs"); t.compile_fail("tests/ui/pinned_drop/*.rs"); t.compile_fail("tests/ui/project/*.rs"); t.compile_fail("tests/ui/unsafe_unpin/*.rs"); t.compile_fail("tests/ui/unstable-features/*.rs"); t.pass("tests/ui/unstable-features/run-pass/*.rs"); } pin-project-0.4.8/tests/pin_project.rs010064400007650000024000000255541361143547600162450ustar0000000000000000#![no_std] #![warn(unsafe_code)] #![warn(rust_2018_idioms, single_use_lifetimes)] #![allow(dead_code)] use core::{marker::PhantomPinned, pin::Pin}; use pin_project::{pin_project, pinned_drop, UnsafeUnpin}; #[test] fn test_pin_project() { #[pin_project] struct Struct { #[pin] field1: T, field2: U, } let mut foo = Struct { field1: 1, field2: 2 }; let mut foo_orig = Pin::new(&mut foo); let foo = foo_orig.as_mut().project(); let x: Pin<&mut i32> = foo.field1; assert_eq!(*x, 1); let y: &mut i32 = foo.field2; assert_eq!(*y, 2); assert_eq!(foo_orig.as_ref().field1, 1); assert_eq!(foo_orig.as_ref().field2, 2); let mut foo = Struct { field1: 1, field2: 2 }; let foo = Pin::new(&mut foo).project(); let __StructProjection { field1, field2 } = foo; let _: Pin<&mut i32> = field1; let _: &mut i32 = field2; #[pin_project] struct TupleStruct(#[pin] T, U); let mut bar = TupleStruct(1, 2); let bar = Pin::new(&mut bar).project(); let x: Pin<&mut i32> = bar.0; assert_eq!(*x, 1); let y: &mut i32 = bar.1; assert_eq!(*y, 2); #[pin_project] #[derive(Eq, PartialEq, Debug)] enum Enum { Variant1(#[pin] A, B), Variant2 { #[pin] field1: C, field2: D, }, None, } let mut baz = Enum::Variant1(1, 2); let mut baz_orig = Pin::new(&mut baz); let baz = baz_orig.as_mut().project(); match baz { __EnumProjection::Variant1(x, y) => { let x: Pin<&mut i32> = x; assert_eq!(*x, 1); let y: &mut i32 = y; assert_eq!(*y, 2); } __EnumProjection::Variant2 { field1, field2 } => { let _x: Pin<&mut i32> = field1; let _y: &mut i32 = field2; } __EnumProjection::None => {} } assert_eq!(Pin::into_ref(baz_orig).get_ref(), &Enum::Variant1(1, 2)); let mut baz = Enum::Variant2 { field1: 3, field2: 4 }; let mut baz = Pin::new(&mut baz).project(); match &mut baz { __EnumProjection::Variant1(x, y) => { let _x: &mut Pin<&mut i32> = x; let _y: &mut &mut i32 = y; } __EnumProjection::Variant2 { field1, field2 } => { let x: &mut Pin<&mut i32> = field1; assert_eq!(**x, 3); let y: &mut &mut i32 = field2; assert_eq!(**y, 4); } __EnumProjection::None => {} } if let __EnumProjection::Variant2 { field1, field2 } = baz { let x: Pin<&mut i32> = field1; assert_eq!(*x, 3); let y: &mut i32 = field2; assert_eq!(*y, 4); } } #[test] fn enum_project_set() { #[pin_project] #[derive(Eq, PartialEq, Debug)] enum Bar { Variant1(#[pin] u8), Variant2(bool), } let mut bar = Bar::Variant1(25); let mut bar_orig = Pin::new(&mut bar); let bar_proj = bar_orig.as_mut().project(); match bar_proj { __BarProjection::Variant1(val) => { let new_bar = Bar::Variant2(val.as_ref().get_ref() == &25); bar_orig.set(new_bar); } _ => unreachable!(), } assert_eq!(bar, Bar::Variant2(true)); } #[test] fn where_clause_and_associated_type_fields() { #[pin_project] struct Struct1 where I: Iterator, { #[pin] field1: I, field2: I::Item, } #[pin_project] struct Struct2 where I: Iterator, { #[pin] field1: I, field2: J, } #[pin_project] pub struct Struct3 where T: 'static, { field: T, } trait Static: 'static {} impl Static for Struct3 {} #[pin_project] enum Enum where I: Iterator, { Variant1(#[pin] I), Variant2(I::Item), } } #[allow(explicit_outlives_requirements)] // https://github.com/rust-lang/rust/issues/60993 #[test] fn unsized_in_where_clause() { #[pin_project] struct Struct where I: ?Sized, { #[pin] field: I, } } #[test] fn derive_copy() { #[pin_project] #[derive(Clone, Copy)] struct Struct { val: T, } fn is_copy() {} is_copy::>(); } #[test] fn move_out() { struct NotCopy; #[pin_project] struct Struct { val: NotCopy, } let foo = Struct { val: NotCopy }; let _val: NotCopy = foo.val; #[pin_project] enum Enum { Variant(NotCopy), } let bar = Enum::Variant(NotCopy); let _val: NotCopy = match bar { Enum::Variant(val) => val, }; } #[test] fn trait_bounds_on_type_generics() { #[pin_project] pub struct Struct1<'a, T: ?Sized> { field: &'a mut T, } #[pin_project] pub struct Struct2<'a, T: ::core::fmt::Debug> { field: &'a mut T, } #[pin_project] pub struct Struct3<'a, T: core::fmt::Debug> { field: &'a mut T, } #[pin_project] pub struct Struct4<'a, T: core::fmt::Debug + core::fmt::Display> { field: &'a mut T, } #[pin_project] pub struct Struct5<'a, T: core::fmt::Debug + ?Sized> { field: &'a mut T, } #[pin_project] pub struct Struct6<'a, T: core::fmt::Debug = [u8; 16]> { field: &'a mut T, } let _: Struct6<'_> = Struct6 { field: &mut [0u8; 16] }; #[pin_project] pub struct Struct7 { field: T, } trait Static: 'static {} impl Static for Struct7 {} #[pin_project] pub struct Struct8<'a, 'b: 'a> { field1: &'a u8, field2: &'b u8, } #[pin_project] pub struct TupleStruct<'a, T: ?Sized>(&'a mut T); #[pin_project] enum Enum<'a, T: ?Sized> { Variant(&'a mut T), } } #[test] fn overlapping_lifetime_names() { #[pin_project] pub struct Foo<'pin, T> { #[pin] field: &'pin mut T, } } #[test] fn combine() { #[pin_project(PinnedDrop, UnsafeUnpin)] pub struct Foo { field1: u8, #[pin] field2: T, } #[pinned_drop] impl PinnedDrop for Foo { fn drop(self: Pin<&mut Self>) {} } #[allow(unsafe_code)] unsafe impl UnsafeUnpin for Foo {} } #[test] fn private_type_in_public_type() { #[pin_project] pub struct PublicStruct { #[pin] inner: PrivateStruct, } struct PrivateStruct(T); } #[test] fn lifetime_project() { #[pin_project] struct Struct1 { #[pin] pinned: T, unpinned: U, } #[pin_project] struct Struct2<'a, T, U> { #[pin] pinned: &'a mut T, unpinned: U, } #[pin_project] enum Enum { Variant { #[pin] pinned: T, unpinned: U, }, } impl Struct1 { fn get_pin_ref<'a>(self: Pin<&'a Self>) -> Pin<&'a T> { self.project_ref().pinned } fn get_pin_mut<'a>(self: Pin<&'a mut Self>) -> Pin<&'a mut T> { self.project().pinned } } impl<'b, T, U> Struct2<'b, T, U> { fn get_pin_ref<'a>(self: Pin<&'a Self>) -> Pin<&'a &'b mut T> { self.project_ref().pinned } fn get_pin_mut<'a>(self: Pin<&'a mut Self>) -> Pin<&'a mut &'b mut T> { self.project().pinned } } impl Enum { fn get_pin_ref<'a>(self: Pin<&'a Self>) -> Pin<&'a T> { match self.project_ref() { __EnumProjectionRef::Variant { pinned, .. } => pinned, } } fn get_pin_mut<'a>(self: Pin<&'a mut Self>) -> Pin<&'a mut T> { match self.project() { __EnumProjection::Variant { pinned, .. } => pinned, } } } } #[rustversion::since(1.36)] #[test] fn lifetime_project_elided() { #[pin_project] struct Struct1 { #[pin] pinned: T, unpinned: U, } #[pin_project] struct Struct2<'a, T, U> { #[pin] pinned: &'a mut T, unpinned: U, } #[pin_project] enum Enum { Variant { #[pin] pinned: T, unpinned: U, }, } impl Struct1 { fn get_pin_ref(self: Pin<&Self>) -> Pin<&T> { self.project_ref().pinned } fn get_pin_mut(self: Pin<&mut Self>) -> Pin<&mut T> { self.project().pinned } } impl<'b, T, U> Struct2<'b, T, U> { fn get_pin_ref(self: Pin<&Self>) -> Pin<&&'b mut T> { self.project_ref().pinned } fn get_pin_mut(self: Pin<&mut Self>) -> Pin<&mut &'b mut T> { self.project().pinned } } impl Enum { fn get_pin_ref(self: Pin<&Self>) -> Pin<&T> { match self.project_ref() { __EnumProjectionRef::Variant { pinned, .. } => pinned, } } fn get_pin_mut(self: Pin<&mut Self>) -> Pin<&mut T> { match self.project() { __EnumProjection::Variant { pinned, .. } => pinned, } } } } mod visibility { use pin_project::pin_project; #[pin_project] pub(crate) struct A { pub b: u8, } } #[test] fn visibility() { let mut x = visibility::A { b: 0 }; let x = Pin::new(&mut x); let y = x.as_ref().project_ref(); let _: &u8 = y.b; let y = x.project(); let _: &mut u8 = y.b; } #[test] fn trivial_bounds() { #[pin_project] pub struct NoGenerics { #[pin] field: PhantomPinned, } } #[test] fn dst() { #[pin_project] pub struct A { x: T, } let _: &mut A = &mut A { x: 0u8 } as _; #[pin_project] pub struct B { #[pin] x: T, } #[pin_project] pub struct C(T); #[pin_project] pub struct D(#[pin] T); } #[test] fn dyn_type() { #[pin_project] struct Struct1 { a: i32, f: dyn core::fmt::Debug, } #[pin_project] struct Struct2 { a: i32, #[pin] f: dyn core::fmt::Debug, } #[pin_project] struct Struct3 { a: i32, f: dyn core::fmt::Debug + Send, } #[pin_project] struct Struct4 { a: i32, #[pin] f: dyn core::fmt::Debug + Send, } } #[test] fn self_in_where_clause() { pub trait Trait {} #[pin_project] pub struct Struct1 where Self: Trait, { x: T, } impl Trait for Struct1 {} pub trait Trait2 { type Foo; } #[pin_project] pub struct Struct2 where Self: Trait2>, ::Foo: Trait, { x: T, } impl Trait2 for Struct2 { type Foo = Struct1; } } pin-project-0.4.8/tests/pinned_drop.rs010064400007650000024000000120411361143547600162150ustar0000000000000000#![warn(unsafe_code)] #![warn(rust_2018_idioms, single_use_lifetimes)] #![allow(dead_code)] use pin_project::{pin_project, pinned_drop}; use std::pin::Pin; #[test] fn safe_project() { #[pin_project(PinnedDrop)] pub struct Struct<'a> { was_dropped: &'a mut bool, #[pin] field: u8, } #[pinned_drop] impl PinnedDrop for Struct<'_> { fn drop(self: Pin<&mut Self>) { **self.project().was_dropped = true; } } let mut was_dropped = false; drop(Struct { was_dropped: &mut was_dropped, field: 42 }); assert!(was_dropped); } #[test] fn mut_self_argument() { #[pin_project(PinnedDrop)] struct Struct { data: usize, } #[pinned_drop] impl PinnedDrop for Struct { fn drop(mut self: Pin<&mut Self>) { let _: &mut _ = &mut self.data; } } } #[test] fn self_in_vec() { #[pin_project(PinnedDrop)] struct Struct { data: usize, } #[pinned_drop] impl PinnedDrop for Struct { fn drop(self: Pin<&mut Self>) { let _: Vec<_> = vec![self.data]; } } } #[test] fn self_in_macro_containing_fn() { #[pin_project(PinnedDrop)] pub struct Struct { data: usize, } macro_rules! emit { ($($tt:tt)*) => { $($tt)* }; } #[pinned_drop] impl PinnedDrop for Struct { fn drop(self: Pin<&mut Self>) { let _ = emit!({ impl Struct { pub fn f(self) {} } }); self.data; } } } #[test] fn self_call() { #[pin_project(PinnedDrop)] pub struct Struct { data: usize, } trait Trait { fn self_ref(&self) {} fn self_pin_ref(self: Pin<&Self>) {} fn self_mut(&mut self) {} fn self_pin_mut(self: Pin<&mut Self>) {} fn assoc_fn(_this: Pin<&mut Self>) {} } impl Trait for Struct {} #[pinned_drop] impl PinnedDrop for Struct { fn drop(mut self: Pin<&mut Self>) { self.self_ref(); self.as_ref().self_pin_ref(); self.self_mut(); self.as_mut().self_pin_mut(); Self::assoc_fn(self.as_mut()); ::assoc_fn(self.as_mut()); } } } // See also `ui/pinned_drop/self.rs`. #[test] fn self_expr() { #[pin_project(PinnedDrop)] pub struct Struct { x: usize, } #[pinned_drop] impl PinnedDrop for Struct { fn drop(mut self: Pin<&mut Self>) { let _: Self = Self { x: 0 }; } } #[pin_project(PinnedDrop)] pub struct TupleStruct(usize); #[pinned_drop] impl PinnedDrop for TupleStruct { fn drop(mut self: Pin<&mut Self>) { let _: Self = Self(0); } } #[rustversion::since(1.37)] #[pin_project(PinnedDrop)] pub enum Enum { StructVariant { x: usize }, TupleVariant(usize), } #[rustversion::since(1.37)] #[pinned_drop] impl PinnedDrop for Enum { fn drop(mut self: Pin<&mut Self>) { // let _: Self = Self::StructVariant { x: 0 }; //~ ERROR can't use generic parameters from outer function [E0401] let _: Self = Self::TupleVariant(0); } } } // See also `ui/pinned_drop/self.rs`. #[test] fn self_pat() { #[pin_project(PinnedDrop)] pub struct Struct { x: usize, } #[pinned_drop] impl PinnedDrop for Struct { fn drop(mut self: Pin<&mut Self>) { // match *self { // Self { x: _ } => {} //~ ERROR can't use generic parameters from outer function [E0401] // } // if let Self { x: _ } = *self {} //~ ERROR can't use generic parameters from outer function [E0401] // let Self { x: _ } = *self; //~ ERROR can't use generic parameters from outer function [E0401] } } #[pin_project(PinnedDrop)] pub struct TupleStruct(usize); #[pinned_drop] impl PinnedDrop for TupleStruct { #[allow(irrefutable_let_patterns)] fn drop(mut self: Pin<&mut Self>) { match *self { Self(_) => {} } if let Self(_) = *self {} let Self(_) = *self; } } #[rustversion::since(1.37)] #[pin_project(PinnedDrop)] pub enum Enum { StructVariant { x: usize }, TupleVariant(usize), } #[rustversion::since(1.37)] #[pinned_drop] impl PinnedDrop for Enum { fn drop(mut self: Pin<&mut Self>) { // match *self { // Self::StructVariant { x: _ } => {} //~ ERROR can't use generic parameters from outer function [E0401] // Self::TupleVariant(_) => {} //~ ERROR can't use generic parameters from outer function [E0401] // } // if let Self::StructVariant { x: _ } = *self {} //~ ERROR can't use generic parameters from outer function [E0401] // if let Self::TupleVariant(_) = *self {} //~ ERROR can't use generic parameters from outer function [E0401] } } } pin-project-0.4.8/tests/project.rs010064400007650000024000000066741361127335300153730ustar0000000000000000#![warn(unsafe_code)] #![warn(rust_2018_idioms, single_use_lifetimes)] #![allow(dead_code)] use pin_project::{pin_project, project}; use std::pin::Pin; #[project] // Nightly does not need a dummy attribute to the function. #[test] fn project_stmt_expr() { // struct #[pin_project] struct Foo { #[pin] field1: T, field2: U, } let mut foo = Foo { field1: 1, field2: 2 }; #[project] let Foo { field1, field2 } = Pin::new(&mut foo).project(); let x: Pin<&mut i32> = field1; assert_eq!(*x, 1); let y: &mut i32 = field2; assert_eq!(*y, 2); // tuple struct #[pin_project] struct Bar(#[pin] T, U); let mut bar = Bar(1, 2); #[project] let Bar(x, y) = Pin::new(&mut bar).project(); let x: Pin<&mut i32> = x; assert_eq!(*x, 1); let y: &mut i32 = y; assert_eq!(*y, 2); // enum #[pin_project] enum Baz { Variant1(#[pin] A, B), Variant2 { #[pin] field1: C, field2: D, }, None, } let mut baz = Baz::Variant1(1, 2); let mut baz = Pin::new(&mut baz).project(); #[project] match &mut baz { Baz::Variant1(x, y) => { let x: &mut Pin<&mut i32> = x; assert_eq!(**x, 1); let y: &mut &mut i32 = y; assert_eq!(**y, 2); } Baz::Variant2 { field1, field2 } => { let _x: &mut Pin<&mut i32> = field1; let _y: &mut &mut i32 = field2; } Baz::None => {} } #[project] let val = match &mut baz { Baz::Variant1(_, _) => true, Baz::Variant2 { .. } => false, Baz::None => false, }; assert_eq!(val, true); } #[test] fn project_impl() { #[pin_project] struct HasGenerics { #[pin] field1: T, field2: U, } #[project] impl HasGenerics { fn a(self) { let Self { field1, field2 } = self; let _x: Pin<&mut T> = field1; let _y: &mut U = field2; } } #[pin_project] struct NoneGenerics { #[pin] field1: i32, field2: u32, } #[project] impl NoneGenerics {} #[pin_project] struct HasLifetimes<'a, T, U> { #[pin] field1: &'a mut T, field2: U, } #[project] impl HasLifetimes<'_, T, U> {} #[pin_project] struct HasOverlappingLifetimes<'pin, T, U> { #[pin] field1: &'pin mut T, field2: U, } #[allow(single_use_lifetimes)] #[project] impl<'pin, T, U> HasOverlappingLifetimes<'pin, T, U> {} #[pin_project] struct HasOverlappingLifetimes2 { #[pin] field1: T, field2: U, } #[allow(single_use_lifetimes)] #[project] impl HasOverlappingLifetimes2 { fn foo<'pin>(&'pin self) {} } } #[pin_project] struct A { #[pin] field: u8, } mod project_use_1 { use crate::A; use core::pin::Pin; use pin_project::project; #[project] use crate::A; #[project] #[test] fn project_use() { let mut x = A { field: 0 }; #[project] let A { field } = Pin::new(&mut x).project(); let _: Pin<&mut u8> = field; } } mod project_use_2 { #[project] use crate::A; use pin_project::project; #[project] impl A { fn project_use(self) {} } } pin-project-0.4.8/tests/project_ref.rs010064400007650000024000000055741361127335300162250ustar0000000000000000#![warn(unsafe_code)] #![warn(rust_2018_idioms, single_use_lifetimes)] #![allow(dead_code)] use pin_project::{pin_project, project_ref}; use std::pin::Pin; #[project_ref] // Nightly does not need a dummy attribute to the function. #[test] fn project_stmt_expr() { // struct #[pin_project] struct Foo { #[pin] field1: T, field2: U, } let foo = Foo { field1: 1, field2: 2 }; #[project_ref] let Foo { field1, field2 } = Pin::new(&foo).project_ref(); let x: Pin<&i32> = field1; assert_eq!(*x, 1); let y: &i32 = field2; assert_eq!(*y, 2); // tuple struct #[pin_project] struct Bar(#[pin] T, U); let bar = Bar(1, 2); #[project_ref] let Bar(x, y) = Pin::new(&bar).project_ref(); let x: Pin<&i32> = x; assert_eq!(*x, 1); let y: &i32 = y; assert_eq!(*y, 2); // enum #[pin_project] enum Baz { Variant1(#[pin] A, B), Variant2 { #[pin] field1: C, field2: D, }, None, } let baz = Baz::Variant1(1, 2); let baz = Pin::new(&baz).project_ref(); #[project_ref] match &baz { Baz::Variant1(x, y) => { let x: &Pin<&i32> = x; assert_eq!(**x, 1); let y: &&i32 = y; assert_eq!(**y, 2); } Baz::Variant2 { field1, field2 } => { let _x: &Pin<&i32> = field1; let _y: &&i32 = field2; } Baz::None => {} } #[project_ref] let val = match &baz { Baz::Variant1(_, _) => true, Baz::Variant2 { .. } => false, Baz::None => false, }; assert_eq!(val, true); } #[test] fn project_impl() { #[pin_project] struct HasGenerics { #[pin] field1: T, field2: U, } #[project_ref] impl HasGenerics { fn a(self) { let Self { field1, field2 } = self; let _x: Pin<&T> = field1; let _y: &U = field2; } } #[pin_project] struct NoneGenerics { #[pin] field1: i32, field2: u32, } #[project_ref] impl NoneGenerics {} #[pin_project] struct HasLifetimes<'a, T, U> { #[pin] field1: &'a mut T, field2: U, } #[project_ref] impl HasLifetimes<'_, T, U> {} #[pin_project] struct HasOverlappingLifetimes<'pin, T, U> { #[pin] field1: &'pin mut T, field2: U, } #[allow(single_use_lifetimes)] #[project_ref] impl<'pin, T, U> HasOverlappingLifetimes<'pin, T, U> {} #[pin_project] struct HasOverlappingLifetimes2 { #[pin] field1: T, field2: U, } #[allow(single_use_lifetimes)] #[project_ref] impl HasOverlappingLifetimes2 { fn foo<'pin>(&'pin self) {} } } pin-project-0.4.8/tests/repr_packed.rs010064400007650000024000000031531361134231300161620ustar0000000000000000#![warn(unsafe_code)] #![warn(rust_2018_idioms, single_use_lifetimes)] #![allow(dead_code)] #![deny(safe_packed_borrows)] use std::cell::Cell; // Ensure that the compiler doesn't copy the fields // of #[repr(packed)] types during drop, if the field has alignment 1 // (that is, any reference to the field is guaranteed to have proper alignment) // We are currently unable to statically prevent the usage of #[pin_project] // on #[repr(packed)] types composed entirely of fields of alignment 1. // This shouldn't lead to undefined behavior, as long as the compiler doesn't // try to move the field anyway during drop. // // This tests validates that the compiler is doing what we expect. #[test] fn weird_repr_packed() { // We keep track of the field address during // drop using a thread local, to avoid changing // the layout of our #[repr(packed)] type. thread_local! { static FIELD_ADDR: Cell = Cell::new(0); } #[repr(packed)] struct Foo { field: u8, } impl Drop for Foo { fn drop(&mut self) { FIELD_ADDR.with(|f| { f.set(&self.field as *const u8 as usize); }) } } let field_addr = { // We let this field drop by going out of scope, // rather than explicitly calling drop(foo). // Calling drop(foo) causes 'foo' to be moved // into the 'drop' function, resulting in a different // address. let foo = Foo { field: 27 }; let field_addr = &foo.field as *const u8 as usize; field_addr }; assert_eq!(field_addr, FIELD_ADDR.with(|f| f.get())); } pin-project-0.4.8/tests/ui/cfg/cfg_attr-resolve.rs010064400007650000024000000003161361134257100203310ustar0000000000000000use std::pin::Pin; #[cfg_attr(any(), pin_project::pin_project)] struct Foo { inner: T, } fn main() { let mut x = Foo { inner: 0_u8 }; let _x = Pin::new(&mut x).project(); //~ ERROR E0599 } pin-project-0.4.8/tests/ui/cfg/cfg_attr-resolve.stderr010064400007650000024000000004611361127335300212120ustar0000000000000000error[E0599]: no method named `project` found for struct `std::pin::Pin<&mut Foo>` in the current scope --> $DIR/cfg_attr-resolve.rs:10:31 | 10 | let _x = Pin::new(&mut x).project(); //~ ERROR E0599 | ^^^^^^^ method not found in `std::pin::Pin<&mut Foo>` pin-project-0.4.8/tests/ui/cfg/cfg_attr-type-mismatch.rs010064400007650000024000000010051361127335300214330ustar0000000000000000use pin_project::pin_project; use std::pin::Pin; #[cfg_attr(not(any()), pin_project)] struct Foo { #[cfg_attr(any(), pin)] inner: T, } #[cfg_attr(not(any()), pin_project)] struct Bar { #[cfg_attr(not(any()), pin)] inner: T, } fn main() { let mut x = Foo { inner: 0_u8 }; let x = Pin::new(&mut x).project(); let _: Pin<&mut u8> = x.inner; //~ ERROR E0308 let mut x = Bar { inner: 0_u8 }; let x = Pin::new(&mut x).project(); let _: &mut u8 = x.inner; //~ ERROR E0308 } pin-project-0.4.8/tests/ui/cfg/cfg_attr-type-mismatch.stderr010064400007650000024000000015711361127335300223220ustar0000000000000000error[E0308]: mismatched types --> $DIR/cfg_attr-type-mismatch.rs:19:27 | 19 | let _: Pin<&mut u8> = x.inner; //~ ERROR E0308 | ------------ ^^^^^^^ expected struct `std::pin::Pin`, found `&mut u8` | | | expected due to this | = note: expected struct `std::pin::Pin<&mut u8>` found mutable reference `&mut u8` error[E0308]: mismatched types --> $DIR/cfg_attr-type-mismatch.rs:23:22 | 23 | let _: &mut u8 = x.inner; //~ ERROR E0308 | ------- ^^^^^^^ | | | | | expected `&mut u8`, found struct `std::pin::Pin` | | help: consider mutably borrowing here: `&mut x.inner` | expected due to this | = note: expected mutable reference `&mut u8` found struct `std::pin::Pin<&mut u8>` pin-project-0.4.8/tests/ui/cfg/cfg_attr-unpin.rs010064400007650000024000000006351361127335300200100ustar0000000000000000use pin_project::pin_project; use std::marker::PhantomPinned; #[cfg_attr(any(), pin_project)] struct Foo { inner: T, } #[cfg_attr(not(any()), pin_project)] struct Bar { #[cfg_attr(not(any()), pin)] inner: T, } fn is_unpin() {} fn main() { is_unpin::>(); // ERROR E0277 is_unpin::>(); // Ok is_unpin::>(); //~ ERROR E0277 } pin-project-0.4.8/tests/ui/cfg/cfg_attr-unpin.stderr010064400007650000024000000030201361127335300206560ustar0000000000000000error[E0277]: the trait bound `std::marker::PhantomPinned: std::marker::Unpin` is not satisfied in `Foo` --> $DIR/cfg_attr-unpin.rs:18:5 | 15 | fn is_unpin() {} | -------- ----- required by this bound in `is_unpin` ... 18 | is_unpin::>(); // ERROR E0277 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ within `Foo`, the trait `std::marker::Unpin` is not implemented for `std::marker::PhantomPinned` | = help: the following implementations were found: = note: required because it appears within the type `Foo` error[E0277]: the trait bound `std::marker::PhantomPinned: std::marker::Unpin` is not satisfied in `__Bar<'_, std::marker::PhantomPinned>` --> $DIR/cfg_attr-unpin.rs:20:5 | 15 | fn is_unpin() {} | -------- ----- required by this bound in `is_unpin` ... 20 | is_unpin::>(); //~ ERROR E0277 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ within `__Bar<'_, std::marker::PhantomPinned>`, the trait `std::marker::Unpin` is not implemented for `std::marker::PhantomPinned` | = help: the following implementations were found: = note: required because it appears within the type `__Bar<'_, std::marker::PhantomPinned>` = note: required because of the requirements on the impl of `std::marker::Unpin` for `Bar` pin-project-0.4.8/tests/ui/cfg/packed_sneaky-span-issue-1.rs010064400007650000024000000005371361127335300221150ustar0000000000000000use auxiliary_macros::hidden_repr; use pin_project::pin_project; //~ ERROR may not be used on #[repr(packed)] types // span is lost. // Refs: https://github.com/rust-lang/rust/issues/43081 #[pin_project] #[hidden_repr(packed)] struct Foo { #[cfg(not(any()))] #[pin] field: u32, #[cfg(any())] #[pin] field: u8, } fn main() {} pin-project-0.4.8/tests/ui/cfg/packed_sneaky-span-issue-1.stderr010064400007650000024000000001111361127335300227600ustar0000000000000000error: #[pin_project] attribute may not be used on #[repr(packed)] types pin-project-0.4.8/tests/ui/cfg/packed_sneaky-span-issue-2.rs010064400007650000024000000005371361127335300221160ustar0000000000000000use auxiliary_macros::hidden_repr; use pin_project::pin_project; //~ ERROR may not be used on #[repr(packed)] types // span is lost. // Refs: https://github.com/rust-lang/rust/issues/43081 #[pin_project] #[hidden_repr(packed)] struct Foo { #[cfg(any())] #[pin] field: u32, #[cfg(not(any()))] #[pin] field: u8, } fn main() {} pin-project-0.4.8/tests/ui/cfg/packed_sneaky-span-issue-2.stderr010064400007650000024000000001111361127335300227610ustar0000000000000000error: #[pin_project] attribute may not be used on #[repr(packed)] types pin-project-0.4.8/tests/ui/cfg/packed_sneaky.rs010064400007650000024000000005061361127335300176660ustar0000000000000000use auxiliary_macros::hidden_repr_cfg_not_any; use pin_project::pin_project; // `#[hidden_repr_cfg_not_any(packed)]` generates `#[cfg_attr(not(any()), repr(packed))]`. #[pin_project] #[hidden_repr_cfg_not_any(packed)] //~ ERROR may not be used on #[repr(packed)] types struct Foo { #[pin] field: u32, } fn main() {} pin-project-0.4.8/tests/ui/cfg/packed_sneaky.stderr010064400007650000024000000003551361127335300205470ustar0000000000000000error: #[pin_project] attribute may not be used on #[repr(packed)] types --> $DIR/packed_sneaky.rs:6:1 | 6 | #[hidden_repr_cfg_not_any(packed)] //~ ERROR may not be used on #[repr(packed)] types | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ pin-project-0.4.8/tests/ui/cfg/proper_unpin.rs010064400007650000024000000007201361127335300176030ustar0000000000000000use pin_project::pin_project; use std::marker::PhantomPinned; #[pin_project] struct Foo { #[cfg(any())] #[pin] inner: T, #[cfg(not(any()))] inner: T, } #[pin_project] struct Bar { #[cfg(any())] inner: T, #[cfg(not(any()))] #[pin] inner: T, } fn is_unpin() {} fn main() { is_unpin::>(); // Ok is_unpin::>(); // Ok is_unpin::>(); //~ ERROR E0277 } pin-project-0.4.8/tests/ui/cfg/proper_unpin.stderr010064400007650000024000000015141361127335300204640ustar0000000000000000error[E0277]: the trait bound `std::marker::PhantomPinned: std::marker::Unpin` is not satisfied in `__Bar<'_, std::marker::PhantomPinned>` --> $DIR/proper_unpin.rs:27:5 | 22 | fn is_unpin() {} | -------- ----- required by this bound in `is_unpin` ... 27 | is_unpin::>(); //~ ERROR E0277 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ within `__Bar<'_, std::marker::PhantomPinned>`, the trait `std::marker::Unpin` is not implemented for `std::marker::PhantomPinned` | = help: the following implementations were found: = note: required because it appears within the type `__Bar<'_, std::marker::PhantomPinned>` = note: required because of the requirements on the impl of `std::marker::Unpin` for `Bar` pin-project-0.4.8/tests/ui/cfg/unsupported.rs010064400007650000024000000003651361127335300174600ustar0000000000000000use pin_project::pin_project; //~ ERROR may not be used on structs with zero fields // span is lost. // Refs: https://github.com/rust-lang/rust/issues/43081 #[pin_project] struct Struct { #[cfg(any())] #[pin] f: u8, } fn main() {} pin-project-0.4.8/tests/ui/cfg/unsupported.stderr010064400007650000024000000001141361127335300203270ustar0000000000000000error: #[pin_project] attribute may not be used on structs with zero fields pin-project-0.4.8/tests/ui/pin_project/add-attr-to-struct.rs010064400007650000024000000006161361127335300223060ustar0000000000000000use auxiliary_macros::add_attr; use pin_project::pin_project; use std::marker::PhantomPinned; #[pin_project] #[add_attr(struct)] //~ ERROR duplicate #[pin] attribute struct Foo { #[pin] field: PhantomPinned, } #[add_attr(struct)] //~ ERROR #[pin] attribute may only be used on fields of structs or variants #[pin_project] struct Bar { #[pin] field: PhantomPinned, } fn main() {} pin-project-0.4.8/tests/ui/pin_project/add-attr-to-struct.stderr010064400007650000024000000006241361127335300231640ustar0000000000000000error: duplicate #[pin] attribute --> $DIR/add-attr-to-struct.rs:6:1 | 6 | #[add_attr(struct)] //~ ERROR duplicate #[pin] attribute | ^^^^^^^^^^^^^^^^^^^ error: #[pin] attribute may only be used on fields of structs or variants --> $DIR/add-attr-to-struct.rs:12:1 | 12 | #[add_attr(struct)] //~ ERROR #[pin] attribute may only be used on fields of structs or variants | ^^^^^^^^^^^^^^^^^^^ pin-project-0.4.8/tests/ui/pin_project/add-pinned-field.rs010064400007650000024000000005331361127335300217260ustar0000000000000000use auxiliary_macros::add_pinned_field; use pin_project::pin_project; fn is_unpin() {} #[pin_project] #[add_pinned_field] struct Foo { #[pin] field: u32, } #[add_pinned_field] #[pin_project] struct Bar { #[pin] field: u32, } fn main() { is_unpin::(); //~ ERROR E0277 is_unpin::(); //~ ERROR E0277 } pin-project-0.4.8/tests/ui/pin_project/add-pinned-field.stderr010064400007650000024000000026051361127335300226070ustar0000000000000000error[E0277]: the trait bound `std::marker::PhantomPinned: std::marker::Unpin` is not satisfied in `__Foo<'_>` --> $DIR/add-pinned-field.rs:21:5 | 4 | fn is_unpin() {} | -------- ----- required by this bound in `is_unpin` ... 21 | is_unpin::(); //~ ERROR E0277 | ^^^^^^^^^^^^^^^ within `__Foo<'_>`, the trait `std::marker::Unpin` is not implemented for `std::marker::PhantomPinned` | = help: the following implementations were found: = note: required because it appears within the type `__Foo<'_>` = note: required because of the requirements on the impl of `std::marker::Unpin` for `Foo` error[E0277]: the trait bound `std::marker::PhantomPinned: std::marker::Unpin` is not satisfied in `__Bar<'_>` --> $DIR/add-pinned-field.rs:22:5 | 4 | fn is_unpin() {} | -------- ----- required by this bound in `is_unpin` ... 22 | is_unpin::(); //~ ERROR E0277 | ^^^^^^^^^^^^^^^ within `__Bar<'_>`, the trait `std::marker::Unpin` is not implemented for `std::marker::PhantomPinned` | = help: the following implementations were found: = note: required because it appears within the type `__Bar<'_>` = note: required because of the requirements on the impl of `std::marker::Unpin` for `Bar` pin-project-0.4.8/tests/ui/pin_project/conflict-drop.rs010064400007650000024000000007531361127335300214110ustar0000000000000000use pin_project::{pin_project, pinned_drop}; use std::pin::Pin; #[pin_project] //~ ERROR E0119 struct Foo { #[pin] future: T, field: U, } impl Drop for Foo { fn drop(&mut self) {} } #[pin_project(PinnedDrop)] //~ ERROR E0119 struct Bar { #[pin] future: T, field: U, } #[pinned_drop] impl PinnedDrop for Bar { fn drop(self: Pin<&mut Self>) {} } impl Drop for Bar { fn drop(&mut self) {} } fn main() {} pin-project-0.4.8/tests/ui/pin_project/conflict-drop.stderr010064400007650000024000000011541361127335300222640ustar0000000000000000error[E0119]: conflicting implementations of trait `FooMustNotImplDrop` for type `Foo<_, _>`: --> $DIR/conflict-drop.rs:4:1 | 4 | #[pin_project] //~ ERROR E0119 | ^^^^^^^^^^^^^^ | | | first implementation here | conflicting implementation for `Foo<_, _>` error[E0119]: conflicting implementations of trait `std::ops::Drop` for type `Bar<_, _>`: --> $DIR/conflict-drop.rs:15:1 | 15 | #[pin_project(PinnedDrop)] //~ ERROR E0119 | ^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `Bar<_, _>` ... 27 | impl Drop for Bar { | ----------------------------- first implementation here pin-project-0.4.8/tests/ui/pin_project/conflict-unpin.rs010064400007650000024000000013151361127335300215710ustar0000000000000000use pin_project::pin_project; // The same implementation. #[pin_project] //~ ERROR E0119 struct Foo { #[pin] future: T, field: U, } // conflicting implementations impl Unpin for Foo where T: Unpin {} // Conditional Unpin impl // The implementation that under different conditions. #[pin_project] //~ ERROR E0119 struct Bar { #[pin] future: T, field: U, } // conflicting implementations impl Unpin for Bar {} // Non-conditional Unpin impl #[pin_project] //~ ERROR E0119 struct Baz { #[pin] future: T, field: U, } // conflicting implementations impl Unpin for Baz {} // Conditional Unpin impl fn main() {} pin-project-0.4.8/tests/ui/pin_project/conflict-unpin.stderr010064400007650000024000000022001361127335300224420ustar0000000000000000error[E0119]: conflicting implementations of trait `std::marker::Unpin` for type `Foo<_, _>`: --> $DIR/conflict-unpin.rs:5:1 | 5 | #[pin_project] //~ ERROR E0119 | ^^^^^^^^^^^^^^ conflicting implementation for `Foo<_, _>` ... 13 | impl Unpin for Foo where T: Unpin {} // Conditional Unpin impl | --------------------------------------------- first implementation here error[E0119]: conflicting implementations of trait `std::marker::Unpin` for type `Bar<_, _>`: --> $DIR/conflict-unpin.rs:17:1 | 17 | #[pin_project] //~ ERROR E0119 | ^^^^^^^^^^^^^^ conflicting implementation for `Bar<_, _>` ... 25 | impl Unpin for Bar {} // Non-conditional Unpin impl | ------------------------------ first implementation here error[E0119]: conflicting implementations of trait `std::marker::Unpin` for type `Baz<_, _>`: --> $DIR/conflict-unpin.rs:27:1 | 27 | #[pin_project] //~ ERROR E0119 | ^^^^^^^^^^^^^^ conflicting implementation for `Baz<_, _>` ... 35 | impl Unpin for Baz {} // Conditional Unpin impl | -------------------------------------------- first implementation here pin-project-0.4.8/tests/ui/pin_project/duplicate-argument.rs010064400007650000024000000011541361127335300224340ustar0000000000000000use pin_project::pin_project; #[pin_project(UnsafeUnpin, UnsafeUnpin)] //~ ERROR duplicate `UnsafeUnpin` argument struct UnsafeUnpin { #[pin] pinned: T, } #[pin_project(PinnedDrop, PinnedDrop)] //~ ERROR duplicate `PinnedDrop` argument struct PinnedDrop { #[pin] pinned: T, } #[pin_project(PinnedDrop, UnsafeUnpin, UnsafeUnpin)] //~ ERROR duplicate `UnsafeUnpin` argument struct Duplicate3 { #[pin] pinned: T, } #[pin_project(PinnedDrop, UnsafeUnpin, PinnedDrop, PinnedDrop)] //~ ERROR duplicate `PinnedDrop` argument struct Duplicate4 { #[pin] pinned: T, } fn main() {} pin-project-0.4.8/tests/ui/pin_project/duplicate-argument.stderr010064400007650000024000000016171361127335300233170ustar0000000000000000error: duplicate `UnsafeUnpin` argument --> $DIR/duplicate-argument.rs:3:28 | 3 | #[pin_project(UnsafeUnpin, UnsafeUnpin)] //~ ERROR duplicate `UnsafeUnpin` argument | ^^^^^^^^^^^ error: duplicate `PinnedDrop` argument --> $DIR/duplicate-argument.rs:9:27 | 9 | #[pin_project(PinnedDrop, PinnedDrop)] //~ ERROR duplicate `PinnedDrop` argument | ^^^^^^^^^^ error: duplicate `UnsafeUnpin` argument --> $DIR/duplicate-argument.rs:15:40 | 15 | #[pin_project(PinnedDrop, UnsafeUnpin, UnsafeUnpin)] //~ ERROR duplicate `UnsafeUnpin` argument | ^^^^^^^^^^^ error: duplicate `PinnedDrop` argument --> $DIR/duplicate-argument.rs:21:40 | 21 | #[pin_project(PinnedDrop, UnsafeUnpin, PinnedDrop, PinnedDrop)] //~ ERROR duplicate `PinnedDrop` argument | ^^^^^^^^^^ pin-project-0.4.8/tests/ui/pin_project/invalid.rs010064400007650000024000000016201361127335300202660ustar0000000000000000use pin_project::pin_project; #[pin_project] struct A { #[pin()] //~ ERROR unexpected token pinned: T, } #[pin_project] struct B(#[pin(foo)] T); //~ ERROR unexpected token #[pin_project] enum C { A(#[pin(foo)] T), //~ ERROR unexpected token } #[pin_project] enum D { A { #[pin(foo)] //~ ERROR unexpected token pinned: T, }, } #[pin_project(UnsafeUnpin,,)] //~ ERROR expected identifier struct E { #[pin] pinned: T, } #[pin_project(Foo)] //~ ERROR unexpected argument struct F { #[pin] pinned: T, } #[pin_project] enum G { #[pin] //~ ERROR may only be used on fields of structs or variants A(T), } #[pin_project] #[pin] //~ ERROR may only be used on fields of structs or variants enum H { A(T), } #[pin_project] struct I { #[pin] #[pin] //~ ERROR duplicate #[pin] attribute pinned: T, } fn main() {} pin-project-0.4.8/tests/ui/pin_project/invalid.stderr010064400007650000024000000025461361127335300211550ustar0000000000000000error: unexpected token: () --> $DIR/invalid.rs:5:10 | 5 | #[pin()] //~ ERROR unexpected token | ^^ error: unexpected token: (foo) --> $DIR/invalid.rs:10:18 | 10 | struct B(#[pin(foo)] T); //~ ERROR unexpected token | ^^^^^ error: unexpected token: (foo) --> $DIR/invalid.rs:14:12 | 14 | A(#[pin(foo)] T), //~ ERROR unexpected token | ^^^^^ error: unexpected token: (foo) --> $DIR/invalid.rs:20:14 | 20 | #[pin(foo)] //~ ERROR unexpected token | ^^^^^ error: expected identifier --> $DIR/invalid.rs:25:27 | 25 | #[pin_project(UnsafeUnpin,,)] //~ ERROR expected identifier | ^ error: unexpected argument: Foo --> $DIR/invalid.rs:31:15 | 31 | #[pin_project(Foo)] //~ ERROR unexpected argument | ^^^ error: #[pin] attribute may only be used on fields of structs or variants --> $DIR/invalid.rs:39:5 | 39 | #[pin] //~ ERROR may only be used on fields of structs or variants | ^^^^^^ error: #[pin] attribute may only be used on fields of structs or variants --> $DIR/invalid.rs:44:1 | 44 | #[pin] //~ ERROR may only be used on fields of structs or variants | ^^^^^^ error: duplicate #[pin] attribute --> $DIR/invalid.rs:52:5 | 52 | #[pin] //~ ERROR duplicate #[pin] attribute | ^^^^^^ pin-project-0.4.8/tests/ui/pin_project/overlapping_unpin_struct.rs010064400007650000024000000004041361127335300240020ustar0000000000000000use pin_project::pin_project; use std::marker::PhantomPinned; #[pin_project] struct Foo { #[pin] inner: T, } struct __Foo {} impl Unpin for __Foo {} fn is_unpin() {} fn main() { is_unpin::>(); //~ ERROR E0277 } pin-project-0.4.8/tests/ui/pin_project/overlapping_unpin_struct.stderr010064400007650000024000000015301361127335300246620ustar0000000000000000error[E0277]: the trait bound `std::marker::PhantomPinned: std::marker::Unpin` is not satisfied in `__Foo<'_, std::marker::PhantomPinned>` --> $DIR/overlapping_unpin_struct.rs:17:5 | 14 | fn is_unpin() {} | -------- ----- required by this bound in `is_unpin` ... 17 | is_unpin::>(); //~ ERROR E0277 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ within `__Foo<'_, std::marker::PhantomPinned>`, the trait `std::marker::Unpin` is not implemented for `std::marker::PhantomPinned` | = help: the following implementations were found: = note: required because it appears within the type `__Foo<'_, std::marker::PhantomPinned>` = note: required because of the requirements on the impl of `std::marker::Unpin` for `Foo` pin-project-0.4.8/tests/ui/pin_project/packed.rs010064400007650000024000000007361361127335300200760ustar0000000000000000use pin_project::pin_project; #[pin_project] #[repr(packed, C)] //~ ERROR may not be used on #[repr(packed)] types struct A { #[pin] field: u8, } // Test putting 'repr' before the 'pin_project' attribute #[repr(packed, C)] //~ ERROR may not be used on #[repr(packed)] types #[pin_project] struct B { #[pin] field: u8, } #[pin_project] #[repr(packed(2))] //~ ERROR may not be used on #[repr(packed)] types struct C { #[pin] field: u32, } fn main() {} pin-project-0.4.8/tests/ui/pin_project/packed.stderr010064400007650000024000000011221361127335300207430ustar0000000000000000error: #[pin_project] attribute may not be used on #[repr(packed)] types --> $DIR/packed.rs:4:8 | 4 | #[repr(packed, C)] //~ ERROR may not be used on #[repr(packed)] types | ^^^^^^ error: #[pin_project] attribute may not be used on #[repr(packed)] types --> $DIR/packed.rs:11:8 | 11 | #[repr(packed, C)] //~ ERROR may not be used on #[repr(packed)] types | ^^^^^^ error: #[pin_project] attribute may not be used on #[repr(packed)] types --> $DIR/packed.rs:19:8 | 19 | #[repr(packed(2))] //~ ERROR may not be used on #[repr(packed)] types | ^^^^^^^^^ pin-project-0.4.8/tests/ui/pin_project/packed_sneaky-1.rs010064400007650000024000000012161361127335300216000ustar0000000000000000use auxiliary_macros::hidden_repr; use pin_project::{pin_project, pinned_drop, UnsafeUnpin}; use std::pin::Pin; #[pin_project] //~ ERROR may not be used on #[repr(packed)] types #[hidden_repr(packed)] struct A { #[pin] field: u32, } #[pin_project(UnsafeUnpin)] //~ ERROR may not be used on #[repr(packed)] types #[hidden_repr(packed)] struct C { #[pin] field: u32, } unsafe impl UnsafeUnpin for C {} #[pin_project(PinnedDrop)] //~ ERROR may not be used on #[repr(packed)] types #[hidden_repr(packed)] struct D { #[pin] field: u32, } #[pinned_drop] impl PinnedDrop for D { fn drop(self: Pin<&mut Self>) {} } fn main() {} pin-project-0.4.8/tests/ui/pin_project/packed_sneaky-1.stderr010064400007650000024000000007701361127335300224630ustar0000000000000000error: #[pin_project] attribute may not be used on #[repr(packed)] types --> $DIR/packed_sneaky-1.rs:6:1 | 6 | #[hidden_repr(packed)] | ^^^^^^^^^^^^^^^^^^^^^^ error: #[pin_project] attribute may not be used on #[repr(packed)] types --> $DIR/packed_sneaky-1.rs:13:1 | 13 | #[hidden_repr(packed)] | ^^^^^^^^^^^^^^^^^^^^^^ error: #[pin_project] attribute may not be used on #[repr(packed)] types --> $DIR/packed_sneaky-1.rs:22:1 | 22 | #[hidden_repr(packed)] | ^^^^^^^^^^^^^^^^^^^^^^ pin-project-0.4.8/tests/ui/pin_project/packed_sneaky-2.rs010064400007650000024000000003531361127335300216020ustar0000000000000000use auxiliary_macros::hidden_repr_macro; use pin_project::pin_project; hidden_repr_macro! { //~ ERROR may not be used on #[repr(packed)] types #[pin_project] struct B { #[pin] field: u32, } } fn main() {} pin-project-0.4.8/tests/ui/pin_project/packed_sneaky-2.stderr010064400007650000024000000005461361127335300224650ustar0000000000000000error: #[pin_project] attribute may not be used on #[repr(packed)] types --> $DIR/packed_sneaky-2.rs:4:1 | 4 | / hidden_repr_macro! { //~ ERROR may not be used on #[repr(packed)] types 5 | | #[pin_project] 6 | | struct B { 7 | | #[pin] 8 | | field: u32, 9 | | } 10 | | } | | ^ in this macro invocation | |_| | pin-project-0.4.8/tests/ui/pin_project/private_in_public-enum.rs010064400007650000024000000005011361127335300232750ustar0000000000000000// Even if allows private_in_public, these are errors. #![allow(private_in_public)] pub enum PublicEnum { Variant(PrivateEnum), } enum PrivateEnum { Variant(u8), } mod foo { pub(crate) enum CrateEnum { Variant(PrivateEnum), } enum PrivateEnum { Variant(u8), } } fn main() {} pin-project-0.4.8/tests/ui/pin_project/private_in_public-enum.stderr010064400007650000024000000010401361127335300241530ustar0000000000000000error[E0446]: private type `PrivateEnum` in public interface --> $DIR/private_in_public-enum.rs:6:13 | 6 | Variant(PrivateEnum), | ^^^^^^^^^^^ can't leak private type ... 9 | enum PrivateEnum { | - `PrivateEnum` declared as private error[E0446]: private type `foo::PrivateEnum` in public interface --> $DIR/private_in_public-enum.rs:15:17 | 15 | Variant(PrivateEnum), | ^^^^^^^^^^^ can't leak private type ... 18 | enum PrivateEnum { | - `foo::PrivateEnum` declared as private pin-project-0.4.8/tests/ui/pin_project/proper_unpin.rs010064400007650000024000000012611361127335300213610ustar0000000000000000use pin_project::pin_project; use std::marker::PhantomPinned; struct Inner { val: T, } #[pin_project] struct Foo { #[pin] inner: Inner, other: U, } #[pin_project] pub struct TrivialBounds { #[pin] field1: PhantomPinned, } #[pin_project] struct Bar<'a, T, U> { #[pin] inner: &'a mut Inner, other: U, } fn is_unpin() {} fn main() { is_unpin::>(); //~ ERROR E0277 is_unpin::>(); // Ok is_unpin::>(); //~ ERROR E0277 is_unpin::(); //~ ERROR E0277 is_unpin::>(); //~ Ok } pin-project-0.4.8/tests/ui/pin_project/proper_unpin.stderr010064400007650000024000000053601361127335300222440ustar0000000000000000error[E0277]: the trait bound `std::marker::PhantomPinned: std::marker::Unpin` is not satisfied in `__Foo<'_, std::marker::PhantomPinned, ()>` --> $DIR/proper_unpin.rs:31:5 | 28 | fn is_unpin() {} | -------- ----- required by this bound in `is_unpin` ... 31 | is_unpin::>(); //~ ERROR E0277 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ within `__Foo<'_, std::marker::PhantomPinned, ()>`, the trait `std::marker::Unpin` is not implemented for `std::marker::PhantomPinned` | = help: the following implementations were found: = note: required because it appears within the type `Inner` = note: required because it appears within the type `__Foo<'_, std::marker::PhantomPinned, ()>` = note: required because of the requirements on the impl of `std::marker::Unpin` for `Foo` error[E0277]: the trait bound `std::marker::PhantomPinned: std::marker::Unpin` is not satisfied in `__Foo<'_, std::marker::PhantomPinned, std::marker::PhantomPinned>` --> $DIR/proper_unpin.rs:33:5 | 28 | fn is_unpin() {} | -------- ----- required by this bound in `is_unpin` ... 33 | is_unpin::>(); //~ ERROR E0277 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ within `__Foo<'_, std::marker::PhantomPinned, std::marker::PhantomPinned>`, the trait `std::marker::Unpin` is not implemented for `std::marker::PhantomPinned` | = help: the following implementations were found: = note: required because it appears within the type `Inner` = note: required because it appears within the type `__Foo<'_, std::marker::PhantomPinned, std::marker::PhantomPinned>` = note: required because of the requirements on the impl of `std::marker::Unpin` for `Foo` error[E0277]: the trait bound `std::marker::PhantomPinned: std::marker::Unpin` is not satisfied in `__TrivialBounds<'_>` --> $DIR/proper_unpin.rs:35:5 | 28 | fn is_unpin() {} | -------- ----- required by this bound in `is_unpin` ... 35 | is_unpin::(); //~ ERROR E0277 | ^^^^^^^^^^^^^^^^^^^^^^^^^ within `__TrivialBounds<'_>`, the trait `std::marker::Unpin` is not implemented for `std::marker::PhantomPinned` | = help: the following implementations were found: = note: required because it appears within the type `__TrivialBounds<'_>` = note: required because of the requirements on the impl of `std::marker::Unpin` for `TrivialBounds` pin-project-0.4.8/tests/ui/pin_project/remove-attr-from-field.rs010064400007650000024000000012441361127335300231310ustar0000000000000000use auxiliary_macros::remove_attr; use pin_project::pin_project; use std::{marker::PhantomPinned, pin::Pin}; fn is_unpin() {} #[pin_project] #[remove_attr(field)] struct Foo { #[pin] field: PhantomPinned, } #[remove_attr(field)] #[pin_project] struct Bar { #[pin] field: PhantomPinned, } fn main() { is_unpin::(); is_unpin::(); let mut x = Foo { field: PhantomPinned }; let x = Pin::new(&mut x).project(); let _: Pin<&mut PhantomPinned> = x.field; //~ ERROR E0308 let mut x = Bar { field: PhantomPinned }; let x = Pin::new(&mut x).project(); let _: Pin<&mut PhantomPinned> = x.field; //~ ERROR E0308 } pin-project-0.4.8/tests/ui/pin_project/remove-attr-from-field.stderr010064400007650000024000000017051361127335300240120ustar0000000000000000error[E0308]: mismatched types --> $DIR/remove-attr-from-field.rs:27:38 | 27 | let _: Pin<&mut PhantomPinned> = x.field; //~ ERROR E0308 | ----------------------- ^^^^^^^ expected struct `std::pin::Pin`, found `&mut std::marker::PhantomPinned` | | | expected due to this | = note: expected struct `std::pin::Pin<&mut std::marker::PhantomPinned>` found mutable reference `&mut std::marker::PhantomPinned` error[E0308]: mismatched types --> $DIR/remove-attr-from-field.rs:31:38 | 31 | let _: Pin<&mut PhantomPinned> = x.field; //~ ERROR E0308 | ----------------------- ^^^^^^^ expected struct `std::pin::Pin`, found `&mut std::marker::PhantomPinned` | | | expected due to this | = note: expected struct `std::pin::Pin<&mut std::marker::PhantomPinned>` found mutable reference `&mut std::marker::PhantomPinned` pin-project-0.4.8/tests/ui/pin_project/remove-attr-from-struct.rs010064400007650000024000000013401361127335300233670ustar0000000000000000use auxiliary_macros::remove_attr; use pin_project::pin_project; use std::{marker::PhantomPinned, pin::Pin}; fn is_unpin() {} #[pin_project] #[remove_attr(struct)] struct Foo { #[pin] //~ ERROR cannot find attribute `pin` in this scope field: PhantomPinned, } #[remove_attr(struct)] #[pin_project] struct Bar { #[pin] //~ ERROR cannot find attribute `pin` in this scope field: PhantomPinned, } fn main() { is_unpin::(); //~ ERROR E0277 is_unpin::(); //~ ERROR E0277 let mut x = Foo { field: PhantomPinned }; let _x = Pin::new(&mut x).project(); //~ ERROR E0277,E0599 let mut x = Bar { field: PhantomPinned }; let _x = Pin::new(&mut x).project(); //~ ERROR E0277,E0599 } pin-project-0.4.8/tests/ui/pin_project/remove-attr-from-struct.stderr010064400007650000024000000064211361127335300242530ustar0000000000000000error: cannot find attribute `pin` in this scope --> $DIR/remove-attr-from-struct.rs:10:7 | 10 | #[pin] //~ ERROR cannot find attribute `pin` in this scope | ^^^ error: cannot find attribute `pin` in this scope --> $DIR/remove-attr-from-struct.rs:17:7 | 17 | #[pin] //~ ERROR cannot find attribute `pin` in this scope | ^^^ error[E0277]: the trait bound `std::marker::PhantomPinned: std::marker::Unpin` is not satisfied in `Foo` --> $DIR/remove-attr-from-struct.rs:22:5 | 5 | fn is_unpin() {} | -------- ----- required by this bound in `is_unpin` ... 22 | is_unpin::(); //~ ERROR E0277 | ^^^^^^^^^^^^^^^ within `Foo`, the trait `std::marker::Unpin` is not implemented for `std::marker::PhantomPinned` | = help: the following implementations were found: = note: required because it appears within the type `Foo` error[E0277]: the trait bound `std::marker::PhantomPinned: std::marker::Unpin` is not satisfied in `Bar` --> $DIR/remove-attr-from-struct.rs:23:5 | 5 | fn is_unpin() {} | -------- ----- required by this bound in `is_unpin` ... 23 | is_unpin::(); //~ ERROR E0277 | ^^^^^^^^^^^^^^^ within `Bar`, the trait `std::marker::Unpin` is not implemented for `std::marker::PhantomPinned` | = help: the following implementations were found: = note: required because it appears within the type `Bar` error[E0277]: the trait bound `std::marker::PhantomPinned: std::marker::Unpin` is not satisfied in `Foo` --> $DIR/remove-attr-from-struct.rs:26:14 | 26 | let _x = Pin::new(&mut x).project(); //~ ERROR E0277,E0599 | ^^^^^^^^ within `Foo`, the trait `std::marker::Unpin` is not implemented for `std::marker::PhantomPinned` | = help: the following implementations were found: = note: required because it appears within the type `Foo` = note: required by `std::pin::Pin::

::new` error[E0599]: no method named `project` found for struct `std::pin::Pin<&mut Foo>` in the current scope --> $DIR/remove-attr-from-struct.rs:26:31 | 26 | let _x = Pin::new(&mut x).project(); //~ ERROR E0277,E0599 | ^^^^^^^ method not found in `std::pin::Pin<&mut Foo>` error[E0277]: the trait bound `std::marker::PhantomPinned: std::marker::Unpin` is not satisfied in `Bar` --> $DIR/remove-attr-from-struct.rs:29:14 | 29 | let _x = Pin::new(&mut x).project(); //~ ERROR E0277,E0599 | ^^^^^^^^ within `Bar`, the trait `std::marker::Unpin` is not implemented for `std::marker::PhantomPinned` | = help: the following implementations were found: = note: required because it appears within the type `Bar` = note: required by `std::pin::Pin::

::new` error[E0599]: no method named `project` found for struct `std::pin::Pin<&mut Bar>` in the current scope --> $DIR/remove-attr-from-struct.rs:29:31 | 29 | let _x = Pin::new(&mut x).project(); //~ ERROR E0277,E0599 | ^^^^^^^ method not found in `std::pin::Pin<&mut Bar>` pin-project-0.4.8/tests/ui/pin_project/safe_packed_borrows.rs010064400007650000024000000006741361127335300226520ustar0000000000000000#![deny(safe_packed_borrows)] // Refs: https://github.com/rust-lang/rust/issues/46043 #[repr(packed)] struct A { field: u32, } #[repr(packed(2))] struct B { field: u32, } fn main() { let a = A { field: 1 }; &a.field; //~ ERROR borrow of packed field is unsafe and requires unsafe function or block let b = B { field: 1 }; &b.field; //~ ERROR borrow of packed field is unsafe and requires unsafe function or block } pin-project-0.4.8/tests/ui/pin_project/safe_packed_borrows.stderr010064400007650000024000000026421361127335300235260ustar0000000000000000error: borrow of packed field is unsafe and requires unsafe function or block (error E0133) --> $DIR/safe_packed_borrows.rs:17:5 | 17 | &a.field; //~ ERROR borrow of packed field is unsafe and requires unsafe function or block | ^^^^^^^^ | note: lint level defined here --> $DIR/safe_packed_borrows.rs:1:9 | 1 | #![deny(safe_packed_borrows)] | ^^^^^^^^^^^^^^^^^^^ = 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 = note: fields of packed structs might be misaligned: dereferencing a misaligned pointer or even just creating a misaligned reference is undefined behavior error: borrow of packed field is unsafe and requires unsafe function or block (error E0133) --> $DIR/safe_packed_borrows.rs:20:5 | 20 | &b.field; //~ ERROR borrow of packed field is unsafe and requires unsafe function or block | ^^^^^^^^ | = 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 = note: fields of packed structs might be misaligned: dereferencing a misaligned pointer or even just creating a misaligned reference is undefined behavior pin-project-0.4.8/tests/ui/pin_project/unpin_sneaky.rs010064400007650000024000000002241361134262400213400ustar0000000000000000use pin_project::pin_project; #[pin_project] struct Foo { #[pin] inner: u8, } impl Unpin for __Foo {} //~ ERROR E0412,E0321 fn main() {} pin-project-0.4.8/tests/ui/pin_project/unpin_sneaky.stderr010064400007650000024000000012001361127335300222140ustar0000000000000000error[E0412]: cannot find type `__Foo` in this scope --> $DIR/unpin_sneaky.rs:9:16 | 9 | impl Unpin for __Foo {} //~ ERROR E0412,E0321 | ^^^^^ not found in this scope | help: possible candidate is found in another module, you can import it into scope | 1 | use crate::__Foo; | error[E0321]: cross-crate traits with a default impl, like `std::marker::Unpin`, can only be implemented for a struct/enum type, not `[type error]` --> $DIR/unpin_sneaky.rs:9:1 | 9 | impl Unpin for __Foo {} //~ ERROR E0412,E0321 | ^^^^^^^^^^^^^^^^^^^^ can't implement cross-crate trait with a default impl for non-struct/enum type pin-project-0.4.8/tests/ui/pin_project/unsupported.rs010064400007650000024000000012401361127335300212260ustar0000000000000000use pin_project::pin_project; #[pin_project] struct Struct1 {} //~ ERROR may not be used on structs with zero fields #[pin_project] struct Struct2(); //~ ERROR may not be used on structs with zero fields #[pin_project] struct Struct3; //~ ERROR may not be used on structs with units #[pin_project] enum Enum1 {} //~ ERROR may not be used on enums without variants #[pin_project] enum Enum2 { A = 2, //~ ERROR may not be used on enums with discriminants } #[pin_project] enum Enum3 { A, //~ ERROR may not be used on enums that have no field B, } #[pin_project] union Union { //~^ ERROR may only be used on structs or enums x: u8, } fn main() {} pin-project-0.4.8/tests/ui/pin_project/unsupported.stderr010064400007650000024000000026431361127335300221150ustar0000000000000000error: #[pin_project] attribute may not be used on structs with zero fields --> $DIR/unsupported.rs:4:16 | 4 | struct Struct1 {} //~ ERROR may not be used on structs with zero fields | ^^ error: #[pin_project] attribute may not be used on structs with zero fields --> $DIR/unsupported.rs:7:15 | 7 | struct Struct2(); //~ ERROR may not be used on structs with zero fields | ^^ error: #[pin_project] attribute may not be used on structs with units --> $DIR/unsupported.rs:10:8 | 10 | struct Struct3; //~ ERROR may not be used on structs with units | ^^^^^^^ error: #[pin_project] attribute may not be used on enums without variants --> $DIR/unsupported.rs:13:12 | 13 | enum Enum1 {} //~ ERROR may not be used on enums without variants | ^^ error: #[pin_project] attribute may not be used on enums with discriminants --> $DIR/unsupported.rs:17:9 | 17 | A = 2, //~ ERROR may not be used on enums with discriminants | ^ error: #[pin_project] attribute may not be used on enums that have no field --> $DIR/unsupported.rs:22:5 | 22 | / A, //~ ERROR may not be used on enums that have no field 23 | | B, | |______^ error: #[pin_project] attribute may only be used on structs or enums --> $DIR/unsupported.rs:27:1 | 27 | / union Union { 28 | | //~^ ERROR may only be used on structs or enums 29 | | x: u8, 30 | | } | |_^ pin-project-0.4.8/tests/ui/pinned_drop/forget-pinned-drop-impl.rs010064400007650000024000000002101361143547600232670ustar0000000000000000use pin_project::pin_project; #[pin_project(PinnedDrop)] //~ ERROR E0277 pub struct Struct { #[pin] field: u8, } fn main() {} pin-project-0.4.8/tests/ui/pinned_drop/forget-pinned-drop-impl.stderr010064400007650000024000000005521361143547600241570ustar0000000000000000error[E0277]: the trait bound `Struct: pin_project::__private::PinnedDrop` is not satisfied --> $DIR/forget-pinned-drop-impl.rs:3:15 | 3 | #[pin_project(PinnedDrop)] //~ ERROR E0277 | ^^^^^^^^^^ the trait `pin_project::__private::PinnedDrop` is not implemented for `Struct` | = note: required by `pin_project::__private::PinnedDrop::drop` pin-project-0.4.8/tests/ui/pinned_drop/invalid.rs010064400007650000024000000054221361127335300202570ustar0000000000000000use pin_project::{pin_project, pinned_drop}; #[pin_project(PinnedDrop)] pub struct A { #[pin] field: u8, } #[pinned_drop(foo)] //~ ERROR unexpected token impl PinnedDrop for A { fn drop(self: Pin<&mut Self>) {} } #[pin_project(PinnedDrop)] pub struct B { #[pin] field: u8, } #[pinned_drop] impl Drop for B { //~^ ERROR #[pinned_drop] may only be used on implementation for the `PinnedDrop` trait fn drop(&mut self) {} } #[pin_project(PinnedDrop)] pub struct C { #[pin] field: u8, } #[pinned_drop] impl C { //~^ ERROR #[pinned_drop] may only be used on implementation for the `PinnedDrop` trait fn drop(&mut self) {} } #[pin_project(PinnedDrop)] pub struct D { #[pin] field: u8, } #[pinned_drop] impl PinnedDrop for D { fn drop(&mut self) {} //~ ERROR method `drop` must take an argument `self: Pin<&mut Self>` } #[pin_project(PinnedDrop)] pub struct E { #[pin] field: u8, } #[pinned_drop] impl PinnedDrop for E { fn drop_baz(&mut self) {} //~ ERROR method `drop_baz` is not a member of trait `PinnedDrop } #[pin_project(PinnedDrop)] pub struct F { #[pin] field: u8, } #[pinned_drop] unsafe impl PinnedDrop for F { //~^ ERROR implementing the trait `PinnedDrop` is not unsafe fn drop(self: Pin<&mut Self>) {} } #[pin_project(PinnedDrop)] pub struct G { #[pin] field: u8, } #[pinned_drop] impl PinnedDrop for G { unsafe fn drop(self: Pin<&mut Self>) {} //~ ERROR implementing the method `drop` is not unsafe } #[pin_project(PinnedDrop)] pub struct H { #[pin] field: u8, } #[pinned_drop] impl PinnedDrop for H { const A: u8 = 0; //~ ERROR const `A` is not a member of trait `PinnedDrop` fn drop(self: Pin<&mut Self>) {} } #[pin_project(PinnedDrop)] pub struct I { #[pin] field: u8, } #[pinned_drop] impl PinnedDrop for I { fn drop(self: Pin<&mut Self>) {} const A: u8 = 0; //~ ERROR const `A` is not a member of trait `PinnedDrop` } #[pin_project(PinnedDrop)] pub struct J { #[pin] field: u8, } #[pinned_drop] impl PinnedDrop for J { type A = u8; //~ ERROR type `A` is not a member of trait `PinnedDrop` fn drop(self: Pin<&mut Self>) {} } #[pin_project(PinnedDrop)] pub struct K { #[pin] field: u8, } #[pinned_drop] impl PinnedDrop for K { fn drop(self: Pin<&mut Self>) {} type A = u8; //~ ERROR type `A` is not a member of trait `PinnedDrop` } #[pin_project(PinnedDrop)] pub struct L { #[pin] field: u8, } #[pinned_drop] impl PinnedDrop for L { fn drop(self: Pin<&mut Self>) {} fn drop(self: Pin<&mut Self>) {} //~ ERROR duplicate definitions with name `drop` } #[pin_project(PinnedDrop)] //~ ERROR E0277 pub struct M { #[pin] field: u8, } #[pinned_drop] fn drop(_this: Pin<&mut M>) {} //~ ERROR expected `impl` fn main() {} pin-project-0.4.8/tests/ui/pinned_drop/invalid.stderr010064400007650000024000000052161361127335300211370ustar0000000000000000error: unexpected token: foo --> $DIR/invalid.rs:9:15 | 9 | #[pinned_drop(foo)] //~ ERROR unexpected token | ^^^ error: #[pinned_drop] may only be used on implementation for the `PinnedDrop` trait --> $DIR/invalid.rs:21:6 | 21 | impl Drop for B { | ^^^^ error: #[pinned_drop] may only be used on implementation for the `PinnedDrop` trait --> $DIR/invalid.rs:33:6 | 33 | impl C { | ^ error: method `drop` must take an argument `self: Pin<&mut Self>` --> $DIR/invalid.rs:46:13 | 46 | fn drop(&mut self) {} //~ ERROR method `drop` must take an argument `self: Pin<&mut Self>` | ^^^^^^^^^ error: method `drop_baz` is not a member of trait `PinnedDrop --> $DIR/invalid.rs:57:8 | 57 | fn drop_baz(&mut self) {} //~ ERROR method `drop_baz` is not a member of trait `PinnedDrop | ^^^^^^^^ error: implementing the trait `PinnedDrop` is not unsafe --> $DIR/invalid.rs:67:1 | 67 | unsafe impl PinnedDrop for F { | ^^^^^^ error: implementing the method `drop` is not unsafe --> $DIR/invalid.rs:80:5 | 80 | unsafe fn drop(self: Pin<&mut Self>) {} //~ ERROR implementing the method `drop` is not unsafe | ^^^^^^ error: const `A` is not a member of trait `PinnedDrop` --> $DIR/invalid.rs:91:5 | 91 | const A: u8 = 0; //~ ERROR const `A` is not a member of trait `PinnedDrop` | ^^^^^^^^^^^^^^^^ error: const `A` is not a member of trait `PinnedDrop` --> $DIR/invalid.rs:104:5 | 104 | const A: u8 = 0; //~ ERROR const `A` is not a member of trait `PinnedDrop` | ^^^^^^^^^^^^^^^^ error: type `A` is not a member of trait `PinnedDrop` --> $DIR/invalid.rs:115:5 | 115 | type A = u8; //~ ERROR type `A` is not a member of trait `PinnedDrop` | ^^^^^^^^^^^^ error: type `A` is not a member of trait `PinnedDrop` --> $DIR/invalid.rs:128:5 | 128 | type A = u8; //~ ERROR type `A` is not a member of trait `PinnedDrop` | ^^^^^^^^^^^^ error: duplicate definitions with name `drop` --> $DIR/invalid.rs:140:5 | 140 | fn drop(self: Pin<&mut Self>) {} //~ ERROR duplicate definitions with name `drop` | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: expected `impl` --> $DIR/invalid.rs:150:1 | 150 | fn drop(_this: Pin<&mut M>) {} //~ ERROR expected `impl` | ^^ error[E0277]: the trait bound `M: pin_project::__private::PinnedDrop` is not satisfied --> $DIR/invalid.rs:143:15 | 143 | #[pin_project(PinnedDrop)] //~ ERROR E0277 | ^^^^^^^^^^ the trait `pin_project::__private::PinnedDrop` is not implemented for `M` | = note: required by `pin_project::__private::PinnedDrop::drop` pin-project-0.4.8/tests/ui/pinned_drop/pinned-drop-no-attr-arg.rs010064400007650000024000000003501361355151100231710ustar0000000000000000use pin_project::{pin_project, pinned_drop}; use std::pin::Pin; #[pin_project] struct Foo { #[pin] field: u8, } #[pinned_drop] impl PinnedDrop for Foo { //~ ERROR E0119 fn drop(self: Pin<&mut Self>) {} } fn main() {} pin-project-0.4.8/tests/ui/pinned_drop/pinned-drop-no-attr-arg.stderr010064400007650000024000000005171361355151100240550ustar0000000000000000error[E0119]: conflicting implementations of trait `pin_project::__private::PinnedDrop` for type `Foo`: --> $DIR/pinned-drop-no-attr-arg.rs:11:1 | 4 | #[pin_project] | -------------- first implementation here ... 11 | impl PinnedDrop for Foo { //~ ERROR E0119 | ^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `Foo` pin-project-0.4.8/tests/ui/pinned_drop/ref-self.rs010064400007650000024000000005221361133565000203270ustar0000000000000000// `ref (mut) self` are rejected by rustc. use std::pin::Pin; pub struct Struct { field: u8, } impl Struct { fn method_ref(ref self: Pin<&mut Self>) {} //~ ERROR expected identifier, found keyword `self` fn method_ref_mut(ref mut self: Pin<&mut Self>) {} //~ ERROR expected identifier, found keyword `self` } fn main() {} pin-project-0.4.8/tests/ui/pinned_drop/ref-self.stderr010064400007650000024000000010151361133565000212040ustar0000000000000000error: expected identifier, found keyword `self` --> $DIR/ref-self.rs:10:23 | 10 | fn method_ref(ref self: Pin<&mut Self>) {} //~ ERROR expected identifier, found keyword `self` | ^^^^ expected identifier, found keyword error: expected identifier, found keyword `self` --> $DIR/ref-self.rs:11:31 | 11 | fn method_ref_mut(ref mut self: Pin<&mut Self>) {} //~ ERROR expected identifier, found keyword `self` | ^^^^ expected identifier, found keyword pin-project-0.4.8/tests/ui/pinned_drop/self.rs010064400007650000024000000051251361133565000175610ustar0000000000000000use pin_project::{pin_project, pinned_drop}; use std::pin::Pin; fn self_expr() { #[pin_project(PinnedDrop)] pub struct Struct { x: usize, } #[pinned_drop] impl PinnedDrop for Struct { fn drop(mut self: Pin<&mut Self>) { let _: Self = Self { x: 0 }; } } #[pin_project(PinnedDrop)] pub struct TupleStruct(usize); #[pinned_drop] impl PinnedDrop for TupleStruct { fn drop(mut self: Pin<&mut Self>) { let _: Self = Self(0); } } #[pin_project(PinnedDrop)] pub enum Enum { StructVariant { x: usize }, TupleVariant(usize), } #[pinned_drop] impl PinnedDrop for Enum { fn drop(mut self: Pin<&mut Self>) { let _: Self = Self::StructVariant { x: 0 }; //~ ERROR can't use generic parameters from outer function [E0401] let _: Self = Self::TupleVariant(0); } } } fn self_pat() { #[pin_project(PinnedDrop)] pub struct Struct { x: usize, } #[pinned_drop] impl PinnedDrop for Struct { fn drop(mut self: Pin<&mut Self>) { match *self { Self { x: _ } => {} //~ ERROR can't use generic parameters from outer function [E0401] } if let Self { x: _ } = *self {} //~ ERROR can't use generic parameters from outer function [E0401] let Self { x: _ } = *self; //~ ERROR can't use generic parameters from outer function [E0401] } } #[pin_project(PinnedDrop)] pub struct TupleStruct(usize); #[pinned_drop] impl PinnedDrop for TupleStruct { #[allow(irrefutable_let_patterns)] fn drop(mut self: Pin<&mut Self>) { match *self { Self(_) => {} } if let Self(_) = *self {} let Self(_) = *self; } } #[pin_project(PinnedDrop)] pub enum Enum { StructVariant { x: usize }, TupleVariant(usize), } #[pinned_drop] impl PinnedDrop for Enum { fn drop(mut self: Pin<&mut Self>) { match *self { Self::StructVariant { x: _ } => {} //~ ERROR can't use generic parameters from outer function [E0401] Self::TupleVariant(_) => {} //~ ERROR can't use generic parameters from outer function [E0401] } if let Self::StructVariant { x: _ } = *self {} //~ ERROR can't use generic parameters from outer function [E0401] if let Self::TupleVariant(_) = *self {} //~ ERROR can't use generic parameters from outer function [E0401] } } } fn main() {} pin-project-0.4.8/tests/ui/pinned_drop/self.stderr010064400007650000024000000077141361133565000204460ustar0000000000000000error[E0401]: can't use generic parameters from outer function --> $DIR/self.rs:36:27 | 34 | impl PinnedDrop for Enum { | ---- `Self` type implicitly declared here, by this `impl` 35 | fn drop(mut self: Pin<&mut Self>) { 36 | let _: Self = Self::StructVariant { x: 0 }; //~ ERROR can't use generic parameters from outer function [E0401] | ^^^^^^^^^^^^^^^^^^^ | | | use of generic parameter from outer function | use a type here instead error[E0401]: can't use generic parameters from outer function --> $DIR/self.rs:52:17 | 49 | impl PinnedDrop for Struct { | ---- `Self` type implicitly declared here, by this `impl` ... 52 | Self { x: _ } => {} //~ ERROR can't use generic parameters from outer function [E0401] | ^^^^ | | | use of generic parameter from outer function | use a type here instead error[E0401]: can't use generic parameters from outer function --> $DIR/self.rs:54:20 | 49 | impl PinnedDrop for Struct { | ---- `Self` type implicitly declared here, by this `impl` ... 54 | if let Self { x: _ } = *self {} //~ ERROR can't use generic parameters from outer function [E0401] | ^^^^ | | | use of generic parameter from outer function | use a type here instead error[E0401]: can't use generic parameters from outer function --> $DIR/self.rs:55:17 | 49 | impl PinnedDrop for Struct { | ---- `Self` type implicitly declared here, by this `impl` ... 55 | let Self { x: _ } = *self; //~ ERROR can't use generic parameters from outer function [E0401] | ^^^^ | | | use of generic parameter from outer function | use a type here instead error[E0401]: can't use generic parameters from outer function --> $DIR/self.rs:84:17 | 81 | impl PinnedDrop for Enum { | ---- `Self` type implicitly declared here, by this `impl` ... 84 | Self::StructVariant { x: _ } => {} //~ ERROR can't use generic parameters from outer function [E0401] | ^^^^^^^^^^^^^^^^^^^ | | | use of generic parameter from outer function | use a type here instead error[E0401]: can't use generic parameters from outer function --> $DIR/self.rs:85:17 | 81 | impl PinnedDrop for Enum { | ---- `Self` type implicitly declared here, by this `impl` ... 85 | Self::TupleVariant(_) => {} //~ ERROR can't use generic parameters from outer function [E0401] | ^^^^^^^^^^^^^^^^^^ | | | use of generic parameter from outer function | use a type here instead error[E0401]: can't use generic parameters from outer function --> $DIR/self.rs:87:20 | 81 | impl PinnedDrop for Enum { | ---- `Self` type implicitly declared here, by this `impl` ... 87 | if let Self::StructVariant { x: _ } = *self {} //~ ERROR can't use generic parameters from outer function [E0401] | ^^^^^^^^^^^^^^^^^^^ | | | use of generic parameter from outer function | use a type here instead error[E0401]: can't use generic parameters from outer function --> $DIR/self.rs:88:20 | 81 | impl PinnedDrop for Enum { | ---- `Self` type implicitly declared here, by this `impl` ... 88 | if let Self::TupleVariant(_) = *self {} //~ ERROR can't use generic parameters from outer function [E0401] | ^^^^^^^^^^^^^^^^^^ | | | use of generic parameter from outer function | use a type here instead pin-project-0.4.8/tests/ui/pinned_drop/unsafe-code.rs010064400007650000024000000005771361143547600210360ustar0000000000000000use pin_project::{pin_project, pinned_drop}; use std::pin::Pin; #[pin_project(PinnedDrop)] pub struct Struct { #[pin] field: u8, } #[pinned_drop] impl PinnedDrop for Struct { fn drop(self: Pin<&mut Self>) { self.project().field.get_unchecked_mut(); //~ ERROR call to unsafe function is unsafe and requires unsafe function or block [E0133] } } fn main() {} pin-project-0.4.8/tests/ui/pinned_drop/unsafe-code.stderr010064400007650000024000000007011361127335300216740ustar0000000000000000error[E0133]: call to unsafe function is unsafe and requires unsafe function or block --> $DIR/unsafe-code.rs:13:9 | 13 | self.project().field.get_unchecked_mut(); //~ ERROR call to unsafe function is unsafe and requires unsafe function or block [E0133] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ call to unsafe function | = note: consult the function's documentation for information on how to avoid undefined behavior pin-project-0.4.8/tests/ui/project/ambiguous-let.rs010064400007650000024000000010511361127335300205450ustar0000000000000000use pin_project::{pin_project, project}; #[pin_project] enum Enum { A(#[pin] A), B(B), } struct Struct(T); #[project] fn foo() { let mut foo: Enum = Enum::A(true); #[project] let Struct(x) = match Pin::new(&mut foo).project() { //~^ ERROR Both initializer expression and pattern are replaceable, you need to split the initializer expression into separate let bindings to avoid ambiguity Enum::A(_) => Struct(true), Enum::B(_) => unreachable!(), }; assert!(x); } fn main() {} pin-project-0.4.8/tests/ui/project/ambiguous-let.stderr010064400007650000024000000004261361127335300214310ustar0000000000000000error: Both initializer expression and pattern are replaceable, you need to split the initializer expression into separate let bindings to avoid ambiguity --> $DIR/ambiguous-let.rs:16:9 | 16 | let Struct(x) = match Pin::new(&mut foo).project() { | ^^^^^^^^^ pin-project-0.4.8/tests/ui/project/invalid.rs010064400007650000024000000007011361134277600174250ustar0000000000000000use pin_project::{pin_project, project}; #[pin_project] struct A { #[pin] future: T, } #[project] fn foo() { let mut x = A { future: 0 }; #[project(foo)] //~ ERROR unexpected token let A { future } = Pin::new(&mut x).project(); } #[project] fn bar() { let mut x = A { future: 0 }; #[project] #[project] //~ ERROR duplicate #[project] attribute let A { future } = Pin::new(&mut x).project(); } fn main() {} pin-project-0.4.8/tests/ui/project/invalid.stderr010064400007650000024000000004441361127335300203020ustar0000000000000000error: unexpected token: (foo) --> $DIR/invalid.rs:12:14 | 12 | #[project(foo)] //~ ERROR unexpected token | ^^^^^ error: duplicate #[project] attribute --> $DIR/invalid.rs:20:5 | 20 | #[project] //~ ERROR duplicate #[project] attribute | ^^^^^^^^^^ pin-project-0.4.8/tests/ui/project/type-mismatch.rs010064400007650000024000000032361361143547600205710ustar0000000000000000#![feature(proc_macro_hygiene, stmt_expr_attributes)] use pin_project::{pin_project, project}; use std::pin::Pin; #[project] fn type_mismatch() { #[pin_project] enum Enum { Variant1(#[pin] A, B), Variant2 { #[pin] field1: C, field2: D, }, None, } let mut foo = Enum::Variant1(1, 2); let mut foo = Pin::new(&mut foo).project(); #[project] match &mut foo { Enum::Variant1(x, y) => { let x: &mut Pin<&mut i32> = x; assert_eq!(**x, 1); let y: &mut &mut i32 = y; assert_eq!(**y, 2); } Enum::Variant2 { field1, field2 } => { let _x: &mut Pin<&mut i32> = field1; let _y: &mut &mut i32 = field2; } None => {} //~ ERROR mismatched types } } //~ ERROR mismatched types // span is lost. // Refs: https://github.com/rust-lang/rust/issues/43081 fn type_mismatch_span_issue() { #[pin_project] enum Enum { Variant1(#[pin] A, B), Variant2 { #[pin] field1: C, field2: D, }, None, } let mut foo = Enum::Variant1(1, 2); let mut foo = Pin::new(&mut foo).project(); #[project] match &mut foo { Enum::Variant1(x, y) => { let x: &mut Pin<&mut i32> = x; assert_eq!(**x, 1); let y: &mut &mut i32 = y; assert_eq!(**y, 2); } Enum::Variant2 { field1, field2 } => { let _x: &mut Pin<&mut i32> = field1; let _y: &mut &mut i32 = field2; } None => {} } } fn main() {} pin-project-0.4.8/tests/ui/project/type-mismatch.stderr010064400007650000024000000010501361143547600214400ustar0000000000000000error[E0308]: mismatched types --> $DIR/type-mismatch.rs:35:9 | 35 | None => {} //~ ERROR mismatched types | ^^^^ expected enum `type_mismatch::__EnumProjection`, found enum `std::option::Option` | = note: expected enum `type_mismatch::__EnumProjection<'_, {integer}, {integer}, _, _>` found enum `std::option::Option<_>` error[E0308]: mismatched types | = note: expected enum `type_mismatch_span_issue::__EnumProjection<'_, {integer}, {integer}, _, _>` found enum `std::option::Option<_>` pin-project-0.4.8/tests/ui/project/use-public.rs010064400007650000024000000002731361134062100200360ustar0000000000000000use pin_project::pin_project; #[pin_project] struct A { field: u8, } pub mod b { use pin_project::project; #[project] pub use crate::A; //~ ERROR E0365 } fn main() {} pin-project-0.4.8/tests/ui/project/use-public.stderr010064400007650000024000000004371361127335300207260ustar0000000000000000error[E0365]: `__AProjection` is private, and cannot be re-exported --> $DIR/use-public.rs:12:13 | 12 | pub use crate::A; //~ ERROR E0365 | ^^^^^^^^ re-export of private `__AProjection` | = note: consider declaring type or module `__AProjection` with `pub` pin-project-0.4.8/tests/ui/project/use.rs010064400007650000024000000005121361127335300165650ustar0000000000000000use pin_project::pin_project; #[pin_project] struct A { field: u8, } mod b { use pin_project::project; #[project] use crate::A as B; //~ ERROR #[project] attribute may not be used on renamed imports #[project] use crate::*; //~ ERROR #[project] attribute may not be used on glob imports } fn main() {} pin-project-0.4.8/tests/ui/project/use.stderr010064400007650000024000000006331361127335300174500ustar0000000000000000error: #[project] attribute may not be used on renamed imports --> $DIR/use.rs:12:16 | 12 | use crate::A as B; //~ ERROR #[project] attribute may not be used on renamed imports | ^^^^^^ error: #[project] attribute may not be used on glob imports --> $DIR/use.rs:14:16 | 14 | use crate::*; //~ ERROR #[project] attribute may not be used on glob imports | ^ pin-project-0.4.8/tests/ui/unsafe_unpin/not-implement-unsafe-unpin.rs010064400007650000024000000003271361143547600242250ustar0000000000000000use pin_project::pin_project; #[pin_project(UnsafeUnpin)] struct Struct { #[pin] inner: T, other: U, } fn is_unpin() {} fn main() { is_unpin::>(); //~ ERROR E0277 } pin-project-0.4.8/tests/ui/unsafe_unpin/not-implement-unsafe-unpin.stderr010064400007650000024000000012321361143547600251000ustar0000000000000000error[E0277]: the trait bound `Struct<(), ()>: pin_project::UnsafeUnpin` is not satisfied --> $DIR/not-implement-unsafe-unpin.rs:13:16 | 10 | fn is_unpin() {} | -------- ----- required by this bound in `is_unpin` ... 13 | is_unpin::>(); //~ ERROR E0277 | ^^^^^^^^^^^^^^ the trait `pin_project::UnsafeUnpin` is not implemented for `Struct<(), ()>` | = note: required because of the requirements on the impl of `pin_project::UnsafeUnpin` for `pin_project::__private::Wrapper<'_, Struct<(), ()>>` = note: required because of the requirements on the impl of `std::marker::Unpin` for `Struct<(), ()>` pin-project-0.4.8/tests/ui/unsafe_unpin/proper_unpin.rs010064400007650000024000000020411361127335300215340ustar0000000000000000use pin_project::{pin_project, UnsafeUnpin}; use std::marker::PhantomPinned; fn is_unpin() {} #[pin_project(UnsafeUnpin)] pub struct Blah { field1: U, #[pin] field2: T, } #[allow(unsafe_code)] unsafe impl UnsafeUnpin for Blah {} #[pin_project(UnsafeUnpin)] pub struct TrivialBounds { #[pin] field1: PhantomPinned, } #[pin_project(UnsafeUnpin)] pub struct OverlappingLifetimeNames<'pin, T, U> { #[pin] field1: U, #[pin] field2: Option, field3: &'pin (), } #[allow(unsafe_code)] unsafe impl UnsafeUnpin for OverlappingLifetimeNames<'_, T, U> {} fn main() { is_unpin::>(); //~ ERROR E0277 is_unpin::>(); // Ok is_unpin::>(); //~ ERROR E0277 is_unpin::(); //~ ERROR E0277 is_unpin::>(); //~ ERROR E0277 is_unpin::>(); //~ ERROR E0277 } pin-project-0.4.8/tests/ui/unsafe_unpin/proper_unpin.stderr010064400007650000024000000114301361127335300224150ustar0000000000000000error[E0277]: the trait bound `std::marker::PhantomPinned: std::marker::Unpin` is not satisfied --> $DIR/proper_unpin.rs:35:5 | 4 | fn is_unpin() {} | -------- ----- required by this bound in `is_unpin` ... 35 | is_unpin::>(); //~ ERROR E0277 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::marker::Unpin` is not implemented for `std::marker::PhantomPinned` | = help: the following implementations were found: = note: required because of the requirements on the impl of `pin_project::UnsafeUnpin` for `Blah` = note: required because of the requirements on the impl of `pin_project::UnsafeUnpin` for `pin_project::__private::Wrapper<'_, Blah>` = note: required because of the requirements on the impl of `std::marker::Unpin` for `Blah` error[E0277]: the trait bound `std::marker::PhantomPinned: std::marker::Unpin` is not satisfied --> $DIR/proper_unpin.rs:37:5 | 4 | fn is_unpin() {} | -------- ----- required by this bound in `is_unpin` ... 37 | is_unpin::>(); //~ ERROR E0277 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::marker::Unpin` is not implemented for `std::marker::PhantomPinned` | = help: the following implementations were found: = note: required because of the requirements on the impl of `pin_project::UnsafeUnpin` for `Blah` = note: required because of the requirements on the impl of `pin_project::UnsafeUnpin` for `pin_project::__private::Wrapper<'_, Blah>` = note: required because of the requirements on the impl of `std::marker::Unpin` for `Blah` error[E0277]: the trait bound `TrivialBounds: pin_project::UnsafeUnpin` is not satisfied --> $DIR/proper_unpin.rs:39:16 | 4 | fn is_unpin() {} | -------- ----- required by this bound in `is_unpin` ... 39 | is_unpin::(); //~ ERROR E0277 | ^^^^^^^^^^^^^ the trait `pin_project::UnsafeUnpin` is not implemented for `TrivialBounds` | = note: required because of the requirements on the impl of `pin_project::UnsafeUnpin` for `pin_project::__private::Wrapper<'_, TrivialBounds>` = note: required because of the requirements on the impl of `std::marker::Unpin` for `TrivialBounds` error[E0277]: the trait bound `std::marker::PhantomPinned: std::marker::Unpin` is not satisfied --> $DIR/proper_unpin.rs:41:5 | 4 | fn is_unpin() {} | -------- ----- required by this bound in `is_unpin` ... 41 | is_unpin::>(); //~ ERROR E0277 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::marker::Unpin` is not implemented for `std::marker::PhantomPinned` | = help: the following implementations were found: = note: required because of the requirements on the impl of `pin_project::UnsafeUnpin` for `OverlappingLifetimeNames<'_, std::marker::PhantomPinned, ()>` = note: required because of the requirements on the impl of `pin_project::UnsafeUnpin` for `pin_project::__private::Wrapper<'_, OverlappingLifetimeNames<'_, std::marker::PhantomPinned, ()>>` = note: required because of the requirements on the impl of `std::marker::Unpin` for `OverlappingLifetimeNames<'_, std::marker::PhantomPinned, ()>` error[E0277]: the trait bound `std::marker::PhantomPinned: std::marker::Unpin` is not satisfied --> $DIR/proper_unpin.rs:42:5 | 4 | fn is_unpin() {} | -------- ----- required by this bound in `is_unpin` ... 42 | is_unpin::>(); //~ ERROR E0277 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::marker::Unpin` is not implemented for `std::marker::PhantomPinned` | = help: the following implementations were found: = note: required because of the requirements on the impl of `pin_project::UnsafeUnpin` for `OverlappingLifetimeNames<'_, (), std::marker::PhantomPinned>` = note: required because of the requirements on the impl of `pin_project::UnsafeUnpin` for `pin_project::__private::Wrapper<'_, OverlappingLifetimeNames<'_, (), std::marker::PhantomPinned>>` = note: required because of the requirements on the impl of `std::marker::Unpin` for `OverlappingLifetimeNames<'_, (), std::marker::PhantomPinned>` pin-project-0.4.8/tests/ui/unstable-features/marker_trait_attr-feature-gate.rs010064400007650000024000000005311361127335300260420ustar0000000000000000// NB: If you change this test, change 'marker_trait_attr.rs' at the same time. use pin_project::pin_project; use std::marker::PhantomPinned; #[pin_project] //~ ERROR E0119 struct Foo { #[pin] x: T, } // unsound Unpin impl impl Unpin for Foo {} fn is_unpin() {} fn main() { is_unpin::>() } pin-project-0.4.8/tests/ui/unstable-features/marker_trait_attr-feature-gate.stderr010064400007650000024000000005161361127335300267240ustar0000000000000000error[E0119]: conflicting implementations of trait `std::marker::Unpin` for type `Foo<_>`: --> $DIR/marker_trait_attr-feature-gate.rs:6:1 | 6 | #[pin_project] //~ ERROR E0119 | ^^^^^^^^^^^^^^ conflicting implementation for `Foo<_>` ... 13 | impl Unpin for Foo {} | ------------------------ first implementation here pin-project-0.4.8/tests/ui/unstable-features/marker_trait_attr.rs010064400007650000024000000010671361143547600235060ustar0000000000000000// NB: If you change this test, change 'marker_trait_attr-feature-gate.rs' at the same time. // marker_trait_attr // Tracking issue: https://github.com/rust-lang/rust/issues/29864 #![feature(marker_trait_attr)] // See https://github.com/taiki-e/pin-project/issues/105#issuecomment-535355974 use pin_project::pin_project; use std::marker::PhantomPinned; #[pin_project] //~ ERROR E0119 struct Struct { #[pin] x: T, } // unsound Unpin impl impl Unpin for Struct {} fn is_unpin() {} fn main() { is_unpin::>() } pin-project-0.4.8/tests/ui/unstable-features/marker_trait_attr.stderr010064400007650000024000000005161361143547600243630ustar0000000000000000error[E0119]: conflicting implementations of trait `std::marker::Unpin` for type `Struct<_>`: --> $DIR/marker_trait_attr.rs:12:1 | 12 | #[pin_project] //~ ERROR E0119 | ^^^^^^^^^^^^^^ conflicting implementation for `Struct<_>` ... 19 | impl Unpin for Struct {} | --------------------------- first implementation here pin-project-0.4.8/tests/ui/unstable-features/overlapping_marker_traits-feature-gate.rs010064400007650000024000000005521361143547600276120ustar0000000000000000// NB: If you change this test, change 'overlapping_marker_traits.rs' at the same time. use pin_project::pin_project; use std::marker::PhantomPinned; #[pin_project] //~ ERROR E0119 struct Struct { #[pin] x: T, } // unsound Unpin impl impl Unpin for Struct {} fn is_unpin() {} fn main() { is_unpin::>() } pin-project-0.4.8/tests/ui/unstable-features/overlapping_marker_traits-feature-gate.stderr010064400007650000024000000005421361143547600304700ustar0000000000000000error[E0119]: conflicting implementations of trait `std::marker::Unpin` for type `Struct<_>`: --> $DIR/overlapping_marker_traits-feature-gate.rs:6:1 | 6 | #[pin_project] //~ ERROR E0119 | ^^^^^^^^^^^^^^ conflicting implementation for `Struct<_>` ... 13 | impl Unpin for Struct {} | --------------------------- first implementation here pin-project-0.4.8/tests/ui/unstable-features/README.md010064400007650000024000000003661361127335300206740ustar0000000000000000# UI tests for unstable features These tests check how the guarantees and features provided by pin-project interact with unstable language features. The names of the files contained in this directory need to begin with the name of the feature. pin-project-0.4.8/tests/ui/unstable-features/run-pass/overlapping_marker_traits.rs010064400007650000024000000010641361127335300270040ustar0000000000000000// NB: If you change this test, change 'overlapping_marker_traits-feature-gate.rs' at the same time. // overlapping_marker_traits // Tracking issue: https://github.com/rust-lang/rust/issues/29864 #![feature(overlapping_marker_traits)] // See https://github.com/rust-lang/rust/issues/29864#issuecomment-515780867. use pin_project::pin_project; use std::marker::PhantomPinned; #[pin_project] struct Foo { #[pin] x: T, } // unsound Unpin impl impl Unpin for Foo {} fn is_unpin() {} fn main() { is_unpin::>() } pin-project-0.4.8/tests/ui/unstable-features/run-pass/stmt_expr_attributes.rs010064400007650000024000000030211361127335300260150ustar0000000000000000// NB: If you change this test, change 'stmt_expr_attributes-feature-gate.rs' at the same time. // proc_macro_hygiene // Tracking issue: https://github.com/rust-lang/rust/issues/54727 #![feature(proc_macro_hygiene)] // stmt_expr_attributes // Tracking issue: https://github.com/rust-lang/rust/issues/15701 #![feature(stmt_expr_attributes)] use pin_project::{pin_project, project}; use std::pin::Pin; fn project_stmt_expr_nightly() { #[pin_project] enum Baz { Variant1(#[pin] A, B), Variant2 { #[pin] field1: C, field2: D, }, None, } let mut baz = Baz::Variant1(1, 2); let mut baz = Pin::new(&mut baz).project(); #[project] match &mut baz { Baz::Variant1(x, y) => { let x: &mut Pin<&mut i32> = x; assert_eq!(**x, 1); let y: &mut &mut i32 = y; assert_eq!(**y, 2); } Baz::Variant2 { field1, field2 } => { let _x: &mut Pin<&mut i32> = field1; let _y: &mut &mut i32 = field2; } Baz::None => {} } let () = #[project] match &mut baz { Baz::Variant1(x, y) => { let x: &mut Pin<&mut i32> = x; assert_eq!(**x, 1); let y: &mut &mut i32 = y; assert_eq!(**y, 2); } Baz::Variant2 { field1, field2 } => { let _x: &mut Pin<&mut i32> = field1; let _y: &mut &mut i32 = field2; } Baz::None => {} }; } fn main() {} pin-project-0.4.8/tests/ui/unstable-features/stmt_expr_attributes-feature-gate.rs010064400007650000024000000024671361143547600266370ustar0000000000000000// NB: If you change this test, change 'stmt_expr_attributes.rs' at the same time. use pin_project::{pin_project, project}; use std::pin::Pin; fn project_stmt_expr_nightly() { #[pin_project] enum Enum { Variant1(#[pin] A, B), Variant2 { #[pin] field1: C, field2: D, }, None, } let mut baz = Enum::Variant1(1, 2); let mut baz = Pin::new(&mut baz).project(); #[project] //~ ERROR E0658 match &mut baz { Enum::Variant1(x, y) => { let x: &mut Pin<&mut i32> = x; assert_eq!(**x, 1); let y: &mut &mut i32 = y; assert_eq!(**y, 2); } Enum::Variant2 { field1, field2 } => { let _x: &mut Pin<&mut i32> = field1; let _y: &mut &mut i32 = field2; } Enum::None => {} } let () = #[project] //~ ERROR E0658 match &mut baz { Enum::Variant1(x, y) => { let x: &mut Pin<&mut i32> = x; assert_eq!(**x, 1); let y: &mut &mut i32 = y; assert_eq!(**y, 2); } Enum::Variant2 { field1, field2 } => { let _x: &mut Pin<&mut i32> = field1; let _y: &mut &mut i32 = field2; } Enum::None => {} }; } fn main() {} pin-project-0.4.8/tests/ui/unstable-features/stmt_expr_attributes-feature-gate.stderr010064400007650000024000000026311361127335300275010ustar0000000000000000error[E0658]: attributes on expressions are experimental --> $DIR/stmt_expr_attributes-feature-gate.rs:22:5 | 22 | #[project] //~ ERROR E0658 | ^^^^^^^^^^ | = note: for more information, see https://github.com/rust-lang/rust/issues/15701 = help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable error[E0658]: attributes on expressions are experimental --> $DIR/stmt_expr_attributes-feature-gate.rs:38:14 | 38 | let () = #[project] //~ ERROR E0658 | ^^^^^^^^^^ | = note: for more information, see https://github.com/rust-lang/rust/issues/15701 = help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable error[E0658]: custom attributes cannot be applied to expressions --> $DIR/stmt_expr_attributes-feature-gate.rs:22:5 | 22 | #[project] //~ ERROR E0658 | ^^^^^^^^^^ | = note: for more information, see https://github.com/rust-lang/rust/issues/54727 = help: add `#![feature(proc_macro_hygiene)]` to the crate attributes to enable error[E0658]: custom attributes cannot be applied to expressions --> $DIR/stmt_expr_attributes-feature-gate.rs:38:14 | 38 | let () = #[project] //~ ERROR E0658 | ^^^^^^^^^^ | = note: for more information, see https://github.com/rust-lang/rust/issues/54727 = help: add `#![feature(proc_macro_hygiene)]` to the crate attributes to enable pin-project-0.4.8/tests/ui/unstable-features/trivial_bounds-bug.rs010064400007650000024000000015171361143547600235670ustar0000000000000000// NB: If you change this test, change 'trivial_bounds-feature-gate.rs' at the same time. // trivial_bounds // Tracking issue: https://github.com/rust-lang/rust/issues/48214 #![feature(trivial_bounds)] use std::marker::{PhantomData, PhantomPinned}; fn phantom_pinned() { struct A(PhantomPinned); // bug of trivial_bounds? impl Unpin for A where PhantomPinned: Unpin {} //~ ERROR E0277 struct Wrapper(T); impl Unpin for Wrapper where T: Unpin {} struct B(PhantomPinned); impl Unpin for B where Wrapper: Unpin {} //~ Ok struct WrapperWithLifetime<'a, T>(PhantomData<&'a ()>, T); impl Unpin for WrapperWithLifetime<'_, T> where T: Unpin {} struct C(PhantomPinned); impl<'a> Unpin for C where WrapperWithLifetime<'a, PhantomPinned>: Unpin {} // Ok } fn main() {} pin-project-0.4.8/tests/ui/unstable-features/trivial_bounds-bug.stderr010064400007650000024000000010041361143547600244350ustar0000000000000000error[E0277]: the trait bound `std::marker::PhantomPinned: std::marker::Unpin` is not satisfied --> $DIR/trivial_bounds-bug.rs:13:5 | 13 | impl Unpin for A where PhantomPinned: Unpin {} //~ ERROR E0277 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::marker::Unpin` is not implemented for `std::marker::PhantomPinned` | = help: the following implementations were found: = note: required by `std::marker::Unpin` pin-project-0.4.8/tests/ui/unstable-features/trivial_bounds-feature-gate.rs010064400007650000024000000023221361143547600253560ustar0000000000000000// NB: If you change this test, change 'trivial_bounds.rs' at the same time. use std::marker::{PhantomData, PhantomPinned}; fn phantom_pinned() { struct A(PhantomPinned); impl Unpin for A where PhantomPinned: Unpin {} //~ ERROR E0277 struct Wrapper(T); impl Unpin for Wrapper where T: Unpin {} struct B(PhantomPinned); impl Unpin for B where Wrapper: Unpin {} //~ ERROR E0277 struct WrapperWithLifetime<'a, T>(PhantomData<&'a ()>, T); impl Unpin for WrapperWithLifetime<'_, T> where T: Unpin {} struct C(PhantomPinned); impl<'a> Unpin for C where WrapperWithLifetime<'a, PhantomPinned>: Unpin {} // Ok } fn inner() { struct Inner(PhantomPinned); struct A(Inner); impl Unpin for A where Inner: Unpin {} //~ ERROR E0277 struct Wrapper(T); impl Unpin for Wrapper where T: Unpin {} struct B(Inner); impl Unpin for B where Wrapper: Unpin {} //~ ERROR E0277 struct WrapperWithLifetime<'a, T>(PhantomData<&'a ()>, T); impl Unpin for WrapperWithLifetime<'_, T> where T: Unpin {} struct C(Inner); impl<'a> Unpin for C where WrapperWithLifetime<'a, Inner>: Unpin {} // Ok } fn main() {} pin-project-0.4.8/tests/ui/unstable-features/trivial_bounds-feature-gate.stderr010064400007650000024000000054201361143547600262370ustar0000000000000000error[E0277]: the trait bound `std::marker::PhantomPinned: std::marker::Unpin` is not satisfied --> $DIR/trivial_bounds-feature-gate.rs:8:5 | 8 | impl Unpin for A where PhantomPinned: Unpin {} //~ ERROR E0277 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::marker::Unpin` is not implemented for `std::marker::PhantomPinned` | = help: the following implementations were found: = help: see issue #48214 = help: add `#![feature(trivial_bounds)]` to the crate attributes to enable error[E0277]: the trait bound `std::marker::PhantomPinned: std::marker::Unpin` is not satisfied --> $DIR/trivial_bounds-feature-gate.rs:16:5 | 16 | impl Unpin for B where Wrapper: Unpin {} //~ ERROR E0277 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::marker::Unpin` is not implemented for `std::marker::PhantomPinned` | = help: the following implementations were found: = note: required because of the requirements on the impl of `std::marker::Unpin` for `phantom_pinned::Wrapper` = help: see issue #48214 = help: add `#![feature(trivial_bounds)]` to the crate attributes to enable error[E0277]: the trait bound `std::marker::PhantomPinned: std::marker::Unpin` is not satisfied in `inner::Inner` --> $DIR/trivial_bounds-feature-gate.rs:33:5 | 33 | impl Unpin for A where Inner: Unpin {} //~ ERROR E0277 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ within `inner::Inner`, the trait `std::marker::Unpin` is not implemented for `std::marker::PhantomPinned` | = help: the following implementations were found: = note: required because it appears within the type `inner::Inner` = help: see issue #48214 = help: add `#![feature(trivial_bounds)]` to the crate attributes to enable error[E0277]: the trait bound `std::marker::PhantomPinned: std::marker::Unpin` is not satisfied in `inner::Inner` --> $DIR/trivial_bounds-feature-gate.rs:41:5 | 41 | impl Unpin for B where Wrapper: Unpin {} //~ ERROR E0277 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ within `inner::Inner`, the trait `std::marker::Unpin` is not implemented for `std::marker::PhantomPinned` | = help: the following implementations were found: = note: required because it appears within the type `inner::Inner` = note: required because of the requirements on the impl of `std::marker::Unpin` for `inner::Wrapper` = help: see issue #48214 = help: add `#![feature(trivial_bounds)]` to the crate attributes to enable pin-project-0.4.8/tests/ui/unstable-features/trivial_bounds.rs010064400007650000024000000016701361143547600230140ustar0000000000000000// NB: If you change this test, change 'trivial_bounds-feature-gate.rs' at the same time. // trivial_bounds // Tracking issue: https://github.com/rust-lang/rust/issues/48214 #![feature(trivial_bounds)] #![deny(trivial_bounds)] use std::marker::{PhantomData, PhantomPinned}; fn inner() { struct Inner(PhantomPinned); struct A(Inner); impl Unpin for A where Inner: Unpin {} //~ ERROR std::marker::Unpin does not depend on any type or lifetime parameters struct Wrapper(T); impl Unpin for Wrapper where T: Unpin {} struct B(Inner); impl Unpin for B where Wrapper: Unpin {} //~ ERROR std::marker::Unpin does not depend on any type or lifetime parameters struct WrapperWithLifetime<'a, T>(PhantomData<&'a ()>, T); impl Unpin for WrapperWithLifetime<'_, T> where T: Unpin {} struct C(Inner); impl<'a> Unpin for C where WrapperWithLifetime<'a, Inner>: Unpin {} // Ok } fn main() {} pin-project-0.4.8/tests/ui/unstable-features/trivial_bounds.stderr010064400007650000024000000014361361143547600236730ustar0000000000000000error: Trait bound inner::Inner: std::marker::Unpin does not depend on any type or lifetime parameters --> $DIR/trivial_bounds.rs:15:35 | 15 | impl Unpin for A where Inner: Unpin {} //~ ERROR std::marker::Unpin does not depend on any type or lifetime parameters | ^^^^^ | note: lint level defined here --> $DIR/trivial_bounds.rs:6:9 | 6 | #![deny(trivial_bounds)] | ^^^^^^^^^^^^^^ error: Trait bound inner::Wrapper: std::marker::Unpin does not depend on any type or lifetime parameters --> $DIR/trivial_bounds.rs:23:44 | 23 | impl Unpin for B where Wrapper: Unpin {} //~ ERROR std::marker::Unpin does not depend on any type or lifetime parameters | ^^^^^ pin-project-0.4.8/tests/unsafe_unpin.rs010064400007650000024000000030511361127335300164010ustar0000000000000000#![warn(unsafe_code)] #![warn(rust_2018_idioms, single_use_lifetimes)] #![allow(dead_code)] use pin_project::{pin_project, UnsafeUnpin}; use std::{marker::PhantomPinned, pin::Pin}; fn is_unpin() {} #[pin_project(UnsafeUnpin)] pub struct Blah { field1: U, #[pin] field2: T, } #[allow(unsafe_code)] unsafe impl UnsafeUnpin for Blah {} #[pin_project(UnsafeUnpin)] pub struct OverlappingLifetimeNames<'pin, T, U> { #[pin] field1: T, field2: U, field3: &'pin (), } #[allow(unsafe_code)] unsafe impl UnsafeUnpin for OverlappingLifetimeNames<'_, T, U> {} #[test] fn unsafe_unpin() { is_unpin::>(); is_unpin::>(); } #[test] fn trivial_bounds() { #[pin_project(UnsafeUnpin)] pub struct NotImplementUnsafUnpin { #[pin] field: PhantomPinned, } } #[test] fn dst() { #[pin_project(UnsafeUnpin)] pub struct A { x: T, } #[pin_project(UnsafeUnpin)] pub struct B { #[pin] x: T, } #[pin_project(UnsafeUnpin)] pub struct C(T); #[pin_project(UnsafeUnpin)] pub struct D(#[pin] T); } #[test] fn test() { let mut x = OverlappingLifetimeNames { field1: 0, field2: 1, field3: &() }; let x = Pin::new(&mut x); let y = x.as_ref().project_ref(); let _: Pin<&u8> = y.field1; let _: &u8 = y.field2; let y = x.project(); let _: Pin<&mut u8> = y.field1; let _: &mut u8 = y.field2; } pin-project-0.4.8/Cargo.lock0000644000000043551361355310600113620ustar00# This file is automatically @generated by Cargo. # It is not intended for manual editing. [[package]] name = "pin-project" version = "0.4.8" dependencies = [ "pin-project-internal 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "pin-project-internal" version = "0.4.8" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "syn 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "proc-macro2" version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "quote" version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "syn" version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "unicode-xid" version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" [metadata] "checksum pin-project-internal 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)" = "385322a45f2ecf3410c68d2a549a4a2685e8051d0f278e39743ff4e451cb9b3f" "checksum proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "9c9e470a8dc4aeae2dee2f335e8f533e2d4b347e1434e5671afc49b054592f27" "checksum quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "053a8c8bcc71fcce321828dc897a98ab9760bef03a4fc36693c231e5b3216cfe" "checksum syn 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "66850e97125af79138385e9b88339cbcd037e3f28ceab8c5ad98e64f0f1f80bf" "checksum unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c"