зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1716518 - Upgrade pin-project-lite to v0.1.12 and v0.2.6. r=emilio
Differential Revision: https://phabricator.services.mozilla.com/D117831
This commit is contained in:
Родитель
9256567eb6
Коммит
b049e1aa27
|
@ -1699,7 +1699,7 @@ dependencies = [
|
|||
"futures-core",
|
||||
"futures-sink",
|
||||
"futures-task",
|
||||
"pin-project-lite 0.2.4",
|
||||
"pin-project-lite 0.2.6",
|
||||
"pin-utils",
|
||||
]
|
||||
|
||||
|
@ -3830,15 +3830,15 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "pin-project-lite"
|
||||
version = "0.1.4"
|
||||
version = "0.1.12"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "237844750cfbb86f67afe27eee600dfbbcb6188d734139b534cbfbf4f96792ae"
|
||||
checksum = "257b64915a082f7811703966789728173279bdebb956b143dbcd23f6f970a777"
|
||||
|
||||
[[package]]
|
||||
name = "pin-project-lite"
|
||||
version = "0.2.4"
|
||||
version = "0.2.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "439697af366c49a6d0a010c56a0d97685bc140ce0d377b13a2ea2aa42d64a827"
|
||||
checksum = "dc0e1f259c92177c30a4c9d177246edd0a3568b25756a977d0632cf8fa37e905"
|
||||
|
||||
[[package]]
|
||||
name = "pin-utils"
|
||||
|
@ -5199,7 +5199,7 @@ dependencies = [
|
|||
"lazy_static",
|
||||
"memchr",
|
||||
"mio",
|
||||
"pin-project-lite 0.1.4",
|
||||
"pin-project-lite 0.1.12",
|
||||
"slab",
|
||||
]
|
||||
|
||||
|
@ -5356,7 +5356,7 @@ dependencies = [
|
|||
"futures-core",
|
||||
"futures-sink",
|
||||
"log",
|
||||
"pin-project-lite 0.1.4",
|
||||
"pin-project-lite 0.1.12",
|
||||
"tokio 0.2.18",
|
||||
]
|
||||
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
{"files":{"CHANGELOG.md":"8eb961687eb18a203d2bf746a24f2be25c61f5fff3d0b378bfd2024afcc25620","Cargo.toml":"57bcf2cf00d18ed9ea2abbcd7bfaab33512c58628d4765d2483ccda2ca64f9f1","LICENSE-APACHE":"0d542e0c8804e39aa7f37eb00da5a762149dc682d7829451287e11b938e94594","LICENSE-MIT":"23f18e03dc49df91622fe2a76176497404e46ced8a715d9d2b67a7446571cca3","README.md":"00c5f78218b433dcb02ee227b583d23a1528514a307579d411a9d9920be53a19","src/lib.rs":"36c5eab3d62ff2043a125bf7878753585e0c7ff4a279cf75f6aa196da2446340","tests/auxiliary/mod.rs":"7e263e987e09b77e384f734384a00a71c5b70230bb1b5376446ef003a8da9372","tests/compiletest.rs":"39d2a829c224453bb4eab9779001a919f5d97e865ca666afc448b8782ac3f733","tests/include/basic.rs":"c3f9a1703b7a4f370842e0678b4ecd739f8452aec184b1115f11e0c3822e79e0","tests/lint.rs":"4664659c071e9d77c7e076a5e4762583312751cc5e9b9034366c232310eacd78","tests/proper_unpin.rs":"b8cb75c403a96ddd1f58c31e04f6299c69b7ceda59b67b481cff7d461841d68c","tests/test.rs":"eb3a0b3fe756b9ccf379100393b08347459ad994ab7eec1bd53ec2b25b8ba2f0","tests/ui/conflict-drop.rs":"55e6809b5f59dd81e32c2c89b742c0c76db6b099a1d2621e5b882c0d20f92837","tests/ui/conflict-drop.stderr":"b29a458533f0312b2b04e9a0dfea17fce2ba423ef764ec3e2996a315c00a4cf8","tests/ui/conflict-unpin.rs":"51b3b6720fa581b63167d6ac941a1ea1bf739b09954931b2bc2f7abe2d934f26","tests/ui/conflict-unpin.stderr":"ab8e9acab4ffcdff1d0065e9504d64a0220267ab9f18b2840c97da8c0bbbf984","tests/ui/invalid-bounds.rs":"f86f23d377df015182f2f5dae6464a4f98c37f2198e0646f721fedc4017cb82c","tests/ui/invalid-bounds.stderr":"59c3b887b5f2d87804c25c54f4427e616947821c8f3fc5642dfc1ced67520b71","tests/ui/invalid.rs":"7304bd4a5bac1419382742432cfa8af83535d7be8cfad52c661410e0e9e8207a","tests/ui/invalid.stderr":"cb935ec370a87ba511aeef64613e7351b2eac9e574b5a256c7cb3c30f4bd74a6","tests/ui/overlapping_lifetime_names.rs":"a64c42cc56fa4751d73a1db80a7deb568427dc96f30c1a29665067d8c0ecb2c9","tests/ui/overlapping_lifetime_names.stderr":"ebfd5c08e7c472f49d49d67de9308e647a6a6b1e289308bf2d60d79d72521457","tests/ui/overlapping_unpin_struct.rs":"5fde23ef628d2dbd27377ffa472fc19b1c6873122f38c3fb1f84fda8602f55f3","tests/ui/overlapping_unpin_struct.stderr":"e83e99bacdf6564727c77dafe5eaf000b4de6e784e6032b9b0ecca831ecc528c","tests/ui/packed.rs":"1f1a34aafbff9a59b94cdf3a53df03e9fc661d9e27e0f9962bad7f9bdad03b14","tests/ui/packed.stderr":"4acb1514ca0a2c3b9448b28a71ab81d1dce37ba42f1af8b3220f926f0ca556e4","tests/ui/unpin_sneaky.rs":"12e97a387ce1af6ee6a567687674aab70e96962a48f2433c39976d0b3e2c3341","tests/ui/unpin_sneaky.stderr":"7b2bc76faca39f77968c798674f2321111a74a5754512149320ea4cdd3e278d5","tests/ui/unsupported.rs":"14defa90e736f314bbbc219973929b77bdd22e5f7e4c4c88403db764f4d167d6","tests/ui/unsupported.stderr":"310a8a7ed4e8120fa570957800e6cc86ff5561580a241ab808092e99a1f3b8b2"},"package":"257b64915a082f7811703966789728173279bdebb956b143dbcd23f6f970a777"}
|
|
@ -0,0 +1,111 @@
|
|||
# Changelog
|
||||
|
||||
All notable changes to this project will be documented in this file.
|
||||
|
||||
This project adheres to [Semantic Versioning](https://semver.org).
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
## [0.1.12] - 2021-03-02
|
||||
|
||||
- [Prepare for removal of `safe_packed_borrows` lint.](https://github.com/taiki-e/pin-project-lite/pull/55) See [#55](https://github.com/taiki-e/pin-project-lite/pull/55) for details.
|
||||
|
||||
## [0.1.11] - 2020-10-20
|
||||
|
||||
**Note: This release has been yanked.** See [#55](https://github.com/taiki-e/pin-project-lite/pull/55) for details.
|
||||
|
||||
- Suppress `clippy::redundant_pub_crate` lint in generated code.
|
||||
|
||||
- Documentation improvements.
|
||||
|
||||
## [0.1.10] - 2020-10-01
|
||||
|
||||
**Note: This release has been yanked.** See [#55](https://github.com/taiki-e/pin-project-lite/pull/55) for details.
|
||||
|
||||
- Suppress `drop_bounds` lint, which will be added to rustc in the future. See [taiki-e/pin-project#272](https://github.com/taiki-e/pin-project/issues/272) for more details.
|
||||
|
||||
## [0.1.9] - 2020-09-29
|
||||
|
||||
**Note: This release has been yanked.** See [#55](https://github.com/taiki-e/pin-project-lite/pull/55) for details.
|
||||
|
||||
- [Fix trailing comma support in generics.](https://github.com/taiki-e/pin-project-lite/pull/32)
|
||||
|
||||
## [0.1.8] - 2020-09-26
|
||||
|
||||
**Note: This release has been yanked.** See [#55](https://github.com/taiki-e/pin-project-lite/pull/55) for details.
|
||||
|
||||
- [Fix compatibility of generated code with `forbid(future_incompatible)`.](https://github.com/taiki-e/pin-project-lite/pull/30)
|
||||
|
||||
Note: This does not guarantee compatibility with `forbid(future_incompatible)` in the future.
|
||||
If rustc adds a new lint, we may not be able to keep this.
|
||||
|
||||
## [0.1.7] - 2020-06-04
|
||||
|
||||
**Note: This release has been yanked.** See [#55](https://github.com/taiki-e/pin-project-lite/pull/55) for details.
|
||||
|
||||
- [Support `?Sized` bounds in where clauses.](https://github.com/taiki-e/pin-project-lite/pull/22)
|
||||
|
||||
- [Fix lifetime inference error when an associated type is used in fields.](https://github.com/taiki-e/pin-project-lite/pull/20)
|
||||
|
||||
- Suppress `clippy::used_underscore_binding` lint in generated code.
|
||||
|
||||
- Documentation improvements.
|
||||
|
||||
## [0.1.6] - 2020-05-31
|
||||
|
||||
**Note: This release has been yanked.** See [#55](https://github.com/taiki-e/pin-project-lite/pull/55) for details.
|
||||
|
||||
- [Support lifetime bounds in where clauses.](https://github.com/taiki-e/pin-project-lite/pull/18)
|
||||
|
||||
- Documentation improvements.
|
||||
|
||||
## [0.1.5] - 2020-05-07
|
||||
|
||||
**Note: This release has been yanked.** See [#55](https://github.com/taiki-e/pin-project-lite/pull/55) for details.
|
||||
|
||||
- [Support overwriting the name of `core` crate.](https://github.com/taiki-e/pin-project-lite/pull/14)
|
||||
|
||||
## [0.1.4] - 2020-01-20
|
||||
|
||||
**Note: This release has been yanked.** See [#55](https://github.com/taiki-e/pin-project-lite/pull/55) for details.
|
||||
|
||||
- [Support ?Sized bounds in generic parameters.](https://github.com/taiki-e/pin-project-lite/pull/9)
|
||||
|
||||
## [0.1.3] - 2020-01-20
|
||||
|
||||
**Note: This release has been yanked.** See [#55](https://github.com/taiki-e/pin-project-lite/pull/55) for details.
|
||||
|
||||
- [Support lifetime bounds in generic parameters.](https://github.com/taiki-e/pin-project-lite/pull/7)
|
||||
|
||||
## [0.1.2] - 2020-01-05
|
||||
|
||||
**Note: This release has been yanked.** See [#55](https://github.com/taiki-e/pin-project-lite/pull/55) for details.
|
||||
|
||||
- [Support recognizing default generic parameters.](https://github.com/taiki-e/pin-project-lite/pull/6)
|
||||
|
||||
## [0.1.1] - 2019-11-15
|
||||
|
||||
**Note: This release has been yanked.** See [#55](https://github.com/taiki-e/pin-project-lite/pull/55) for details.
|
||||
|
||||
- [`pin_project!` macro now determines the visibility of the projection type/method is based on the original type.](https://github.com/taiki-e/pin-project-lite/pull/5)
|
||||
|
||||
## [0.1.0] - 2019-10-22
|
||||
|
||||
**Note: This release has been yanked.** See [#55](https://github.com/taiki-e/pin-project-lite/pull/55) for details.
|
||||
|
||||
Initial release
|
||||
|
||||
[Unreleased]: https://github.com/taiki-e/pin-project-lite/compare/v0.1.12...HEAD
|
||||
[0.1.12]: https://github.com/taiki-e/pin-project-lite/compare/v0.1.11...v0.1.12
|
||||
[0.1.11]: https://github.com/taiki-e/pin-project-lite/compare/v0.1.10...v0.1.11
|
||||
[0.1.10]: https://github.com/taiki-e/pin-project-lite/compare/v0.1.9...v0.1.10
|
||||
[0.1.9]: https://github.com/taiki-e/pin-project-lite/compare/v0.1.8...v0.1.9
|
||||
[0.1.8]: https://github.com/taiki-e/pin-project-lite/compare/v0.1.7...v0.1.8
|
||||
[0.1.7]: https://github.com/taiki-e/pin-project-lite/compare/v0.1.6...v0.1.7
|
||||
[0.1.6]: https://github.com/taiki-e/pin-project-lite/compare/v0.1.5...v0.1.6
|
||||
[0.1.5]: https://github.com/taiki-e/pin-project-lite/compare/v0.1.4...v0.1.5
|
||||
[0.1.4]: https://github.com/taiki-e/pin-project-lite/compare/v0.1.3...v0.1.4
|
||||
[0.1.3]: https://github.com/taiki-e/pin-project-lite/compare/v0.1.2...v0.1.3
|
||||
[0.1.2]: https://github.com/taiki-e/pin-project-lite/compare/v0.1.1...v0.1.2
|
||||
[0.1.1]: https://github.com/taiki-e/pin-project-lite/compare/v0.1.0...v0.1.1
|
||||
[0.1.0]: https://github.com/taiki-e/pin-project-lite/releases/tag/v0.1.0
|
|
@ -13,18 +13,24 @@
|
|||
[package]
|
||||
edition = "2018"
|
||||
name = "pin-project-lite"
|
||||
version = "0.1.4"
|
||||
version = "0.1.12"
|
||||
authors = ["Taiki Endo <te316e89@gmail.com>"]
|
||||
exclude = ["/.*", "/scripts"]
|
||||
description = "A lightweight version of pin-project written with declarative macros.\n"
|
||||
homepage = "https://github.com/taiki-e/pin-project-lite"
|
||||
documentation = "https://docs.rs/pin-project-lite"
|
||||
readme = "README.md"
|
||||
keywords = ["pin", "macros"]
|
||||
categories = ["no-std", "rust-patterns"]
|
||||
license = "Apache-2.0 OR MIT"
|
||||
repository = "https://github.com/taiki-e/pin-project-lite"
|
||||
[package.metadata.docs.rs]
|
||||
targets = ["x86_64-unknown-linux-gnu"]
|
||||
|
||||
[dependencies]
|
||||
[dev-dependencies.rustversion]
|
||||
version = "1.0"
|
||||
version = "1"
|
||||
|
||||
[dev-dependencies.static_assertions]
|
||||
version = "1"
|
||||
|
||||
[dev-dependencies.trybuild]
|
||||
version = "1.0"
|
||||
version = "1"
|
|
@ -175,28 +175,3 @@
|
|||
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.
|
|
@ -9,7 +9,7 @@
|
|||
[crates-url]: https://crates.io/crates/pin-project-lite
|
||||
[docs-badge]: https://docs.rs/pin-project-lite/badge.svg
|
||||
[docs-url]: https://docs.rs/pin-project-lite
|
||||
[license-badge]: https://img.shields.io/crates/l/pin-project-lite.svg
|
||||
[license-badge]: https://img.shields.io/badge/license-Apache--2.0%20OR%20MIT-blue.svg
|
||||
[license]: #license
|
||||
[rustc-badge]: https://img.shields.io/badge/rustc-1.37+-lightgray.svg
|
||||
[rustc-url]: https://blog.rust-lang.org/2019/08/15/Rust-1.37.0.html
|
||||
|
@ -29,6 +29,8 @@ The current pin-project-lite requires Rust 1.37 or later.
|
|||
|
||||
## Examples
|
||||
|
||||
[`pin_project!`] macro creates a projection type covering all the fields of struct.
|
||||
|
||||
```rust
|
||||
use pin_project_lite::pin_project;
|
||||
use std::pin::Pin;
|
||||
|
@ -42,7 +44,7 @@ pin_project! {
|
|||
}
|
||||
|
||||
impl<T, U> Struct<T, U> {
|
||||
fn foo(self: Pin<&mut Self>) {
|
||||
fn method(self: Pin<&mut Self>) {
|
||||
let this = self.project();
|
||||
let _: Pin<&mut T> = this.pinned; // Pinned reference to the field
|
||||
let _: &mut U = this.unpinned; // Normal reference to the field
|
||||
|
@ -76,20 +78,22 @@ pin-project-lite will refuse anything other than a braced struct with named fiel
|
|||
|
||||
### Different: No support for custom Drop implementation
|
||||
|
||||
[pin-project supports this.][pinned-drop]
|
||||
pin-project supports this by [`#[pinned_drop]`][pinned-drop].
|
||||
|
||||
### Different: No support for custom Unpin implementation
|
||||
|
||||
[pin-project supports this.][unsafe-unpin]
|
||||
pin-project supports this by [`UnsafeUnpin`][unsafe-unpin] and [`!Unpin`][not-unpin].
|
||||
|
||||
### Different: No support for pattern matching and destructing
|
||||
|
||||
[pin-project supports this.][projection-helper]
|
||||
[pin-project supports this.][naming]
|
||||
|
||||
[`pin_project!`]: https://docs.rs/pin-project-lite/0.1/pin_project_lite/macro.pin_project.html
|
||||
[naming]: https://docs.rs/pin-project/1/pin_project/attr.pin_project.html
|
||||
[not-unpin]: https://docs.rs/pin-project/1/pin_project/attr.pin_project.html#unpin
|
||||
[pin-project]: https://github.com/taiki-e/pin-project
|
||||
[pinned-drop]: https://docs.rs/pin-project/0.4/pin_project/attr.pin_project.html#pinned_drop
|
||||
[unsafe-unpin]: https://docs.rs/pin-project/0.4/pin_project/trait.UnsafeUnpin.html
|
||||
[projection-helper]: https://docs.rs/pin-project/0.4/pin_project/attr.project.html#let-bindings
|
||||
[pinned-drop]: https://docs.rs/pin-project/1/pin_project/attr.pin_project.html#pinned_drop
|
||||
[unsafe-unpin]: https://docs.rs/pin-project/1/pin_project/attr.pin_project.html#unsafeunpin
|
||||
|
||||
## License
|
||||
|
|
@ -0,0 +1,628 @@
|
|||
//! A lightweight version of [pin-project] written with declarative macros.
|
||||
//!
|
||||
//! # Examples
|
||||
//!
|
||||
//! [`pin_project!`] macro creates a projection type covering all the fields of struct.
|
||||
//!
|
||||
//! ```rust
|
||||
//! use std::pin::Pin;
|
||||
//!
|
||||
//! use pin_project_lite::pin_project;
|
||||
//!
|
||||
//! pin_project! {
|
||||
//! struct Struct<T, U> {
|
||||
//! #[pin]
|
||||
//! pinned: T,
|
||||
//! unpinned: U,
|
||||
//! }
|
||||
//! }
|
||||
//!
|
||||
//! impl<T, U> Struct<T, U> {
|
||||
//! fn method(self: Pin<&mut Self>) {
|
||||
//! let this = self.project();
|
||||
//! let _: Pin<&mut T> = this.pinned; // Pinned reference to the field
|
||||
//! let _: &mut U = this.unpinned; // Normal reference to the field
|
||||
//! }
|
||||
//! }
|
||||
//! ```
|
||||
//!
|
||||
//! # [pin-project] vs pin-project-lite
|
||||
//!
|
||||
//! Here are some similarities and differences compared to [pin-project].
|
||||
//!
|
||||
//! ## Similar: Safety
|
||||
//!
|
||||
//! pin-project-lite guarantees safety in much the same way as [pin-project]. Both are completely safe unless you write other unsafe code.
|
||||
//!
|
||||
//! ## Different: Minimal design
|
||||
//!
|
||||
//! This library does not tackle as expansive of a range of use cases as [pin-project] does. If your use case is not already covered, please use [pin-project].
|
||||
//!
|
||||
//! ## Different: No proc-macro related dependencies
|
||||
//!
|
||||
//! This is the **only** reason to use this crate. However, **if you already have proc-macro related dependencies in your crate's dependency graph, there is no benefit from using this crate.** (Note: There is almost no difference in the amount of code generated between [pin-project] and pin-project-lite.)
|
||||
//!
|
||||
//! ## Different: No useful error messages
|
||||
//!
|
||||
//! This macro does not handle any invalid input. So error messages are not to be useful in most cases. If you do need useful error messages, then upon error you can pass the same input to [pin-project] to receive a helpful description of the compile error.
|
||||
//!
|
||||
//! ## Different: Structs only
|
||||
//!
|
||||
//! pin-project-lite will refuse anything other than a braced struct with named fields. Enums and tuple structs are not supported.
|
||||
//!
|
||||
//! ## Different: No support for custom Drop implementation
|
||||
//!
|
||||
//! pin-project supports this by [`#[pinned_drop]`][pinned-drop].
|
||||
//!
|
||||
//! ## Different: No support for custom Unpin implementation
|
||||
//!
|
||||
//! pin-project supports this by [`UnsafeUnpin`][unsafe-unpin] and [`!Unpin`][not-unpin].
|
||||
//!
|
||||
//! ## Different: No support for pattern matching and destructing
|
||||
//!
|
||||
//! [pin-project supports this.][naming]
|
||||
//!
|
||||
//! [naming]: https://docs.rs/pin-project/1/pin_project/attr.pin_project.html
|
||||
//! [not-unpin]: https://docs.rs/pin-project/1/pin_project/attr.pin_project.html#unpin
|
||||
//! [pin-project]: https://github.com/taiki-e/pin-project
|
||||
//! [pinned-drop]: https://docs.rs/pin-project/1/pin_project/attr.pin_project.html#pinned_drop
|
||||
//! [unsafe-unpin]: https://docs.rs/pin-project/1/pin_project/attr.pin_project.html#unsafeunpin
|
||||
|
||||
#![no_std]
|
||||
#![doc(test(
|
||||
no_crate_inject,
|
||||
attr(deny(warnings, rust_2018_idioms, single_use_lifetimes), allow(dead_code))
|
||||
))]
|
||||
#![warn(unsafe_code)]
|
||||
#![warn(future_incompatible, rust_2018_idioms, single_use_lifetimes, unreachable_pub)]
|
||||
#![warn(clippy::all, clippy::default_trait_access)]
|
||||
// mem::take and #[non_exhaustive] requires Rust 1.40, matches! requires Rust 1.42
|
||||
#![allow(
|
||||
clippy::mem_replace_with_default,
|
||||
clippy::manual_non_exhaustive,
|
||||
clippy::match_like_matches_macro
|
||||
)]
|
||||
|
||||
/// A macro that creates a projection type covering all the fields of struct.
|
||||
///
|
||||
/// This macro creates a projection type according to the following rules:
|
||||
///
|
||||
/// * For the field that uses `#[pin]` attribute, makes the pinned reference to the field.
|
||||
/// * For the other fields, makes the unpinned reference to the field.
|
||||
///
|
||||
/// And the following methods are implemented on the original type:
|
||||
///
|
||||
/// ```rust
|
||||
/// # use std::pin::Pin;
|
||||
/// # type Projection<'a> = &'a ();
|
||||
/// # type ProjectionRef<'a> = &'a ();
|
||||
/// # trait Dox {
|
||||
/// fn project(self: Pin<&mut Self>) -> Projection<'_>;
|
||||
/// fn project_ref(self: Pin<&Self>) -> ProjectionRef<'_>;
|
||||
/// # }
|
||||
/// ```
|
||||
///
|
||||
/// The visibility of the projected type and projection method is based on the
|
||||
/// original type. However, if the visibility of the original type is `pub`,
|
||||
/// the visibility of the projected type and the projection method is `pub(crate)`.
|
||||
///
|
||||
/// # Safety
|
||||
///
|
||||
/// `pin_project!` macro guarantees safety in much the same way as [pin-project] crate.
|
||||
/// Both are completely safe unless you write other unsafe code.
|
||||
///
|
||||
/// See [pin-project] crate for more details.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```rust
|
||||
/// use std::pin::Pin;
|
||||
///
|
||||
/// use pin_project_lite::pin_project;
|
||||
///
|
||||
/// pin_project! {
|
||||
/// struct Struct<T, U> {
|
||||
/// #[pin]
|
||||
/// pinned: T,
|
||||
/// unpinned: U,
|
||||
/// }
|
||||
/// }
|
||||
///
|
||||
/// impl<T, U> Struct<T, U> {
|
||||
/// fn method(self: Pin<&mut Self>) {
|
||||
/// let this = self.project();
|
||||
/// let _: Pin<&mut T> = this.pinned; // Pinned reference to the field
|
||||
/// let _: &mut U = this.unpinned; // Normal reference to the field
|
||||
/// }
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
/// If you want to call the `project()` method multiple times or later use the
|
||||
/// original [`Pin`] type, it needs to use [`.as_mut()`][`Pin::as_mut`] to avoid
|
||||
/// consuming the [`Pin`].
|
||||
///
|
||||
/// ```rust
|
||||
/// use std::pin::Pin;
|
||||
///
|
||||
/// use pin_project_lite::pin_project;
|
||||
///
|
||||
/// pin_project! {
|
||||
/// struct Struct<T> {
|
||||
/// #[pin]
|
||||
/// field: T,
|
||||
/// }
|
||||
/// }
|
||||
///
|
||||
/// impl<T> Struct<T> {
|
||||
/// fn call_project_twice(mut self: Pin<&mut Self>) {
|
||||
/// // `project` consumes `self`, so reborrow the `Pin<&mut Self>` via `as_mut`.
|
||||
/// self.as_mut().project();
|
||||
/// self.as_mut().project();
|
||||
/// }
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
/// # `!Unpin`
|
||||
///
|
||||
/// If you want to ensure that [`Unpin`] is not implemented, use `#[pin]`
|
||||
/// attribute for a [`PhantomPinned`] field.
|
||||
///
|
||||
/// ```rust
|
||||
/// use std::marker::PhantomPinned;
|
||||
///
|
||||
/// use pin_project_lite::pin_project;
|
||||
///
|
||||
/// pin_project! {
|
||||
/// struct Struct<T> {
|
||||
/// field: T,
|
||||
/// #[pin] // <------ This `#[pin]` is required to make `Struct` to `!Unpin`.
|
||||
/// _pin: PhantomPinned,
|
||||
/// }
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
/// Note that using [`PhantomPinned`] without `#[pin]` attribute has no effect.
|
||||
///
|
||||
/// [`PhantomPinned`]: core::marker::PhantomPinned
|
||||
/// [`Pin::as_mut`]: core::pin::Pin::as_mut
|
||||
/// [`Pin`]: core::pin::Pin
|
||||
/// [pin-project]: https://github.com/taiki-e/pin-project
|
||||
#[macro_export]
|
||||
macro_rules! pin_project {
|
||||
($($tt:tt)*) => {
|
||||
$crate::__pin_project_internal! { $($tt)* }
|
||||
};
|
||||
}
|
||||
|
||||
// limitations:
|
||||
// * no support for tuple structs and enums.
|
||||
// * no support for naming the projection types.
|
||||
// * no support for multiple trait/lifetime bounds.
|
||||
// * no support for `Self` in where clauses. (wontfix)
|
||||
// * no support for overlapping lifetime names. (wontfix)
|
||||
// * no interoperability with other field attributes.
|
||||
// * no useful error messages. (wontfix)
|
||||
// etc...
|
||||
|
||||
// Not public API.
|
||||
#[doc(hidden)]
|
||||
#[macro_export]
|
||||
macro_rules! __pin_project_internal {
|
||||
// =============================================================================================
|
||||
// main: struct
|
||||
(@struct_internal;
|
||||
[$proj_vis:vis]
|
||||
[$(#[$attrs:meta])* $vis:vis struct $ident:ident]
|
||||
[$($def_generics:tt)*]
|
||||
[$($impl_generics:tt)*] [$($ty_generics:tt)*] [$(where $($where_clause:tt)*)?]
|
||||
{
|
||||
$(
|
||||
$(#[$pin:ident])?
|
||||
$field_vis:vis $field:ident: $field_ty:ty
|
||||
),+
|
||||
}
|
||||
) => {
|
||||
$(#[$attrs])*
|
||||
$vis struct $ident $($def_generics)*
|
||||
$(where
|
||||
$($where_clause)*)?
|
||||
{
|
||||
$(
|
||||
$field_vis $field: $field_ty
|
||||
),+
|
||||
}
|
||||
|
||||
#[allow(explicit_outlives_requirements)]
|
||||
#[allow(single_use_lifetimes)] // https://github.com/rust-lang/rust/issues/55058
|
||||
#[allow(clippy::redundant_pub_crate)]
|
||||
#[allow(clippy::used_underscore_binding)]
|
||||
const _: () = {
|
||||
$crate::__pin_project_internal! { @make_proj_ty_struct;
|
||||
[$proj_vis]
|
||||
[$vis struct $ident]
|
||||
[$($impl_generics)*] [$($ty_generics)*] [$(where $($where_clause)*)?]
|
||||
{
|
||||
$(
|
||||
$(#[$pin])?
|
||||
$field_vis $field: $field_ty
|
||||
),+
|
||||
}
|
||||
}
|
||||
|
||||
impl <$($impl_generics)*> $ident <$($ty_generics)*>
|
||||
$(where
|
||||
$($where_clause)*)?
|
||||
{
|
||||
$proj_vis fn project<'__pin>(
|
||||
self: $crate::__private::Pin<&'__pin mut Self>,
|
||||
) -> Projection <'__pin, $($ty_generics)*> {
|
||||
unsafe {
|
||||
let Self { $($field),* } = self.get_unchecked_mut();
|
||||
Projection {
|
||||
$(
|
||||
$field: $crate::__pin_project_internal!(@make_unsafe_field_proj;
|
||||
$(#[$pin])? $field
|
||||
)
|
||||
),+
|
||||
}
|
||||
}
|
||||
}
|
||||
$proj_vis fn project_ref<'__pin>(
|
||||
self: $crate::__private::Pin<&'__pin Self>,
|
||||
) -> ProjectionRef <'__pin, $($ty_generics)*> {
|
||||
unsafe {
|
||||
let Self { $($field),* } = self.get_ref();
|
||||
ProjectionRef {
|
||||
$(
|
||||
$field: $crate::__pin_project_internal!(@make_unsafe_field_proj;
|
||||
$(#[$pin])? $field
|
||||
)
|
||||
),+
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$crate::__pin_project_internal! { @make_unpin_impl;
|
||||
[$vis $ident]
|
||||
[$($impl_generics)*] [$($ty_generics)*] [$(where $($where_clause)*)?]
|
||||
$(
|
||||
$field: $crate::__pin_project_internal!(@make_unpin_bound;
|
||||
$(#[$pin])? $field_ty
|
||||
)
|
||||
),+
|
||||
}
|
||||
|
||||
$crate::__pin_project_internal! { @make_drop_impl;
|
||||
[$ident]
|
||||
[$($impl_generics)*] [$($ty_generics)*] [$(where $($where_clause)*)?]
|
||||
}
|
||||
|
||||
// Ensure that it's impossible to use pin projections on a #[repr(packed)] struct.
|
||||
//
|
||||
// Taking a reference to a packed field is UB, and applying
|
||||
// `#[forbid(unaligned_references)]` makes sure that doing this 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.
|
||||
//
|
||||
// Note:
|
||||
// - Lint-based tricks aren't perfect, but they're much better than nothing:
|
||||
// https://github.com/taiki-e/pin-project-lite/issues/26
|
||||
//
|
||||
// - Enable both unaligned_references and safe_packed_borrows lints
|
||||
// because unaligned_references lint does not exist in older compilers:
|
||||
// https://github.com/taiki-e/pin-project-lite/pull/55
|
||||
// https://github.com/rust-lang/rust/pull/82525
|
||||
#[forbid(unaligned_references, safe_packed_borrows)]
|
||||
fn __assert_not_repr_packed <$($impl_generics)*> (this: &$ident <$($ty_generics)*>)
|
||||
$(where
|
||||
$($where_clause)*)?
|
||||
{
|
||||
$(
|
||||
let _ = &this.$field;
|
||||
)+
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
// =============================================================================================
|
||||
// make_proj_ty: struct
|
||||
(@make_proj_ty_struct;
|
||||
[$proj_vis:vis]
|
||||
[$vis:vis struct $ident:ident]
|
||||
[$($impl_generics:tt)*] [$($ty_generics:tt)*] [$(where $($where_clause:tt)* )?]
|
||||
{
|
||||
$(
|
||||
$(#[$pin:ident])?
|
||||
$field_vis:vis $field:ident: $field_ty:ty
|
||||
),+
|
||||
}
|
||||
) => {
|
||||
#[allow(dead_code)] // This lint warns unused fields/variants.
|
||||
#[allow(clippy::mut_mut)] // This lint warns `&mut &mut <ty>`.
|
||||
#[allow(clippy::type_repetition_in_bounds)] // https://github.com/rust-lang/rust-clippy/issues/4326
|
||||
$proj_vis struct Projection <'__pin, $($impl_generics)*>
|
||||
where
|
||||
$ident <$($ty_generics)*>: '__pin
|
||||
$(, $($where_clause)*)?
|
||||
{
|
||||
$(
|
||||
$field_vis $field: $crate::__pin_project_internal!(@make_proj_field;
|
||||
$(#[$pin])? $field_ty; mut
|
||||
)
|
||||
),+
|
||||
}
|
||||
#[allow(dead_code)] // This lint warns unused fields/variants.
|
||||
#[allow(clippy::type_repetition_in_bounds)] // https://github.com/rust-lang/rust-clippy/issues/4326
|
||||
$proj_vis struct ProjectionRef <'__pin, $($impl_generics)*>
|
||||
where
|
||||
$ident <$($ty_generics)*>: '__pin
|
||||
$(, $($where_clause)*)?
|
||||
{
|
||||
$(
|
||||
$field_vis $field: $crate::__pin_project_internal!(@make_proj_field;
|
||||
$(#[$pin])? $field_ty;
|
||||
)
|
||||
),+
|
||||
}
|
||||
};
|
||||
|
||||
// =============================================================================================
|
||||
// make_unpin_impl
|
||||
(@make_unpin_impl;
|
||||
[$vis:vis $ident:ident]
|
||||
[$($impl_generics:tt)*] [$($ty_generics:tt)*] [$(where $($where_clause:tt)* )?]
|
||||
$($field:tt)*
|
||||
) => {
|
||||
// Automatically create the appropriate conditional `Unpin` implementation.
|
||||
//
|
||||
// Basically this is equivalent to the following code:
|
||||
// ```rust
|
||||
// impl<T, U> Unpin for Struct<T, U> where T: Unpin {}
|
||||
// ```
|
||||
//
|
||||
// However, if struct is public and there is a private type field,
|
||||
// this would cause an E0446 (private type in public interface).
|
||||
//
|
||||
// When RFC 2145 is implemented (rust-lang/rust#48054),
|
||||
// this will become a lint, rather then a hard error.
|
||||
//
|
||||
// As a workaround for this, we generate a new struct, containing all of the pinned
|
||||
// fields from our #[pin_project] type. This struct is delcared within
|
||||
// a function, which makes it impossible to be named by user code.
|
||||
// This guarnatees that it will use the default auto-trait impl for Unpin -
|
||||
// that is, it will implement Unpin iff all of its fields implement Unpin.
|
||||
// This type can be safely declared as 'public', satisfiying the privacy
|
||||
// checker without actually allowing user code to access it.
|
||||
//
|
||||
// This allows users to apply the #[pin_project] attribute to types
|
||||
// regardless of the privacy of the types of their fields.
|
||||
//
|
||||
// See also https://github.com/taiki-e/pin-project/pull/53.
|
||||
$vis struct __Origin <'__pin, $($impl_generics)*>
|
||||
$(where
|
||||
$($where_clause)*)?
|
||||
{
|
||||
__dummy_lifetime: $crate::__private::PhantomData<&'__pin ()>,
|
||||
$($field)*
|
||||
}
|
||||
impl <'__pin, $($impl_generics)*> $crate::__private::Unpin for $ident <$($ty_generics)*>
|
||||
where
|
||||
__Origin <'__pin, $($ty_generics)*>: $crate::__private::Unpin
|
||||
$(, $($where_clause)*)?
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
// =============================================================================================
|
||||
// make_drop_impl
|
||||
(@make_drop_impl;
|
||||
[$ident:ident]
|
||||
[$($impl_generics:tt)*] [$($ty_generics:tt)*] [$(where $($where_clause:tt)* )?]
|
||||
) => {
|
||||
// Ensure that struct does not implement `Drop`.
|
||||
//
|
||||
// There are two possible cases:
|
||||
// 1. The user type does not implement Drop. In this case,
|
||||
// the first blanked impl will not apply to it. This code
|
||||
// will compile, as there is only one impl of MustNotImplDrop for the user type
|
||||
// 2. The user type does impl Drop. This will make the blanket impl applicable,
|
||||
// which will then comflict with the explicit MustNotImplDrop impl below.
|
||||
// This will result in a compilation error, which is exactly what we want.
|
||||
trait MustNotImplDrop {}
|
||||
#[allow(clippy::drop_bounds, drop_bounds)]
|
||||
impl<T: $crate::__private::Drop> MustNotImplDrop for T {}
|
||||
impl <$($impl_generics)*> MustNotImplDrop for $ident <$($ty_generics)*>
|
||||
$(where
|
||||
$($where_clause)*)?
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
// =============================================================================================
|
||||
// make_unpin_bound
|
||||
(@make_unpin_bound;
|
||||
#[pin]
|
||||
$field_ty:ty
|
||||
) => {
|
||||
$field_ty
|
||||
};
|
||||
(@make_unpin_bound;
|
||||
$field_ty:ty
|
||||
) => {
|
||||
$crate::__private::AlwaysUnpin<$field_ty>
|
||||
};
|
||||
|
||||
// =============================================================================================
|
||||
// make_unsafe_field_proj
|
||||
(@make_unsafe_field_proj;
|
||||
#[pin]
|
||||
$field:ident
|
||||
) => {
|
||||
$crate::__private::Pin::new_unchecked($field)
|
||||
};
|
||||
(@make_unsafe_field_proj;
|
||||
$field:ident
|
||||
) => {
|
||||
$field
|
||||
};
|
||||
|
||||
// =============================================================================================
|
||||
// make_proj_field
|
||||
(@make_proj_field;
|
||||
#[pin]
|
||||
$field_ty:ty;
|
||||
$($mut:ident)?
|
||||
) => {
|
||||
$crate::__private::Pin<&'__pin $($mut)? ($field_ty)>
|
||||
};
|
||||
(@make_proj_field;
|
||||
$field_ty:ty;
|
||||
$($mut:ident)?
|
||||
) => {
|
||||
&'__pin $($mut)? ($field_ty)
|
||||
};
|
||||
|
||||
// =============================================================================================
|
||||
// Parses input and determines visibility
|
||||
(
|
||||
$(#[$attrs:meta])*
|
||||
pub struct $ident:ident $(<
|
||||
$( $lifetime:lifetime $(: $lifetime_bound:lifetime)? ),* $(,)?
|
||||
$( $generics:ident
|
||||
$(: $generics_bound:path)?
|
||||
$(: ?$generics_unsized_bound:path)?
|
||||
$(: $generics_lifetime_bound:lifetime)?
|
||||
$(= $generics_default:ty)?
|
||||
),* $(,)?
|
||||
>)?
|
||||
$(where
|
||||
$( $where_clause_ty:ty
|
||||
$(: $where_clause_bound:path)?
|
||||
$(: ?$where_clause_unsized_bound:path)?
|
||||
$(: $where_clause_lifetime_bound:lifetime)?
|
||||
),* $(,)?
|
||||
)?
|
||||
{
|
||||
$(
|
||||
$(#[$pin:ident])?
|
||||
$field_vis:vis $field:ident: $field_ty:ty
|
||||
),+ $(,)?
|
||||
}
|
||||
) => {
|
||||
$crate::__pin_project_internal! { @struct_internal;
|
||||
[pub(crate)]
|
||||
[$(#[$attrs])* pub struct $ident]
|
||||
[$(<
|
||||
$( $lifetime $(: $lifetime_bound)? ,)*
|
||||
$( $generics
|
||||
$(: $generics_bound)?
|
||||
$(: ?$generics_unsized_bound)?
|
||||
$(: $generics_lifetime_bound)?
|
||||
$(= $generics_default)?
|
||||
),*
|
||||
>)?]
|
||||
[$(
|
||||
$( $lifetime $(: $lifetime_bound)? ,)*
|
||||
$( $generics
|
||||
$(: $generics_bound)?
|
||||
$(: ?$generics_unsized_bound)?
|
||||
$(: $generics_lifetime_bound)?
|
||||
),*
|
||||
)?]
|
||||
[$( $( $lifetime ,)* $( $generics ),* )?]
|
||||
[$(where $( $where_clause_ty
|
||||
$(: $where_clause_bound)?
|
||||
$(: ?$where_clause_unsized_bound)?
|
||||
$(: $where_clause_lifetime_bound)?
|
||||
),* )?]
|
||||
{
|
||||
$(
|
||||
$(#[$pin])?
|
||||
$field_vis $field: $field_ty
|
||||
),+
|
||||
}
|
||||
}
|
||||
};
|
||||
(
|
||||
$(#[$attrs:meta])*
|
||||
$vis:vis struct $ident:ident $(<
|
||||
$( $lifetime:lifetime $(: $lifetime_bound:lifetime)? ),* $(,)?
|
||||
$( $generics:ident
|
||||
$(: $generics_bound:path)?
|
||||
$(: ?$generics_unsized_bound:path)?
|
||||
$(: $generics_lifetime_bound:lifetime)?
|
||||
$(= $generics_default:ty)?
|
||||
),* $(,)?
|
||||
>)?
|
||||
$(where
|
||||
$( $where_clause_ty:ty
|
||||
$(: $where_clause_bound:path)?
|
||||
$(: ?$where_clause_unsized_bound:path)?
|
||||
$(: $where_clause_lifetime_bound:lifetime)?
|
||||
),* $(,)?
|
||||
)?
|
||||
{
|
||||
$(
|
||||
$(#[$pin:ident])?
|
||||
$field_vis:vis $field:ident: $field_ty:ty
|
||||
),+ $(,)?
|
||||
}
|
||||
) => {
|
||||
$crate::__pin_project_internal! { @struct_internal;
|
||||
[$vis]
|
||||
[$(#[$attrs])* $vis struct $ident]
|
||||
[$(<
|
||||
$( $lifetime $(: $lifetime_bound)? ,)*
|
||||
$( $generics
|
||||
$(: $generics_bound)?
|
||||
$(: ?$generics_unsized_bound)?
|
||||
$(: $generics_lifetime_bound)?
|
||||
$(= $generics_default)?
|
||||
),*
|
||||
>)?]
|
||||
[$(
|
||||
$( $lifetime $(: $lifetime_bound)? ,)*
|
||||
$( $generics
|
||||
$(: $generics_bound)?
|
||||
$(: ?$generics_unsized_bound)?
|
||||
$(: $generics_lifetime_bound)?
|
||||
),*
|
||||
)?]
|
||||
[$( $( $lifetime ,)* $( $generics ),* )?]
|
||||
[$(where $( $where_clause_ty
|
||||
$(: $where_clause_bound)?
|
||||
$(: ?$where_clause_unsized_bound)?
|
||||
$(: $where_clause_lifetime_bound)?
|
||||
),* )?]
|
||||
{
|
||||
$(
|
||||
$(#[$pin])?
|
||||
$field_vis $field: $field_ty
|
||||
),+
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// Not public API.
|
||||
#[doc(hidden)]
|
||||
pub mod __private {
|
||||
#[doc(hidden)]
|
||||
pub use core::{
|
||||
marker::{PhantomData, Unpin},
|
||||
ops::Drop,
|
||||
pin::Pin,
|
||||
};
|
||||
|
||||
// This is an internal helper struct used by `pin_project!`.
|
||||
#[doc(hidden)]
|
||||
pub struct AlwaysUnpin<T: ?Sized>(PhantomData<T>);
|
||||
|
||||
impl<T: ?Sized> Unpin for AlwaysUnpin<T> {}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
#![allow(dead_code, unused_macros)]
|
||||
|
||||
macro_rules! assert_unpin {
|
||||
($ty:ty) => {
|
||||
static_assertions::assert_impl_all!($ty: Unpin);
|
||||
};
|
||||
}
|
||||
macro_rules! assert_not_unpin {
|
||||
($ty:ty) => {
|
||||
static_assertions::assert_not_impl_all!($ty: Unpin);
|
||||
};
|
||||
}
|
|
@ -1,4 +1,3 @@
|
|||
#![warn(unsafe_code)]
|
||||
#![warn(rust_2018_idioms, single_use_lifetimes)]
|
||||
|
||||
#[rustversion::attr(not(nightly), ignore)]
|
|
@ -0,0 +1,10 @@
|
|||
// default pin_project! is completely safe.
|
||||
|
||||
::pin_project_lite::pin_project! {
|
||||
#[derive(Debug)]
|
||||
pub struct DefaultStruct<T, U> {
|
||||
#[pin]
|
||||
pub pinned: T,
|
||||
pub unpinned: U,
|
||||
}
|
||||
}
|
|
@ -0,0 +1,131 @@
|
|||
#![forbid(unsafe_code)]
|
||||
#![warn(nonstandard_style, rust_2018_idioms, rustdoc, unused)]
|
||||
// Note: This does not guarantee compatibility with forbidding these lints in the future.
|
||||
// If rustc adds a new lint, we may not be able to keep this.
|
||||
#![forbid(future_incompatible, rust_2018_compatibility)]
|
||||
#![allow(unknown_lints)] // for old compilers
|
||||
#![warn(
|
||||
box_pointers,
|
||||
deprecated_in_future,
|
||||
elided_lifetimes_in_paths,
|
||||
explicit_outlives_requirements,
|
||||
macro_use_extern_crate,
|
||||
meta_variable_misuse,
|
||||
missing_copy_implementations,
|
||||
missing_crate_level_docs,
|
||||
missing_debug_implementations,
|
||||
missing_docs,
|
||||
non_ascii_idents,
|
||||
single_use_lifetimes,
|
||||
trivial_casts,
|
||||
trivial_numeric_casts,
|
||||
unaligned_references,
|
||||
unreachable_pub,
|
||||
unused_extern_crates,
|
||||
unused_import_braces,
|
||||
unused_lifetimes,
|
||||
unused_qualifications,
|
||||
unused_results,
|
||||
variant_size_differences
|
||||
)]
|
||||
// absolute_paths_not_starting_with_crate, anonymous_parameters, keyword_idents, pointer_structural_match: forbidden as a part of future_incompatible
|
||||
// missing_doc_code_examples, private_doc_tests, invalid_html_tags: warned as a part of rustdoc
|
||||
// unsafe_block_in_unsafe_fn: unstable
|
||||
// unsafe_code: forbidden
|
||||
// unstable_features: deprecated: https://doc.rust-lang.org/beta/rustc/lints/listing/allowed-by-default.html#unstable-features
|
||||
// unused_crate_dependencies: unrelated
|
||||
#![warn(clippy::all, clippy::pedantic, clippy::nursery)]
|
||||
#![warn(clippy::restriction)]
|
||||
#![allow(clippy::blanket_clippy_restriction_lints)] // this is a test, so enable all restriction lints intentionally.
|
||||
|
||||
// Check interoperability with rustc and clippy lints.
|
||||
|
||||
pub mod basic {
|
||||
include!("include/basic.rs");
|
||||
}
|
||||
|
||||
pub mod box_pointers {
|
||||
use pin_project_lite::pin_project;
|
||||
|
||||
pin_project! {
|
||||
#[derive(Debug)]
|
||||
pub struct Struct {
|
||||
#[pin]
|
||||
pub p: Box<isize>,
|
||||
pub u: Box<isize>,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub mod explicit_outlives_requirements {
|
||||
use pin_project_lite::pin_project;
|
||||
|
||||
pin_project! {
|
||||
#[derive(Debug)]
|
||||
pub struct Struct<'a, T, U>
|
||||
where
|
||||
T: ?Sized,
|
||||
U: ?Sized,
|
||||
{
|
||||
#[pin]
|
||||
pub pinned: &'a mut T,
|
||||
pub unpinned: &'a mut U,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub mod clippy_mut_mut {
|
||||
use pin_project_lite::pin_project;
|
||||
|
||||
pin_project! {
|
||||
#[derive(Debug)]
|
||||
pub struct Struct<'a, T, U> {
|
||||
#[pin]
|
||||
pub pinned: &'a mut T,
|
||||
pub unpinned: &'a mut U,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(unreachable_pub)]
|
||||
mod clippy_redundant_pub_crate {
|
||||
use pin_project_lite::pin_project;
|
||||
|
||||
pin_project! {
|
||||
#[derive(Debug)]
|
||||
pub struct Struct<T, U> {
|
||||
#[pin]
|
||||
pub pinned: T,
|
||||
pub unpinned: U,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub mod clippy_type_repetition_in_bounds {
|
||||
use pin_project_lite::pin_project;
|
||||
|
||||
pin_project! {
|
||||
#[derive(Debug)]
|
||||
pub struct Struct<T, U>
|
||||
where
|
||||
Struct<T, U>: Sized,
|
||||
{
|
||||
#[pin]
|
||||
pub pinned: T,
|
||||
pub unpinned: U,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub mod clippy_used_underscore_binding {
|
||||
use pin_project_lite::pin_project;
|
||||
|
||||
pin_project! {
|
||||
#[derive(Debug)]
|
||||
pub struct Struct<T, U> {
|
||||
#[pin]
|
||||
pub _pinned: T,
|
||||
pub _unpinned: U,
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
#![warn(rust_2018_idioms, single_use_lifetimes)]
|
||||
#![allow(dead_code)]
|
||||
|
||||
#[macro_use]
|
||||
mod auxiliary;
|
||||
|
||||
pub mod default {
|
||||
use std::marker::PhantomPinned;
|
||||
|
||||
use pin_project_lite::pin_project;
|
||||
|
||||
struct Inner<T> {
|
||||
f: T,
|
||||
}
|
||||
|
||||
assert_unpin!(Inner<()>);
|
||||
assert_not_unpin!(Inner<PhantomPinned>);
|
||||
|
||||
pin_project! {
|
||||
struct Foo<T, U> {
|
||||
#[pin]
|
||||
f1: Inner<T>,
|
||||
f2: U,
|
||||
}
|
||||
}
|
||||
|
||||
assert_unpin!(Foo<(), ()>);
|
||||
assert_unpin!(Foo<(), PhantomPinned>);
|
||||
assert_not_unpin!(Foo<PhantomPinned, ()>);
|
||||
assert_not_unpin!(Foo<PhantomPinned, PhantomPinned>);
|
||||
|
||||
pin_project! {
|
||||
struct TrivialBounds {
|
||||
#[pin]
|
||||
f: PhantomPinned,
|
||||
}
|
||||
}
|
||||
|
||||
assert_not_unpin!(TrivialBounds);
|
||||
|
||||
pin_project! {
|
||||
struct Bar<'a, T, U> {
|
||||
#[pin]
|
||||
f1: &'a mut Inner<T>,
|
||||
f2: U,
|
||||
}
|
||||
}
|
||||
|
||||
assert_unpin!(Bar<'_, PhantomPinned, PhantomPinned>);
|
||||
}
|
|
@ -1,55 +1,66 @@
|
|||
#![no_std]
|
||||
#![warn(unsafe_code)]
|
||||
#![warn(rust_2018_idioms, single_use_lifetimes)]
|
||||
#![allow(dead_code)]
|
||||
|
||||
#[macro_use]
|
||||
mod auxiliary;
|
||||
|
||||
use core::{marker::PhantomPinned, pin::Pin};
|
||||
|
||||
use pin_project_lite::pin_project;
|
||||
|
||||
#[test]
|
||||
fn test_pin_project() {
|
||||
fn projection() {
|
||||
pin_project! {
|
||||
struct Foo<T, U> {
|
||||
struct Struct<T, U> {
|
||||
#[pin]
|
||||
field1: T,
|
||||
field2: U,
|
||||
f1: T,
|
||||
f2: U,
|
||||
}
|
||||
}
|
||||
|
||||
let mut foo = Foo { field1: 1, field2: 2 };
|
||||
let mut s = Struct { f1: 1, f2: 2 };
|
||||
let mut s_orig = Pin::new(&mut s);
|
||||
let s = s_orig.as_mut().project();
|
||||
|
||||
let mut foo_orig = Pin::new(&mut foo);
|
||||
let foo = foo_orig.as_mut().project();
|
||||
|
||||
let x: Pin<&mut i32> = foo.field1;
|
||||
let x: Pin<&mut i32> = s.f1;
|
||||
assert_eq!(*x, 1);
|
||||
|
||||
let y: &mut i32 = foo.field2;
|
||||
let y: &mut i32 = s.f2;
|
||||
assert_eq!(*y, 2);
|
||||
|
||||
assert_eq!(foo_orig.as_ref().field1, 1);
|
||||
assert_eq!(foo_orig.as_ref().field2, 2);
|
||||
assert_eq!(s_orig.as_ref().f1, 1);
|
||||
assert_eq!(s_orig.as_ref().f2, 2);
|
||||
|
||||
let mut foo = Foo { field1: 1, field2: 2 };
|
||||
let mut s = Struct { f1: 1, f2: 2 };
|
||||
|
||||
let foo = Pin::new(&mut foo).project();
|
||||
let s = Pin::new(&mut s).project();
|
||||
|
||||
let field1 = foo.field1;
|
||||
let field2 = foo.field2;
|
||||
let _: Pin<&mut i32> = field1;
|
||||
let _: &mut i32 = field2;
|
||||
let _: Pin<&mut i32> = s.f1;
|
||||
let _: &mut i32 = s.f2;
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn where_clause_and_associated_type_fields() {
|
||||
fn where_clause() {
|
||||
pin_project! {
|
||||
struct Struct<T>
|
||||
where
|
||||
T: Copy,
|
||||
{
|
||||
f: T,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn where_clause_and_associated_type_field() {
|
||||
pin_project! {
|
||||
struct Struct1<I>
|
||||
where
|
||||
I: Iterator,
|
||||
{
|
||||
#[pin]
|
||||
field1: I,
|
||||
field2: I::Item,
|
||||
f1: I,
|
||||
f2: I::Item,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -59,47 +70,31 @@ fn where_clause_and_associated_type_fields() {
|
|||
I: Iterator<Item = J>,
|
||||
{
|
||||
#[pin]
|
||||
field1: I,
|
||||
field2: J,
|
||||
f1: I,
|
||||
f2: J,
|
||||
}
|
||||
}
|
||||
|
||||
// TODO(#7): where clause does not support yet.
|
||||
pin_project! {
|
||||
pub struct Struct3<T>
|
||||
where
|
||||
T: 'static,
|
||||
{
|
||||
f: T,
|
||||
}
|
||||
}
|
||||
|
||||
// pin_project! {
|
||||
// pub struct Struct3<T>
|
||||
// where
|
||||
// T: 'static,
|
||||
// {
|
||||
// field: T,
|
||||
// }
|
||||
// }
|
||||
trait Static: 'static {}
|
||||
|
||||
// trait Static: 'static {}
|
||||
|
||||
// impl<T> Static for Struct3<T> {}
|
||||
impl<T> Static for Struct3<T> {}
|
||||
}
|
||||
|
||||
// #[allow(explicit_outlives_requirements)] // https://github.com/rust-lang/rust/issues/60993
|
||||
// #[test]
|
||||
// fn unsized_in_where_clause() {
|
||||
// pin_project! {
|
||||
// struct Struct<I>
|
||||
// where
|
||||
// I: ?Sized,
|
||||
// {
|
||||
// #[pin]
|
||||
// field: I,
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
#[test]
|
||||
fn derive_copy() {
|
||||
pin_project! {
|
||||
#[derive(Clone, Copy)]
|
||||
struct Struct<T> {
|
||||
val: T,
|
||||
f: T,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -114,57 +109,57 @@ fn move_out() {
|
|||
|
||||
pin_project! {
|
||||
struct Struct {
|
||||
val: NotCopy,
|
||||
f: NotCopy,
|
||||
}
|
||||
}
|
||||
|
||||
let foo = Struct { val: NotCopy };
|
||||
let _val: NotCopy = foo.val;
|
||||
let x = Struct { f: NotCopy };
|
||||
let _val: NotCopy = x.f;
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn trait_bounds_on_type_generics() {
|
||||
pin_project! {
|
||||
pub struct Struct1<'a, T: ?Sized> {
|
||||
field: &'a mut T,
|
||||
f: &'a mut T,
|
||||
}
|
||||
}
|
||||
|
||||
pin_project! {
|
||||
pub struct Struct2<'a, T: ::core::fmt::Debug> {
|
||||
field: &'a mut T,
|
||||
f: &'a mut T,
|
||||
}
|
||||
}
|
||||
|
||||
pin_project! {
|
||||
pub struct Struct3<'a, T: core::fmt::Debug> {
|
||||
field: &'a mut T,
|
||||
f: &'a mut T,
|
||||
}
|
||||
}
|
||||
|
||||
// pin_project! {
|
||||
// pub struct Struct4<'a, T: core::fmt::Debug + core::fmt::Display> {
|
||||
// field: &'a mut T,
|
||||
// f: &'a mut T,
|
||||
// }
|
||||
// }
|
||||
|
||||
// pin_project! {
|
||||
// pub struct Struct5<'a, T: core::fmt::Debug + ?Sized> {
|
||||
// field: &'a mut T,
|
||||
// f: &'a mut T,
|
||||
// }
|
||||
// }
|
||||
|
||||
pin_project! {
|
||||
pub struct Struct6<'a, T: core::fmt::Debug = [u8; 16]> {
|
||||
field: &'a mut T,
|
||||
f: &'a mut T,
|
||||
}
|
||||
}
|
||||
|
||||
let _: Struct6<'_> = Struct6 { field: &mut [0u8; 16] };
|
||||
let _: Struct6<'_> = Struct6 { f: &mut [0u8; 16] };
|
||||
|
||||
pin_project! {
|
||||
pub struct Struct7<T: 'static> {
|
||||
field: T,
|
||||
f: T,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -174,8 +169,8 @@ fn trait_bounds_on_type_generics() {
|
|||
|
||||
pin_project! {
|
||||
pub struct Struct8<'a, 'b: 'a> {
|
||||
field1: &'a u8,
|
||||
field2: &'b u8,
|
||||
f1: &'a u8,
|
||||
f2: &'b u8,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -192,6 +187,7 @@ fn private_type_in_public_type() {
|
|||
struct PrivateStruct<T>(T);
|
||||
}
|
||||
|
||||
#[allow(clippy::needless_lifetimes)]
|
||||
#[test]
|
||||
fn lifetime_project() {
|
||||
pin_project! {
|
||||
|
@ -217,6 +213,12 @@ fn lifetime_project() {
|
|||
fn get_pin_mut<'a>(self: Pin<&'a mut Self>) -> Pin<&'a mut T> {
|
||||
self.project().pinned
|
||||
}
|
||||
fn get_pin_ref_elided(self: Pin<&Self>) -> Pin<&T> {
|
||||
self.project_ref().pinned
|
||||
}
|
||||
fn get_pin_mut_elided(self: Pin<&mut Self>) -> Pin<&mut T> {
|
||||
self.project().pinned
|
||||
}
|
||||
}
|
||||
|
||||
impl<'b, T, U> Struct2<'b, T, U> {
|
||||
|
@ -226,41 +228,10 @@ fn lifetime_project() {
|
|||
fn get_pin_mut<'a>(self: Pin<&'a mut Self>) -> Pin<&'a mut &'b mut T> {
|
||||
self.project().pinned
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn lifetime_project_elided() {
|
||||
pin_project! {
|
||||
struct Struct1<T, U> {
|
||||
#[pin]
|
||||
pinned: T,
|
||||
unpinned: U,
|
||||
}
|
||||
}
|
||||
|
||||
pin_project! {
|
||||
struct Struct2<'a, T, U> {
|
||||
#[pin]
|
||||
pinned: &'a mut T,
|
||||
unpinned: U,
|
||||
}
|
||||
}
|
||||
|
||||
impl<T, U> Struct1<T, U> {
|
||||
fn get_pin_ref(self: Pin<&Self>) -> Pin<&T> {
|
||||
fn get_pin_ref_elided(self: Pin<&Self>) -> Pin<&&'b mut 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> {
|
||||
fn get_pin_mut_elided(self: Pin<&mut Self>) -> Pin<&mut &'b mut T> {
|
||||
self.project().pinned
|
||||
}
|
||||
}
|
||||
|
@ -270,20 +241,20 @@ mod visibility {
|
|||
use pin_project_lite::pin_project;
|
||||
|
||||
pin_project! {
|
||||
pub(crate) struct A {
|
||||
pub b: u8,
|
||||
pub(crate) struct S {
|
||||
pub f: u8,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn visibility() {
|
||||
let mut x = visibility::A { b: 0 };
|
||||
let mut x = visibility::S { f: 0 };
|
||||
let x = Pin::new(&mut x);
|
||||
let y = x.as_ref().project_ref();
|
||||
let _: &u8 = y.b;
|
||||
let _: &u8 = y.f;
|
||||
let y = x.project();
|
||||
let _: &mut u8 = y.b;
|
||||
let _: &mut u8 = y.f;
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -291,25 +262,59 @@ fn trivial_bounds() {
|
|||
pin_project! {
|
||||
pub struct NoGenerics {
|
||||
#[pin]
|
||||
field: PhantomPinned,
|
||||
f: PhantomPinned,
|
||||
}
|
||||
}
|
||||
|
||||
assert_not_unpin!(NoGenerics);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn dst() {
|
||||
pin_project! {
|
||||
pub struct A<T: ?Sized> {
|
||||
x: T,
|
||||
pub struct Struct1<T: ?Sized> {
|
||||
f: T,
|
||||
}
|
||||
}
|
||||
|
||||
let _: &mut A<dyn core::fmt::Debug> = &mut A { x: 0u8 } as _;
|
||||
let mut x = Struct1 { f: 0_u8 };
|
||||
let x: Pin<&mut Struct1<dyn core::fmt::Debug>> = Pin::new(&mut x as _);
|
||||
let _y: &mut (dyn core::fmt::Debug) = x.project().f;
|
||||
|
||||
pin_project! {
|
||||
pub struct B<T: ?Sized> {
|
||||
pub struct Struct2<T: ?Sized> {
|
||||
#[pin]
|
||||
x: T,
|
||||
f: T,
|
||||
}
|
||||
}
|
||||
|
||||
let mut x = Struct2 { f: 0_u8 };
|
||||
let x: Pin<&mut Struct2<dyn core::fmt::Debug + Unpin>> = Pin::new(&mut x as _);
|
||||
let _y: Pin<&mut (dyn core::fmt::Debug + Unpin)> = x.project().f;
|
||||
|
||||
pin_project! {
|
||||
struct Struct3<T>
|
||||
where
|
||||
T: ?Sized,
|
||||
{
|
||||
f: T,
|
||||
}
|
||||
}
|
||||
|
||||
pin_project! {
|
||||
struct Struct4<T>
|
||||
where
|
||||
T: ?Sized,
|
||||
{
|
||||
#[pin]
|
||||
f: T,
|
||||
}
|
||||
}
|
||||
|
||||
pin_project! {
|
||||
struct Struct11<'a, T: ?Sized, U: ?Sized> {
|
||||
f1: &'a mut T,
|
||||
f2: U,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -318,14 +323,12 @@ fn dst() {
|
|||
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,
|
||||
}
|
||||
|
@ -333,16 +336,81 @@ fn dyn_type() {
|
|||
|
||||
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 no_infer_outlives() {
|
||||
trait Trait<X> {
|
||||
type Y;
|
||||
}
|
||||
|
||||
struct Struct1<A>(A);
|
||||
|
||||
impl<X, T> Trait<X> for Struct1<T> {
|
||||
type Y = Option<T>;
|
||||
}
|
||||
|
||||
pin_project! {
|
||||
struct Struct2<A, B> {
|
||||
_f: <Struct1<A> as Trait<B>>::Y,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// https://github.com/taiki-e/pin-project-lite/issues/31
|
||||
#[test]
|
||||
fn trailing_comma() {
|
||||
pub trait T {}
|
||||
|
||||
pin_project! {
|
||||
pub struct S1<
|
||||
A: T,
|
||||
B: T,
|
||||
> {
|
||||
f: (A, B),
|
||||
}
|
||||
}
|
||||
|
||||
pin_project! {
|
||||
pub struct S2<
|
||||
A,
|
||||
B,
|
||||
>
|
||||
where
|
||||
A: T,
|
||||
B: T,
|
||||
{
|
||||
f: (A, B),
|
||||
}
|
||||
}
|
||||
|
||||
pin_project! {
|
||||
#[allow(explicit_outlives_requirements)]
|
||||
pub struct S3<
|
||||
'a,
|
||||
A: 'a,
|
||||
B: 'a,
|
||||
> {
|
||||
f: &'a (A, B),
|
||||
}
|
||||
}
|
||||
|
||||
// pin_project! {
|
||||
// pub struct S4<
|
||||
// 'a,
|
||||
// 'b: 'a, // <-----
|
||||
// > {
|
||||
// f: &'a &'b (),
|
||||
// }
|
||||
// }
|
||||
}
|
134
third_party/rust/pin-project-lite-0.1.12/tests/ui/invalid-bounds.stderr
поставляемый
Normal file
134
third_party/rust/pin-project-lite-0.1.12/tests/ui/invalid-bounds.stderr
поставляемый
Normal file
|
@ -0,0 +1,134 @@
|
|||
error: no rules expected the token `:`
|
||||
--> $DIR/invalid-bounds.rs:4:33
|
||||
|
|
||||
4 | struct Generics1<T: 'static : Sized> { //~ ERROR no rules expected the token `:`
|
||||
| ^ no rules expected this token in macro call
|
||||
|
||||
error: no rules expected the token `:`
|
||||
--> $DIR/invalid-bounds.rs:10:33
|
||||
|
|
||||
10 | struct Generics2<T: 'static : ?Sized> { //~ ERROR no rules expected the token `:`
|
||||
| ^ no rules expected this token in macro call
|
||||
|
||||
error: expected one of `+`, `,`, `=`, or `>`, found `:`
|
||||
--> $DIR/invalid-bounds.rs:15:1
|
||||
|
|
||||
15 | / pin_project! {
|
||||
16 | | struct Generics3<T: Sized : 'static> { //~ ERROR expected one of `+`, `,`, `=`, or `>`, found `:`
|
||||
17 | | field: T,
|
||||
18 | | }
|
||||
19 | | }
|
||||
| | ^
|
||||
| | |
|
||||
| | expected one of `+`, `,`, `=`, or `>`
|
||||
| |_unexpected token
|
||||
| in this macro invocation
|
||||
|
|
||||
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
error: expected one of `+`, `,`, `=`, or `>`, found `:`
|
||||
--> $DIR/invalid-bounds.rs:21:1
|
||||
|
|
||||
21 | / pin_project! {
|
||||
22 | | struct Generics4<T: ?Sized : 'static> { //~ ERROR expected one of `+`, `,`, `=`, or `>`, found `:`
|
||||
23 | | field: T,
|
||||
24 | | }
|
||||
25 | | }
|
||||
| | ^
|
||||
| | |
|
||||
| | expected one of `+`, `,`, `=`, or `>`
|
||||
| |_unexpected token
|
||||
| in this macro invocation
|
||||
|
|
||||
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
error: expected one of `+`, `,`, `=`, or `>`, found `:`
|
||||
--> $DIR/invalid-bounds.rs:27:1
|
||||
|
|
||||
27 | / pin_project! {
|
||||
28 | | struct Generics5<T: Sized : ?Sized> { //~ ERROR expected one of `+`, `,`, `=`, or `>`, found `:`
|
||||
29 | | field: T,
|
||||
30 | | }
|
||||
31 | | }
|
||||
| | ^
|
||||
| | |
|
||||
| | expected one of `+`, `,`, `=`, or `>`
|
||||
| |_unexpected token
|
||||
| in this macro invocation
|
||||
|
|
||||
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
error: no rules expected the token `Sized`
|
||||
--> $DIR/invalid-bounds.rs:34:34
|
||||
|
|
||||
34 | struct Generics6<T: ?Sized : Sized> { //~ ERROR no rules expected the token `Sized`
|
||||
| ^^^^^ no rules expected this token in macro call
|
||||
|
||||
error: no rules expected the token `:`
|
||||
--> $DIR/invalid-bounds.rs:42:20
|
||||
|
|
||||
42 | T: 'static : Sized //~ ERROR no rules expected the token `:`
|
||||
| ^ no rules expected this token in macro call
|
||||
|
||||
error: no rules expected the token `:`
|
||||
--> $DIR/invalid-bounds.rs:51:20
|
||||
|
|
||||
51 | T: 'static : ?Sized //~ ERROR no rules expected the token `:`
|
||||
| ^ no rules expected this token in macro call
|
||||
|
||||
error: expected `where`, or `{` after struct name, found `:`
|
||||
--> $DIR/invalid-bounds.rs:57:1
|
||||
|
|
||||
57 | / pin_project! {
|
||||
58 | | struct WhereClause3<T>
|
||||
59 | | where
|
||||
60 | | T: Sized : 'static //~ ERROR expected `where`, or `{` after struct name, found `:`
|
||||
... |
|
||||
63 | | }
|
||||
64 | | }
|
||||
| | ^
|
||||
| | |
|
||||
| |_expected `where`, or `{` after struct name
|
||||
| in this macro invocation
|
||||
|
|
||||
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
error: expected `where`, or `{` after struct name, found `:`
|
||||
--> $DIR/invalid-bounds.rs:66:1
|
||||
|
|
||||
66 | / pin_project! {
|
||||
67 | | struct WhereClause4<T>
|
||||
68 | | where
|
||||
69 | | T: ?Sized : 'static //~ ERROR expected `where`, or `{` after struct name, found `:`
|
||||
... |
|
||||
72 | | }
|
||||
73 | | }
|
||||
| | ^
|
||||
| | |
|
||||
| |_expected `where`, or `{` after struct name
|
||||
| in this macro invocation
|
||||
|
|
||||
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
error: expected `where`, or `{` after struct name, found `:`
|
||||
--> $DIR/invalid-bounds.rs:75:1
|
||||
|
|
||||
75 | / pin_project! {
|
||||
76 | | struct WhereClause5<T>
|
||||
77 | | where
|
||||
78 | | T: Sized : ?Sized //~ ERROR expected `where`, or `{` after struct name, found `:`
|
||||
... |
|
||||
81 | | }
|
||||
82 | | }
|
||||
| | ^
|
||||
| | |
|
||||
| |_expected `where`, or `{` after struct name
|
||||
| in this macro invocation
|
||||
|
|
||||
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
error: no rules expected the token `Sized`
|
||||
--> $DIR/invalid-bounds.rs:87:21
|
||||
|
|
||||
87 | T: ?Sized : Sized //~ ERROR no rules expected the token `Sized`
|
||||
| ^^^^^ no rules expected this token in macro call
|
|
@ -0,0 +1,19 @@
|
|||
use pin_project_lite::pin_project;
|
||||
|
||||
pin_project! { //~ ERROR reference to packed field is unaligned
|
||||
#[repr(packed, C)]
|
||||
struct Packed {
|
||||
#[pin]
|
||||
field: u16,
|
||||
}
|
||||
}
|
||||
|
||||
pin_project! { //~ ERROR reference to packed field is unaligned
|
||||
#[repr(packed(2))]
|
||||
struct PackedN {
|
||||
#[pin]
|
||||
field: u32,
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
|
@ -0,0 +1,107 @@
|
|||
error: reference to packed field is unaligned
|
||||
--> $DIR/packed.rs:3:1
|
||||
|
|
||||
3 | / pin_project! { //~ ERROR reference to packed field is unaligned
|
||||
4 | | #[repr(packed, C)]
|
||||
5 | | struct Packed {
|
||||
6 | | #[pin]
|
||||
7 | | field: u16,
|
||||
8 | | }
|
||||
9 | | }
|
||||
| |_^
|
||||
|
|
||||
note: the lint level is defined here
|
||||
--> $DIR/packed.rs:3:1
|
||||
|
|
||||
3 | / pin_project! { //~ ERROR reference to packed field is unaligned
|
||||
4 | | #[repr(packed, C)]
|
||||
5 | | struct Packed {
|
||||
6 | | #[pin]
|
||||
7 | | field: u16,
|
||||
8 | | }
|
||||
9 | | }
|
||||
| |_^
|
||||
= note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)
|
||||
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
error: reference to packed field is unaligned
|
||||
--> $DIR/packed.rs:11:1
|
||||
|
|
||||
11 | / pin_project! { //~ ERROR reference to packed field is unaligned
|
||||
12 | | #[repr(packed(2))]
|
||||
13 | | struct PackedN {
|
||||
14 | | #[pin]
|
||||
15 | | field: u32,
|
||||
16 | | }
|
||||
17 | | }
|
||||
| |_^
|
||||
|
|
||||
note: the lint level is defined here
|
||||
--> $DIR/packed.rs:11:1
|
||||
|
|
||||
11 | / pin_project! { //~ ERROR reference to packed field is unaligned
|
||||
12 | | #[repr(packed(2))]
|
||||
13 | | struct PackedN {
|
||||
14 | | #[pin]
|
||||
15 | | field: u32,
|
||||
16 | | }
|
||||
17 | | }
|
||||
| |_^
|
||||
= note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)
|
||||
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
error: borrow of packed field is unsafe and requires unsafe function or block (error E0133)
|
||||
--> $DIR/packed.rs:3:1
|
||||
|
|
||||
3 | / pin_project! { //~ ERROR reference to packed field is unaligned
|
||||
4 | | #[repr(packed, C)]
|
||||
5 | | struct Packed {
|
||||
6 | | #[pin]
|
||||
7 | | field: u16,
|
||||
8 | | }
|
||||
9 | | }
|
||||
| |_^
|
||||
|
|
||||
note: the lint level is defined here
|
||||
--> $DIR/packed.rs:3:1
|
||||
|
|
||||
3 | / pin_project! { //~ ERROR reference to packed field is unaligned
|
||||
4 | | #[repr(packed, C)]
|
||||
5 | | struct Packed {
|
||||
6 | | #[pin]
|
||||
7 | | field: u16,
|
||||
8 | | }
|
||||
9 | | }
|
||||
| |_^
|
||||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
= note: for more information, see issue #46043 <https://github.com/rust-lang/rust/issues/46043>
|
||||
= note: fields of packed structs might be misaligned: dereferencing a misaligned pointer or even just creating a misaligned reference is undefined behavior
|
||||
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
error: borrow of packed field is unsafe and requires unsafe function or block (error E0133)
|
||||
--> $DIR/packed.rs:11:1
|
||||
|
|
||||
11 | / pin_project! { //~ ERROR reference to packed field is unaligned
|
||||
12 | | #[repr(packed(2))]
|
||||
13 | | struct PackedN {
|
||||
14 | | #[pin]
|
||||
15 | | field: u32,
|
||||
16 | | }
|
||||
17 | | }
|
||||
| |_^
|
||||
|
|
||||
note: the lint level is defined here
|
||||
--> $DIR/packed.rs:11:1
|
||||
|
|
||||
11 | / pin_project! { //~ ERROR reference to packed field is unaligned
|
||||
12 | | #[repr(packed(2))]
|
||||
13 | | struct PackedN {
|
||||
14 | | #[pin]
|
||||
15 | | field: u32,
|
||||
16 | | }
|
||||
17 | | }
|
||||
| |_^
|
||||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
= note: for more information, see issue #46043 <https://github.com/rust-lang/rust/issues/46043>
|
||||
= note: fields of packed structs might be misaligned: dereferencing a misaligned pointer or even just creating a misaligned reference is undefined behavior
|
||||
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
|
|
@ -1 +0,0 @@
|
|||
{"files":{"CHANGELOG.md":"f3f611059446979ec88ad60bbc10c88b03344a78fe7352d1c96d8c90677ba81c","Cargo.toml":"8d385982debe367eb5fccfe3aca22147742db78b66b7dd67c43c33dc943c921d","LICENSE-APACHE":"cfc7749b96f63bd31c3c42b5c471bf756814053e847c10f3eb003417bc523d30","LICENSE-MIT":"23f18e03dc49df91622fe2a76176497404e46ced8a715d9d2b67a7446571cca3","README.md":"c9dca7888b355c14d2506e7a2f5646f000e56c23312354767b3adb1efb10c7f3","ci/install-component.sh":"2d7d6276f1b2c90601bdad6c98213a26f65e332fd2433fd6649051d8145b01ef","ci/install-rust.sh":"1169f71b716fc1980ca2fcc0b3735b601519ac6d6808481bdd704714e13db9aa","src/lib.rs":"88d2496e42b17ee985f96b17ffee501e4ac3974031719d2836b48906563208b0","tests/compiletest.rs":"cd1e9f4bcecec60e95b2d5853162dbf60d20cea1e58c774142ce5731912ef47b","tests/test.rs":"880aea52c8c3ea1ebf9cb87a737cbc389d54cf99ba44a98262bc89644c8d7d90","tests/ui/conflict-drop.rs":"55e6809b5f59dd81e32c2c89b742c0c76db6b099a1d2621e5b882c0d20f92837","tests/ui/conflict-drop.stderr":"c6d2d419ec2eb06e1a2eb9b4541278415517acb55ad054cb4ced38a049eadcaf","tests/ui/conflict-unpin.rs":"51b3b6720fa581b63167d6ac941a1ea1bf739b09954931b2bc2f7abe2d934f26","tests/ui/conflict-unpin.stderr":"3966c1b4cefddf2892b967be69cddd4c56064c22ee80f275d51217ae0fee24e3","tests/ui/invalid-bounds.rs":"cfaa9530a84033a680ac21dbcccb7887e49c665fe9fa9a2d403d9f76a838bc58","tests/ui/invalid-bounds.stderr":"a6c2087dd408f0ff5790536dd162b9c849dc3b25b80438341e7974e2ff9760e6","tests/ui/invalid.rs":"7304bd4a5bac1419382742432cfa8af83535d7be8cfad52c661410e0e9e8207a","tests/ui/invalid.stderr":"cb935ec370a87ba511aeef64613e7351b2eac9e574b5a256c7cb3c30f4bd74a6","tests/ui/overlapping_lifetime_names.rs":"a64c42cc56fa4751d73a1db80a7deb568427dc96f30c1a29665067d8c0ecb2c9","tests/ui/overlapping_lifetime_names.stderr":"d0e4f80c1b9c262fd1937c092c6f046bad84b704000fe1bc2cb3790229e5df00","tests/ui/overlapping_unpin_struct.rs":"5fde23ef628d2dbd27377ffa472fc19b1c6873122f38c3fb1f84fda8602f55f3","tests/ui/overlapping_unpin_struct.stderr":"2a7590446a6efa299d4cf9b5e02699118c252658537d458bf1bfcc0837065611","tests/ui/packed.rs":"12b14e183c809b267f0feff0b6c8bf8d664315e6959d236bd7a0887fc226b9bf","tests/ui/packed.stderr":"b9cf7c2e9874ca27d3de03a87624cabebc0fe3772e1b5af0d795f018cf489f46","tests/ui/proper_unpin.rs":"274e59d488d2a1640b7aed707b80623800df19ed7277f28e8f2c463185a3b7a2","tests/ui/proper_unpin.stderr":"6ee5760ff8f19cc47f721ec9f63236f41dc84ae95f34d84b7fe0c13302a91431","tests/ui/unpin_sneaky.rs":"12e97a387ce1af6ee6a567687674aab70e96962a48f2433c39976d0b3e2c3341","tests/ui/unpin_sneaky.stderr":"9cec3997d07771c9cc1b4f6cb5da2e932945a7dda7146d7f44624d110d44fcf6","tests/ui/unsupported.rs":"14defa90e736f314bbbc219973929b77bdd22e5f7e4c4c88403db764f4d167d6","tests/ui/unsupported.stderr":"310a8a7ed4e8120fa570957800e6cc86ff5561580a241ab808092e99a1f3b8b2"},"package":"237844750cfbb86f67afe27eee600dfbbcb6188d734139b534cbfbf4f96792ae"}
|
|
@ -1,42 +0,0 @@
|
|||
# Changelog
|
||||
|
||||
All notable changes to this project will be documented in this file.
|
||||
|
||||
This project adheres to [Semantic Versioning](https://semver.org).
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
## [0.1.4] - 2020-01-20
|
||||
|
||||
* [Support ?Sized bounds in generic parameters.][9]
|
||||
|
||||
[9]: https://github.com/taiki-e/pin-project-lite/pull/9
|
||||
|
||||
## [0.1.3] - 2020-01-20
|
||||
|
||||
* [Support lifetime bounds in generic parameters.][7]
|
||||
|
||||
[7]: https://github.com/taiki-e/pin-project-lite/pull/7
|
||||
|
||||
## [0.1.2] - 2020-01-05
|
||||
|
||||
* [Support recognizing default generic parameters.][6]
|
||||
|
||||
[6]: https://github.com/taiki-e/pin-project-lite/pull/6
|
||||
|
||||
## [0.1.1] - 2019-11-15
|
||||
|
||||
* [`pin_project!` macro now determines the visibility of the projection type/method is based on the original type.][5]
|
||||
|
||||
[5]: https://github.com/taiki-e/pin-project-lite/pull/5
|
||||
|
||||
## [0.1.0] - 2019-10-22
|
||||
|
||||
Initial release
|
||||
|
||||
[Unreleased]: https://github.com/taiki-e/pin-project-lite/compare/v0.1.4...HEAD
|
||||
[0.1.4]: https://github.com/taiki-e/pin-project-lite/compare/v0.1.3...v0.1.4
|
||||
[0.1.3]: https://github.com/taiki-e/pin-project-lite/compare/v0.1.2...v0.1.3
|
||||
[0.1.2]: https://github.com/taiki-e/pin-project-lite/compare/v0.1.1...v0.1.2
|
||||
[0.1.1]: https://github.com/taiki-e/pin-project-lite/compare/v0.1.0...v0.1.1
|
||||
[0.1.0]: https://github.com/taiki-e/pin-project-lite/releases/tag/v0.1.0
|
|
@ -1,29 +0,0 @@
|
|||
#!/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
|
|
@ -1,20 +0,0 @@
|
|||
#!/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
|
|
@ -1,466 +0,0 @@
|
|||
//! A lightweight version of [pin-project] written with declarative macros.
|
||||
//!
|
||||
//! ## Examples
|
||||
//!
|
||||
//! ```rust
|
||||
//! use pin_project_lite::pin_project;
|
||||
//! use std::pin::Pin;
|
||||
//!
|
||||
//! pin_project! {
|
||||
//! struct Struct<T, U> {
|
||||
//! #[pin]
|
||||
//! pinned: T,
|
||||
//! unpinned: U,
|
||||
//! }
|
||||
//! }
|
||||
//!
|
||||
//! impl<T, U> Struct<T, U> {
|
||||
//! fn 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
|
||||
//! }
|
||||
//! }
|
||||
//! ```
|
||||
//!
|
||||
//! ## [pin-project] vs pin-project-lite
|
||||
//!
|
||||
//! Here are some similarities and differences compared to [pin-project].
|
||||
//!
|
||||
//! ### Similar: Safety
|
||||
//!
|
||||
//! pin-project-lite guarantees safety in much the same way as [pin-project]. Both are completely safe unless you write other unsafe code.
|
||||
//!
|
||||
//! ### Different: Minimal design
|
||||
//!
|
||||
//! This library does not tackle as expansive of a range of use cases as [pin-project] does. If your use case is not already covered, please use [pin-project].
|
||||
//!
|
||||
//! ### Different: No proc-macro related dependencies
|
||||
//!
|
||||
//! This is the **only** reason to use this crate. However, **if you already have proc-macro related dependencies in your crate's dependency graph, there is no benefit from using this crate.** (Note: There is almost no difference in the amount of code generated between [pin-project] and pin-project-lite.)
|
||||
//!
|
||||
//! ### Different: No useful error messages
|
||||
//!
|
||||
//! This macro does not handle any invalid input. So error messages are not to be useful in most cases. If you do need useful error messages, then upon error you can pass the same input to [pin-project] to receive a helpful description of the compile error.
|
||||
//!
|
||||
//! ### Different: Structs only
|
||||
//!
|
||||
//! pin-project-lite will refuse anything other than a braced struct with named fields. Enums and tuple structs are not supported.
|
||||
//!
|
||||
//! ### Different: No support for custom Drop implementation
|
||||
//!
|
||||
//! [pin-project supports this.][pinned-drop]
|
||||
//!
|
||||
//! ### Different: No support for custom Unpin implementation
|
||||
//!
|
||||
//! [pin-project supports this.][unsafe-unpin]
|
||||
//!
|
||||
//! ### Different: No support for pattern matching and destructing
|
||||
//!
|
||||
//! [pin-project supports this.][projection-helper]
|
||||
//!
|
||||
//! [pin-project]: https://github.com/taiki-e/pin-project
|
||||
//! [pinned-drop]: https://docs.rs/pin-project/0.4/pin_project/attr.pin_project.html#pinned_drop
|
||||
//! [unsafe-unpin]: https://docs.rs/pin-project/0.4/pin_project/trait.UnsafeUnpin.html
|
||||
//! [projection-helper]: https://docs.rs/pin-project/0.4/pin_project/attr.project.html#let-bindings
|
||||
|
||||
#![no_std]
|
||||
#![recursion_limit = "256"]
|
||||
#![doc(html_root_url = "https://docs.rs/pin-project-lite/0.1.4")]
|
||||
#![doc(test(
|
||||
no_crate_inject,
|
||||
attr(deny(warnings, rust_2018_idioms, single_use_lifetimes), allow(dead_code))
|
||||
))]
|
||||
#![warn(unsafe_code)]
|
||||
#![warn(rust_2018_idioms, single_use_lifetimes, unreachable_pub)]
|
||||
#![warn(clippy::all)]
|
||||
// mem::take requires Rust 1.40
|
||||
#![allow(clippy::mem_replace_with_default)]
|
||||
|
||||
/// A macro that creates a projection struct covering all the fields.
|
||||
///
|
||||
/// This macro creates a projection struct according to the following rules:
|
||||
///
|
||||
/// - For the field that uses `#[pin]` attribute, makes the pinned reference to
|
||||
/// the field.
|
||||
/// - For the other fields, makes the unpinned reference to the field.
|
||||
///
|
||||
/// The following methods are implemented on the original type:
|
||||
///
|
||||
/// ```
|
||||
/// # use std::pin::Pin;
|
||||
/// # type Projection<'a> = &'a ();
|
||||
/// # type ProjectionRef<'a> = &'a ();
|
||||
/// # trait Dox {
|
||||
/// fn project(self: Pin<&mut Self>) -> Projection<'_>;
|
||||
/// fn project_ref(self: Pin<&Self>) -> ProjectionRef<'_>;
|
||||
/// # }
|
||||
/// ```
|
||||
///
|
||||
/// The visibility of the projected type and projection method is based on the
|
||||
/// original type. However, if the visibility of the original type is `pub`,
|
||||
/// the visibility of the projected type and the projection method is `pub(crate)`.
|
||||
///
|
||||
/// If you want to call the `project` method multiple times or later use the
|
||||
/// original Pin type, it needs to use [`.as_mut()`][`Pin::as_mut`] to avoid
|
||||
/// consuming the `Pin`.
|
||||
///
|
||||
/// ## Safety
|
||||
///
|
||||
/// `pin_project!` macro guarantees safety in much the same way as [pin-project] crate.
|
||||
/// Both are completely safe unless you write other unsafe code.
|
||||
///
|
||||
/// See [pin-project] crate for more details.
|
||||
///
|
||||
/// ## Examples
|
||||
///
|
||||
/// ```rust
|
||||
/// use pin_project_lite::pin_project;
|
||||
/// use std::pin::Pin;
|
||||
///
|
||||
/// pin_project! {
|
||||
/// struct Struct<T, U> {
|
||||
/// #[pin]
|
||||
/// pinned: T,
|
||||
/// unpinned: U,
|
||||
/// }
|
||||
/// }
|
||||
///
|
||||
/// impl<T, U> Struct<T, U> {
|
||||
/// fn 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
|
||||
/// }
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
/// Note that borrowing the field where `#[pin]` attribute is used multiple
|
||||
/// times requires using [`.as_mut()`][`Pin::as_mut`] to avoid
|
||||
/// consuming the `Pin`.
|
||||
///
|
||||
/// [pin-project]: https://github.com/taiki-e/pin-project
|
||||
/// [`Pin::as_mut`]: core::pin::Pin::as_mut
|
||||
#[macro_export]
|
||||
macro_rules! pin_project {
|
||||
// determine_visibility
|
||||
(
|
||||
$(#[$attrs:meta])*
|
||||
pub struct $ident:ident
|
||||
$(<
|
||||
$( $lifetime:lifetime $(: $lifetime_bound:lifetime)? ),* $(,)?
|
||||
$( $generics:ident $(: $generics_bound:path)? $(: ?$generics_unsized_bound:path)? $(: $generics_lifetime_bound:lifetime)? $(= $generics_default:ty)? ),* $(,)?
|
||||
>)?
|
||||
$(where
|
||||
$($where_clause_ty:ty : $where_clause_bound:path),* $(,)?
|
||||
)?
|
||||
{
|
||||
$(
|
||||
$(#[$pin:ident])?
|
||||
$field_vis:vis $field:ident: $field_ty:ty
|
||||
),+ $(,)?
|
||||
}
|
||||
) => {
|
||||
$crate::pin_project! {@internal (pub(crate))
|
||||
$(#[$attrs])*
|
||||
pub struct $ident
|
||||
$(<
|
||||
$( $lifetime $(: $lifetime_bound)? ),*
|
||||
$( $generics $(: $generics_bound)? $(: ?$generics_unsized_bound)? $(: $generics_lifetime_bound)? $(= $generics_default)? ),*
|
||||
>)?
|
||||
$(where
|
||||
$($where_clause_ty : $where_clause_bound),*
|
||||
)?
|
||||
{
|
||||
$(
|
||||
$(#[$pin])?
|
||||
$field_vis $field: $field_ty
|
||||
),+
|
||||
}
|
||||
}
|
||||
};
|
||||
(
|
||||
$(#[$attrs:meta])*
|
||||
$vis:vis struct $ident:ident
|
||||
$(<
|
||||
$( $lifetime:lifetime $(: $lifetime_bound:lifetime)? ),* $(,)?
|
||||
$( $generics:ident $(: $generics_bound:path)? $(: ?$generics_unsized_bound:path)? $(: $generics_lifetime_bound:lifetime)? $(= $generics_default:ty)? ),* $(,)?
|
||||
>)?
|
||||
$(where
|
||||
$($where_clause_ty:ty : $where_clause_bound:path),* $(,)?
|
||||
)?
|
||||
{
|
||||
$(
|
||||
$(#[$pin:ident])?
|
||||
$field_vis:vis $field:ident: $field_ty:ty
|
||||
),+ $(,)?
|
||||
}
|
||||
) => {
|
||||
$crate::pin_project! {@internal ($vis)
|
||||
$(#[$attrs])*
|
||||
$vis struct $ident
|
||||
$(<
|
||||
$( $lifetime $(: $lifetime_bound)? ),*
|
||||
$( $generics $(: $generics_bound)? $(: ?$generics_unsized_bound)? $(: $generics_lifetime_bound)? $(= $generics_default)? ),*
|
||||
>)?
|
||||
$(where
|
||||
$($where_clause_ty : $where_clause_bound),*
|
||||
)?
|
||||
{
|
||||
$(
|
||||
$(#[$pin])?
|
||||
$field_vis $field: $field_ty
|
||||
),+
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
(@internal ($proj_vis:vis)
|
||||
// limitation: does not support tuple structs and enums (wontfix)
|
||||
// limitation: no projection helper (wontfix)
|
||||
$(#[$attrs:meta])*
|
||||
$vis:vis struct $ident:ident
|
||||
$(<
|
||||
$( $lifetime:lifetime $(: $lifetime_bound:lifetime)? ),*
|
||||
// limitation: does not support multiple trait/lifetime bounds and ? trait bounds.
|
||||
$( $generics:ident $(: $generics_bound:path)? $(: ?$generics_unsized_bound:path)? $(: $generics_lifetime_bound:lifetime)? $(= $generics_default:ty)? ),*
|
||||
>)?
|
||||
$(where
|
||||
// limitation: does not support multiple trait/lifetime bounds and ? trait bounds.
|
||||
$($where_clause_ty:ty : $where_clause_bound:path),*
|
||||
)?
|
||||
{
|
||||
$(
|
||||
// limitation: cannot interoperate with other attributes.
|
||||
$(#[$pin:ident])?
|
||||
$field_vis:vis $field:ident: $field_ty:ty
|
||||
),+
|
||||
}
|
||||
) => {
|
||||
$(#[$attrs])*
|
||||
$vis struct $ident
|
||||
$(< $( $lifetime $(: $lifetime_bound)? ,)* $( $generics $(: $generics_bound)? $(: ?$generics_unsized_bound)? $(: $generics_lifetime_bound)? $(= $generics_default)? ,)* >)?
|
||||
$(where
|
||||
$($where_clause_ty: $where_clause_bound),*
|
||||
)*
|
||||
{
|
||||
$(
|
||||
$field_vis $field: $field_ty
|
||||
),+
|
||||
}
|
||||
|
||||
// limitation: underscore_const_names requires rust 1.37+ (wontfix)
|
||||
const _: () = {
|
||||
#[allow(clippy::mut_mut)] // This lint warns `&mut &mut <ty>`.
|
||||
#[allow(dead_code)] // This lint warns unused fields/variants.
|
||||
$proj_vis struct Projection
|
||||
<'__pin $(, $( $lifetime $(: $lifetime_bound)? ,)* $( $generics $(: $generics_bound)? $(: ?$generics_unsized_bound)? $(: $generics_lifetime_bound)? ),* )?>
|
||||
$(where
|
||||
$($where_clause_ty: $where_clause_bound),*
|
||||
)*
|
||||
{
|
||||
$(
|
||||
$field_vis $field: $crate::pin_project!(@make_proj_field $(#[$pin])? $field_ty; mut)
|
||||
),+
|
||||
}
|
||||
#[allow(dead_code)] // This lint warns unused fields/variants.
|
||||
$proj_vis struct ProjectionRef
|
||||
<'__pin $(, $( $lifetime $(: $lifetime_bound)? ,)* $( $generics $(: $generics_bound)? $(: ?$generics_unsized_bound)? $(: $generics_lifetime_bound)? ),* )?>
|
||||
$(where
|
||||
$($where_clause_ty: $where_clause_bound),*
|
||||
)*
|
||||
{
|
||||
$(
|
||||
$field_vis $field: $crate::pin_project!(@make_proj_field $(#[$pin])? $field_ty;)
|
||||
),+
|
||||
}
|
||||
|
||||
impl $(< $( $lifetime $(: $lifetime_bound)? ,)* $( $generics $(: $generics_bound)? $(: ?$generics_unsized_bound)? $(: $generics_lifetime_bound)? ),* >)?
|
||||
$ident $(< $($lifetime,)* $($generics),* >)?
|
||||
$(where
|
||||
$($where_clause_ty: $where_clause_bound),*
|
||||
)*
|
||||
{
|
||||
$proj_vis fn project<'__pin>(
|
||||
self: ::core::pin::Pin<&'__pin mut Self>,
|
||||
) -> Projection<'__pin $(, $($lifetime,)* $($generics),* )?> {
|
||||
unsafe {
|
||||
let this = self.get_unchecked_mut();
|
||||
Projection {
|
||||
$(
|
||||
$field: $crate::pin_project!(@make_unsafe_field_proj this; $(#[$pin])? $field; mut)
|
||||
),+
|
||||
}
|
||||
}
|
||||
}
|
||||
$proj_vis fn project_ref<'__pin>(
|
||||
self: ::core::pin::Pin<&'__pin Self>,
|
||||
) -> ProjectionRef<'__pin $(, $($lifetime,)* $($generics),* )?> {
|
||||
unsafe {
|
||||
let this = self.get_ref();
|
||||
ProjectionRef {
|
||||
$(
|
||||
$field: $crate::pin_project!(@make_unsafe_field_proj this; $(#[$pin])? $field;)
|
||||
),+
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Automatically create the appropriate conditional `Unpin` implementation.
|
||||
//
|
||||
// Basically this is equivalent to the following code:
|
||||
// ```rust
|
||||
// impl<T, U> Unpin for Struct<T, U> where T: Unpin {}
|
||||
// ```
|
||||
//
|
||||
// However, if struct is public and there is a private type field,
|
||||
// this would cause an E0446 (private type in public interface).
|
||||
//
|
||||
// When RFC 2145 is implemented (rust-lang/rust#48054),
|
||||
// this will become a lint, rather then a hard error.
|
||||
//
|
||||
// As a workaround for this, we generate a new struct, containing all of the pinned
|
||||
// fields from our #[pin_project] type. This struct is delcared within
|
||||
// a function, which makes it impossible to be named by user code.
|
||||
// This guarnatees that it will use the default auto-trait impl for Unpin -
|
||||
// that is, it will implement Unpin iff all of its fields implement Unpin.
|
||||
// This type can be safely declared as 'public', satisfiying the privacy
|
||||
// checker without actually allowing user code to access it.
|
||||
//
|
||||
// This allows users to apply the #[pin_project] attribute to types
|
||||
// regardless of the privacy of the types of their fields.
|
||||
//
|
||||
// See also https://github.com/taiki-e/pin-project/pull/53.
|
||||
$vis struct __Origin
|
||||
<'__pin $(, $( $lifetime $(: $lifetime_bound)? ,)* $( $generics $(: $generics_bound)? $(: ?$generics_unsized_bound)? $(: $generics_lifetime_bound)? ),* )?>
|
||||
$(where
|
||||
$($where_clause_ty: $where_clause_bound),*
|
||||
)*
|
||||
{
|
||||
__dummy_lifetime: ::core::marker::PhantomData<&'__pin ()>,
|
||||
$(
|
||||
$field: $crate::pin_project!(@make_unpin_bound $(#[$pin])? $field_ty)
|
||||
),+
|
||||
}
|
||||
impl <'__pin $(, $( $lifetime $(: $lifetime_bound)? ,)* $($generics $(: $generics_bound)? $(: ?$generics_unsized_bound)? $(: $generics_lifetime_bound)? ),* )?> ::core::marker::Unpin
|
||||
for $ident $(< $($lifetime,)* $($generics),* >)?
|
||||
where
|
||||
__Origin <'__pin $(, $($lifetime,)* $($generics),* )?>: ::core::marker::Unpin
|
||||
$(,
|
||||
$($where_clause_ty: $where_clause_bound),*
|
||||
)*
|
||||
{
|
||||
}
|
||||
|
||||
// Ensure that struct does not implement `Drop`.
|
||||
//
|
||||
// There are two possible cases:
|
||||
// 1. The user type does not implement Drop. In this case,
|
||||
// the first blanked impl will not apply to it. This code
|
||||
// will compile, as there is only one impl of MustNotImplDrop for the user type
|
||||
// 2. The user type does impl Drop. This will make the blanket impl applicable,
|
||||
// which will then comflict with the explicit MustNotImplDrop impl below.
|
||||
// This will result in a compilation error, which is exactly what we want.
|
||||
trait MustNotImplDrop {}
|
||||
#[allow(clippy::drop_bounds)]
|
||||
impl<T: ::core::ops::Drop> MustNotImplDrop for T {}
|
||||
#[allow(single_use_lifetimes)]
|
||||
impl $(< $( $lifetime $(: $lifetime_bound)? ,)* $($generics $(: $generics_bound)? $(: ?$generics_unsized_bound)? $(: $generics_lifetime_bound)? ),*>)? MustNotImplDrop
|
||||
for $ident $(< $($lifetime,)* $($generics),* >)?
|
||||
$(where
|
||||
$($where_clause_ty: $where_clause_bound),*
|
||||
)*
|
||||
{}
|
||||
|
||||
// Ensure that it's impossible to use pin projections on a #[repr(packed)] struct.
|
||||
//
|
||||
// Taking a reference to a packed field is unsafe, amd appplying
|
||||
// #[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 __assert_not_repr_packed
|
||||
$(< $($lifetime $(: $lifetime_bound)? ,)* $( $generics $(: $generics_bound)? $(: ?$generics_unsized_bound)? $(: $generics_lifetime_bound)? ),* >)?
|
||||
(
|
||||
this: &$ident $(< $($lifetime,)* $($generics),* >)?
|
||||
)
|
||||
$(where
|
||||
$($where_clause_ty: $where_clause_bound),*
|
||||
)*
|
||||
{
|
||||
$(
|
||||
&this.$field;
|
||||
)+
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
// make_unpin_bound
|
||||
(@make_unpin_bound
|
||||
#[pin]
|
||||
$field_ty:ty
|
||||
) => {
|
||||
$field_ty
|
||||
};
|
||||
(@make_unpin_bound
|
||||
$field_ty:ty
|
||||
) => {
|
||||
$crate::__private::AlwaysUnpin<$field_ty>
|
||||
};
|
||||
|
||||
// make_unsafe_field_proj
|
||||
(@make_unsafe_field_proj
|
||||
$this:ident;
|
||||
#[pin]
|
||||
$field:ident;
|
||||
$($mut:ident)?
|
||||
) => {
|
||||
::core::pin::Pin::new_unchecked(&$($mut)? $this.$field)
|
||||
};
|
||||
(@make_unsafe_field_proj
|
||||
$this:ident;
|
||||
$field:ident;
|
||||
$($mut:ident)?
|
||||
) => {
|
||||
&$($mut)? $this.$field
|
||||
};
|
||||
|
||||
// make_proj_field
|
||||
(@make_proj_field
|
||||
#[pin]
|
||||
$field_ty:ty;
|
||||
$($mut:ident)?
|
||||
) => {
|
||||
::core::pin::Pin<&'__pin $($mut)? ($field_ty)>
|
||||
};
|
||||
(@make_proj_field
|
||||
$field_ty:ty;
|
||||
$($mut:ident)?
|
||||
) => {
|
||||
&'__pin $($mut)? ($field_ty)
|
||||
};
|
||||
|
||||
// limitation: no useful error messages (wontfix)
|
||||
}
|
||||
|
||||
// Not public API.
|
||||
#[doc(hidden)]
|
||||
pub mod __private {
|
||||
use core::marker::PhantomData;
|
||||
|
||||
// This is an internal helper struct used by `pin_project!`.
|
||||
#[doc(hidden)]
|
||||
pub struct AlwaysUnpin<T: ?Sized>(PhantomData<T>);
|
||||
|
||||
impl<T: ?Sized> Unpin for AlwaysUnpin<T> {}
|
||||
}
|
|
@ -1,15 +0,0 @@
|
|||
use pin_project_lite::pin_project;
|
||||
|
||||
pin_project! {
|
||||
struct A<T: 'static : ?Sized> { //~ ERROR no rules expected the token `:`
|
||||
field: T,
|
||||
}
|
||||
}
|
||||
|
||||
pin_project! {
|
||||
struct B<T: Sized : 'static> { //~ ERROR expected one of `+`, `,`, `=`, or `>`, found `:`
|
||||
field: T,
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
|
@ -1,21 +0,0 @@
|
|||
error: no rules expected the token `:`
|
||||
--> $DIR/invalid-bounds.rs:4:25
|
||||
|
|
||||
4 | struct A<T: 'static : ?Sized> { //~ ERROR no rules expected the token `:`
|
||||
| ^ no rules expected this token in macro call
|
||||
|
||||
error: expected one of `+`, `,`, `=`, or `>`, found `:`
|
||||
--> $DIR/invalid-bounds.rs:9:1
|
||||
|
|
||||
9 | / pin_project! {
|
||||
10 | | struct B<T: Sized : 'static> { //~ ERROR expected one of `+`, `,`, `=`, or `>`, found `:`
|
||||
11 | | field: T,
|
||||
12 | | }
|
||||
13 | | }
|
||||
| | ^
|
||||
| | |
|
||||
| | expected one of `+`, `,`, `=`, or `>`
|
||||
| |_unexpected token
|
||||
| in this macro invocation
|
||||
|
|
||||
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
|
|
@ -1,13 +0,0 @@
|
|||
error[E0277]: the trait bound `std::marker::PhantomPinned: std::marker::Unpin` is not satisfied in `_::__Origin<'_, std::marker::PhantomPinned>`
|
||||
--> $DIR/overlapping_unpin_struct.rs:18:5
|
||||
|
|
||||
15 | fn is_unpin<T: Unpin>() {}
|
||||
| -------- ----- required by this bound in `is_unpin`
|
||||
...
|
||||
18 | is_unpin::<Foo<PhantomPinned>>(); //~ ERROR E0277
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ within `_::__Origin<'_, std::marker::PhantomPinned>`, the trait `std::marker::Unpin` is not implemented for `std::marker::PhantomPinned`
|
||||
|
|
||||
= help: the following implementations were found:
|
||||
<std::marker::PhantomPinned as std::marker::Unpin>
|
||||
= note: required because it appears within the type `_::__Origin<'_, std::marker::PhantomPinned>`
|
||||
= note: required because of the requirements on the impl of `std::marker::Unpin` for `Foo<std::marker::PhantomPinned>`
|
|
@ -1,19 +0,0 @@
|
|||
use pin_project_lite::pin_project;
|
||||
|
||||
pin_project! { //~ ERROR borrow of packed field is unsafe and requires unsafe function or block
|
||||
#[repr(packed, C)]
|
||||
struct A {
|
||||
#[pin]
|
||||
field: u16,
|
||||
}
|
||||
}
|
||||
|
||||
pin_project! { //~ ERROR borrow of packed field is unsafe and requires unsafe function or block
|
||||
#[repr(packed(2))]
|
||||
struct C {
|
||||
#[pin]
|
||||
field: u32,
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
|
@ -1,55 +0,0 @@
|
|||
error: borrow of packed field is unsafe and requires unsafe function or block (error E0133)
|
||||
--> $DIR/packed.rs:3:1
|
||||
|
|
||||
3 | / pin_project! { //~ ERROR borrow of packed field is unsafe and requires unsafe function or block
|
||||
4 | | #[repr(packed, C)]
|
||||
5 | | struct A {
|
||||
6 | | #[pin]
|
||||
7 | | field: u16,
|
||||
8 | | }
|
||||
9 | | }
|
||||
| |_^
|
||||
|
|
||||
note: lint level defined here
|
||||
--> $DIR/packed.rs:3:1
|
||||
|
|
||||
3 | / pin_project! { //~ ERROR borrow of packed field is unsafe and requires unsafe function or block
|
||||
4 | | #[repr(packed, C)]
|
||||
5 | | struct A {
|
||||
6 | | #[pin]
|
||||
7 | | field: u16,
|
||||
8 | | }
|
||||
9 | | }
|
||||
| |_^
|
||||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
= note: for more information, see issue #46043 <https://github.com/rust-lang/rust/issues/46043>
|
||||
= note: fields of packed structs might be misaligned: dereferencing a misaligned pointer or even just creating a misaligned reference is undefined behavior
|
||||
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
|
||||
|
||||
error: borrow of packed field is unsafe and requires unsafe function or block (error E0133)
|
||||
--> $DIR/packed.rs:11:1
|
||||
|
|
||||
11 | / pin_project! { //~ ERROR borrow of packed field is unsafe and requires unsafe function or block
|
||||
12 | | #[repr(packed(2))]
|
||||
13 | | struct C {
|
||||
14 | | #[pin]
|
||||
15 | | field: u32,
|
||||
16 | | }
|
||||
17 | | }
|
||||
| |_^
|
||||
|
|
||||
note: lint level defined here
|
||||
--> $DIR/packed.rs:11:1
|
||||
|
|
||||
11 | / pin_project! { //~ ERROR borrow of packed field is unsafe and requires unsafe function or block
|
||||
12 | | #[repr(packed(2))]
|
||||
13 | | struct C {
|
||||
14 | | #[pin]
|
||||
15 | | field: u32,
|
||||
16 | | }
|
||||
17 | | }
|
||||
| |_^
|
||||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
= note: for more information, see issue #46043 <https://github.com/rust-lang/rust/issues/46043>
|
||||
= note: fields of packed structs might be misaligned: dereferencing a misaligned pointer or even just creating a misaligned reference is undefined behavior
|
||||
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
|
|
@ -1,41 +0,0 @@
|
|||
use pin_project_lite::pin_project;
|
||||
use std::marker::PhantomPinned;
|
||||
|
||||
struct Inner<T> {
|
||||
val: T,
|
||||
}
|
||||
|
||||
pin_project! {
|
||||
struct Foo<T, U> {
|
||||
#[pin]
|
||||
inner: Inner<T>,
|
||||
other: U,
|
||||
}
|
||||
}
|
||||
|
||||
pin_project! {
|
||||
pub struct TrivialBounds {
|
||||
#[pin]
|
||||
field1: PhantomPinned,
|
||||
}
|
||||
}
|
||||
|
||||
pin_project! {
|
||||
struct Bar<'a, T, U> {
|
||||
#[pin]
|
||||
inner: &'a mut Inner<T>,
|
||||
other: U,
|
||||
}
|
||||
}
|
||||
|
||||
fn is_unpin<T: Unpin>() {}
|
||||
|
||||
fn main() {
|
||||
is_unpin::<Foo<PhantomPinned, ()>>(); //~ ERROR E0277
|
||||
is_unpin::<Foo<(), PhantomPinned>>(); // Ok
|
||||
is_unpin::<Foo<PhantomPinned, PhantomPinned>>(); //~ ERROR E0277
|
||||
|
||||
is_unpin::<TrivialBounds>(); //~ ERROR E0277
|
||||
|
||||
is_unpin::<Bar<'_, PhantomPinned, PhantomPinned>>(); //~ Ok
|
||||
}
|
|
@ -1,43 +0,0 @@
|
|||
error[E0277]: the trait bound `std::marker::PhantomPinned: std::marker::Unpin` is not satisfied in `_::__Origin<'_, std::marker::PhantomPinned, ()>`
|
||||
--> $DIR/proper_unpin.rs:34:5
|
||||
|
|
||||
31 | fn is_unpin<T: Unpin>() {}
|
||||
| -------- ----- required by this bound in `is_unpin`
|
||||
...
|
||||
34 | is_unpin::<Foo<PhantomPinned, ()>>(); //~ ERROR E0277
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ within `_::__Origin<'_, std::marker::PhantomPinned, ()>`, the trait `std::marker::Unpin` is not implemented for `std::marker::PhantomPinned`
|
||||
|
|
||||
= help: the following implementations were found:
|
||||
<std::marker::PhantomPinned as std::marker::Unpin>
|
||||
= note: required because it appears within the type `Inner<std::marker::PhantomPinned>`
|
||||
= note: required because it appears within the type `_::__Origin<'_, std::marker::PhantomPinned, ()>`
|
||||
= note: required because of the requirements on the impl of `std::marker::Unpin` for `Foo<std::marker::PhantomPinned, ()>`
|
||||
|
||||
error[E0277]: the trait bound `std::marker::PhantomPinned: std::marker::Unpin` is not satisfied in `_::__Origin<'_, std::marker::PhantomPinned, std::marker::PhantomPinned>`
|
||||
--> $DIR/proper_unpin.rs:36:5
|
||||
|
|
||||
31 | fn is_unpin<T: Unpin>() {}
|
||||
| -------- ----- required by this bound in `is_unpin`
|
||||
...
|
||||
36 | is_unpin::<Foo<PhantomPinned, PhantomPinned>>(); //~ ERROR E0277
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ within `_::__Origin<'_, std::marker::PhantomPinned, std::marker::PhantomPinned>`, the trait `std::marker::Unpin` is not implemented for `std::marker::PhantomPinned`
|
||||
|
|
||||
= help: the following implementations were found:
|
||||
<std::marker::PhantomPinned as std::marker::Unpin>
|
||||
= note: required because it appears within the type `Inner<std::marker::PhantomPinned>`
|
||||
= note: required because it appears within the type `_::__Origin<'_, std::marker::PhantomPinned, std::marker::PhantomPinned>`
|
||||
= note: required because of the requirements on the impl of `std::marker::Unpin` for `Foo<std::marker::PhantomPinned, std::marker::PhantomPinned>`
|
||||
|
||||
error[E0277]: the trait bound `std::marker::PhantomPinned: std::marker::Unpin` is not satisfied in `_::__Origin<'_>`
|
||||
--> $DIR/proper_unpin.rs:38:5
|
||||
|
|
||||
31 | fn is_unpin<T: Unpin>() {}
|
||||
| -------- ----- required by this bound in `is_unpin`
|
||||
...
|
||||
38 | is_unpin::<TrivialBounds>(); //~ ERROR E0277
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ within `_::__Origin<'_>`, the trait `std::marker::Unpin` is not implemented for `std::marker::PhantomPinned`
|
||||
|
|
||||
= help: the following implementations were found:
|
||||
<std::marker::PhantomPinned as std::marker::Unpin>
|
||||
= note: required because it appears within the type `_::__Origin<'_>`
|
||||
= note: required because of the requirements on the impl of `std::marker::Unpin` for `TrivialBounds`
|
Различия файлов скрыты, потому что одна или несколько строк слишком длинны
|
@ -10,24 +10,42 @@ Note: In this file, do not use the hard wrap in the middle of a sentence for com
|
|||
|
||||
## [Unreleased]
|
||||
|
||||
## [0.2.6] - 2021-03-04
|
||||
|
||||
- [Support item attributes in any order.](https://github.com/taiki-e/pin-project-lite/pull/57)
|
||||
|
||||
## [0.2.5] - 2021-03-02
|
||||
|
||||
- [Prepare for removal of `safe_packed_borrows` lint.](https://github.com/taiki-e/pin-project-lite/pull/55) See [#55](https://github.com/taiki-e/pin-project-lite/pull/55) for details.
|
||||
|
||||
## [0.2.4] - 2021-01-11
|
||||
|
||||
**Note: This release has been yanked.** See [#55](https://github.com/taiki-e/pin-project-lite/pull/55) for details.
|
||||
|
||||
- [Add `project_replace`.](https://github.com/taiki-e/pin-project-lite/pull/43)
|
||||
|
||||
## [0.2.3] - 2021-01-09
|
||||
|
||||
**Note: This release has been yanked.** See [#55](https://github.com/taiki-e/pin-project-lite/pull/55) for details.
|
||||
|
||||
- [Suppress `clippy::unknown_clippy_lints` lint in generated code.](https://github.com/taiki-e/pin-project-lite/pull/47)
|
||||
|
||||
## [0.2.2] - 2021-01-09
|
||||
|
||||
**Note: This release has been yanked.** See [#55](https://github.com/taiki-e/pin-project-lite/pull/55) for details.
|
||||
|
||||
- [Suppress `clippy::ref_option_ref` lint in generated code.](https://github.com/taiki-e/pin-project-lite/pull/45)
|
||||
|
||||
## [0.2.1] - 2021-01-05
|
||||
|
||||
**Note: This release has been yanked.** See [#55](https://github.com/taiki-e/pin-project-lite/pull/55) for details.
|
||||
|
||||
- Exclude unneeded files from crates.io.
|
||||
|
||||
## [0.2.0] - 2020-11-13
|
||||
|
||||
**Note: This release has been yanked.** See [#55](https://github.com/taiki-e/pin-project-lite/pull/55) for details.
|
||||
|
||||
- [`pin_project!` macro now supports enums.](https://github.com/taiki-e/pin-project-lite/pull/28)
|
||||
|
||||
To use `pin_project!` on enums, you need to name the projection type returned from the method.
|
||||
|
@ -77,22 +95,34 @@ Note: In this file, do not use the hard wrap in the middle of a sentence for com
|
|||
}
|
||||
```
|
||||
|
||||
## [0.1.12] - 2021-03-02
|
||||
|
||||
- [Prepare for removal of `safe_packed_borrows` lint.](https://github.com/taiki-e/pin-project-lite/pull/55) See [#55](https://github.com/taiki-e/pin-project-lite/pull/55) for details.
|
||||
|
||||
## [0.1.11] - 2020-10-20
|
||||
|
||||
**Note: This release has been yanked.** See [#55](https://github.com/taiki-e/pin-project-lite/pull/55) for details.
|
||||
|
||||
- Suppress `clippy::redundant_pub_crate` lint in generated code.
|
||||
|
||||
- Documentation improvements.
|
||||
|
||||
## [0.1.10] - 2020-10-01
|
||||
|
||||
**Note: This release has been yanked.** See [#55](https://github.com/taiki-e/pin-project-lite/pull/55) for details.
|
||||
|
||||
- Suppress `drop_bounds` lint, which will be added to rustc in the future. See [taiki-e/pin-project#272](https://github.com/taiki-e/pin-project/issues/272) for more details.
|
||||
|
||||
## [0.1.9] - 2020-09-29
|
||||
|
||||
**Note: This release has been yanked.** See [#55](https://github.com/taiki-e/pin-project-lite/pull/55) for details.
|
||||
|
||||
- [Fix trailing comma support in generics.](https://github.com/taiki-e/pin-project-lite/pull/32)
|
||||
|
||||
## [0.1.8] - 2020-09-26
|
||||
|
||||
**Note: This release has been yanked.** See [#55](https://github.com/taiki-e/pin-project-lite/pull/55) for details.
|
||||
|
||||
- [Fix compatibility of generated code with `forbid(future_incompatible)`.](https://github.com/taiki-e/pin-project-lite/pull/30)
|
||||
|
||||
Note: This does not guarantee compatibility with `forbid(future_incompatible)` in the future.
|
||||
|
@ -100,6 +130,8 @@ Note: In this file, do not use the hard wrap in the middle of a sentence for com
|
|||
|
||||
## [0.1.7] - 2020-06-04
|
||||
|
||||
**Note: This release has been yanked.** See [#55](https://github.com/taiki-e/pin-project-lite/pull/55) for details.
|
||||
|
||||
- [Support `?Sized` bounds in where clauses.](https://github.com/taiki-e/pin-project-lite/pull/22)
|
||||
|
||||
- [Fix lifetime inference error when an associated type is used in fields.](https://github.com/taiki-e/pin-project-lite/pull/20)
|
||||
|
@ -110,40 +142,57 @@ Note: In this file, do not use the hard wrap in the middle of a sentence for com
|
|||
|
||||
## [0.1.6] - 2020-05-31
|
||||
|
||||
**Note: This release has been yanked.** See [#55](https://github.com/taiki-e/pin-project-lite/pull/55) for details.
|
||||
|
||||
- [Support lifetime bounds in where clauses.](https://github.com/taiki-e/pin-project-lite/pull/18)
|
||||
|
||||
- Documentation improvements.
|
||||
|
||||
## [0.1.5] - 2020-05-07
|
||||
|
||||
**Note: This release has been yanked.** See [#55](https://github.com/taiki-e/pin-project-lite/pull/55) for details.
|
||||
|
||||
- [Support overwriting the name of `core` crate.](https://github.com/taiki-e/pin-project-lite/pull/14)
|
||||
|
||||
## [0.1.4] - 2020-01-20
|
||||
|
||||
**Note: This release has been yanked.** See [#55](https://github.com/taiki-e/pin-project-lite/pull/55) for details.
|
||||
|
||||
- [Support ?Sized bounds in generic parameters.](https://github.com/taiki-e/pin-project-lite/pull/9)
|
||||
|
||||
## [0.1.3] - 2020-01-20
|
||||
|
||||
**Note: This release has been yanked.** See [#55](https://github.com/taiki-e/pin-project-lite/pull/55) for details.
|
||||
|
||||
- [Support lifetime bounds in generic parameters.](https://github.com/taiki-e/pin-project-lite/pull/7)
|
||||
|
||||
## [0.1.2] - 2020-01-05
|
||||
|
||||
**Note: This release has been yanked.** See [#55](https://github.com/taiki-e/pin-project-lite/pull/55) for details.
|
||||
|
||||
- [Support recognizing default generic parameters.](https://github.com/taiki-e/pin-project-lite/pull/6)
|
||||
|
||||
## [0.1.1] - 2019-11-15
|
||||
|
||||
**Note: This release has been yanked.** See [#55](https://github.com/taiki-e/pin-project-lite/pull/55) for details.
|
||||
|
||||
- [`pin_project!` macro now determines the visibility of the projection type/method is based on the original type.](https://github.com/taiki-e/pin-project-lite/pull/5)
|
||||
|
||||
## [0.1.0] - 2019-10-22
|
||||
|
||||
**Note: This release has been yanked.** See [#55](https://github.com/taiki-e/pin-project-lite/pull/55) for details.
|
||||
|
||||
Initial release
|
||||
|
||||
[Unreleased]: https://github.com/taiki-e/pin-project-lite/compare/v0.2.4...HEAD
|
||||
[Unreleased]: https://github.com/taiki-e/pin-project-lite/compare/v0.2.6...HEAD
|
||||
[0.2.6]: https://github.com/taiki-e/pin-project-lite/compare/v0.2.5...v0.2.6
|
||||
[0.2.5]: https://github.com/taiki-e/pin-project-lite/compare/v0.2.4...v0.2.5
|
||||
[0.2.4]: https://github.com/taiki-e/pin-project-lite/compare/v0.2.3...v0.2.4
|
||||
[0.2.3]: https://github.com/taiki-e/pin-project-lite/compare/v0.2.2...v0.2.3
|
||||
[0.2.2]: https://github.com/taiki-e/pin-project-lite/compare/v0.2.1...v0.2.2
|
||||
[0.2.1]: https://github.com/taiki-e/pin-project-lite/compare/v0.2.0...v0.2.1
|
||||
[0.2.0]: https://github.com/taiki-e/pin-project-lite/compare/v0.1.11...v0.2.0
|
||||
[0.1.12]: https://github.com/taiki-e/pin-project-lite/compare/v0.1.11...v0.1.12
|
||||
[0.1.11]: https://github.com/taiki-e/pin-project-lite/compare/v0.1.10...v0.1.11
|
||||
[0.1.10]: https://github.com/taiki-e/pin-project-lite/compare/v0.1.9...v0.1.10
|
||||
[0.1.9]: https://github.com/taiki-e/pin-project-lite/compare/v0.1.8...v0.1.9
|
||||
|
|
|
@ -13,18 +13,20 @@
|
|||
[package]
|
||||
edition = "2018"
|
||||
name = "pin-project-lite"
|
||||
version = "0.2.4"
|
||||
version = "0.2.6"
|
||||
authors = ["Taiki Endo <te316e89@gmail.com>"]
|
||||
exclude = ["/.github", "/scripts"]
|
||||
exclude = ["/.*", "/scripts"]
|
||||
description = "A lightweight version of pin-project written with declarative macros.\n"
|
||||
documentation = "https://docs.rs/pin-project-lite"
|
||||
readme = "README.md"
|
||||
keywords = ["pin", "macros"]
|
||||
categories = ["no-std", "rust-patterns"]
|
||||
license = "Apache-2.0 OR MIT"
|
||||
repository = "https://github.com/taiki-e/pin-project-lite"
|
||||
[package.metadata.docs.rs]
|
||||
targets = ["x86_64-unknown-linux-gnu"]
|
||||
[dev-dependencies.macrotest]
|
||||
version = "1.0.8"
|
||||
|
||||
[dev-dependencies.rustversion]
|
||||
version = "1"
|
||||
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
# pin-project-lite
|
||||
|
||||
[![crates.io](https://img.shields.io/crates/v/pin-project-lite.svg?style=flat-square&logo=rust)](https://crates.io/crates/pin-project-lite)
|
||||
[![crates.io](https://img.shields.io/crates/v/pin-project-lite?style=flat-square&logo=rust)](https://crates.io/crates/pin-project-lite)
|
||||
[![docs.rs](https://img.shields.io/badge/docs.rs-pin--project--lite-blue?style=flat-square)](https://docs.rs/pin-project-lite)
|
||||
[![license](https://img.shields.io/badge/license-Apache--2.0_OR_MIT-blue.svg?style=flat-square)](#license)
|
||||
[![rustc](https://img.shields.io/badge/rustc-1.37+-blue.svg?style=flat-square)](https://www.rust-lang.org)
|
||||
[![build status](https://img.shields.io/github/workflow/status/taiki-e/pin-project-lite/CI/master?style=flat-square)](https://github.com/taiki-e/pin-project-lite/actions?query=workflow%3ACI+branch%3Amaster)
|
||||
[![license](https://img.shields.io/badge/license-Apache--2.0_OR_MIT-blue?style=flat-square)](#license)
|
||||
[![rustc](https://img.shields.io/badge/rustc-1.37+-blue?style=flat-square&logo=rust)](https://www.rust-lang.org)
|
||||
[![build status](https://img.shields.io/github/workflow/status/taiki-e/pin-project-lite/CI/main?style=flat-square&logo=github)](https://github.com/taiki-e/pin-project-lite/actions)
|
||||
|
||||
A lightweight version of [pin-project] written with declarative macros.
|
||||
|
||||
|
|
|
@ -5,9 +5,10 @@
|
|||
//! [`pin_project!`] macro creates a projection type covering all the fields of struct.
|
||||
//!
|
||||
//! ```rust
|
||||
//! use pin_project_lite::pin_project;
|
||||
//! use std::pin::Pin;
|
||||
//!
|
||||
//! use pin_project_lite::pin_project;
|
||||
//!
|
||||
//! pin_project! {
|
||||
//! struct Struct<T, U> {
|
||||
//! #[pin]
|
||||
|
@ -29,9 +30,10 @@
|
|||
//! returned from the method.
|
||||
//!
|
||||
//! ```rust
|
||||
//! use pin_project_lite::pin_project;
|
||||
//! use std::pin::Pin;
|
||||
//!
|
||||
//! use pin_project_lite::pin_project;
|
||||
//!
|
||||
//! pin_project! {
|
||||
//! #[project = EnumProj]
|
||||
//! enum Enum<T, U> {
|
||||
|
@ -165,23 +167,6 @@
|
|||
/// # }
|
||||
/// ```
|
||||
///
|
||||
/// The `#[project]` (and `#[project_ref]`) attribute must precede the other
|
||||
/// attributes except for `#[doc]`. For example, the following code will not be compiled:
|
||||
///
|
||||
/// ```rust,compile_fail
|
||||
/// # use pin_project_lite::pin_project;
|
||||
/// # use std::pin::Pin;
|
||||
/// pin_project! {
|
||||
/// /// documents (`#[doc]`) can be placed before `#[project]`.
|
||||
/// #[derive(Clone)] // <--- ERROR
|
||||
/// #[project = EnumProj]
|
||||
/// #[derive(Debug)] // <--- Ok
|
||||
/// enum Enum<T> {
|
||||
/// Variant { #[pin] field: T },
|
||||
/// }
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
/// Also, note that the projection types returned by `project` and `project_ref` have
|
||||
/// an additional lifetime at the beginning of generics.
|
||||
///
|
||||
|
@ -205,9 +190,10 @@
|
|||
/// # Examples
|
||||
///
|
||||
/// ```rust
|
||||
/// use pin_project_lite::pin_project;
|
||||
/// use std::pin::Pin;
|
||||
///
|
||||
/// use pin_project_lite::pin_project;
|
||||
///
|
||||
/// pin_project! {
|
||||
/// struct Struct<T, U> {
|
||||
/// #[pin]
|
||||
|
@ -229,9 +215,10 @@
|
|||
/// returned from the method.
|
||||
///
|
||||
/// ```rust
|
||||
/// use pin_project_lite::pin_project;
|
||||
/// use std::pin::Pin;
|
||||
///
|
||||
/// use pin_project_lite::pin_project;
|
||||
///
|
||||
/// pin_project! {
|
||||
/// #[project = EnumProj]
|
||||
/// enum Enum<T> {
|
||||
|
@ -260,9 +247,10 @@
|
|||
/// consuming the [`Pin`].
|
||||
///
|
||||
/// ```rust
|
||||
/// use pin_project_lite::pin_project;
|
||||
/// use std::pin::Pin;
|
||||
///
|
||||
/// use pin_project_lite::pin_project;
|
||||
///
|
||||
/// pin_project! {
|
||||
/// struct Struct<T> {
|
||||
/// #[pin]
|
||||
|
@ -285,9 +273,10 @@
|
|||
/// attribute for a [`PhantomPinned`] field.
|
||||
///
|
||||
/// ```rust
|
||||
/// use pin_project_lite::pin_project;
|
||||
/// use std::marker::PhantomPinned;
|
||||
///
|
||||
/// use pin_project_lite::pin_project;
|
||||
///
|
||||
/// pin_project! {
|
||||
/// struct Struct<T> {
|
||||
/// field: T,
|
||||
|
@ -305,94 +294,9 @@
|
|||
/// [pin-project]: https://github.com/taiki-e/pin-project
|
||||
#[macro_export]
|
||||
macro_rules! pin_project {
|
||||
// Parses options
|
||||
(
|
||||
$(#[doc $($doc:tt)*])*
|
||||
#[project = $proj_mut_ident:ident]
|
||||
#[project_ref = $proj_ref_ident:ident]
|
||||
#[project_replace = $proj_replace_ident:ident]
|
||||
$($tt:tt)*
|
||||
) => {
|
||||
($($tt:tt)*) => {
|
||||
$crate::__pin_project_internal! {
|
||||
[$proj_mut_ident][$proj_ref_ident][$proj_replace_ident]
|
||||
$(#[doc $($doc)*])*
|
||||
$($tt)*
|
||||
}
|
||||
};
|
||||
(
|
||||
$(#[doc $($doc:tt)*])*
|
||||
#[project = $proj_mut_ident:ident]
|
||||
#[project_ref = $proj_ref_ident:ident]
|
||||
$($tt:tt)*
|
||||
) => {
|
||||
$crate::__pin_project_internal! {
|
||||
[$proj_mut_ident][$proj_ref_ident][]
|
||||
$(#[doc $($doc)*])*
|
||||
$($tt)*
|
||||
}
|
||||
};
|
||||
(
|
||||
$(#[doc $($doc:tt)*])*
|
||||
#[project = $proj_mut_ident:ident]
|
||||
#[project_replace = $proj_replace_ident:ident]
|
||||
$($tt:tt)*
|
||||
) => {
|
||||
$crate::__pin_project_internal! {
|
||||
[$proj_mut_ident][][$proj_replace_ident]
|
||||
$(#[doc $($doc)*])*
|
||||
$($tt)*
|
||||
}
|
||||
};
|
||||
(
|
||||
$(#[doc $($doc:tt)*])*
|
||||
#[project_ref = $proj_ref_ident:ident]
|
||||
#[project_replace = $proj_replace_ident:ident]
|
||||
$($tt:tt)*
|
||||
) => {
|
||||
$crate::__pin_project_internal! {
|
||||
[][$proj_ref_ident][$proj_replace_ident]
|
||||
$(#[doc $($doc)*])*
|
||||
$($tt)*
|
||||
}
|
||||
};
|
||||
(
|
||||
$(#[doc $($doc:tt)*])*
|
||||
#[project = $proj_mut_ident:ident]
|
||||
$($tt:tt)*
|
||||
) => {
|
||||
$crate::__pin_project_internal! {
|
||||
[$proj_mut_ident][][]
|
||||
$(#[doc $($doc)*])*
|
||||
$($tt)*
|
||||
}
|
||||
};
|
||||
(
|
||||
$(#[doc $($doc:tt)*])*
|
||||
#[project_ref = $proj_ref_ident:ident]
|
||||
$($tt:tt)*
|
||||
) => {
|
||||
$crate::__pin_project_internal! {
|
||||
[][$proj_ref_ident][]
|
||||
$(#[doc $($doc)*])*
|
||||
$($tt)*
|
||||
}
|
||||
};
|
||||
(
|
||||
$(#[doc $($doc:tt)*])*
|
||||
#[project_replace = $proj_replace_ident:ident]
|
||||
$($tt:tt)*
|
||||
) => {
|
||||
$crate::__pin_project_internal! {
|
||||
[][][$proj_replace_ident]
|
||||
$(#[doc $($doc)*])*
|
||||
$($tt)*
|
||||
}
|
||||
};
|
||||
(
|
||||
$($tt:tt)*
|
||||
) => {
|
||||
$crate::__pin_project_internal! {
|
||||
[][][]
|
||||
[][][][]
|
||||
$($tt)*
|
||||
}
|
||||
};
|
||||
|
@ -584,10 +488,8 @@ macro_rules! __pin_project_internal {
|
|||
|
||||
// Ensure that it's impossible to use pin projections on a #[repr(packed)] struct.
|
||||
//
|
||||
// Taking a reference to a packed field is unsafe, amd appplying
|
||||
// #[forbid(safe_packed_borrows)] makes sure that doing this without
|
||||
// an 'unsafe' block (which we deliberately do not generate)
|
||||
// is a hard error.
|
||||
// Taking a reference to a packed field is UB, and applying
|
||||
// `#[forbid(unaligned_references)]` makes sure that doing this is a hard error.
|
||||
//
|
||||
// If the struct ends up having #[repr(packed)] applied somehow,
|
||||
// this will generate an (unfriendly) error message. Under all reasonable
|
||||
|
@ -595,7 +497,16 @@ macro_rules! __pin_project_internal {
|
|||
// a much nicer error above.
|
||||
//
|
||||
// See https://github.com/taiki-e/pin-project/pull/34 for more details.
|
||||
#[forbid(safe_packed_borrows)]
|
||||
//
|
||||
// Note:
|
||||
// - Lint-based tricks aren't perfect, but they're much better than nothing:
|
||||
// https://github.com/taiki-e/pin-project-lite/issues/26
|
||||
//
|
||||
// - Enable both unaligned_references and safe_packed_borrows lints
|
||||
// because unaligned_references lint does not exist in older compilers:
|
||||
// https://github.com/taiki-e/pin-project-lite/pull/55
|
||||
// https://github.com/rust-lang/rust/pull/82525
|
||||
#[forbid(unaligned_references, safe_packed_borrows)]
|
||||
fn __assert_not_repr_packed <$($impl_generics)*> (this: &$ident <$($ty_generics)*>)
|
||||
$(where
|
||||
$($where_clause)*)?
|
||||
|
@ -1401,13 +1312,86 @@ macro_rules! __pin_project_internal {
|
|||
|
||||
// =============================================================================================
|
||||
// Parses input and determines visibility
|
||||
|
||||
(
|
||||
[]
|
||||
[$($proj_ref_ident:ident)?]
|
||||
[$($proj_replace_ident:ident)?]
|
||||
[$($attrs:tt)*]
|
||||
|
||||
#[project = $proj_mut_ident:ident]
|
||||
$($tt:tt)*
|
||||
) => {
|
||||
$crate::__pin_project_internal! {
|
||||
[$proj_mut_ident]
|
||||
[$($proj_ref_ident)?]
|
||||
[$($proj_replace_ident)?]
|
||||
[$($attrs)*]
|
||||
$($tt)*
|
||||
}
|
||||
};
|
||||
|
||||
{
|
||||
[$($proj_mut_ident:ident)?]
|
||||
[]
|
||||
[$($proj_replace_ident:ident)?]
|
||||
[$($attrs:tt)*]
|
||||
|
||||
#[project_ref = $proj_ref_ident:ident]
|
||||
$($tt:tt)*
|
||||
} => {
|
||||
$crate::__pin_project_internal! {
|
||||
[$($proj_mut_ident)?]
|
||||
[$proj_ref_ident]
|
||||
[$($proj_replace_ident)?]
|
||||
[$($attrs)*]
|
||||
$($tt)*
|
||||
}
|
||||
};
|
||||
|
||||
{
|
||||
[$($proj_mut_ident:ident)?]
|
||||
[$($proj_ref_ident:ident)?]
|
||||
[]
|
||||
[$($attrs:tt)*]
|
||||
|
||||
#[project_replace = $proj_replace_ident:ident]
|
||||
$($tt:tt)*
|
||||
} => {
|
||||
$crate::__pin_project_internal! {
|
||||
[$($proj_mut_ident)?]
|
||||
[$($proj_ref_ident)?]
|
||||
[$proj_replace_ident]
|
||||
[$($attrs)*]
|
||||
$($tt)*
|
||||
}
|
||||
};
|
||||
|
||||
{
|
||||
[$($proj_mut_ident:ident)?]
|
||||
[$($proj_ref_ident:ident)?]
|
||||
[$($proj_replace_ident:ident)?]
|
||||
[$($attrs:tt)*]
|
||||
|
||||
#[$($attr:tt)*]
|
||||
$($tt:tt)*
|
||||
} => {
|
||||
$crate::__pin_project_internal! {
|
||||
[$($proj_mut_ident)?]
|
||||
[$($proj_ref_ident)?]
|
||||
[$($proj_replace_ident)?]
|
||||
[$($attrs)* #[$($attr)*]]
|
||||
$($tt)*
|
||||
}
|
||||
};
|
||||
|
||||
// struct
|
||||
(
|
||||
[$($proj_mut_ident:ident)?]
|
||||
[$($proj_ref_ident:ident)?]
|
||||
[$($proj_replace_ident:ident)?]
|
||||
[$($attrs:tt)*]
|
||||
|
||||
$(#[$attrs:meta])*
|
||||
pub struct $ident:ident $(<
|
||||
$( $lifetime:lifetime $(: $lifetime_bound:lifetime)? ),* $(,)?
|
||||
$( $generics:ident
|
||||
|
@ -1436,7 +1420,7 @@ macro_rules! __pin_project_internal {
|
|||
[$($proj_ref_ident)?]
|
||||
[$($proj_replace_ident)?]
|
||||
[pub(crate)]
|
||||
[$(#[$attrs])* pub struct $ident]
|
||||
[$($attrs)* pub struct $ident]
|
||||
[$(<
|
||||
$( $lifetime $(: $lifetime_bound)? ,)*
|
||||
$( $generics
|
||||
|
@ -1472,8 +1456,8 @@ macro_rules! __pin_project_internal {
|
|||
[$($proj_mut_ident:ident)?]
|
||||
[$($proj_ref_ident:ident)?]
|
||||
[$($proj_replace_ident:ident)?]
|
||||
[$($attrs:tt)*]
|
||||
|
||||
$(#[$attrs:meta])*
|
||||
$vis:vis struct $ident:ident $(<
|
||||
$( $lifetime:lifetime $(: $lifetime_bound:lifetime)? ),* $(,)?
|
||||
$( $generics:ident
|
||||
|
@ -1502,7 +1486,7 @@ macro_rules! __pin_project_internal {
|
|||
[$($proj_ref_ident)?]
|
||||
[$($proj_replace_ident)?]
|
||||
[$vis]
|
||||
[$(#[$attrs])* $vis struct $ident]
|
||||
[$($attrs)* $vis struct $ident]
|
||||
[$(<
|
||||
$( $lifetime $(: $lifetime_bound)? ,)*
|
||||
$( $generics
|
||||
|
@ -1539,8 +1523,8 @@ macro_rules! __pin_project_internal {
|
|||
[$($proj_mut_ident:ident)?]
|
||||
[$($proj_ref_ident:ident)?]
|
||||
[$($proj_replace_ident:ident)?]
|
||||
[$($attrs:tt)*]
|
||||
|
||||
$(#[$attrs:meta])*
|
||||
pub enum $ident:ident $(<
|
||||
$( $lifetime:lifetime $(: $lifetime_bound:lifetime)? ),* $(,)?
|
||||
$( $generics:ident
|
||||
|
@ -1574,7 +1558,7 @@ macro_rules! __pin_project_internal {
|
|||
[$($proj_ref_ident)?]
|
||||
[$($proj_replace_ident)?]
|
||||
[pub(crate)]
|
||||
[$(#[$attrs])* pub enum $ident]
|
||||
[$($attrs)* pub enum $ident]
|
||||
[$(<
|
||||
$( $lifetime $(: $lifetime_bound)? ,)*
|
||||
$( $generics
|
||||
|
@ -1615,8 +1599,8 @@ macro_rules! __pin_project_internal {
|
|||
[$($proj_mut_ident:ident)?]
|
||||
[$($proj_ref_ident:ident)?]
|
||||
[$($proj_replace_ident:ident)?]
|
||||
[$($attrs:tt)*]
|
||||
|
||||
$(#[$attrs:meta])*
|
||||
$vis:vis enum $ident:ident $(<
|
||||
$( $lifetime:lifetime $(: $lifetime_bound:lifetime)? ),* $(,)?
|
||||
$( $generics:ident
|
||||
|
@ -1650,7 +1634,7 @@ macro_rules! __pin_project_internal {
|
|||
[$($proj_ref_ident)?]
|
||||
[$($proj_replace_ident)?]
|
||||
[$vis]
|
||||
[$(#[$attrs])* $vis enum $ident]
|
||||
[$($attrs)* $vis enum $ident]
|
||||
[$(<
|
||||
$( $lifetime $(: $lifetime_bound)? ,)*
|
||||
$( $generics
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
#![allow(dead_code, unused_macros)]
|
||||
#![allow(box_pointers, unreachable_pub)]
|
||||
#![allow(clippy::restriction)]
|
||||
|
||||
macro_rules! assert_unpin {
|
||||
($ty:ty) => {
|
||||
|
|
|
@ -11,5 +11,5 @@ fn ui() {
|
|||
}
|
||||
|
||||
let t = trybuild::TestCases::new();
|
||||
t.compile_fail("tests/ui/*.rs");
|
||||
t.compile_fail("tests/ui/*/*.rs");
|
||||
}
|
||||
|
|
|
@ -2,9 +2,10 @@
|
|||
|
||||
// Refs: https://doc.rust-lang.org/reference/destructors.html
|
||||
|
||||
use pin_project_lite::pin_project;
|
||||
use std::{cell::Cell, panic, pin::Pin, thread};
|
||||
|
||||
use pin_project_lite::pin_project;
|
||||
|
||||
struct D<'a>(&'a Cell<usize>, usize);
|
||||
|
||||
impl Drop for D<'_> {
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
# Expansion tests
|
||||
|
||||
Similar to ui tests, but instead of checking the compiler output, this checks
|
||||
the code generated by macros.
|
||||
|
||||
See [examples](https://github.com/taiki-e/pin-project/tree/HEAD/examples) for
|
||||
descriptions of what the generated code does, and why it needs to be generated.
|
||||
|
||||
To run this test, run the following command:
|
||||
|
||||
```sh
|
||||
cargo +nightly test --test expandtest
|
||||
```
|
||||
|
||||
Locally, this test updates the files in the `expand` directory if there are
|
||||
changes to the generated code. If there are any changes to the files in the
|
||||
`expand` directory after running the test, please commit them.
|
127
third_party/rust/pin-project-lite/tests/expand/default/enum.expanded.rs
поставляемый
Normal file
127
third_party/rust/pin-project-lite/tests/expand/default/enum.expanded.rs
поставляемый
Normal file
|
@ -0,0 +1,127 @@
|
|||
use pin_project_lite::pin_project;
|
||||
enum Enum<T, U> {
|
||||
Struct { pinned: T, unpinned: U },
|
||||
Unit,
|
||||
}
|
||||
#[allow(dead_code)]
|
||||
#[allow(single_use_lifetimes)]
|
||||
#[allow(clippy::unknown_clippy_lints)]
|
||||
#[allow(clippy::mut_mut)]
|
||||
#[allow(clippy::redundant_pub_crate)]
|
||||
#[allow(clippy::ref_option_ref)]
|
||||
#[allow(clippy::type_repetition_in_bounds)]
|
||||
enum EnumProj<'__pin, T, U>
|
||||
where
|
||||
Enum<T, U>: '__pin,
|
||||
{
|
||||
Struct {
|
||||
pinned: ::pin_project_lite::__private::Pin<&'__pin mut (T)>,
|
||||
unpinned: &'__pin mut (U),
|
||||
},
|
||||
Unit,
|
||||
}
|
||||
#[allow(dead_code)]
|
||||
#[allow(single_use_lifetimes)]
|
||||
#[allow(clippy::unknown_clippy_lints)]
|
||||
#[allow(clippy::mut_mut)]
|
||||
#[allow(clippy::redundant_pub_crate)]
|
||||
#[allow(clippy::ref_option_ref)]
|
||||
#[allow(clippy::type_repetition_in_bounds)]
|
||||
enum EnumProjRef<'__pin, T, U>
|
||||
where
|
||||
Enum<T, U>: '__pin,
|
||||
{
|
||||
Struct {
|
||||
pinned: ::pin_project_lite::__private::Pin<&'__pin (T)>,
|
||||
unpinned: &'__pin (U),
|
||||
},
|
||||
Unit,
|
||||
}
|
||||
#[allow(dead_code)]
|
||||
#[allow(single_use_lifetimes)]
|
||||
#[allow(clippy::mut_mut)]
|
||||
#[allow(clippy::redundant_pub_crate)]
|
||||
#[allow(clippy::type_repetition_in_bounds)]
|
||||
enum EnumProjReplace<T, U> {
|
||||
Struct {
|
||||
pinned: ::pin_project_lite::__private::PhantomData<T>,
|
||||
unpinned: U,
|
||||
},
|
||||
Unit,
|
||||
}
|
||||
#[allow(single_use_lifetimes)]
|
||||
#[allow(clippy::unknown_clippy_lints)]
|
||||
#[allow(clippy::used_underscore_binding)]
|
||||
const _: () = {
|
||||
impl<T, U> Enum<T, U> {
|
||||
fn project<'__pin>(
|
||||
self: ::pin_project_lite::__private::Pin<&'__pin mut Self>,
|
||||
) -> EnumProj<'__pin, T, U> {
|
||||
unsafe {
|
||||
match self.get_unchecked_mut() {
|
||||
Self::Struct { pinned, unpinned } => EnumProj::Struct {
|
||||
pinned: ::pin_project_lite::__private::Pin::new_unchecked(pinned),
|
||||
unpinned: unpinned,
|
||||
},
|
||||
Self::Unit => EnumProj::Unit,
|
||||
}
|
||||
}
|
||||
}
|
||||
fn project_ref<'__pin>(
|
||||
self: ::pin_project_lite::__private::Pin<&'__pin Self>,
|
||||
) -> EnumProjRef<'__pin, T, U> {
|
||||
unsafe {
|
||||
match self.get_ref() {
|
||||
Self::Struct { pinned, unpinned } => EnumProjRef::Struct {
|
||||
pinned: ::pin_project_lite::__private::Pin::new_unchecked(pinned),
|
||||
unpinned: unpinned,
|
||||
},
|
||||
Self::Unit => EnumProjRef::Unit,
|
||||
}
|
||||
}
|
||||
}
|
||||
fn project_replace(
|
||||
self: ::pin_project_lite::__private::Pin<&mut Self>,
|
||||
replacement: Self,
|
||||
) -> EnumProjReplace<T, U> {
|
||||
unsafe {
|
||||
let __self_ptr: *mut Self = self.get_unchecked_mut();
|
||||
let __guard = ::pin_project_lite::__private::UnsafeOverwriteGuard {
|
||||
target: __self_ptr,
|
||||
value: ::pin_project_lite::__private::ManuallyDrop::new(replacement),
|
||||
};
|
||||
match &mut *__self_ptr {
|
||||
Self::Struct { pinned, unpinned } => {
|
||||
let result = EnumProjReplace::Struct {
|
||||
pinned: ::pin_project_lite::__private::PhantomData,
|
||||
unpinned: ::pin_project_lite::__private::ptr::read(unpinned),
|
||||
};
|
||||
{
|
||||
(
|
||||
::pin_project_lite::__private::UnsafeDropInPlaceGuard(pinned),
|
||||
(),
|
||||
);
|
||||
}
|
||||
result
|
||||
}
|
||||
Self::Unit => EnumProjReplace::Unit,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#[allow(non_snake_case)]
|
||||
struct __Origin<'__pin, T, U> {
|
||||
__dummy_lifetime: ::pin_project_lite::__private::PhantomData<&'__pin ()>,
|
||||
Struct: (T, ::pin_project_lite::__private::AlwaysUnpin<U>),
|
||||
Unit: (),
|
||||
}
|
||||
impl<'__pin, T, U> ::pin_project_lite::__private::Unpin for Enum<T, U> where
|
||||
__Origin<'__pin, T, U>: ::pin_project_lite::__private::Unpin
|
||||
{
|
||||
}
|
||||
trait MustNotImplDrop {}
|
||||
#[allow(clippy::drop_bounds, drop_bounds)]
|
||||
impl<T: ::pin_project_lite::__private::Drop> MustNotImplDrop for T {}
|
||||
impl<T, U> MustNotImplDrop for Enum<T, U> {}
|
||||
};
|
||||
fn main() {}
|
|
@ -0,0 +1,17 @@
|
|||
use pin_project_lite::pin_project;
|
||||
|
||||
pin_project! {
|
||||
#[project = EnumProj]
|
||||
#[project_ref = EnumProjRef]
|
||||
#[project_replace = EnumProjReplace]
|
||||
enum Enum<T, U> {
|
||||
Struct {
|
||||
#[pin]
|
||||
pinned: T,
|
||||
unpinned: U,
|
||||
},
|
||||
Unit,
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
84
third_party/rust/pin-project-lite/tests/expand/default/struct.expanded.rs
поставляемый
Normal file
84
third_party/rust/pin-project-lite/tests/expand/default/struct.expanded.rs
поставляемый
Normal file
|
@ -0,0 +1,84 @@
|
|||
use pin_project_lite::pin_project;
|
||||
struct Struct<T, U> {
|
||||
pinned: T,
|
||||
unpinned: U,
|
||||
}
|
||||
#[allow(explicit_outlives_requirements)]
|
||||
#[allow(single_use_lifetimes)]
|
||||
#[allow(clippy::unknown_clippy_lints)]
|
||||
#[allow(clippy::redundant_pub_crate)]
|
||||
#[allow(clippy::used_underscore_binding)]
|
||||
const _: () = {
|
||||
#[allow(dead_code)]
|
||||
#[allow(single_use_lifetimes)]
|
||||
#[allow(clippy::unknown_clippy_lints)]
|
||||
#[allow(clippy::mut_mut)]
|
||||
#[allow(clippy::redundant_pub_crate)]
|
||||
#[allow(clippy::ref_option_ref)]
|
||||
#[allow(clippy::type_repetition_in_bounds)]
|
||||
struct Projection<'__pin, T, U>
|
||||
where
|
||||
Struct<T, U>: '__pin,
|
||||
{
|
||||
pinned: ::pin_project_lite::__private::Pin<&'__pin mut (T)>,
|
||||
unpinned: &'__pin mut (U),
|
||||
}
|
||||
#[allow(dead_code)]
|
||||
#[allow(single_use_lifetimes)]
|
||||
#[allow(clippy::unknown_clippy_lints)]
|
||||
#[allow(clippy::mut_mut)]
|
||||
#[allow(clippy::redundant_pub_crate)]
|
||||
#[allow(clippy::ref_option_ref)]
|
||||
#[allow(clippy::type_repetition_in_bounds)]
|
||||
struct ProjectionRef<'__pin, T, U>
|
||||
where
|
||||
Struct<T, U>: '__pin,
|
||||
{
|
||||
pinned: ::pin_project_lite::__private::Pin<&'__pin (T)>,
|
||||
unpinned: &'__pin (U),
|
||||
}
|
||||
impl<T, U> Struct<T, U> {
|
||||
fn project<'__pin>(
|
||||
self: ::pin_project_lite::__private::Pin<&'__pin mut Self>,
|
||||
) -> Projection<'__pin, T, U> {
|
||||
unsafe {
|
||||
let Self { pinned, unpinned } = self.get_unchecked_mut();
|
||||
Projection {
|
||||
pinned: ::pin_project_lite::__private::Pin::new_unchecked(pinned),
|
||||
unpinned: unpinned,
|
||||
}
|
||||
}
|
||||
}
|
||||
fn project_ref<'__pin>(
|
||||
self: ::pin_project_lite::__private::Pin<&'__pin Self>,
|
||||
) -> ProjectionRef<'__pin, T, U> {
|
||||
unsafe {
|
||||
let Self { pinned, unpinned } = self.get_ref();
|
||||
ProjectionRef {
|
||||
pinned: ::pin_project_lite::__private::Pin::new_unchecked(pinned),
|
||||
unpinned: unpinned,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#[allow(non_snake_case)]
|
||||
struct __Origin<'__pin, T, U> {
|
||||
__dummy_lifetime: ::pin_project_lite::__private::PhantomData<&'__pin ()>,
|
||||
pinned: T,
|
||||
unpinned: ::pin_project_lite::__private::AlwaysUnpin<U>,
|
||||
}
|
||||
impl<'__pin, T, U> ::pin_project_lite::__private::Unpin for Struct<T, U> where
|
||||
__Origin<'__pin, T, U>: ::pin_project_lite::__private::Unpin
|
||||
{
|
||||
}
|
||||
trait MustNotImplDrop {}
|
||||
#[allow(clippy::drop_bounds, drop_bounds)]
|
||||
impl<T: ::pin_project_lite::__private::Drop> MustNotImplDrop for T {}
|
||||
impl<T, U> MustNotImplDrop for Struct<T, U> {}
|
||||
#[forbid(unaligned_references, safe_packed_borrows)]
|
||||
fn __assert_not_repr_packed<T, U>(this: &Struct<T, U>) {
|
||||
let _ = &this.pinned;
|
||||
let _ = &this.unpinned;
|
||||
}
|
||||
};
|
||||
fn main() {}
|
|
@ -0,0 +1,11 @@
|
|||
use pin_project_lite::pin_project;
|
||||
|
||||
pin_project! {
|
||||
struct Struct<T, U> {
|
||||
#[pin]
|
||||
pinned: T,
|
||||
unpinned: U,
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
88
third_party/rust/pin-project-lite/tests/expand/multifields/enum.expanded.rs
поставляемый
Normal file
88
third_party/rust/pin-project-lite/tests/expand/multifields/enum.expanded.rs
поставляемый
Normal file
|
@ -0,0 +1,88 @@
|
|||
use pin_project_lite::pin_project;
|
||||
enum Enum<T, U> {
|
||||
Struct {
|
||||
pinned1: T,
|
||||
pinned2: T,
|
||||
unpinned1: U,
|
||||
unpinned2: U,
|
||||
},
|
||||
Unit,
|
||||
}
|
||||
#[allow(dead_code)]
|
||||
#[allow(single_use_lifetimes)]
|
||||
#[allow(clippy::mut_mut)]
|
||||
#[allow(clippy::redundant_pub_crate)]
|
||||
#[allow(clippy::type_repetition_in_bounds)]
|
||||
enum EnumProjReplace<T, U> {
|
||||
Struct {
|
||||
pinned1: ::pin_project_lite::__private::PhantomData<T>,
|
||||
pinned2: ::pin_project_lite::__private::PhantomData<T>,
|
||||
unpinned1: U,
|
||||
unpinned2: U,
|
||||
},
|
||||
Unit,
|
||||
}
|
||||
#[allow(single_use_lifetimes)]
|
||||
#[allow(clippy::unknown_clippy_lints)]
|
||||
#[allow(clippy::used_underscore_binding)]
|
||||
const _: () = {
|
||||
impl<T, U> Enum<T, U> {
|
||||
fn project_replace(
|
||||
self: ::pin_project_lite::__private::Pin<&mut Self>,
|
||||
replacement: Self,
|
||||
) -> EnumProjReplace<T, U> {
|
||||
unsafe {
|
||||
let __self_ptr: *mut Self = self.get_unchecked_mut();
|
||||
let __guard = ::pin_project_lite::__private::UnsafeOverwriteGuard {
|
||||
target: __self_ptr,
|
||||
value: ::pin_project_lite::__private::ManuallyDrop::new(replacement),
|
||||
};
|
||||
match &mut *__self_ptr {
|
||||
Self::Struct {
|
||||
pinned1,
|
||||
pinned2,
|
||||
unpinned1,
|
||||
unpinned2,
|
||||
} => {
|
||||
let result = EnumProjReplace::Struct {
|
||||
pinned1: ::pin_project_lite::__private::PhantomData,
|
||||
pinned2: ::pin_project_lite::__private::PhantomData,
|
||||
unpinned1: ::pin_project_lite::__private::ptr::read(unpinned1),
|
||||
unpinned2: ::pin_project_lite::__private::ptr::read(unpinned2),
|
||||
};
|
||||
{
|
||||
(
|
||||
::pin_project_lite::__private::UnsafeDropInPlaceGuard(pinned1),
|
||||
::pin_project_lite::__private::UnsafeDropInPlaceGuard(pinned2),
|
||||
(),
|
||||
(),
|
||||
);
|
||||
}
|
||||
result
|
||||
}
|
||||
Self::Unit => EnumProjReplace::Unit,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#[allow(non_snake_case)]
|
||||
struct __Origin<'__pin, T, U> {
|
||||
__dummy_lifetime: ::pin_project_lite::__private::PhantomData<&'__pin ()>,
|
||||
Struct: (
|
||||
T,
|
||||
T,
|
||||
::pin_project_lite::__private::AlwaysUnpin<U>,
|
||||
::pin_project_lite::__private::AlwaysUnpin<U>,
|
||||
),
|
||||
Unit: (),
|
||||
}
|
||||
impl<'__pin, T, U> ::pin_project_lite::__private::Unpin for Enum<T, U> where
|
||||
__Origin<'__pin, T, U>: ::pin_project_lite::__private::Unpin
|
||||
{
|
||||
}
|
||||
trait MustNotImplDrop {}
|
||||
#[allow(clippy::drop_bounds, drop_bounds)]
|
||||
impl<T: ::pin_project_lite::__private::Drop> MustNotImplDrop for T {}
|
||||
impl<T, U> MustNotImplDrop for Enum<T, U> {}
|
||||
};
|
||||
fn main() {}
|
|
@ -0,0 +1,18 @@
|
|||
use pin_project_lite::pin_project;
|
||||
|
||||
pin_project! {
|
||||
#[project_replace = EnumProjReplace]
|
||||
enum Enum<T, U> {
|
||||
Struct {
|
||||
#[pin]
|
||||
pinned1: T,
|
||||
#[pin]
|
||||
pinned2: T,
|
||||
unpinned1: U,
|
||||
unpinned2: U,
|
||||
},
|
||||
Unit,
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
152
third_party/rust/pin-project-lite/tests/expand/multifields/struct.expanded.rs
поставляемый
Normal file
152
third_party/rust/pin-project-lite/tests/expand/multifields/struct.expanded.rs
поставляемый
Normal file
|
@ -0,0 +1,152 @@
|
|||
use pin_project_lite::pin_project;
|
||||
struct Struct<T, U> {
|
||||
pinned1: T,
|
||||
pinned2: T,
|
||||
unpinned1: U,
|
||||
unpinned2: U,
|
||||
}
|
||||
#[allow(dead_code)]
|
||||
#[allow(single_use_lifetimes)]
|
||||
#[allow(clippy::mut_mut)]
|
||||
#[allow(clippy::redundant_pub_crate)]
|
||||
#[allow(clippy::type_repetition_in_bounds)]
|
||||
struct StructProjReplace<T, U> {
|
||||
pinned1: ::pin_project_lite::__private::PhantomData<T>,
|
||||
pinned2: ::pin_project_lite::__private::PhantomData<T>,
|
||||
unpinned1: U,
|
||||
unpinned2: U,
|
||||
}
|
||||
#[allow(explicit_outlives_requirements)]
|
||||
#[allow(single_use_lifetimes)]
|
||||
#[allow(clippy::unknown_clippy_lints)]
|
||||
#[allow(clippy::redundant_pub_crate)]
|
||||
#[allow(clippy::used_underscore_binding)]
|
||||
const _: () = {
|
||||
#[allow(dead_code)]
|
||||
#[allow(single_use_lifetimes)]
|
||||
#[allow(clippy::unknown_clippy_lints)]
|
||||
#[allow(clippy::mut_mut)]
|
||||
#[allow(clippy::redundant_pub_crate)]
|
||||
#[allow(clippy::ref_option_ref)]
|
||||
#[allow(clippy::type_repetition_in_bounds)]
|
||||
struct Projection<'__pin, T, U>
|
||||
where
|
||||
Struct<T, U>: '__pin,
|
||||
{
|
||||
pinned1: ::pin_project_lite::__private::Pin<&'__pin mut (T)>,
|
||||
pinned2: ::pin_project_lite::__private::Pin<&'__pin mut (T)>,
|
||||
unpinned1: &'__pin mut (U),
|
||||
unpinned2: &'__pin mut (U),
|
||||
}
|
||||
#[allow(dead_code)]
|
||||
#[allow(single_use_lifetimes)]
|
||||
#[allow(clippy::unknown_clippy_lints)]
|
||||
#[allow(clippy::mut_mut)]
|
||||
#[allow(clippy::redundant_pub_crate)]
|
||||
#[allow(clippy::ref_option_ref)]
|
||||
#[allow(clippy::type_repetition_in_bounds)]
|
||||
struct ProjectionRef<'__pin, T, U>
|
||||
where
|
||||
Struct<T, U>: '__pin,
|
||||
{
|
||||
pinned1: ::pin_project_lite::__private::Pin<&'__pin (T)>,
|
||||
pinned2: ::pin_project_lite::__private::Pin<&'__pin (T)>,
|
||||
unpinned1: &'__pin (U),
|
||||
unpinned2: &'__pin (U),
|
||||
}
|
||||
impl<T, U> Struct<T, U> {
|
||||
fn project<'__pin>(
|
||||
self: ::pin_project_lite::__private::Pin<&'__pin mut Self>,
|
||||
) -> Projection<'__pin, T, U> {
|
||||
unsafe {
|
||||
let Self {
|
||||
pinned1,
|
||||
pinned2,
|
||||
unpinned1,
|
||||
unpinned2,
|
||||
} = self.get_unchecked_mut();
|
||||
Projection {
|
||||
pinned1: ::pin_project_lite::__private::Pin::new_unchecked(pinned1),
|
||||
pinned2: ::pin_project_lite::__private::Pin::new_unchecked(pinned2),
|
||||
unpinned1: unpinned1,
|
||||
unpinned2: unpinned2,
|
||||
}
|
||||
}
|
||||
}
|
||||
fn project_ref<'__pin>(
|
||||
self: ::pin_project_lite::__private::Pin<&'__pin Self>,
|
||||
) -> ProjectionRef<'__pin, T, U> {
|
||||
unsafe {
|
||||
let Self {
|
||||
pinned1,
|
||||
pinned2,
|
||||
unpinned1,
|
||||
unpinned2,
|
||||
} = self.get_ref();
|
||||
ProjectionRef {
|
||||
pinned1: ::pin_project_lite::__private::Pin::new_unchecked(pinned1),
|
||||
pinned2: ::pin_project_lite::__private::Pin::new_unchecked(pinned2),
|
||||
unpinned1: unpinned1,
|
||||
unpinned2: unpinned2,
|
||||
}
|
||||
}
|
||||
}
|
||||
fn project_replace(
|
||||
self: ::pin_project_lite::__private::Pin<&mut Self>,
|
||||
replacement: Self,
|
||||
) -> StructProjReplace<T, U> {
|
||||
unsafe {
|
||||
let __self_ptr: *mut Self = self.get_unchecked_mut();
|
||||
let __guard = ::pin_project_lite::__private::UnsafeOverwriteGuard {
|
||||
target: __self_ptr,
|
||||
value: ::pin_project_lite::__private::ManuallyDrop::new(replacement),
|
||||
};
|
||||
let Self {
|
||||
pinned1,
|
||||
pinned2,
|
||||
unpinned1,
|
||||
unpinned2,
|
||||
} = &mut *__self_ptr;
|
||||
let result = StructProjReplace {
|
||||
pinned1: ::pin_project_lite::__private::PhantomData,
|
||||
pinned2: ::pin_project_lite::__private::PhantomData,
|
||||
unpinned1: ::pin_project_lite::__private::ptr::read(unpinned1),
|
||||
unpinned2: ::pin_project_lite::__private::ptr::read(unpinned2),
|
||||
};
|
||||
{
|
||||
(
|
||||
::pin_project_lite::__private::UnsafeDropInPlaceGuard(pinned1),
|
||||
::pin_project_lite::__private::UnsafeDropInPlaceGuard(pinned2),
|
||||
(),
|
||||
(),
|
||||
);
|
||||
}
|
||||
result
|
||||
}
|
||||
}
|
||||
}
|
||||
#[allow(non_snake_case)]
|
||||
struct __Origin<'__pin, T, U> {
|
||||
__dummy_lifetime: ::pin_project_lite::__private::PhantomData<&'__pin ()>,
|
||||
pinned1: T,
|
||||
pinned2: T,
|
||||
unpinned1: ::pin_project_lite::__private::AlwaysUnpin<U>,
|
||||
unpinned2: ::pin_project_lite::__private::AlwaysUnpin<U>,
|
||||
}
|
||||
impl<'__pin, T, U> ::pin_project_lite::__private::Unpin for Struct<T, U> where
|
||||
__Origin<'__pin, T, U>: ::pin_project_lite::__private::Unpin
|
||||
{
|
||||
}
|
||||
trait MustNotImplDrop {}
|
||||
#[allow(clippy::drop_bounds, drop_bounds)]
|
||||
impl<T: ::pin_project_lite::__private::Drop> MustNotImplDrop for T {}
|
||||
impl<T, U> MustNotImplDrop for Struct<T, U> {}
|
||||
#[forbid(unaligned_references, safe_packed_borrows)]
|
||||
fn __assert_not_repr_packed<T, U>(this: &Struct<T, U>) {
|
||||
let _ = &this.pinned1;
|
||||
let _ = &this.pinned2;
|
||||
let _ = &this.unpinned1;
|
||||
let _ = &this.unpinned2;
|
||||
}
|
||||
};
|
||||
fn main() {}
|
|
@ -0,0 +1,15 @@
|
|||
use pin_project_lite::pin_project;
|
||||
|
||||
pin_project! {
|
||||
#[project_replace = StructProjReplace]
|
||||
struct Struct<T, U> {
|
||||
#[pin]
|
||||
pinned1: T,
|
||||
#[pin]
|
||||
pinned2: T,
|
||||
unpinned1: U,
|
||||
unpinned2: U,
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
127
third_party/rust/pin-project-lite/tests/expand/naming/enum-all.expanded.rs
поставляемый
Normal file
127
third_party/rust/pin-project-lite/tests/expand/naming/enum-all.expanded.rs
поставляемый
Normal file
|
@ -0,0 +1,127 @@
|
|||
use pin_project_lite::pin_project;
|
||||
enum Enum<T, U> {
|
||||
Struct { pinned: T, unpinned: U },
|
||||
Unit,
|
||||
}
|
||||
#[allow(dead_code)]
|
||||
#[allow(single_use_lifetimes)]
|
||||
#[allow(clippy::unknown_clippy_lints)]
|
||||
#[allow(clippy::mut_mut)]
|
||||
#[allow(clippy::redundant_pub_crate)]
|
||||
#[allow(clippy::ref_option_ref)]
|
||||
#[allow(clippy::type_repetition_in_bounds)]
|
||||
enum EnumProj<'__pin, T, U>
|
||||
where
|
||||
Enum<T, U>: '__pin,
|
||||
{
|
||||
Struct {
|
||||
pinned: ::pin_project_lite::__private::Pin<&'__pin mut (T)>,
|
||||
unpinned: &'__pin mut (U),
|
||||
},
|
||||
Unit,
|
||||
}
|
||||
#[allow(dead_code)]
|
||||
#[allow(single_use_lifetimes)]
|
||||
#[allow(clippy::unknown_clippy_lints)]
|
||||
#[allow(clippy::mut_mut)]
|
||||
#[allow(clippy::redundant_pub_crate)]
|
||||
#[allow(clippy::ref_option_ref)]
|
||||
#[allow(clippy::type_repetition_in_bounds)]
|
||||
enum EnumProjRef<'__pin, T, U>
|
||||
where
|
||||
Enum<T, U>: '__pin,
|
||||
{
|
||||
Struct {
|
||||
pinned: ::pin_project_lite::__private::Pin<&'__pin (T)>,
|
||||
unpinned: &'__pin (U),
|
||||
},
|
||||
Unit,
|
||||
}
|
||||
#[allow(dead_code)]
|
||||
#[allow(single_use_lifetimes)]
|
||||
#[allow(clippy::mut_mut)]
|
||||
#[allow(clippy::redundant_pub_crate)]
|
||||
#[allow(clippy::type_repetition_in_bounds)]
|
||||
enum EnumProjReplace<T, U> {
|
||||
Struct {
|
||||
pinned: ::pin_project_lite::__private::PhantomData<T>,
|
||||
unpinned: U,
|
||||
},
|
||||
Unit,
|
||||
}
|
||||
#[allow(single_use_lifetimes)]
|
||||
#[allow(clippy::unknown_clippy_lints)]
|
||||
#[allow(clippy::used_underscore_binding)]
|
||||
const _: () = {
|
||||
impl<T, U> Enum<T, U> {
|
||||
fn project<'__pin>(
|
||||
self: ::pin_project_lite::__private::Pin<&'__pin mut Self>,
|
||||
) -> EnumProj<'__pin, T, U> {
|
||||
unsafe {
|
||||
match self.get_unchecked_mut() {
|
||||
Self::Struct { pinned, unpinned } => EnumProj::Struct {
|
||||
pinned: ::pin_project_lite::__private::Pin::new_unchecked(pinned),
|
||||
unpinned: unpinned,
|
||||
},
|
||||
Self::Unit => EnumProj::Unit,
|
||||
}
|
||||
}
|
||||
}
|
||||
fn project_ref<'__pin>(
|
||||
self: ::pin_project_lite::__private::Pin<&'__pin Self>,
|
||||
) -> EnumProjRef<'__pin, T, U> {
|
||||
unsafe {
|
||||
match self.get_ref() {
|
||||
Self::Struct { pinned, unpinned } => EnumProjRef::Struct {
|
||||
pinned: ::pin_project_lite::__private::Pin::new_unchecked(pinned),
|
||||
unpinned: unpinned,
|
||||
},
|
||||
Self::Unit => EnumProjRef::Unit,
|
||||
}
|
||||
}
|
||||
}
|
||||
fn project_replace(
|
||||
self: ::pin_project_lite::__private::Pin<&mut Self>,
|
||||
replacement: Self,
|
||||
) -> EnumProjReplace<T, U> {
|
||||
unsafe {
|
||||
let __self_ptr: *mut Self = self.get_unchecked_mut();
|
||||
let __guard = ::pin_project_lite::__private::UnsafeOverwriteGuard {
|
||||
target: __self_ptr,
|
||||
value: ::pin_project_lite::__private::ManuallyDrop::new(replacement),
|
||||
};
|
||||
match &mut *__self_ptr {
|
||||
Self::Struct { pinned, unpinned } => {
|
||||
let result = EnumProjReplace::Struct {
|
||||
pinned: ::pin_project_lite::__private::PhantomData,
|
||||
unpinned: ::pin_project_lite::__private::ptr::read(unpinned),
|
||||
};
|
||||
{
|
||||
(
|
||||
::pin_project_lite::__private::UnsafeDropInPlaceGuard(pinned),
|
||||
(),
|
||||
);
|
||||
}
|
||||
result
|
||||
}
|
||||
Self::Unit => EnumProjReplace::Unit,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#[allow(non_snake_case)]
|
||||
struct __Origin<'__pin, T, U> {
|
||||
__dummy_lifetime: ::pin_project_lite::__private::PhantomData<&'__pin ()>,
|
||||
Struct: (T, ::pin_project_lite::__private::AlwaysUnpin<U>),
|
||||
Unit: (),
|
||||
}
|
||||
impl<'__pin, T, U> ::pin_project_lite::__private::Unpin for Enum<T, U> where
|
||||
__Origin<'__pin, T, U>: ::pin_project_lite::__private::Unpin
|
||||
{
|
||||
}
|
||||
trait MustNotImplDrop {}
|
||||
#[allow(clippy::drop_bounds, drop_bounds)]
|
||||
impl<T: ::pin_project_lite::__private::Drop> MustNotImplDrop for T {}
|
||||
impl<T, U> MustNotImplDrop for Enum<T, U> {}
|
||||
};
|
||||
fn main() {}
|
|
@ -0,0 +1,17 @@
|
|||
use pin_project_lite::pin_project;
|
||||
|
||||
pin_project! {
|
||||
#[project = EnumProj]
|
||||
#[project_ref = EnumProjRef]
|
||||
#[project_replace = EnumProjReplace]
|
||||
enum Enum<T, U> {
|
||||
Struct {
|
||||
#[pin]
|
||||
pinned: T,
|
||||
unpinned: U,
|
||||
},
|
||||
Unit,
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
57
third_party/rust/pin-project-lite/tests/expand/naming/enum-mut.expanded.rs
поставляемый
Normal file
57
third_party/rust/pin-project-lite/tests/expand/naming/enum-mut.expanded.rs
поставляемый
Normal file
|
@ -0,0 +1,57 @@
|
|||
use pin_project_lite::pin_project;
|
||||
enum Enum<T, U> {
|
||||
Struct { pinned: T, unpinned: U },
|
||||
Unit,
|
||||
}
|
||||
#[allow(dead_code)]
|
||||
#[allow(single_use_lifetimes)]
|
||||
#[allow(clippy::unknown_clippy_lints)]
|
||||
#[allow(clippy::mut_mut)]
|
||||
#[allow(clippy::redundant_pub_crate)]
|
||||
#[allow(clippy::ref_option_ref)]
|
||||
#[allow(clippy::type_repetition_in_bounds)]
|
||||
enum EnumProj<'__pin, T, U>
|
||||
where
|
||||
Enum<T, U>: '__pin,
|
||||
{
|
||||
Struct {
|
||||
pinned: ::pin_project_lite::__private::Pin<&'__pin mut (T)>,
|
||||
unpinned: &'__pin mut (U),
|
||||
},
|
||||
Unit,
|
||||
}
|
||||
#[allow(single_use_lifetimes)]
|
||||
#[allow(clippy::unknown_clippy_lints)]
|
||||
#[allow(clippy::used_underscore_binding)]
|
||||
const _: () = {
|
||||
impl<T, U> Enum<T, U> {
|
||||
fn project<'__pin>(
|
||||
self: ::pin_project_lite::__private::Pin<&'__pin mut Self>,
|
||||
) -> EnumProj<'__pin, T, U> {
|
||||
unsafe {
|
||||
match self.get_unchecked_mut() {
|
||||
Self::Struct { pinned, unpinned } => EnumProj::Struct {
|
||||
pinned: ::pin_project_lite::__private::Pin::new_unchecked(pinned),
|
||||
unpinned: unpinned,
|
||||
},
|
||||
Self::Unit => EnumProj::Unit,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#[allow(non_snake_case)]
|
||||
struct __Origin<'__pin, T, U> {
|
||||
__dummy_lifetime: ::pin_project_lite::__private::PhantomData<&'__pin ()>,
|
||||
Struct: (T, ::pin_project_lite::__private::AlwaysUnpin<U>),
|
||||
Unit: (),
|
||||
}
|
||||
impl<'__pin, T, U> ::pin_project_lite::__private::Unpin for Enum<T, U> where
|
||||
__Origin<'__pin, T, U>: ::pin_project_lite::__private::Unpin
|
||||
{
|
||||
}
|
||||
trait MustNotImplDrop {}
|
||||
#[allow(clippy::drop_bounds, drop_bounds)]
|
||||
impl<T: ::pin_project_lite::__private::Drop> MustNotImplDrop for T {}
|
||||
impl<T, U> MustNotImplDrop for Enum<T, U> {}
|
||||
};
|
||||
fn main() {}
|
|
@ -0,0 +1,15 @@
|
|||
use pin_project_lite::pin_project;
|
||||
|
||||
pin_project! {
|
||||
#[project = EnumProj]
|
||||
enum Enum<T, U> {
|
||||
Struct {
|
||||
#[pin]
|
||||
pinned: T,
|
||||
unpinned: U,
|
||||
},
|
||||
Unit,
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
26
third_party/rust/pin-project-lite/tests/expand/naming/enum-none.expanded.rs
поставляемый
Normal file
26
third_party/rust/pin-project-lite/tests/expand/naming/enum-none.expanded.rs
поставляемый
Normal file
|
@ -0,0 +1,26 @@
|
|||
use pin_project_lite::pin_project;
|
||||
enum Enum<T, U> {
|
||||
Struct { pinned: T, unpinned: U },
|
||||
Unit,
|
||||
}
|
||||
#[allow(single_use_lifetimes)]
|
||||
#[allow(clippy::unknown_clippy_lints)]
|
||||
#[allow(clippy::used_underscore_binding)]
|
||||
const _: () = {
|
||||
impl<T, U> Enum<T, U> {}
|
||||
#[allow(non_snake_case)]
|
||||
struct __Origin<'__pin, T, U> {
|
||||
__dummy_lifetime: ::pin_project_lite::__private::PhantomData<&'__pin ()>,
|
||||
Struct: (T, ::pin_project_lite::__private::AlwaysUnpin<U>),
|
||||
Unit: (),
|
||||
}
|
||||
impl<'__pin, T, U> ::pin_project_lite::__private::Unpin for Enum<T, U> where
|
||||
__Origin<'__pin, T, U>: ::pin_project_lite::__private::Unpin
|
||||
{
|
||||
}
|
||||
trait MustNotImplDrop {}
|
||||
#[allow(clippy::drop_bounds, drop_bounds)]
|
||||
impl<T: ::pin_project_lite::__private::Drop> MustNotImplDrop for T {}
|
||||
impl<T, U> MustNotImplDrop for Enum<T, U> {}
|
||||
};
|
||||
fn main() {}
|
|
@ -0,0 +1,14 @@
|
|||
use pin_project_lite::pin_project;
|
||||
|
||||
pin_project! {
|
||||
enum Enum<T, U> {
|
||||
Struct {
|
||||
#[pin]
|
||||
pinned: T,
|
||||
unpinned: U,
|
||||
},
|
||||
Unit,
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
57
third_party/rust/pin-project-lite/tests/expand/naming/enum-ref.expanded.rs
поставляемый
Normal file
57
third_party/rust/pin-project-lite/tests/expand/naming/enum-ref.expanded.rs
поставляемый
Normal file
|
@ -0,0 +1,57 @@
|
|||
use pin_project_lite::pin_project;
|
||||
enum Enum<T, U> {
|
||||
Struct { pinned: T, unpinned: U },
|
||||
Unit,
|
||||
}
|
||||
#[allow(dead_code)]
|
||||
#[allow(single_use_lifetimes)]
|
||||
#[allow(clippy::unknown_clippy_lints)]
|
||||
#[allow(clippy::mut_mut)]
|
||||
#[allow(clippy::redundant_pub_crate)]
|
||||
#[allow(clippy::ref_option_ref)]
|
||||
#[allow(clippy::type_repetition_in_bounds)]
|
||||
enum EnumProjRef<'__pin, T, U>
|
||||
where
|
||||
Enum<T, U>: '__pin,
|
||||
{
|
||||
Struct {
|
||||
pinned: ::pin_project_lite::__private::Pin<&'__pin (T)>,
|
||||
unpinned: &'__pin (U),
|
||||
},
|
||||
Unit,
|
||||
}
|
||||
#[allow(single_use_lifetimes)]
|
||||
#[allow(clippy::unknown_clippy_lints)]
|
||||
#[allow(clippy::used_underscore_binding)]
|
||||
const _: () = {
|
||||
impl<T, U> Enum<T, U> {
|
||||
fn project_ref<'__pin>(
|
||||
self: ::pin_project_lite::__private::Pin<&'__pin Self>,
|
||||
) -> EnumProjRef<'__pin, T, U> {
|
||||
unsafe {
|
||||
match self.get_ref() {
|
||||
Self::Struct { pinned, unpinned } => EnumProjRef::Struct {
|
||||
pinned: ::pin_project_lite::__private::Pin::new_unchecked(pinned),
|
||||
unpinned: unpinned,
|
||||
},
|
||||
Self::Unit => EnumProjRef::Unit,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#[allow(non_snake_case)]
|
||||
struct __Origin<'__pin, T, U> {
|
||||
__dummy_lifetime: ::pin_project_lite::__private::PhantomData<&'__pin ()>,
|
||||
Struct: (T, ::pin_project_lite::__private::AlwaysUnpin<U>),
|
||||
Unit: (),
|
||||
}
|
||||
impl<'__pin, T, U> ::pin_project_lite::__private::Unpin for Enum<T, U> where
|
||||
__Origin<'__pin, T, U>: ::pin_project_lite::__private::Unpin
|
||||
{
|
||||
}
|
||||
trait MustNotImplDrop {}
|
||||
#[allow(clippy::drop_bounds, drop_bounds)]
|
||||
impl<T: ::pin_project_lite::__private::Drop> MustNotImplDrop for T {}
|
||||
impl<T, U> MustNotImplDrop for Enum<T, U> {}
|
||||
};
|
||||
fn main() {}
|
|
@ -0,0 +1,15 @@
|
|||
use pin_project_lite::pin_project;
|
||||
|
||||
pin_project! {
|
||||
#[project_ref = EnumProjRef]
|
||||
enum Enum<T, U> {
|
||||
Struct {
|
||||
#[pin]
|
||||
pinned: T,
|
||||
unpinned: U,
|
||||
},
|
||||
Unit,
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
117
third_party/rust/pin-project-lite/tests/expand/naming/struct-all.expanded.rs
поставляемый
Normal file
117
third_party/rust/pin-project-lite/tests/expand/naming/struct-all.expanded.rs
поставляемый
Normal file
|
@ -0,0 +1,117 @@
|
|||
use pin_project_lite::pin_project;
|
||||
struct Struct<T, U> {
|
||||
pinned: T,
|
||||
unpinned: U,
|
||||
}
|
||||
#[allow(dead_code)]
|
||||
#[allow(single_use_lifetimes)]
|
||||
#[allow(clippy::unknown_clippy_lints)]
|
||||
#[allow(clippy::mut_mut)]
|
||||
#[allow(clippy::redundant_pub_crate)]
|
||||
#[allow(clippy::ref_option_ref)]
|
||||
#[allow(clippy::type_repetition_in_bounds)]
|
||||
struct StructProj<'__pin, T, U>
|
||||
where
|
||||
Struct<T, U>: '__pin,
|
||||
{
|
||||
pinned: ::pin_project_lite::__private::Pin<&'__pin mut (T)>,
|
||||
unpinned: &'__pin mut (U),
|
||||
}
|
||||
#[allow(dead_code)]
|
||||
#[allow(single_use_lifetimes)]
|
||||
#[allow(clippy::unknown_clippy_lints)]
|
||||
#[allow(clippy::mut_mut)]
|
||||
#[allow(clippy::redundant_pub_crate)]
|
||||
#[allow(clippy::ref_option_ref)]
|
||||
#[allow(clippy::type_repetition_in_bounds)]
|
||||
struct StructProjRef<'__pin, T, U>
|
||||
where
|
||||
Struct<T, U>: '__pin,
|
||||
{
|
||||
pinned: ::pin_project_lite::__private::Pin<&'__pin (T)>,
|
||||
unpinned: &'__pin (U),
|
||||
}
|
||||
#[allow(dead_code)]
|
||||
#[allow(single_use_lifetimes)]
|
||||
#[allow(clippy::mut_mut)]
|
||||
#[allow(clippy::redundant_pub_crate)]
|
||||
#[allow(clippy::type_repetition_in_bounds)]
|
||||
struct StructProjReplace<T, U> {
|
||||
pinned: ::pin_project_lite::__private::PhantomData<T>,
|
||||
unpinned: U,
|
||||
}
|
||||
#[allow(explicit_outlives_requirements)]
|
||||
#[allow(single_use_lifetimes)]
|
||||
#[allow(clippy::unknown_clippy_lints)]
|
||||
#[allow(clippy::redundant_pub_crate)]
|
||||
#[allow(clippy::used_underscore_binding)]
|
||||
const _: () = {
|
||||
impl<T, U> Struct<T, U> {
|
||||
fn project<'__pin>(
|
||||
self: ::pin_project_lite::__private::Pin<&'__pin mut Self>,
|
||||
) -> StructProj<'__pin, T, U> {
|
||||
unsafe {
|
||||
let Self { pinned, unpinned } = self.get_unchecked_mut();
|
||||
StructProj {
|
||||
pinned: ::pin_project_lite::__private::Pin::new_unchecked(pinned),
|
||||
unpinned: unpinned,
|
||||
}
|
||||
}
|
||||
}
|
||||
fn project_ref<'__pin>(
|
||||
self: ::pin_project_lite::__private::Pin<&'__pin Self>,
|
||||
) -> StructProjRef<'__pin, T, U> {
|
||||
unsafe {
|
||||
let Self { pinned, unpinned } = self.get_ref();
|
||||
StructProjRef {
|
||||
pinned: ::pin_project_lite::__private::Pin::new_unchecked(pinned),
|
||||
unpinned: unpinned,
|
||||
}
|
||||
}
|
||||
}
|
||||
fn project_replace(
|
||||
self: ::pin_project_lite::__private::Pin<&mut Self>,
|
||||
replacement: Self,
|
||||
) -> StructProjReplace<T, U> {
|
||||
unsafe {
|
||||
let __self_ptr: *mut Self = self.get_unchecked_mut();
|
||||
let __guard = ::pin_project_lite::__private::UnsafeOverwriteGuard {
|
||||
target: __self_ptr,
|
||||
value: ::pin_project_lite::__private::ManuallyDrop::new(replacement),
|
||||
};
|
||||
let Self { pinned, unpinned } = &mut *__self_ptr;
|
||||
let result = StructProjReplace {
|
||||
pinned: ::pin_project_lite::__private::PhantomData,
|
||||
unpinned: ::pin_project_lite::__private::ptr::read(unpinned),
|
||||
};
|
||||
{
|
||||
(
|
||||
::pin_project_lite::__private::UnsafeDropInPlaceGuard(pinned),
|
||||
(),
|
||||
);
|
||||
}
|
||||
result
|
||||
}
|
||||
}
|
||||
}
|
||||
#[allow(non_snake_case)]
|
||||
struct __Origin<'__pin, T, U> {
|
||||
__dummy_lifetime: ::pin_project_lite::__private::PhantomData<&'__pin ()>,
|
||||
pinned: T,
|
||||
unpinned: ::pin_project_lite::__private::AlwaysUnpin<U>,
|
||||
}
|
||||
impl<'__pin, T, U> ::pin_project_lite::__private::Unpin for Struct<T, U> where
|
||||
__Origin<'__pin, T, U>: ::pin_project_lite::__private::Unpin
|
||||
{
|
||||
}
|
||||
trait MustNotImplDrop {}
|
||||
#[allow(clippy::drop_bounds, drop_bounds)]
|
||||
impl<T: ::pin_project_lite::__private::Drop> MustNotImplDrop for T {}
|
||||
impl<T, U> MustNotImplDrop for Struct<T, U> {}
|
||||
#[forbid(unaligned_references, safe_packed_borrows)]
|
||||
fn __assert_not_repr_packed<T, U>(this: &Struct<T, U>) {
|
||||
let _ = &this.pinned;
|
||||
let _ = &this.unpinned;
|
||||
}
|
||||
};
|
||||
fn main() {}
|
|
@ -0,0 +1,14 @@
|
|||
use pin_project_lite::pin_project;
|
||||
|
||||
pin_project! {
|
||||
#[project = StructProj]
|
||||
#[project_ref = StructProjRef]
|
||||
#[project_replace = StructProjReplace]
|
||||
struct Struct<T, U> {
|
||||
#[pin]
|
||||
pinned: T,
|
||||
unpinned: U,
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
84
third_party/rust/pin-project-lite/tests/expand/naming/struct-mut.expanded.rs
поставляемый
Normal file
84
third_party/rust/pin-project-lite/tests/expand/naming/struct-mut.expanded.rs
поставляемый
Normal file
|
@ -0,0 +1,84 @@
|
|||
use pin_project_lite::pin_project;
|
||||
struct Struct<T, U> {
|
||||
pinned: T,
|
||||
unpinned: U,
|
||||
}
|
||||
#[allow(dead_code)]
|
||||
#[allow(single_use_lifetimes)]
|
||||
#[allow(clippy::unknown_clippy_lints)]
|
||||
#[allow(clippy::mut_mut)]
|
||||
#[allow(clippy::redundant_pub_crate)]
|
||||
#[allow(clippy::ref_option_ref)]
|
||||
#[allow(clippy::type_repetition_in_bounds)]
|
||||
struct StructProj<'__pin, T, U>
|
||||
where
|
||||
Struct<T, U>: '__pin,
|
||||
{
|
||||
pinned: ::pin_project_lite::__private::Pin<&'__pin mut (T)>,
|
||||
unpinned: &'__pin mut (U),
|
||||
}
|
||||
#[allow(explicit_outlives_requirements)]
|
||||
#[allow(single_use_lifetimes)]
|
||||
#[allow(clippy::unknown_clippy_lints)]
|
||||
#[allow(clippy::redundant_pub_crate)]
|
||||
#[allow(clippy::used_underscore_binding)]
|
||||
const _: () = {
|
||||
#[allow(dead_code)]
|
||||
#[allow(single_use_lifetimes)]
|
||||
#[allow(clippy::unknown_clippy_lints)]
|
||||
#[allow(clippy::mut_mut)]
|
||||
#[allow(clippy::redundant_pub_crate)]
|
||||
#[allow(clippy::ref_option_ref)]
|
||||
#[allow(clippy::type_repetition_in_bounds)]
|
||||
struct ProjectionRef<'__pin, T, U>
|
||||
where
|
||||
Struct<T, U>: '__pin,
|
||||
{
|
||||
pinned: ::pin_project_lite::__private::Pin<&'__pin (T)>,
|
||||
unpinned: &'__pin (U),
|
||||
}
|
||||
impl<T, U> Struct<T, U> {
|
||||
fn project<'__pin>(
|
||||
self: ::pin_project_lite::__private::Pin<&'__pin mut Self>,
|
||||
) -> StructProj<'__pin, T, U> {
|
||||
unsafe {
|
||||
let Self { pinned, unpinned } = self.get_unchecked_mut();
|
||||
StructProj {
|
||||
pinned: ::pin_project_lite::__private::Pin::new_unchecked(pinned),
|
||||
unpinned: unpinned,
|
||||
}
|
||||
}
|
||||
}
|
||||
fn project_ref<'__pin>(
|
||||
self: ::pin_project_lite::__private::Pin<&'__pin Self>,
|
||||
) -> ProjectionRef<'__pin, T, U> {
|
||||
unsafe {
|
||||
let Self { pinned, unpinned } = self.get_ref();
|
||||
ProjectionRef {
|
||||
pinned: ::pin_project_lite::__private::Pin::new_unchecked(pinned),
|
||||
unpinned: unpinned,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#[allow(non_snake_case)]
|
||||
struct __Origin<'__pin, T, U> {
|
||||
__dummy_lifetime: ::pin_project_lite::__private::PhantomData<&'__pin ()>,
|
||||
pinned: T,
|
||||
unpinned: ::pin_project_lite::__private::AlwaysUnpin<U>,
|
||||
}
|
||||
impl<'__pin, T, U> ::pin_project_lite::__private::Unpin for Struct<T, U> where
|
||||
__Origin<'__pin, T, U>: ::pin_project_lite::__private::Unpin
|
||||
{
|
||||
}
|
||||
trait MustNotImplDrop {}
|
||||
#[allow(clippy::drop_bounds, drop_bounds)]
|
||||
impl<T: ::pin_project_lite::__private::Drop> MustNotImplDrop for T {}
|
||||
impl<T, U> MustNotImplDrop for Struct<T, U> {}
|
||||
#[forbid(unaligned_references, safe_packed_borrows)]
|
||||
fn __assert_not_repr_packed<T, U>(this: &Struct<T, U>) {
|
||||
let _ = &this.pinned;
|
||||
let _ = &this.unpinned;
|
||||
}
|
||||
};
|
||||
fn main() {}
|
|
@ -0,0 +1,12 @@
|
|||
use pin_project_lite::pin_project;
|
||||
|
||||
pin_project! {
|
||||
#[project = StructProj]
|
||||
struct Struct<T, U> {
|
||||
#[pin]
|
||||
pinned: T,
|
||||
unpinned: U,
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
84
third_party/rust/pin-project-lite/tests/expand/naming/struct-none.expanded.rs
поставляемый
Normal file
84
third_party/rust/pin-project-lite/tests/expand/naming/struct-none.expanded.rs
поставляемый
Normal file
|
@ -0,0 +1,84 @@
|
|||
use pin_project_lite::pin_project;
|
||||
struct Struct<T, U> {
|
||||
pinned: T,
|
||||
unpinned: U,
|
||||
}
|
||||
#[allow(explicit_outlives_requirements)]
|
||||
#[allow(single_use_lifetimes)]
|
||||
#[allow(clippy::unknown_clippy_lints)]
|
||||
#[allow(clippy::redundant_pub_crate)]
|
||||
#[allow(clippy::used_underscore_binding)]
|
||||
const _: () = {
|
||||
#[allow(dead_code)]
|
||||
#[allow(single_use_lifetimes)]
|
||||
#[allow(clippy::unknown_clippy_lints)]
|
||||
#[allow(clippy::mut_mut)]
|
||||
#[allow(clippy::redundant_pub_crate)]
|
||||
#[allow(clippy::ref_option_ref)]
|
||||
#[allow(clippy::type_repetition_in_bounds)]
|
||||
struct Projection<'__pin, T, U>
|
||||
where
|
||||
Struct<T, U>: '__pin,
|
||||
{
|
||||
pinned: ::pin_project_lite::__private::Pin<&'__pin mut (T)>,
|
||||
unpinned: &'__pin mut (U),
|
||||
}
|
||||
#[allow(dead_code)]
|
||||
#[allow(single_use_lifetimes)]
|
||||
#[allow(clippy::unknown_clippy_lints)]
|
||||
#[allow(clippy::mut_mut)]
|
||||
#[allow(clippy::redundant_pub_crate)]
|
||||
#[allow(clippy::ref_option_ref)]
|
||||
#[allow(clippy::type_repetition_in_bounds)]
|
||||
struct ProjectionRef<'__pin, T, U>
|
||||
where
|
||||
Struct<T, U>: '__pin,
|
||||
{
|
||||
pinned: ::pin_project_lite::__private::Pin<&'__pin (T)>,
|
||||
unpinned: &'__pin (U),
|
||||
}
|
||||
impl<T, U> Struct<T, U> {
|
||||
fn project<'__pin>(
|
||||
self: ::pin_project_lite::__private::Pin<&'__pin mut Self>,
|
||||
) -> Projection<'__pin, T, U> {
|
||||
unsafe {
|
||||
let Self { pinned, unpinned } = self.get_unchecked_mut();
|
||||
Projection {
|
||||
pinned: ::pin_project_lite::__private::Pin::new_unchecked(pinned),
|
||||
unpinned: unpinned,
|
||||
}
|
||||
}
|
||||
}
|
||||
fn project_ref<'__pin>(
|
||||
self: ::pin_project_lite::__private::Pin<&'__pin Self>,
|
||||
) -> ProjectionRef<'__pin, T, U> {
|
||||
unsafe {
|
||||
let Self { pinned, unpinned } = self.get_ref();
|
||||
ProjectionRef {
|
||||
pinned: ::pin_project_lite::__private::Pin::new_unchecked(pinned),
|
||||
unpinned: unpinned,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#[allow(non_snake_case)]
|
||||
struct __Origin<'__pin, T, U> {
|
||||
__dummy_lifetime: ::pin_project_lite::__private::PhantomData<&'__pin ()>,
|
||||
pinned: T,
|
||||
unpinned: ::pin_project_lite::__private::AlwaysUnpin<U>,
|
||||
}
|
||||
impl<'__pin, T, U> ::pin_project_lite::__private::Unpin for Struct<T, U> where
|
||||
__Origin<'__pin, T, U>: ::pin_project_lite::__private::Unpin
|
||||
{
|
||||
}
|
||||
trait MustNotImplDrop {}
|
||||
#[allow(clippy::drop_bounds, drop_bounds)]
|
||||
impl<T: ::pin_project_lite::__private::Drop> MustNotImplDrop for T {}
|
||||
impl<T, U> MustNotImplDrop for Struct<T, U> {}
|
||||
#[forbid(unaligned_references, safe_packed_borrows)]
|
||||
fn __assert_not_repr_packed<T, U>(this: &Struct<T, U>) {
|
||||
let _ = &this.pinned;
|
||||
let _ = &this.unpinned;
|
||||
}
|
||||
};
|
||||
fn main() {}
|
|
@ -0,0 +1,11 @@
|
|||
use pin_project_lite::pin_project;
|
||||
|
||||
pin_project! {
|
||||
struct Struct<T, U> {
|
||||
#[pin]
|
||||
pinned: T,
|
||||
unpinned: U,
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
84
third_party/rust/pin-project-lite/tests/expand/naming/struct-ref.expanded.rs
поставляемый
Normal file
84
third_party/rust/pin-project-lite/tests/expand/naming/struct-ref.expanded.rs
поставляемый
Normal file
|
@ -0,0 +1,84 @@
|
|||
use pin_project_lite::pin_project;
|
||||
struct Struct<T, U> {
|
||||
pinned: T,
|
||||
unpinned: U,
|
||||
}
|
||||
#[allow(dead_code)]
|
||||
#[allow(single_use_lifetimes)]
|
||||
#[allow(clippy::unknown_clippy_lints)]
|
||||
#[allow(clippy::mut_mut)]
|
||||
#[allow(clippy::redundant_pub_crate)]
|
||||
#[allow(clippy::ref_option_ref)]
|
||||
#[allow(clippy::type_repetition_in_bounds)]
|
||||
struct StructProjRef<'__pin, T, U>
|
||||
where
|
||||
Struct<T, U>: '__pin,
|
||||
{
|
||||
pinned: ::pin_project_lite::__private::Pin<&'__pin (T)>,
|
||||
unpinned: &'__pin (U),
|
||||
}
|
||||
#[allow(explicit_outlives_requirements)]
|
||||
#[allow(single_use_lifetimes)]
|
||||
#[allow(clippy::unknown_clippy_lints)]
|
||||
#[allow(clippy::redundant_pub_crate)]
|
||||
#[allow(clippy::used_underscore_binding)]
|
||||
const _: () = {
|
||||
#[allow(dead_code)]
|
||||
#[allow(single_use_lifetimes)]
|
||||
#[allow(clippy::unknown_clippy_lints)]
|
||||
#[allow(clippy::mut_mut)]
|
||||
#[allow(clippy::redundant_pub_crate)]
|
||||
#[allow(clippy::ref_option_ref)]
|
||||
#[allow(clippy::type_repetition_in_bounds)]
|
||||
struct Projection<'__pin, T, U>
|
||||
where
|
||||
Struct<T, U>: '__pin,
|
||||
{
|
||||
pinned: ::pin_project_lite::__private::Pin<&'__pin mut (T)>,
|
||||
unpinned: &'__pin mut (U),
|
||||
}
|
||||
impl<T, U> Struct<T, U> {
|
||||
fn project<'__pin>(
|
||||
self: ::pin_project_lite::__private::Pin<&'__pin mut Self>,
|
||||
) -> Projection<'__pin, T, U> {
|
||||
unsafe {
|
||||
let Self { pinned, unpinned } = self.get_unchecked_mut();
|
||||
Projection {
|
||||
pinned: ::pin_project_lite::__private::Pin::new_unchecked(pinned),
|
||||
unpinned: unpinned,
|
||||
}
|
||||
}
|
||||
}
|
||||
fn project_ref<'__pin>(
|
||||
self: ::pin_project_lite::__private::Pin<&'__pin Self>,
|
||||
) -> StructProjRef<'__pin, T, U> {
|
||||
unsafe {
|
||||
let Self { pinned, unpinned } = self.get_ref();
|
||||
StructProjRef {
|
||||
pinned: ::pin_project_lite::__private::Pin::new_unchecked(pinned),
|
||||
unpinned: unpinned,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#[allow(non_snake_case)]
|
||||
struct __Origin<'__pin, T, U> {
|
||||
__dummy_lifetime: ::pin_project_lite::__private::PhantomData<&'__pin ()>,
|
||||
pinned: T,
|
||||
unpinned: ::pin_project_lite::__private::AlwaysUnpin<U>,
|
||||
}
|
||||
impl<'__pin, T, U> ::pin_project_lite::__private::Unpin for Struct<T, U> where
|
||||
__Origin<'__pin, T, U>: ::pin_project_lite::__private::Unpin
|
||||
{
|
||||
}
|
||||
trait MustNotImplDrop {}
|
||||
#[allow(clippy::drop_bounds, drop_bounds)]
|
||||
impl<T: ::pin_project_lite::__private::Drop> MustNotImplDrop for T {}
|
||||
impl<T, U> MustNotImplDrop for Struct<T, U> {}
|
||||
#[forbid(unaligned_references, safe_packed_borrows)]
|
||||
fn __assert_not_repr_packed<T, U>(this: &Struct<T, U>) {
|
||||
let _ = &this.pinned;
|
||||
let _ = &this.unpinned;
|
||||
}
|
||||
};
|
||||
fn main() {}
|
|
@ -0,0 +1,12 @@
|
|||
use pin_project_lite::pin_project;
|
||||
|
||||
pin_project! {
|
||||
#[project_ref = StructProjRef]
|
||||
struct Struct<T, U> {
|
||||
#[pin]
|
||||
pinned: T,
|
||||
unpinned: U,
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
|
@ -0,0 +1,87 @@
|
|||
use pin_project_lite::pin_project;
|
||||
pub enum Enum<T, U> {
|
||||
Struct { pinned: T, unpinned: U },
|
||||
Unit,
|
||||
}
|
||||
#[allow(dead_code)]
|
||||
#[allow(single_use_lifetimes)]
|
||||
#[allow(clippy::unknown_clippy_lints)]
|
||||
#[allow(clippy::mut_mut)]
|
||||
#[allow(clippy::redundant_pub_crate)]
|
||||
#[allow(clippy::ref_option_ref)]
|
||||
#[allow(clippy::type_repetition_in_bounds)]
|
||||
pub(crate) enum EnumProj<'__pin, T, U>
|
||||
where
|
||||
Enum<T, U>: '__pin,
|
||||
{
|
||||
Struct {
|
||||
pinned: ::pin_project_lite::__private::Pin<&'__pin mut (T)>,
|
||||
unpinned: &'__pin mut (U),
|
||||
},
|
||||
Unit,
|
||||
}
|
||||
#[allow(dead_code)]
|
||||
#[allow(single_use_lifetimes)]
|
||||
#[allow(clippy::unknown_clippy_lints)]
|
||||
#[allow(clippy::mut_mut)]
|
||||
#[allow(clippy::redundant_pub_crate)]
|
||||
#[allow(clippy::ref_option_ref)]
|
||||
#[allow(clippy::type_repetition_in_bounds)]
|
||||
pub(crate) enum EnumProjRef<'__pin, T, U>
|
||||
where
|
||||
Enum<T, U>: '__pin,
|
||||
{
|
||||
Struct {
|
||||
pinned: ::pin_project_lite::__private::Pin<&'__pin (T)>,
|
||||
unpinned: &'__pin (U),
|
||||
},
|
||||
Unit,
|
||||
}
|
||||
#[allow(single_use_lifetimes)]
|
||||
#[allow(clippy::unknown_clippy_lints)]
|
||||
#[allow(clippy::used_underscore_binding)]
|
||||
const _: () = {
|
||||
impl<T, U> Enum<T, U> {
|
||||
pub(crate) fn project<'__pin>(
|
||||
self: ::pin_project_lite::__private::Pin<&'__pin mut Self>,
|
||||
) -> EnumProj<'__pin, T, U> {
|
||||
unsafe {
|
||||
match self.get_unchecked_mut() {
|
||||
Self::Struct { pinned, unpinned } => EnumProj::Struct {
|
||||
pinned: ::pin_project_lite::__private::Pin::new_unchecked(pinned),
|
||||
unpinned: unpinned,
|
||||
},
|
||||
Self::Unit => EnumProj::Unit,
|
||||
}
|
||||
}
|
||||
}
|
||||
pub(crate) fn project_ref<'__pin>(
|
||||
self: ::pin_project_lite::__private::Pin<&'__pin Self>,
|
||||
) -> EnumProjRef<'__pin, T, U> {
|
||||
unsafe {
|
||||
match self.get_ref() {
|
||||
Self::Struct { pinned, unpinned } => EnumProjRef::Struct {
|
||||
pinned: ::pin_project_lite::__private::Pin::new_unchecked(pinned),
|
||||
unpinned: unpinned,
|
||||
},
|
||||
Self::Unit => EnumProjRef::Unit,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#[allow(non_snake_case)]
|
||||
pub struct __Origin<'__pin, T, U> {
|
||||
__dummy_lifetime: ::pin_project_lite::__private::PhantomData<&'__pin ()>,
|
||||
Struct: (T, ::pin_project_lite::__private::AlwaysUnpin<U>),
|
||||
Unit: (),
|
||||
}
|
||||
impl<'__pin, T, U> ::pin_project_lite::__private::Unpin for Enum<T, U> where
|
||||
__Origin<'__pin, T, U>: ::pin_project_lite::__private::Unpin
|
||||
{
|
||||
}
|
||||
trait MustNotImplDrop {}
|
||||
#[allow(clippy::drop_bounds, drop_bounds)]
|
||||
impl<T: ::pin_project_lite::__private::Drop> MustNotImplDrop for T {}
|
||||
impl<T, U> MustNotImplDrop for Enum<T, U> {}
|
||||
};
|
||||
fn main() {}
|
|
@ -0,0 +1,16 @@
|
|||
use pin_project_lite::pin_project;
|
||||
|
||||
pin_project! {
|
||||
#[project = EnumProj]
|
||||
#[project_ref = EnumProjRef]
|
||||
pub enum Enum<T, U> {
|
||||
Struct {
|
||||
#[pin]
|
||||
pinned: T,
|
||||
unpinned: U,
|
||||
},
|
||||
Unit,
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
|
@ -0,0 +1,84 @@
|
|||
use pin_project_lite::pin_project;
|
||||
pub struct Struct<T, U> {
|
||||
pub pinned: T,
|
||||
pub unpinned: U,
|
||||
}
|
||||
#[allow(explicit_outlives_requirements)]
|
||||
#[allow(single_use_lifetimes)]
|
||||
#[allow(clippy::unknown_clippy_lints)]
|
||||
#[allow(clippy::redundant_pub_crate)]
|
||||
#[allow(clippy::used_underscore_binding)]
|
||||
const _: () = {
|
||||
#[allow(dead_code)]
|
||||
#[allow(single_use_lifetimes)]
|
||||
#[allow(clippy::unknown_clippy_lints)]
|
||||
#[allow(clippy::mut_mut)]
|
||||
#[allow(clippy::redundant_pub_crate)]
|
||||
#[allow(clippy::ref_option_ref)]
|
||||
#[allow(clippy::type_repetition_in_bounds)]
|
||||
pub(crate) struct Projection<'__pin, T, U>
|
||||
where
|
||||
Struct<T, U>: '__pin,
|
||||
{
|
||||
pub pinned: ::pin_project_lite::__private::Pin<&'__pin mut (T)>,
|
||||
pub unpinned: &'__pin mut (U),
|
||||
}
|
||||
#[allow(dead_code)]
|
||||
#[allow(single_use_lifetimes)]
|
||||
#[allow(clippy::unknown_clippy_lints)]
|
||||
#[allow(clippy::mut_mut)]
|
||||
#[allow(clippy::redundant_pub_crate)]
|
||||
#[allow(clippy::ref_option_ref)]
|
||||
#[allow(clippy::type_repetition_in_bounds)]
|
||||
pub(crate) struct ProjectionRef<'__pin, T, U>
|
||||
where
|
||||
Struct<T, U>: '__pin,
|
||||
{
|
||||
pub pinned: ::pin_project_lite::__private::Pin<&'__pin (T)>,
|
||||
pub unpinned: &'__pin (U),
|
||||
}
|
||||
impl<T, U> Struct<T, U> {
|
||||
pub(crate) fn project<'__pin>(
|
||||
self: ::pin_project_lite::__private::Pin<&'__pin mut Self>,
|
||||
) -> Projection<'__pin, T, U> {
|
||||
unsafe {
|
||||
let Self { pinned, unpinned } = self.get_unchecked_mut();
|
||||
Projection {
|
||||
pinned: ::pin_project_lite::__private::Pin::new_unchecked(pinned),
|
||||
unpinned: unpinned,
|
||||
}
|
||||
}
|
||||
}
|
||||
pub(crate) fn project_ref<'__pin>(
|
||||
self: ::pin_project_lite::__private::Pin<&'__pin Self>,
|
||||
) -> ProjectionRef<'__pin, T, U> {
|
||||
unsafe {
|
||||
let Self { pinned, unpinned } = self.get_ref();
|
||||
ProjectionRef {
|
||||
pinned: ::pin_project_lite::__private::Pin::new_unchecked(pinned),
|
||||
unpinned: unpinned,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#[allow(non_snake_case)]
|
||||
pub struct __Origin<'__pin, T, U> {
|
||||
__dummy_lifetime: ::pin_project_lite::__private::PhantomData<&'__pin ()>,
|
||||
pinned: T,
|
||||
unpinned: ::pin_project_lite::__private::AlwaysUnpin<U>,
|
||||
}
|
||||
impl<'__pin, T, U> ::pin_project_lite::__private::Unpin for Struct<T, U> where
|
||||
__Origin<'__pin, T, U>: ::pin_project_lite::__private::Unpin
|
||||
{
|
||||
}
|
||||
trait MustNotImplDrop {}
|
||||
#[allow(clippy::drop_bounds, drop_bounds)]
|
||||
impl<T: ::pin_project_lite::__private::Drop> MustNotImplDrop for T {}
|
||||
impl<T, U> MustNotImplDrop for Struct<T, U> {}
|
||||
#[forbid(unaligned_references, safe_packed_borrows)]
|
||||
fn __assert_not_repr_packed<T, U>(this: &Struct<T, U>) {
|
||||
let _ = &this.pinned;
|
||||
let _ = &this.unpinned;
|
||||
}
|
||||
};
|
||||
fn main() {}
|
|
@ -0,0 +1,11 @@
|
|||
use pin_project_lite::pin_project;
|
||||
|
||||
pin_project! {
|
||||
pub struct Struct<T, U> {
|
||||
#[pin]
|
||||
pub pinned: T,
|
||||
pub unpinned: U,
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
|
@ -0,0 +1,41 @@
|
|||
#![cfg(not(miri))]
|
||||
#![warn(rust_2018_idioms, single_use_lifetimes)]
|
||||
|
||||
use std::{
|
||||
env,
|
||||
process::{Command, ExitStatus, Stdio},
|
||||
};
|
||||
|
||||
#[rustversion::attr(not(nightly), ignore)]
|
||||
#[test]
|
||||
fn expandtest() {
|
||||
let is_ci = env::var_os("CI").is_some();
|
||||
let cargo = &*env::var("CARGO").unwrap_or_else(|_| "cargo".into());
|
||||
if !has_command(&[cargo, "expand"]) || !has_command(&[cargo, "fmt"]) {
|
||||
if is_ci {
|
||||
panic!("expandtest requires rustfmt and cargo-expand")
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
let path = "tests/expand/*/*.rs";
|
||||
if is_ci {
|
||||
macrotest::expand_without_refresh(path);
|
||||
} else {
|
||||
env::set_var("MACROTEST", "overwrite");
|
||||
macrotest::expand(path);
|
||||
}
|
||||
}
|
||||
|
||||
fn has_command(command: &[&str]) -> bool {
|
||||
Command::new(command[0])
|
||||
.args(&command[1..])
|
||||
.arg("--version")
|
||||
.stdin(Stdio::null())
|
||||
.stdout(Stdio::null())
|
||||
.stderr(Stdio::null())
|
||||
.status()
|
||||
.as_ref()
|
||||
.map(ExitStatus::success)
|
||||
.unwrap_or(false)
|
||||
}
|
|
@ -7,10 +7,12 @@
|
|||
#![warn(
|
||||
box_pointers,
|
||||
deprecated_in_future,
|
||||
disjoint_capture_drop_reorder,
|
||||
elided_lifetimes_in_paths,
|
||||
explicit_outlives_requirements,
|
||||
macro_use_extern_crate,
|
||||
meta_variable_misuse,
|
||||
missing_abi,
|
||||
missing_copy_implementations,
|
||||
missing_crate_level_docs,
|
||||
missing_debug_implementations,
|
||||
|
@ -28,7 +30,7 @@
|
|||
unused_results,
|
||||
variant_size_differences
|
||||
)]
|
||||
// absolute_paths_not_starting_with_crate, anonymous_parameters, keyword_idents, pointer_structural_match: forbidden as a part of future_incompatible
|
||||
// absolute_paths_not_starting_with_crate, anonymous_parameters, keyword_idents, pointer_structural_match, semicolon_in_expressions_from_macros: forbidden as a part of future_incompatible
|
||||
// missing_doc_code_examples, private_doc_tests, invalid_html_tags: warned as a part of rustdoc
|
||||
// unsafe_block_in_unsafe_fn: unstable
|
||||
// unsafe_code: forbidden
|
||||
|
@ -37,6 +39,7 @@
|
|||
#![warn(clippy::all, clippy::pedantic, clippy::nursery)]
|
||||
#![warn(clippy::restriction)]
|
||||
#![allow(clippy::blanket_clippy_restriction_lints)] // this is a test, so enable all restriction lints intentionally.
|
||||
#![allow(clippy::exhaustive_structs, clippy::exhaustive_enums)] // TODO
|
||||
|
||||
// Check interoperability with rustc and clippy lints.
|
||||
|
||||
|
|
|
@ -5,9 +5,10 @@
|
|||
mod auxiliary;
|
||||
|
||||
pub mod default {
|
||||
use pin_project_lite::pin_project;
|
||||
use std::marker::PhantomPinned;
|
||||
|
||||
use pin_project_lite::pin_project;
|
||||
|
||||
struct Inner<T> {
|
||||
f: T,
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ use core::{
|
|||
marker::{PhantomData, PhantomPinned},
|
||||
pin::Pin,
|
||||
};
|
||||
|
||||
use pin_project_lite::pin_project;
|
||||
|
||||
#[test]
|
||||
|
@ -586,6 +587,21 @@ fn trailing_comma() {
|
|||
|
||||
#[test]
|
||||
fn attrs() {
|
||||
pin_project! {
|
||||
/// dox1
|
||||
#[derive(Clone)]
|
||||
#[project = StructProj]
|
||||
#[project_ref = StructProjRef]
|
||||
/// dox2
|
||||
#[derive(Debug)]
|
||||
/// dox3
|
||||
struct Struct {
|
||||
// TODO
|
||||
// /// dox4
|
||||
f: ()
|
||||
}
|
||||
}
|
||||
|
||||
pin_project! {
|
||||
#[project = Enum1Proj]
|
||||
#[project_ref = Enum1ProjRef]
|
||||
|
@ -599,6 +615,7 @@ fn attrs() {
|
|||
|
||||
pin_project! {
|
||||
/// dox1
|
||||
#[derive(Clone)]
|
||||
#[project = Enum2Proj]
|
||||
#[project_ref = Enum2ProjRef]
|
||||
/// dox2
|
||||
|
|
|
@ -1,19 +0,0 @@
|
|||
use pin_project_lite::pin_project;
|
||||
|
||||
pin_project! { //~ ERROR borrow of packed field is unsafe and requires unsafe function or block
|
||||
#[repr(packed, C)]
|
||||
struct A {
|
||||
#[pin]
|
||||
field: u16,
|
||||
}
|
||||
}
|
||||
|
||||
pin_project! { //~ ERROR borrow of packed field is unsafe and requires unsafe function or block
|
||||
#[repr(packed(2))]
|
||||
struct C {
|
||||
#[pin]
|
||||
field: u32,
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
|
@ -1,55 +0,0 @@
|
|||
error: borrow of packed field is unsafe and requires unsafe function or block (error E0133)
|
||||
--> $DIR/packed.rs:3:1
|
||||
|
|
||||
3 | / pin_project! { //~ ERROR borrow of packed field is unsafe and requires unsafe function or block
|
||||
4 | | #[repr(packed, C)]
|
||||
5 | | struct A {
|
||||
6 | | #[pin]
|
||||
7 | | field: u16,
|
||||
8 | | }
|
||||
9 | | }
|
||||
| |_^
|
||||
|
|
||||
note: the lint level is defined here
|
||||
--> $DIR/packed.rs:3:1
|
||||
|
|
||||
3 | / pin_project! { //~ ERROR borrow of packed field is unsafe and requires unsafe function or block
|
||||
4 | | #[repr(packed, C)]
|
||||
5 | | struct A {
|
||||
6 | | #[pin]
|
||||
7 | | field: u16,
|
||||
8 | | }
|
||||
9 | | }
|
||||
| |_^
|
||||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
= note: for more information, see issue #46043 <https://github.com/rust-lang/rust/issues/46043>
|
||||
= note: fields of packed structs might be misaligned: dereferencing a misaligned pointer or even just creating a misaligned reference is undefined behavior
|
||||
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
error: borrow of packed field is unsafe and requires unsafe function or block (error E0133)
|
||||
--> $DIR/packed.rs:11:1
|
||||
|
|
||||
11 | / pin_project! { //~ ERROR borrow of packed field is unsafe and requires unsafe function or block
|
||||
12 | | #[repr(packed(2))]
|
||||
13 | | struct C {
|
||||
14 | | #[pin]
|
||||
15 | | field: u32,
|
||||
16 | | }
|
||||
17 | | }
|
||||
| |_^
|
||||
|
|
||||
note: the lint level is defined here
|
||||
--> $DIR/packed.rs:11:1
|
||||
|
|
||||
11 | / pin_project! { //~ ERROR borrow of packed field is unsafe and requires unsafe function or block
|
||||
12 | | #[repr(packed(2))]
|
||||
13 | | struct C {
|
||||
14 | | #[pin]
|
||||
15 | | field: u32,
|
||||
16 | | }
|
||||
17 | | }
|
||||
| |_^
|
||||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
= note: for more information, see issue #46043 <https://github.com/rust-lang/rust/issues/46043>
|
||||
= note: fields of packed structs might be misaligned: dereferencing a misaligned pointer or even just creating a misaligned reference is undefined behavior
|
||||
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
|
|
@ -13,4 +13,4 @@ error[E0119]: conflicting implementations of trait `_::MustNotImplDrop` for type
|
|||
| |_first implementation here
|
||||
| conflicting implementation for `Foo<_, _>`
|
||||
|
|
||||
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
|
||||
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
|
|
@ -13,7 +13,7 @@ error[E0119]: conflicting implementations of trait `std::marker::Unpin` for type
|
|||
14 | impl<T, U> Unpin for Foo<T, U> where T: Unpin {} // Conditional Unpin impl
|
||||
| --------------------------------------------- first implementation here
|
||||
|
|
||||
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
|
||||
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
error[E0119]: conflicting implementations of trait `std::marker::Unpin` for type `Bar<_, _>`:
|
||||
--> $DIR/conflict-unpin.rs:18:1
|
||||
|
@ -30,7 +30,7 @@ error[E0119]: conflicting implementations of trait `std::marker::Unpin` for type
|
|||
27 | impl<T, U> Unpin for Bar<T, U> {} // Non-conditional Unpin impl
|
||||
| ------------------------------ first implementation here
|
||||
|
|
||||
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
|
||||
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
error[E0119]: conflicting implementations of trait `std::marker::Unpin` for type `Baz<_, _>`:
|
||||
--> $DIR/conflict-unpin.rs:29:1
|
||||
|
@ -47,4 +47,4 @@ error[E0119]: conflicting implementations of trait `std::marker::Unpin` for type
|
|||
38 | impl<T: Unpin, U: Unpin> Unpin for Baz<T, U> {} // Conditional Unpin impl
|
||||
| -------------------------------------------- first implementation here
|
||||
|
|
||||
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
|
||||
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
|
93
third_party/rust/pin-project-lite/tests/ui/pin_project/invalid-bounds.rs
поставляемый
Normal file
93
third_party/rust/pin-project-lite/tests/ui/pin_project/invalid-bounds.rs
поставляемый
Normal file
|
@ -0,0 +1,93 @@
|
|||
use pin_project_lite::pin_project;
|
||||
|
||||
pin_project! {
|
||||
struct Generics1<T: 'static : Sized> { //~ ERROR no rules expected the token `:`
|
||||
field: T,
|
||||
}
|
||||
}
|
||||
|
||||
pin_project! {
|
||||
struct Generics2<T: 'static : ?Sized> { //~ ERROR no rules expected the token `:`
|
||||
field: T,
|
||||
}
|
||||
}
|
||||
|
||||
pin_project! {
|
||||
struct Generics3<T: Sized : 'static> { //~ ERROR expected one of `+`, `,`, `=`, or `>`, found `:`
|
||||
field: T,
|
||||
}
|
||||
}
|
||||
|
||||
pin_project! {
|
||||
struct Generics4<T: ?Sized : 'static> { //~ ERROR expected one of `+`, `,`, `=`, or `>`, found `:`
|
||||
field: T,
|
||||
}
|
||||
}
|
||||
|
||||
pin_project! {
|
||||
struct Generics5<T: Sized : ?Sized> { //~ ERROR expected one of `+`, `,`, `=`, or `>`, found `:`
|
||||
field: T,
|
||||
}
|
||||
}
|
||||
|
||||
pin_project! {
|
||||
struct Generics6<T: ?Sized : Sized> { //~ ERROR no rules expected the token `Sized`
|
||||
field: T,
|
||||
}
|
||||
}
|
||||
|
||||
pin_project! {
|
||||
struct WhereClause1<T>
|
||||
where
|
||||
T: 'static : Sized //~ ERROR no rules expected the token `:`
|
||||
{
|
||||
field: T,
|
||||
}
|
||||
}
|
||||
|
||||
pin_project! {
|
||||
struct WhereClause2<T>
|
||||
where
|
||||
T: 'static : ?Sized //~ ERROR no rules expected the token `:`
|
||||
{
|
||||
field: T,
|
||||
}
|
||||
}
|
||||
|
||||
pin_project! {
|
||||
struct WhereClause3<T>
|
||||
where
|
||||
T: Sized : 'static //~ ERROR expected `where`, or `{` after struct name, found `:`
|
||||
{
|
||||
field: T,
|
||||
}
|
||||
}
|
||||
|
||||
pin_project! {
|
||||
struct WhereClause4<T>
|
||||
where
|
||||
T: ?Sized : 'static //~ ERROR expected `where`, or `{` after struct name, found `:`
|
||||
{
|
||||
field: T,
|
||||
}
|
||||
}
|
||||
|
||||
pin_project! {
|
||||
struct WhereClause5<T>
|
||||
where
|
||||
T: Sized : ?Sized //~ ERROR expected `where`, or `{` after struct name, found `:`
|
||||
{
|
||||
field: T,
|
||||
}
|
||||
}
|
||||
|
||||
pin_project! {
|
||||
struct WhereClause6<T>
|
||||
where
|
||||
T: ?Sized : Sized //~ ERROR no rules expected the token `Sized`
|
||||
{
|
||||
field: T,
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
|
@ -1,30 +1,16 @@
|
|||
error[E0263]: lifetime name `'__pin` declared twice in the same scope
|
||||
--> $DIR/overlapping_lifetime_names.rs:4:20
|
||||
error[E0496]: lifetime name `'__pin` shadows a lifetime name that is already in scope
|
||||
--> $DIR/overlapping_lifetime_names.rs:3:1
|
||||
|
|
||||
3 | / pin_project! { //~ ERROR E0496
|
||||
4 | | pub struct Foo<'__pin, T> { //~ ERROR E0263
|
||||
| | ^^^^^^ declared twice
|
||||
| | ------ first declared here
|
||||
5 | | #[pin]
|
||||
6 | | field: &'__pin mut T,
|
||||
7 | | }
|
||||
8 | | }
|
||||
| |_- previous declaration here
|
||||
| |_^ lifetime `'__pin` already in scope
|
||||
|
|
||||
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
|
||||
|
||||
error[E0263]: lifetime name `'__pin` declared twice in the same scope
|
||||
--> $DIR/overlapping_lifetime_names.rs:4:20
|
||||
|
|
||||
3 | / pin_project! { //~ ERROR E0496
|
||||
4 | | pub struct Foo<'__pin, T> { //~ ERROR E0263
|
||||
| | ^^^^^^ declared twice
|
||||
5 | | #[pin]
|
||||
6 | | field: &'__pin mut T,
|
||||
7 | | }
|
||||
8 | | }
|
||||
| |_- previous declaration here
|
||||
|
|
||||
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
|
||||
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
error[E0496]: lifetime name `'__pin` shadows a lifetime name that is already in scope
|
||||
--> $DIR/overlapping_lifetime_names.rs:3:1
|
||||
|
@ -36,23 +22,9 @@ error[E0496]: lifetime name `'__pin` shadows a lifetime name that is already in
|
|||
6 | | field: &'__pin mut T,
|
||||
7 | | }
|
||||
8 | | }
|
||||
| |_^ lifetime '__pin already in scope
|
||||
| |_^ lifetime `'__pin` already in scope
|
||||
|
|
||||
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
|
||||
|
||||
error[E0496]: lifetime name `'__pin` shadows a lifetime name that is already in scope
|
||||
--> $DIR/overlapping_lifetime_names.rs:3:1
|
||||
|
|
||||
3 | / pin_project! { //~ ERROR E0496
|
||||
4 | | pub struct Foo<'__pin, T> { //~ ERROR E0263
|
||||
| | ------ first declared here
|
||||
5 | | #[pin]
|
||||
6 | | field: &'__pin mut T,
|
||||
7 | | }
|
||||
8 | | }
|
||||
| |_^ lifetime '__pin already in scope
|
||||
|
|
||||
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
|
||||
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
error[E0263]: lifetime name `'__pin` declared twice in the same scope
|
||||
--> $DIR/overlapping_lifetime_names.rs:4:20
|
||||
|
@ -65,8 +37,6 @@ error[E0263]: lifetime name `'__pin` declared twice in the same scope
|
|||
7 | | }
|
||||
8 | | }
|
||||
| |_- previous declaration here
|
||||
|
|
||||
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
|
||||
|
||||
error[E0263]: lifetime name `'__pin` declared twice in the same scope
|
||||
--> $DIR/overlapping_lifetime_names.rs:4:20
|
||||
|
@ -79,5 +49,27 @@ error[E0263]: lifetime name `'__pin` declared twice in the same scope
|
|||
7 | | }
|
||||
8 | | }
|
||||
| |_- previous declaration here
|
||||
|
||||
error[E0263]: lifetime name `'__pin` declared twice in the same scope
|
||||
--> $DIR/overlapping_lifetime_names.rs:4:20
|
||||
|
|
||||
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
|
||||
3 | / pin_project! { //~ ERROR E0496
|
||||
4 | | pub struct Foo<'__pin, T> { //~ ERROR E0263
|
||||
| | ^^^^^^ declared twice
|
||||
5 | | #[pin]
|
||||
6 | | field: &'__pin mut T,
|
||||
7 | | }
|
||||
8 | | }
|
||||
| |_- previous declaration here
|
||||
|
||||
error[E0263]: lifetime name `'__pin` declared twice in the same scope
|
||||
--> $DIR/overlapping_lifetime_names.rs:4:20
|
||||
|
|
||||
3 | / pin_project! { //~ ERROR E0496
|
||||
4 | | pub struct Foo<'__pin, T> { //~ ERROR E0263
|
||||
| | ^^^^^^ declared twice
|
||||
5 | | #[pin]
|
||||
6 | | field: &'__pin mut T,
|
||||
7 | | }
|
||||
8 | | }
|
||||
| |_- previous declaration here
|
11
third_party/rust/pin-project-lite/tests/ui/pin_project/overlapping_unpin_struct.stderr
поставляемый
Normal file
11
third_party/rust/pin-project-lite/tests/ui/pin_project/overlapping_unpin_struct.stderr
поставляемый
Normal file
|
@ -0,0 +1,11 @@
|
|||
error[E0277]: `PhantomPinned` cannot be unpinned
|
||||
--> $DIR/overlapping_unpin_struct.rs:18:5
|
||||
|
|
||||
15 | fn is_unpin<T: Unpin>() {}
|
||||
| ----- required by this bound in `is_unpin`
|
||||
...
|
||||
18 | is_unpin::<Foo<PhantomPinned>>(); //~ ERROR E0277
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ within `_::__Origin<'_, PhantomPinned>`, the trait `Unpin` is not implemented for `PhantomPinned`
|
||||
|
|
||||
= note: required because it appears within the type `_::__Origin<'_, PhantomPinned>`
|
||||
= note: required because of the requirements on the impl of `Unpin` for `Foo<PhantomPinned>`
|
|
@ -0,0 +1,19 @@
|
|||
use pin_project_lite::pin_project;
|
||||
|
||||
pin_project! { //~ ERROR reference to packed field is unaligned
|
||||
#[repr(packed, C)]
|
||||
struct Packed {
|
||||
#[pin]
|
||||
field: u16,
|
||||
}
|
||||
}
|
||||
|
||||
pin_project! { //~ ERROR reference to packed field is unaligned
|
||||
#[repr(packed(2))]
|
||||
struct PackedN {
|
||||
#[pin]
|
||||
field: u32,
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
Некоторые файлы не были показаны из-за слишком большого количества измененных файлов Показать больше
Загрузка…
Ссылка в новой задаче