From 43a97878ce14b72f0981164f87f2e35e14151312 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 11:22:09 +0200 Subject: Adding upstream version 110.0.1. Signed-off-by: Daniel Baumann --- .../rust/pin-project-lite/.cargo-checksum.json | 1 + third_party/rust/pin-project-lite/CHANGELOG.md | 222 +++ third_party/rust/pin-project-lite/Cargo.toml | 45 + third_party/rust/pin-project-lite/LICENSE-APACHE | 177 +++ third_party/rust/pin-project-lite/LICENSE-MIT | 23 + third_party/rust/pin-project-lite/README.md | 125 ++ third_party/rust/pin-project-lite/src/lib.rs | 1559 ++++++++++++++++++++ third_party/rust/pin-project-lite/tests/README.md | 46 + .../rust/pin-project-lite/tests/auxiliary/mod.rs | 12 + .../rust/pin-project-lite/tests/compiletest.rs | 15 + .../rust/pin-project-lite/tests/drop_order.rs | 169 +++ .../tests/expand/default/enum.expanded.rs | 127 ++ .../pin-project-lite/tests/expand/default/enum.rs | 17 + .../tests/expand/default/struct.expanded.rs | 84 ++ .../tests/expand/default/struct.rs | 11 + .../tests/expand/multifields/enum.expanded.rs | 88 ++ .../tests/expand/multifields/enum.rs | 18 + .../tests/expand/multifields/struct.expanded.rs | 152 ++ .../tests/expand/multifields/struct.rs | 15 + .../tests/expand/naming/enum-all.expanded.rs | 127 ++ .../tests/expand/naming/enum-all.rs | 17 + .../tests/expand/naming/enum-mut.expanded.rs | 57 + .../tests/expand/naming/enum-mut.rs | 15 + .../tests/expand/naming/enum-none.expanded.rs | 26 + .../tests/expand/naming/enum-none.rs | 14 + .../tests/expand/naming/enum-ref.expanded.rs | 57 + .../tests/expand/naming/enum-ref.rs | 15 + .../tests/expand/naming/struct-all.expanded.rs | 117 ++ .../tests/expand/naming/struct-all.rs | 14 + .../tests/expand/naming/struct-mut.expanded.rs | 84 ++ .../tests/expand/naming/struct-mut.rs | 12 + .../tests/expand/naming/struct-none.expanded.rs | 84 ++ .../tests/expand/naming/struct-none.rs | 11 + .../tests/expand/naming/struct-ref.expanded.rs | 84 ++ .../tests/expand/naming/struct-ref.rs | 12 + .../tests/expand/pinned_drop/enum.expanded.rs | 95 ++ .../tests/expand/pinned_drop/enum.rs | 22 + .../tests/expand/pinned_drop/struct.expanded.rs | 92 ++ .../tests/expand/pinned_drop/struct.rs | 17 + .../tests/expand/pub/enum.expanded.rs | 87 ++ .../rust/pin-project-lite/tests/expand/pub/enum.rs | 16 + .../tests/expand/pub/struct.expanded.rs | 84 ++ .../pin-project-lite/tests/expand/pub/struct.rs | 11 + .../rust/pin-project-lite/tests/expandtest.rs | 43 + .../rust/pin-project-lite/tests/include/basic.rs | 35 + third_party/rust/pin-project-lite/tests/lint.rs | 263 ++++ .../rust/pin-project-lite/tests/proper_unpin.rs | 67 + third_party/rust/pin-project-lite/tests/test.rs | 695 +++++++++ .../tests/ui/pin_project/conflict-drop.rs | 15 + .../tests/ui/pin_project/conflict-drop.stderr | 16 + .../tests/ui/pin_project/conflict-unpin.rs | 40 + .../tests/ui/pin_project/conflict-unpin.stderr | 50 + .../tests/ui/pin_project/invalid-bounds.rs | 93 ++ .../tests/ui/pin_project/invalid-bounds.stderr | 428 ++++++ .../tests/ui/pin_project/invalid.rs | 25 + .../tests/ui/pin_project/invalid.stderr | 59 + .../ui/pin_project/overlapping_lifetime_names.rs | 10 + .../pin_project/overlapping_lifetime_names.stderr | 75 + .../ui/pin_project/overlapping_unpin_struct.rs | 20 + .../ui/pin_project/overlapping_unpin_struct.stderr | 33 + .../tests/ui/pin_project/packed.rs | 21 + .../tests/ui/pin_project/packed.stderr | 57 + .../tests/ui/pin_project/unpin_sneaky.rs | 12 + .../tests/ui/pin_project/unpin_sneaky.stderr | 11 + .../tests/ui/pin_project/unsupported.rs | 27 + .../tests/ui/pin_project/unsupported.stderr | 79 + .../tests/ui/pinned_drop/call-drop-inner.rs | 17 + .../tests/ui/pinned_drop/call-drop-inner.stderr | 22 + .../tests/ui/pinned_drop/conditional-drop-impl.rs | 26 + .../ui/pinned_drop/conditional-drop-impl.stderr | 38 + 70 files changed, 6353 insertions(+) create mode 100644 third_party/rust/pin-project-lite/.cargo-checksum.json create mode 100644 third_party/rust/pin-project-lite/CHANGELOG.md create mode 100644 third_party/rust/pin-project-lite/Cargo.toml create mode 100644 third_party/rust/pin-project-lite/LICENSE-APACHE create mode 100644 third_party/rust/pin-project-lite/LICENSE-MIT create mode 100644 third_party/rust/pin-project-lite/README.md create mode 100644 third_party/rust/pin-project-lite/src/lib.rs create mode 100644 third_party/rust/pin-project-lite/tests/README.md create mode 100644 third_party/rust/pin-project-lite/tests/auxiliary/mod.rs create mode 100644 third_party/rust/pin-project-lite/tests/compiletest.rs create mode 100644 third_party/rust/pin-project-lite/tests/drop_order.rs create mode 100644 third_party/rust/pin-project-lite/tests/expand/default/enum.expanded.rs create mode 100644 third_party/rust/pin-project-lite/tests/expand/default/enum.rs create mode 100644 third_party/rust/pin-project-lite/tests/expand/default/struct.expanded.rs create mode 100644 third_party/rust/pin-project-lite/tests/expand/default/struct.rs create mode 100644 third_party/rust/pin-project-lite/tests/expand/multifields/enum.expanded.rs create mode 100644 third_party/rust/pin-project-lite/tests/expand/multifields/enum.rs create mode 100644 third_party/rust/pin-project-lite/tests/expand/multifields/struct.expanded.rs create mode 100644 third_party/rust/pin-project-lite/tests/expand/multifields/struct.rs create mode 100644 third_party/rust/pin-project-lite/tests/expand/naming/enum-all.expanded.rs create mode 100644 third_party/rust/pin-project-lite/tests/expand/naming/enum-all.rs create mode 100644 third_party/rust/pin-project-lite/tests/expand/naming/enum-mut.expanded.rs create mode 100644 third_party/rust/pin-project-lite/tests/expand/naming/enum-mut.rs create mode 100644 third_party/rust/pin-project-lite/tests/expand/naming/enum-none.expanded.rs create mode 100644 third_party/rust/pin-project-lite/tests/expand/naming/enum-none.rs create mode 100644 third_party/rust/pin-project-lite/tests/expand/naming/enum-ref.expanded.rs create mode 100644 third_party/rust/pin-project-lite/tests/expand/naming/enum-ref.rs create mode 100644 third_party/rust/pin-project-lite/tests/expand/naming/struct-all.expanded.rs create mode 100644 third_party/rust/pin-project-lite/tests/expand/naming/struct-all.rs create mode 100644 third_party/rust/pin-project-lite/tests/expand/naming/struct-mut.expanded.rs create mode 100644 third_party/rust/pin-project-lite/tests/expand/naming/struct-mut.rs create mode 100644 third_party/rust/pin-project-lite/tests/expand/naming/struct-none.expanded.rs create mode 100644 third_party/rust/pin-project-lite/tests/expand/naming/struct-none.rs create mode 100644 third_party/rust/pin-project-lite/tests/expand/naming/struct-ref.expanded.rs create mode 100644 third_party/rust/pin-project-lite/tests/expand/naming/struct-ref.rs create mode 100644 third_party/rust/pin-project-lite/tests/expand/pinned_drop/enum.expanded.rs create mode 100644 third_party/rust/pin-project-lite/tests/expand/pinned_drop/enum.rs create mode 100644 third_party/rust/pin-project-lite/tests/expand/pinned_drop/struct.expanded.rs create mode 100644 third_party/rust/pin-project-lite/tests/expand/pinned_drop/struct.rs create mode 100644 third_party/rust/pin-project-lite/tests/expand/pub/enum.expanded.rs create mode 100644 third_party/rust/pin-project-lite/tests/expand/pub/enum.rs create mode 100644 third_party/rust/pin-project-lite/tests/expand/pub/struct.expanded.rs create mode 100644 third_party/rust/pin-project-lite/tests/expand/pub/struct.rs create mode 100644 third_party/rust/pin-project-lite/tests/expandtest.rs create mode 100644 third_party/rust/pin-project-lite/tests/include/basic.rs create mode 100644 third_party/rust/pin-project-lite/tests/lint.rs create mode 100644 third_party/rust/pin-project-lite/tests/proper_unpin.rs create mode 100644 third_party/rust/pin-project-lite/tests/test.rs create mode 100644 third_party/rust/pin-project-lite/tests/ui/pin_project/conflict-drop.rs create mode 100644 third_party/rust/pin-project-lite/tests/ui/pin_project/conflict-drop.stderr create mode 100644 third_party/rust/pin-project-lite/tests/ui/pin_project/conflict-unpin.rs create mode 100644 third_party/rust/pin-project-lite/tests/ui/pin_project/conflict-unpin.stderr create mode 100644 third_party/rust/pin-project-lite/tests/ui/pin_project/invalid-bounds.rs create mode 100644 third_party/rust/pin-project-lite/tests/ui/pin_project/invalid-bounds.stderr create mode 100644 third_party/rust/pin-project-lite/tests/ui/pin_project/invalid.rs create mode 100644 third_party/rust/pin-project-lite/tests/ui/pin_project/invalid.stderr create mode 100644 third_party/rust/pin-project-lite/tests/ui/pin_project/overlapping_lifetime_names.rs create mode 100644 third_party/rust/pin-project-lite/tests/ui/pin_project/overlapping_lifetime_names.stderr create mode 100644 third_party/rust/pin-project-lite/tests/ui/pin_project/overlapping_unpin_struct.rs create mode 100644 third_party/rust/pin-project-lite/tests/ui/pin_project/overlapping_unpin_struct.stderr create mode 100644 third_party/rust/pin-project-lite/tests/ui/pin_project/packed.rs create mode 100644 third_party/rust/pin-project-lite/tests/ui/pin_project/packed.stderr create mode 100644 third_party/rust/pin-project-lite/tests/ui/pin_project/unpin_sneaky.rs create mode 100644 third_party/rust/pin-project-lite/tests/ui/pin_project/unpin_sneaky.stderr create mode 100644 third_party/rust/pin-project-lite/tests/ui/pin_project/unsupported.rs create mode 100644 third_party/rust/pin-project-lite/tests/ui/pin_project/unsupported.stderr create mode 100644 third_party/rust/pin-project-lite/tests/ui/pinned_drop/call-drop-inner.rs create mode 100644 third_party/rust/pin-project-lite/tests/ui/pinned_drop/call-drop-inner.stderr create mode 100644 third_party/rust/pin-project-lite/tests/ui/pinned_drop/conditional-drop-impl.rs create mode 100644 third_party/rust/pin-project-lite/tests/ui/pinned_drop/conditional-drop-impl.stderr (limited to 'third_party/rust/pin-project-lite') diff --git a/third_party/rust/pin-project-lite/.cargo-checksum.json b/third_party/rust/pin-project-lite/.cargo-checksum.json new file mode 100644 index 0000000000..249c55e4be --- /dev/null +++ b/third_party/rust/pin-project-lite/.cargo-checksum.json @@ -0,0 +1 @@ +{"files":{"CHANGELOG.md":"0da6eac8d8957a8aea735942d2e6e226b5cb178a363fe77b87c23272f2e63b1c","Cargo.toml":"b0b0099d5e8af1ffbe68c0b4e367a00602dbf1acab35f8c956129918b17a5425","LICENSE-APACHE":"0d542e0c8804e39aa7f37eb00da5a762149dc682d7829451287e11b938e94594","LICENSE-MIT":"23f18e03dc49df91622fe2a76176497404e46ced8a715d9d2b67a7446571cca3","README.md":"609412221520fc16f47e76131927e4dd11aef38f7c69d92a1116130654f0ee90","src/lib.rs":"7b76a04ae98aa1e9ee85b9a2e1f054384b39df74cdfb375ff46649af8ec4b5b3","tests/README.md":"71fc84264ec08d2b7f1c74c1ba5140a376121b72145cc630b616e6f2536aeafa","tests/auxiliary/mod.rs":"7e263e987e09b77e384f734384a00a71c5b70230bb1b5376446ef003a8da9372","tests/compiletest.rs":"f764ff03c73c8a21c35ee30cf851b9266b2987e88d646d9bd086fc71944eb945","tests/drop_order.rs":"2cb31a8cd5cf4d9a4ba9faf25f99f0e85f9bd7b4778649f843d9c617c6af43fc","tests/expand/default/enum.expanded.rs":"c4db8e05cfe6eab3be39301abf77689f79fdaff52605350a2aee464b2756180e","tests/expand/default/enum.rs":"493d5752c4baa87ed4c48bd41b8e5e263fd5e3f43c4f9195818ef6d26951f63e","tests/expand/default/struct.expanded.rs":"c158632984eaf6ab8ae60b76ff2bf32b20ba10a3cbc4237c9a6ea28c614cdb01","tests/expand/default/struct.rs":"5a6e57d9b6d00cfd4e1e69f37ce0c9d5165a21230d0363f0791665b1015870ce","tests/expand/multifields/enum.expanded.rs":"8bba6a5a2279469bf94c486a6efb2f8c9ed965b716d66ac0660662e11ca0bddb","tests/expand/multifields/enum.rs":"9c79270a7d6d1d42cf8194b579d79e7d44a3fd003243742f0a568ecf0a4f3be3","tests/expand/multifields/struct.expanded.rs":"46ac58981d4ee4eba61b879ba62b313ceac59f9a223ae4984450f72a9173cbd2","tests/expand/multifields/struct.rs":"17f0447d522d48f14d516808bd66baacebdf3ac38188df72f649702a893cda68","tests/expand/naming/enum-all.expanded.rs":"c4db8e05cfe6eab3be39301abf77689f79fdaff52605350a2aee464b2756180e","tests/expand/naming/enum-all.rs":"493d5752c4baa87ed4c48bd41b8e5e263fd5e3f43c4f9195818ef6d26951f63e","tests/expand/naming/enum-mut.expanded.rs":"ce1a12428d3906c8d98516b3afdcbbbda64776e2f0c039e90f3de8f734ab1878","tests/expand/naming/enum-mut.rs":"c1ff4ade049ebbceb2acb99dbc1af5db14de3ba9710ea1ff1b64348766a9e080","tests/expand/naming/enum-none.expanded.rs":"cf8ea074b8079af453a2f98e2217704e96174433e4ac0e07577f9242ad3d5de2","tests/expand/naming/enum-none.rs":"ff22be4ecf4168e2bc68ab249a0ed809a37e3b8e840ef8977d24209ef28ac839","tests/expand/naming/enum-ref.expanded.rs":"277e9642e49f4dc312ea09b4d9f8012994662f565529865102be0fe1657c2b13","tests/expand/naming/enum-ref.rs":"394cbd5d872449e9226cd0834ce7117c395a582567584218dabbef4eb2c1fbac","tests/expand/naming/struct-all.expanded.rs":"807c74c57928e068725fa8272a1d1c671401ed213ce8abf1a405a35b1fb47673","tests/expand/naming/struct-all.rs":"c13c0aacee85b8fca58f85d2d75d2e3907b3e7642f8710ed8c8e54d6015881cc","tests/expand/naming/struct-mut.expanded.rs":"f08b34f7d49ad45ae0a1ae8b64995d63e7e4eed2910a912f6c622a0b8e410b89","tests/expand/naming/struct-mut.rs":"9a7752a6d30e0b7033f3577a72676676900a642cdaf59f942179d1f2a8ba2bb0","tests/expand/naming/struct-none.expanded.rs":"c158632984eaf6ab8ae60b76ff2bf32b20ba10a3cbc4237c9a6ea28c614cdb01","tests/expand/naming/struct-none.rs":"5a6e57d9b6d00cfd4e1e69f37ce0c9d5165a21230d0363f0791665b1015870ce","tests/expand/naming/struct-ref.expanded.rs":"dabc3fda847ab2f4e4ca0ec6f6dc4da43f8de087117dcafb3c15780cebc7af45","tests/expand/naming/struct-ref.rs":"33c4fd344b65650dee44087ada31d4b5acd9d122123360fb7d41718c46699574","tests/expand/pinned_drop/enum.expanded.rs":"56d709a0cfc0c951fe303bf2b034e7fae4fc5271b9a11ade9c6a9c20c89471b3","tests/expand/pinned_drop/enum.rs":"d7e087b6852338fabe7edf39529c8f893a426b4d0c6aba2d2a6be0d95f739cdc","tests/expand/pinned_drop/struct.expanded.rs":"c9b26224339f126ce5f0d36cd8d6c6e84970bf39b94dc11bc42743ad5bdba6be","tests/expand/pinned_drop/struct.rs":"164a25e12b9898c093b5dee2c47a40dd549e6f49ba1c6bb22f4e4c4b98fe76b2","tests/expand/pub/enum.expanded.rs":"56c81c0535f8fb9b83662fc3753f7c07b96eb12392669bb1ae23ffc82b7c4a2c","tests/expand/pub/enum.rs":"5b60dd354a489b0326f5c4f1026b89d1471ddbb45906bc3046a65425c4e5e160","tests/expand/pub/struct.expanded.rs":"525c52bf7185493046618ee0dc1b18bdc0c0a56383f5c7b11c98738211d024a7","tests/expand/pub/struct.rs":"15b7940ce0ad1d5d133dde1870319f2f96a000bfcf29508b8cce1a62876cbd80","tests/expandtest.rs":"898df948c7ee82df0e0823cbde16ccc2b9dba455475665e6d2c7c0a84493e9fb","tests/include/basic.rs":"9e399b682bc74c899d26924c2cab52a911f7392e29300defb6521e561fafafe4","tests/lint.rs":"513ffda15a1e8e64076e8a1b7db709d5de8eebaf7952839974056e99afedde82","tests/proper_unpin.rs":"57a9e8c9029ba7920ec23670b66758916e067c9cecf4d3f8b0035bec25cdb570","tests/test.rs":"8d0ee300af17535dc7fd488433630911ddc3147a3e3ccf0b9dce9f0ccdb10dc3","tests/ui/pin_project/conflict-drop.rs":"55e6809b5f59dd81e32c2c89b742c0c76db6b099a1d2621e5b882c0d20f92837","tests/ui/pin_project/conflict-drop.stderr":"d22314903c031c1dad5fba81b8819fd9a1459ed4f750534032eaa3296db9e4ac","tests/ui/pin_project/conflict-unpin.rs":"51b3b6720fa581b63167d6ac941a1ea1bf739b09954931b2bc2f7abe2d934f26","tests/ui/pin_project/conflict-unpin.stderr":"4ca72632a5926cc70cb489311f6ac2e16b13fb5508cc2afb3b873071b37f3ba4","tests/ui/pin_project/invalid-bounds.rs":"f86f23d377df015182f2f5dae6464a4f98c37f2198e0646f721fedc4017cb82c","tests/ui/pin_project/invalid-bounds.stderr":"12009b6b91820cf199b0b1663d70ddb03c01c4645f0937a6812abe2e0112101c","tests/ui/pin_project/invalid.rs":"7304bd4a5bac1419382742432cfa8af83535d7be8cfad52c661410e0e9e8207a","tests/ui/pin_project/invalid.stderr":"c690c368166c588501f7af306915a5ad131e3d4c5e6c519387f27dc7daaf9e84","tests/ui/pin_project/overlapping_lifetime_names.rs":"36c849a4570c8c0c32ca6c01aa75afbe1136ef73d45f17eb66175e1936678722","tests/ui/pin_project/overlapping_lifetime_names.stderr":"93646dd1a0a9b5106a189d2dbf11ad6010f91ba6adc545fe9fb350d05e5565b9","tests/ui/pin_project/overlapping_unpin_struct.rs":"9a126182d1fe15a30ac60bb223b376aad747d11293d3cf512ad2dce546e3725c","tests/ui/pin_project/overlapping_unpin_struct.stderr":"a7297c94c18c582eba24f801a69dc9ee25f28e58b9c15493ae89aa62bfae045a","tests/ui/pin_project/packed.rs":"2ede405a0d101eb843ea83c2836cc8399da54c105776f2c795f3138e03a1e5ef","tests/ui/pin_project/packed.stderr":"7601fac825e3715b4cc8024bd489c35edbb98baa270a3ac1d591fc683afc5c56","tests/ui/pin_project/unpin_sneaky.rs":"12e97a387ce1af6ee6a567687674aab70e96962a48f2433c39976d0b3e2c3341","tests/ui/pin_project/unpin_sneaky.stderr":"972e313b129ff58d05c1de4ace8f41da18e3813abeda8173cf5e9fdfdbea2251","tests/ui/pin_project/unsupported.rs":"14defa90e736f314bbbc219973929b77bdd22e5f7e4c4c88403db764f4d167d6","tests/ui/pin_project/unsupported.stderr":"2602db59fed6be1ac66e573b2a44e88b7d9ed18674d04fa62f97ee7ad21eaa30","tests/ui/pinned_drop/call-drop-inner.rs":"032260da1fc0e649d97167a8a4ac47eea915000efebdfdc490f050b6f9351027","tests/ui/pinned_drop/call-drop-inner.stderr":"18e4d2be8a25ea7092c91e311cbdd5fae20dee494a168caa01abe01527ed07ce","tests/ui/pinned_drop/conditional-drop-impl.rs":"0b28c74213cee83e7b27223d7d37f903f79abd3dddcc0f969e14047674908085","tests/ui/pinned_drop/conditional-drop-impl.stderr":"a0e102a8746c1d078348d7447d1bd8073afe537fb18c199ec020f0bfd63cfd07"},"package":"e0a7ae3ac2f1173085d398531c705756c94a4c56843785df85a60c1a0afac116"} \ No newline at end of file diff --git a/third_party/rust/pin-project-lite/CHANGELOG.md b/third_party/rust/pin-project-lite/CHANGELOG.md new file mode 100644 index 0000000000..127e467989 --- /dev/null +++ b/third_party/rust/pin-project-lite/CHANGELOG.md @@ -0,0 +1,222 @@ +# Changelog + +All notable changes to this project will be documented in this file. + +This project adheres to [Semantic Versioning](https://semver.org). + + + +## [Unreleased] + +## [0.2.9] - 2022-04-26 + +- Improve compile time of `pin_project!` calls. (#71, thanks @nnethercote) + +## [0.2.8] - 2021-12-31 + +- Fix handling of trailing commas in `PinnedDrop` impl. ([#64](https://github.com/taiki-e/pin-project-lite/pull/64), thanks @Michael-J-Ward) + +## [0.2.7] - 2021-06-26 + +- [Support custom Drop implementation.](https://github.com/taiki-e/pin-project-lite/pull/25) See [#25](https://github.com/taiki-e/pin-project-lite/pull/25) for details. + +## [0.2.6] - 2021-03-04 + +- Support item attributes in any order. ([#57](https://github.com/taiki-e/pin-project-lite/pull/57), thanks @SabrinaJewson) + +## [0.2.5] - 2021-03-02 + +- [Prepare for removal of `safe_packed_borrows` lint.](https://github.com/taiki-e/pin-project-lite/pull/55) See [#55](https://github.com/taiki-e/pin-project-lite/pull/55) for details. + +## [0.2.4] - 2021-01-11 + +**Note:** This release has been yanked. See [#55](https://github.com/taiki-e/pin-project-lite/pull/55) for details. + +- Add `project_replace`. ([#43](https://github.com/taiki-e/pin-project-lite/pull/43), thanks @Marwes) + +## [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. + + ```rust + use pin_project_lite::pin_project; + use std::pin::Pin; + + pin_project! { + #[project = EnumProj] + enum Enum { + Variant { #[pin] pinned: T, unpinned: U }, + } + } + + impl Enum { + fn method(self: Pin<&mut Self>) { + match self.project() { + EnumProj::Variant { pinned, unpinned } => { + let _: Pin<&mut T> = pinned; + let _: &mut U = unpinned; + } + } + } + } + ``` + +- [Support naming the projection types.](https://github.com/taiki-e/pin-project-lite/pull/28) + + By passing an attribute with the same name as the method, you can name the projection type returned from the method: + + ```rust + use pin_project_lite::pin_project; + use std::pin::Pin; + + pin_project! { + #[project = StructProj] + struct Struct { + #[pin] + field: T, + } + } + + fn func(x: Pin<&mut Struct>) { + let StructProj { field } = x.project(); + let _: Pin<&mut T> = field; + } + ``` + +## [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. ([#6](https://github.com/taiki-e/pin-project-lite/pull/6), thanks @kennytm) + +## [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.9...HEAD +[0.2.9]: https://github.com/taiki-e/pin-project-lite/compare/v0.2.8...v0.2.9 +[0.2.8]: https://github.com/taiki-e/pin-project-lite/compare/v0.2.7...v0.2.8 +[0.2.7]: https://github.com/taiki-e/pin-project-lite/compare/v0.2.6...v0.2.7 +[0.2.6]: https://github.com/taiki-e/pin-project-lite/compare/v0.2.5...v0.2.6 +[0.2.5]: https://github.com/taiki-e/pin-project-lite/compare/v0.2.4...v0.2.5 +[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 +[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 diff --git a/third_party/rust/pin-project-lite/Cargo.toml b/third_party/rust/pin-project-lite/Cargo.toml new file mode 100644 index 0000000000..8a9436d877 --- /dev/null +++ b/third_party/rust/pin-project-lite/Cargo.toml @@ -0,0 +1,45 @@ +# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO +# +# When uploading crates to the registry Cargo will automatically +# "normalize" Cargo.toml files for maximal compatibility +# with all versions of Cargo and also rewrite `path` dependencies +# to registry (e.g., crates.io) dependencies. +# +# If you are reading this file be aware that the original Cargo.toml +# will likely look very different (and much more reasonable). +# See Cargo.toml.orig for the original contents. + +[package] +edition = "2018" +rust-version = "1.37" +name = "pin-project-lite" +version = "0.2.9" +exclude = [ + "/.*", + "/tools", +] +description = """ +A lightweight version of pin-project written with declarative macros. +""" +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.rustversion] +version = "1" + +[dev-dependencies.static_assertions] +version = "1" + +[dev-dependencies.trybuild] +version = "1.0.49" diff --git a/third_party/rust/pin-project-lite/LICENSE-APACHE b/third_party/rust/pin-project-lite/LICENSE-APACHE new file mode 100644 index 0000000000..f433b1a53f --- /dev/null +++ b/third_party/rust/pin-project-lite/LICENSE-APACHE @@ -0,0 +1,177 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS diff --git a/third_party/rust/pin-project-lite/LICENSE-MIT b/third_party/rust/pin-project-lite/LICENSE-MIT new file mode 100644 index 0000000000..31aa79387f --- /dev/null +++ b/third_party/rust/pin-project-lite/LICENSE-MIT @@ -0,0 +1,23 @@ +Permission is hereby granted, free of charge, to any +person obtaining a copy of this software and associated +documentation files (the "Software"), to deal in the +Software without restriction, including without +limitation the rights to use, copy, modify, merge, +publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software +is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice +shall be included in all copies or substantial portions +of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF +ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED +TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A +PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT +SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR +IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. diff --git a/third_party/rust/pin-project-lite/README.md b/third_party/rust/pin-project-lite/README.md new file mode 100644 index 0000000000..78adb7e364 --- /dev/null +++ b/third_party/rust/pin-project-lite/README.md @@ -0,0 +1,125 @@ +# 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?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. + +## Usage + +Add this to your `Cargo.toml`: + +```toml +[dependencies] +pin-project-lite = "0.2" +``` + +*Compiler support: requires rustc 1.37+* + +## 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 { + #[pin] + pinned: T, + unpinned: U, + } +} + +impl Struct { + fn method(self: Pin<&mut Self>) { + let this = self.project(); + let _: Pin<&mut T> = this.pinned; // Pinned reference to the field + let _: &mut U = this.unpinned; // Normal reference to the field + } +} +``` + +To use [`pin_project!`] on enums, you need to name the projection type +returned from the method. + +```rust +use std::pin::Pin; + +use pin_project_lite::pin_project; + +pin_project! { + #[project = EnumProj] + enum Enum { + Variant { #[pin] pinned: T, unpinned: U }, + } +} + +impl Enum { + fn method(self: Pin<&mut Self>) { + match self.project() { + EnumProj::Variant { pinned, unpinned } => { + let _: Pin<&mut T> = pinned; + let _: &mut U = unpinned; + } + } + } +} +``` + +## [pin-project] vs pin-project-lite + +Here are some similarities and differences compared to [pin-project]. + +### Similar: Safety + +pin-project-lite guarantees safety in much the same way as [pin-project]. +Both are completely safe unless you write other unsafe code. + +### Different: Minimal design + +This library does not tackle as expansive of a range of use cases as +[pin-project] does. If your use case is not already covered, please use +[pin-project]. + +### Different: No proc-macro related dependencies + +This is the **only** reason to use this crate. However, **if you already +have proc-macro related dependencies in your crate's dependency graph, there +is no benefit from using this crate.** (Note: There is almost no difference +in the amount of code generated between [pin-project] and pin-project-lite.) + +### Different: No useful error messages + +This macro does not handle any invalid input. So error messages are not to +be useful in most cases. If you do need useful error messages, then upon +error you can pass the same input to [pin-project] to receive a helpful +description of the compile error. + +### Different: No support for custom Unpin implementation + +pin-project supports this by [`UnsafeUnpin`][unsafe-unpin] and [`!Unpin`][not-unpin]. + +### Different: No support for tuple structs and tuple variants + +pin-project supports this. + +[`pin_project!`]: https://docs.rs/pin-project-lite/0.2/pin_project_lite/macro.pin_project.html +[not-unpin]: https://docs.rs/pin-project/1/pin_project/attr.pin_project.html#unpin +[pin-project]: https://github.com/taiki-e/pin-project +[unsafe-unpin]: https://docs.rs/pin-project/1/pin_project/attr.pin_project.html#unsafeunpin + +## License + +Licensed under either of [Apache License, Version 2.0](LICENSE-APACHE) or +[MIT license](LICENSE-MIT) at your option. + +Unless you explicitly state otherwise, any contribution intentionally submitted +for inclusion in the work by you, as defined in the Apache-2.0 license, shall +be dual licensed as above, without any additional terms or conditions. diff --git a/third_party/rust/pin-project-lite/src/lib.rs b/third_party/rust/pin-project-lite/src/lib.rs new file mode 100644 index 0000000000..f5ecc990d6 --- /dev/null +++ b/third_party/rust/pin-project-lite/src/lib.rs @@ -0,0 +1,1559 @@ +//! 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 { +//! #[pin] +//! pinned: T, +//! unpinned: U, +//! } +//! } +//! +//! impl Struct { +//! fn method(self: Pin<&mut Self>) { +//! let this = self.project(); +//! let _: Pin<&mut T> = this.pinned; // Pinned reference to the field +//! let _: &mut U = this.unpinned; // Normal reference to the field +//! } +//! } +//! ``` +//! +//! To use [`pin_project!`] on enums, you need to name the projection type +//! returned from the method. +//! +//! ```rust +//! use std::pin::Pin; +//! +//! use pin_project_lite::pin_project; +//! +//! pin_project! { +//! #[project = EnumProj] +//! enum Enum { +//! Variant { #[pin] pinned: T, unpinned: U }, +//! } +//! } +//! +//! impl Enum { +//! fn method(self: Pin<&mut Self>) { +//! match self.project() { +//! EnumProj::Variant { pinned, unpinned } => { +//! let _: Pin<&mut T> = pinned; +//! let _: &mut U = unpinned; +//! } +//! } +//! } +//! } +//! ``` +//! +//! # [pin-project] vs pin-project-lite +//! +//! Here are some similarities and differences compared to [pin-project]. +//! +//! ## Similar: Safety +//! +//! pin-project-lite guarantees safety in much the same way as [pin-project]. +//! Both are completely safe unless you write other unsafe code. +//! +//! ## Different: Minimal design +//! +//! This library does not tackle as expansive of a range of use cases as +//! [pin-project] does. If your use case is not already covered, please use +//! [pin-project]. +//! +//! ## Different: No proc-macro related dependencies +//! +//! This is the **only** reason to use this crate. However, **if you already +//! have proc-macro related dependencies in your crate's dependency graph, there +//! is no benefit from using this crate.** (Note: There is almost no difference +//! in the amount of code generated between [pin-project] and pin-project-lite.) +//! +//! ## Different: No useful error messages +//! +//! This macro does not handle any invalid input. So error messages are not to +//! be useful in most cases. If you do need useful error messages, then upon +//! error you can pass the same input to [pin-project] to receive a helpful +//! description of the compile error. +//! +//! ## Different: No support for custom Unpin implementation +//! +//! pin-project supports this by [`UnsafeUnpin`][unsafe-unpin] and [`!Unpin`][not-unpin]. +//! +//! ## Different: No support for tuple structs and tuple variants +//! +//! pin-project supports this. +//! +//! [not-unpin]: https://docs.rs/pin-project/1/pin_project/attr.pin_project.html#unpin +//! [pin-project]: https://github.com/taiki-e/pin-project +//! [unsafe-unpin]: https://docs.rs/pin-project/1/pin_project/attr.pin_project.html#unsafeunpin + +#![no_std] +#![doc(test( + no_crate_inject, + attr( + deny(warnings, rust_2018_idioms, single_use_lifetimes), + allow(dead_code, unused_variables) + ) +))] +#![warn(rust_2018_idioms, single_use_lifetimes, unreachable_pub)] +#![warn(clippy::default_trait_access, clippy::wildcard_imports)] + +/// A macro that creates a projection type covering all the fields of struct. +/// +/// This macro creates a projection type according to the following rules: +/// +/// - For the field that uses `#[pin]` attribute, makes the pinned reference to the field. +/// - For the other fields, makes the unpinned reference to the field. +/// +/// And the following methods are implemented on the original type: +/// +/// ```rust +/// # use std::pin::Pin; +/// # type Projection<'a> = &'a (); +/// # type ProjectionRef<'a> = &'a (); +/// # trait Dox { +/// fn project(self: Pin<&mut Self>) -> Projection<'_>; +/// fn project_ref(self: Pin<&Self>) -> ProjectionRef<'_>; +/// # } +/// ``` +/// +/// By passing an attribute with the same name as the method to the macro, +/// you can name the projection type returned from the method. This allows you +/// to use pattern matching on the projected types. +/// +/// ```rust +/// # use pin_project_lite::pin_project; +/// # use std::pin::Pin; +/// pin_project! { +/// #[project = EnumProj] +/// enum Enum { +/// Variant { #[pin] field: T }, +/// } +/// } +/// +/// impl Enum { +/// fn method(self: Pin<&mut Self>) { +/// let this: EnumProj<'_, T> = self.project(); +/// match this { +/// EnumProj::Variant { field } => { +/// let _: Pin<&mut T> = field; +/// } +/// } +/// } +/// } +/// ``` +/// +/// By passing the `#[project_replace = MyProjReplace]` attribute you may create an additional +/// method which allows the contents of `Pin<&mut Self>` to be replaced while simultaneously moving +/// out all unpinned fields in `Self`. +/// +/// ```rust +/// # use std::pin::Pin; +/// # type MyProjReplace = (); +/// # trait Dox { +/// fn project_replace(self: Pin<&mut Self>, replacement: Self) -> MyProjReplace; +/// # } +/// ``` +/// +/// Also, note that the projection types returned by `project` and `project_ref` have +/// an additional lifetime at the beginning of generics. +/// +/// ```text +/// let this: EnumProj<'_, T> = self.project(); +/// ^^ +/// ``` +/// +/// The visibility of the projected types and projection methods is based on the +/// original type. However, if the visibility of the original type is `pub`, the +/// visibility of the projected types and the projection methods is downgraded +/// to `pub(crate)`. +/// +/// # Safety +/// +/// `pin_project!` macro guarantees safety in much the same way as [pin-project] crate. +/// Both are completely safe unless you write other unsafe code. +/// +/// See [pin-project] crate for more details. +/// +/// # Examples +/// +/// ```rust +/// use std::pin::Pin; +/// +/// use pin_project_lite::pin_project; +/// +/// pin_project! { +/// struct Struct { +/// #[pin] +/// pinned: T, +/// unpinned: U, +/// } +/// } +/// +/// impl Struct { +/// fn method(self: Pin<&mut Self>) { +/// let this = self.project(); +/// let _: Pin<&mut T> = this.pinned; // Pinned reference to the field +/// let _: &mut U = this.unpinned; // Normal reference to the field +/// } +/// } +/// ``` +/// +/// To use `pin_project!` on enums, you need to name the projection type +/// returned from the method. +/// +/// ```rust +/// use std::pin::Pin; +/// +/// use pin_project_lite::pin_project; +/// +/// pin_project! { +/// #[project = EnumProj] +/// enum Enum { +/// Struct { +/// #[pin] +/// field: T, +/// }, +/// Unit, +/// } +/// } +/// +/// impl Enum { +/// fn method(self: Pin<&mut Self>) { +/// match self.project() { +/// EnumProj::Struct { field } => { +/// let _: Pin<&mut T> = field; +/// } +/// EnumProj::Unit => {} +/// } +/// } +/// } +/// ``` +/// +/// If you want to call the `project()` method multiple times or later use the +/// original [`Pin`] type, it needs to use [`.as_mut()`][`Pin::as_mut`] to avoid +/// consuming the [`Pin`]. +/// +/// ```rust +/// use std::pin::Pin; +/// +/// use pin_project_lite::pin_project; +/// +/// pin_project! { +/// struct Struct { +/// #[pin] +/// field: T, +/// } +/// } +/// +/// impl Struct { +/// 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 { +/// 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 tuple variant (wontfix). +// - no support for multiple trait/lifetime bounds. +// - no support for `Self` in where clauses. (wontfix) +// - no support for overlapping lifetime names. (wontfix) +// - no interoperability with other field attributes. +// - no useful error messages. (wontfix) +// etc... + +#[doc(hidden)] +#[macro_export] +macro_rules! __pin_project_expand { + ( + [$($proj_mut_ident:ident)?] + [$($proj_ref_ident:ident)?] + [$($proj_replace_ident:ident)?] + [$proj_vis:vis] + [$(#[$attrs:meta])* $vis:vis $struct_ty_ident:ident $ident:ident] + [$($def_generics:tt)*] + [$($impl_generics:tt)*] [$($ty_generics:tt)*] [$(where $($where_clause:tt)*)?] + { + $($body_data:tt)* + } + $(impl $($pinned_drop:tt)*)? + ) => { + $crate::__pin_project_reconstruct! { + [$(#[$attrs])* $vis $struct_ty_ident $ident] + [$($def_generics)*] [$($impl_generics)*] + [$($ty_generics)*] [$(where $($where_clause)*)?] + { + $($body_data)* + } + } + + $crate::__pin_project_make_proj_ty! { + [$($proj_mut_ident)?] + [$proj_vis $struct_ty_ident $ident] + [__pin_project_make_proj_field_mut] + [$($impl_generics)*] [$($ty_generics)*] [$(where $($where_clause)*)?] + { + $($body_data)* + } + } + $crate::__pin_project_make_proj_ty! { + [$($proj_ref_ident)?] + [$proj_vis $struct_ty_ident $ident] + [__pin_project_make_proj_field_ref] + [$($impl_generics)*] [$($ty_generics)*] [$(where $($where_clause)*)?] + { + $($body_data)* + } + } + $crate::__pin_project_make_proj_replace_ty! { + [$($proj_replace_ident)?] + [$proj_vis $struct_ty_ident] + [__pin_project_make_proj_field_replace] + [$($impl_generics)*] [$($ty_generics)*] [$(where $($where_clause)*)?] + { + $($body_data)* + } + } + + $crate::__pin_project_constant! { + [$(#[$attrs])* $vis $struct_ty_ident $ident] + [$($proj_mut_ident)?] [$($proj_ref_ident)?] [$($proj_replace_ident)?] + [$proj_vis] + [$($def_generics)*] [$($impl_generics)*] + [$($ty_generics)*] [$(where $($where_clause)*)?] + { + $($body_data)* + } + $(impl $($pinned_drop)*)? + } + }; +} + +#[doc(hidden)] +#[macro_export] +macro_rules! __pin_project_constant { + ( + [$(#[$attrs:meta])* $vis:vis struct $ident:ident] + [$($proj_mut_ident:ident)?] [$($proj_ref_ident:ident)?] [$($proj_replace_ident:ident)?] + [$proj_vis:vis] + [$($def_generics:tt)*] + [$($impl_generics:tt)*] [$($ty_generics:tt)*] [$(where $($where_clause:tt)*)?] + { + $( + $(#[$pin:ident])? + $field_vis:vis $field:ident: $field_ty:ty + ),+ $(,)? + } + $(impl $($pinned_drop:tt)*)? + ) => { + #[allow(explicit_outlives_requirements)] // https://github.com/rust-lang/rust/issues/60993 + #[allow(single_use_lifetimes)] // https://github.com/rust-lang/rust/issues/55058 + // This lint warns of `clippy::*` generated by external macros. + // We allow this lint for compatibility with older compilers. + #[allow(clippy::unknown_clippy_lints)] + #[allow(clippy::redundant_pub_crate)] // This lint warns `pub(crate)` field in private struct. + #[allow(clippy::used_underscore_binding)] + const _: () = { + $crate::__pin_project_make_proj_ty! { + [$($proj_mut_ident)? Projection] + [$proj_vis struct $ident] + [__pin_project_make_proj_field_mut] + [$($impl_generics)*] [$($ty_generics)*] [$(where $($where_clause)*)?] + { + $( + $(#[$pin])? + $field_vis $field: $field_ty + ),+ + } + } + $crate::__pin_project_make_proj_ty! { + [$($proj_ref_ident)? ProjectionRef] + [$proj_vis struct $ident] + [__pin_project_make_proj_field_ref] + [$($impl_generics)*] [$($ty_generics)*] [$(where $($where_clause)*)?] + { + $( + $(#[$pin])? + $field_vis $field: $field_ty + ),+ + } + } + + impl <$($impl_generics)*> $ident <$($ty_generics)*> + $(where + $($where_clause)*)? + { + $crate::__pin_project_struct_make_proj_method! { + [$($proj_mut_ident)? Projection] + [$proj_vis] + [project get_unchecked_mut mut] + [$($ty_generics)*] + { + $( + $(#[$pin])? + $field_vis $field + ),+ + } + } + $crate::__pin_project_struct_make_proj_method! { + [$($proj_ref_ident)? ProjectionRef] + [$proj_vis] + [project_ref get_ref] + [$($ty_generics)*] + { + $( + $(#[$pin])? + $field_vis $field + ),+ + } + } + $crate::__pin_project_struct_make_proj_replace_method! { + [$($proj_replace_ident)?] + [$proj_vis] + [ProjectionReplace] + [$($ty_generics)*] + { + $( + $(#[$pin])? + $field_vis $field + ),+ + } + } + } + + $crate::__pin_project_make_unpin_impl! { + [$vis $ident] + [$($impl_generics)*] [$($ty_generics)*] [$(where $($where_clause)*)?] + $( + $field: $crate::__pin_project_make_unpin_bound!( + $(#[$pin])? $field_ty + ) + ),+ + } + + $crate::__pin_project_make_drop_impl! { + [$ident] + [$($impl_generics)*] [$($ty_generics)*] [$(where $($where_clause)*)?] + $(impl $($pinned_drop)*)? + } + + // Ensure that it's impossible to use pin projections on a #[repr(packed)] struct. + // + // Taking a reference to a packed field is UB, and applying + // `#[forbid(unaligned_references)]` makes sure that doing this is a hard error. + // + // 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; + )+ + } + }; + }; + ( + [$(#[$attrs:meta])* $vis:vis enum $ident:ident] + [$($proj_mut_ident:ident)?] [$($proj_ref_ident:ident)?] [$($proj_replace_ident:ident)?] + [$proj_vis:vis] + [$($def_generics:tt)*] + [$($impl_generics:tt)*] [$($ty_generics:tt)*] [$(where $($where_clause:tt)*)?] + { + $( + $(#[$variant_attrs:meta])* + $variant:ident $({ + $( + $(#[$pin:ident])? + $field:ident: $field_ty:ty + ),+ $(,)? + })? + ),+ $(,)? + } + $(impl $($pinned_drop:tt)*)? + ) => { + #[allow(single_use_lifetimes)] // https://github.com/rust-lang/rust/issues/55058 + // This lint warns of `clippy::*` generated by external macros. + // We allow this lint for compatibility with older compilers. + #[allow(clippy::unknown_clippy_lints)] + #[allow(clippy::used_underscore_binding)] + const _: () = { + impl <$($impl_generics)*> $ident <$($ty_generics)*> + $(where + $($where_clause)*)? + { + $crate::__pin_project_enum_make_proj_method! { + [$($proj_mut_ident)?] + [$proj_vis] + [project get_unchecked_mut mut] + [$($ty_generics)*] + { + $( + $variant $({ + $( + $(#[$pin])? + $field + ),+ + })? + ),+ + } + } + $crate::__pin_project_enum_make_proj_method! { + [$($proj_ref_ident)?] + [$proj_vis] + [project_ref get_ref] + [$($ty_generics)*] + { + $( + $variant $({ + $( + $(#[$pin])? + $field + ),+ + })? + ),+ + } + } + $crate::__pin_project_enum_make_proj_replace_method! { + [$($proj_replace_ident)?] + [$proj_vis] + [$($ty_generics)*] + { + $( + $variant $({ + $( + $(#[$pin])? + $field + ),+ + })? + ),+ + } + } + } + + $crate::__pin_project_make_unpin_impl! { + [$vis $ident] + [$($impl_generics)*] [$($ty_generics)*] [$(where $($where_clause)*)?] + $( + $variant: ($( + $( + $crate::__pin_project_make_unpin_bound!( + $(#[$pin])? $field_ty + ) + ),+ + )?) + ),+ + } + + $crate::__pin_project_make_drop_impl! { + [$ident] + [$($impl_generics)*] [$($ty_generics)*] [$(where $($where_clause)*)?] + $(impl $($pinned_drop)*)? + } + + // We don't need to check for '#[repr(packed)]', + // since it does not apply to enums. + }; + }; +} + +#[doc(hidden)] +#[macro_export] +macro_rules! __pin_project_reconstruct { + ( + [$(#[$attrs:meta])* $vis:vis struct $ident:ident] + [$($def_generics:tt)*] [$($impl_generics:tt)*] + [$($ty_generics:tt)*] [$(where $($where_clause:tt)*)?] + { + $( + $(#[$pin:ident])? + $field_vis:vis $field:ident: $field_ty:ty + ),+ $(,)? + } + ) => { + $(#[$attrs])* + $vis struct $ident $($def_generics)* + $(where + $($where_clause)*)? + { + $( + $field_vis $field: $field_ty + ),+ + } + }; + ( + [$(#[$attrs:meta])* $vis:vis enum $ident:ident] + [$($def_generics:tt)*] [$($impl_generics:tt)*] + [$($ty_generics:tt)*] [$(where $($where_clause:tt)*)?] + { + $( + $(#[$variant_attrs:meta])* + $variant:ident $({ + $( + $(#[$pin:ident])? + $field:ident: $field_ty:ty + ),+ $(,)? + })? + ),+ $(,)? + } + ) => { + $(#[$attrs])* + $vis enum $ident $($def_generics)* + $(where + $($where_clause)*)? + { + $( + $(#[$variant_attrs])* + $variant $({ + $( + $field: $field_ty + ),+ + })? + ),+ + } + }; +} + +#[doc(hidden)] +#[macro_export] +macro_rules! __pin_project_make_proj_ty { + ([] $($field:tt)*) => {}; + ( + [$proj_ty_ident:ident $default_ident:ident] + [$proj_vis:vis struct $ident:ident] + $($field:tt)* + ) => {}; + ( + [$proj_ty_ident:ident] + [$proj_vis:vis struct $ident:ident] + [$__pin_project_make_proj_field:ident] + [$($impl_generics:tt)*] [$($ty_generics:tt)*] [$(where $($where_clause:tt)*)?] + { + $( + $(#[$pin:ident])? + $field_vis:vis $field:ident: $field_ty:ty + ),+ $(,)? + } + ) => { + $crate::__pin_project_make_proj_ty_body! { + [$proj_ty_ident] + [$proj_vis struct $ident] + [$($impl_generics)*] [$($ty_generics)*] [$(where $($where_clause)*)?] + [ + $( + $field_vis $field: $crate::$__pin_project_make_proj_field!( + $(#[$pin])? $field_ty + ) + ),+ + ] + } + }; + ( + [$proj_ty_ident:ident] + [$proj_vis:vis enum $ident:ident] + [$__pin_project_make_proj_field:ident] + [$($impl_generics:tt)*] [$($ty_generics:tt)*] [$(where $($where_clause:tt)*)?] + { + $( + $(#[$variant_attrs:meta])* + $variant:ident $({ + $( + $(#[$pin:ident])? + $field:ident: $field_ty:ty + ),+ $(,)? + })? + ),+ $(,)? + } + ) => { + $crate::__pin_project_make_proj_ty_body! { + [$proj_ty_ident] + [$proj_vis enum $ident] + [$($impl_generics)*] [$($ty_generics)*] [$(where $($where_clause)*)?] + [ + $( + $variant $({ + $( + $field: $crate::$__pin_project_make_proj_field!( + $(#[$pin])? $field_ty + ) + ),+ + })? + ),+ + ] + } + }; +} + +#[doc(hidden)] +#[macro_export] +macro_rules! __pin_project_make_proj_ty_body { + ( + [$proj_ty_ident:ident] + [$proj_vis:vis $struct_ty_ident:ident $ident:ident] + [$($impl_generics:tt)*] [$($ty_generics:tt)*] [$(where $($where_clause:tt)*)?] + [$($body_data:tt)+] + ) => { + #[allow(dead_code)] // This lint warns unused fields/variants. + #[allow(single_use_lifetimes)] // https://github.com/rust-lang/rust/issues/55058 + // This lint warns of `clippy::*` generated by external macros. + // We allow this lint for compatibility with older compilers. + #[allow(clippy::unknown_clippy_lints)] + #[allow(clippy::mut_mut)] // This lint warns `&mut &mut `. (only needed for project) + #[allow(clippy::redundant_pub_crate)] // This lint warns `pub(crate)` field in private struct. + #[allow(clippy::ref_option_ref)] // This lint warns `&Option<&>`. (only needed for project_ref) + #[allow(clippy::type_repetition_in_bounds)] // https://github.com/rust-lang/rust-clippy/issues/4326 + $proj_vis $struct_ty_ident $proj_ty_ident <'__pin, $($impl_generics)*> + where + $ident <$($ty_generics)*>: '__pin + $(, $($where_clause)*)? + { + $($body_data)+ + } + }; +} + +#[doc(hidden)] +#[macro_export] +macro_rules! __pin_project_make_proj_replace_ty { + ([] $($field:tt)*) => {}; + ( + [$proj_ty_ident:ident] + [$proj_vis:vis struct] + [$__pin_project_make_proj_field:ident] + [$($impl_generics:tt)*] [$($ty_generics:tt)*] [$(where $($where_clause:tt)*)?] + { + $( + $(#[$pin:ident])? + $field_vis:vis $field:ident: $field_ty:ty + ),+ $(,)? + } + ) => { + $crate::__pin_project_make_proj_replace_ty_body! { + [$proj_ty_ident] + [$proj_vis struct] + [$($impl_generics)*] [$($ty_generics)*] [$(where $($where_clause)*)?] + [ + $( + $field_vis $field: $crate::$__pin_project_make_proj_field!( + $(#[$pin])? $field_ty + ) + ),+ + ] + } + }; + ( + [$proj_ty_ident:ident] + [$proj_vis:vis enum] + [$__pin_project_make_proj_field:ident] + [$($impl_generics:tt)*] [$($ty_generics:tt)*] [$(where $($where_clause:tt)*)?] + { + $( + $(#[$variant_attrs:meta])* + $variant:ident $({ + $( + $(#[$pin:ident])? + $field:ident: $field_ty:ty + ),+ $(,)? + })? + ),+ $(,)? + } + ) => { + $crate::__pin_project_make_proj_replace_ty_body! { + [$proj_ty_ident] + [$proj_vis enum] + [$($impl_generics)*] [$($ty_generics)*] [$(where $($where_clause)*)?] + [ + $( + $variant $({ + $( + $field: $crate::$__pin_project_make_proj_field!( + $(#[$pin])? $field_ty + ) + ),+ + })? + ),+ + ] + } + }; +} + +#[doc(hidden)] +#[macro_export] +macro_rules! __pin_project_make_proj_replace_ty_body { + ( + [$proj_ty_ident:ident] + [$proj_vis:vis $struct_ty_ident:ident] + [$($impl_generics:tt)*] [$($ty_generics:tt)*] [$(where $($where_clause:tt)*)?] + [$($body_data:tt)+] + ) => { + #[allow(dead_code)] // This lint warns unused fields/variants. + #[allow(single_use_lifetimes)] // https://github.com/rust-lang/rust/issues/55058 + #[allow(clippy::mut_mut)] // This lint warns `&mut &mut `. (only needed for project) + #[allow(clippy::redundant_pub_crate)] // This lint warns `pub(crate)` field in private struct. + #[allow(clippy::type_repetition_in_bounds)] // https://github.com/rust-lang/rust-clippy/issues/4326 + $proj_vis $struct_ty_ident $proj_ty_ident <$($impl_generics)*> + where + $($($where_clause)*)? + { + $($body_data)+ + } + }; +} + +#[doc(hidden)] +#[macro_export] +macro_rules! __pin_project_make_proj_replace_block { + ( + [$($proj_path:tt)+] + { + $( + $(#[$pin:ident])? + $field_vis:vis $field:ident + ),+ + } + ) => { + let result = $($proj_path)* { + $( + $field: $crate::__pin_project_make_replace_field_proj!( + $(#[$pin])? $field + ) + ),+ + }; + + { + ( $( + $crate::__pin_project_make_unsafe_drop_in_place_guard!( + $(#[$pin])? $field + ), + )* ); + } + + result + }; + ([$($proj_path:tt)+]) => { $($proj_path)* }; +} + +#[doc(hidden)] +#[macro_export] +macro_rules! __pin_project_struct_make_proj_method { + ([] $($variant:tt)*) => {}; + ( + [$proj_ty_ident:ident $_ignored_default_arg:ident] + [$proj_vis:vis] + [$method_ident:ident $get_method:ident $($mut:ident)?] + [$($ty_generics:tt)*] + $($variant:tt)* + ) => { + $crate::__pin_project_struct_make_proj_method! { + [$proj_ty_ident] + [$proj_vis] + [$method_ident $get_method $($mut)?] + [$($ty_generics)*] + $($variant)* + } + }; + ( + [$proj_ty_ident:ident] + [$proj_vis:vis] + [$method_ident:ident $get_method:ident $($mut:ident)?] + [$($ty_generics:tt)*] + { + $( + $(#[$pin:ident])? + $field_vis:vis $field:ident + ),+ + } + ) => { + $proj_vis fn $method_ident<'__pin>( + self: $crate::__private::Pin<&'__pin $($mut)? Self>, + ) -> $proj_ty_ident <'__pin, $($ty_generics)*> { + unsafe { + let Self { $($field),* } = self.$get_method(); + $proj_ty_ident { + $( + $field: $crate::__pin_project_make_unsafe_field_proj!( + $(#[$pin])? $field + ) + ),+ + } + } + } + }; +} + +#[doc(hidden)] +#[macro_export] +macro_rules! __pin_project_struct_make_proj_replace_method { + ([] $($field:tt)*) => {}; + ( + [$proj_ty_ident:ident] + [$proj_vis:vis] + [$_proj_ty_ident:ident] + [$($ty_generics:tt)*] + { + $( + $(#[$pin:ident])? + $field_vis:vis $field:ident + ),+ + } + ) => { + $proj_vis fn project_replace( + self: $crate::__private::Pin<&mut Self>, + replacement: Self, + ) -> $proj_ty_ident <$($ty_generics)*> { + unsafe { + let __self_ptr: *mut Self = self.get_unchecked_mut(); + + // Destructors will run in reverse order, so next create a guard to overwrite + // `self` with the replacement value without calling destructors. + let __guard = $crate::__private::UnsafeOverwriteGuard::new(__self_ptr, replacement); + + let Self { $($field),* } = &mut *__self_ptr; + + $crate::__pin_project_make_proj_replace_block! { + [$proj_ty_ident] + { + $( + $(#[$pin])? + $field + ),+ + } + } + } + } + }; +} + +#[doc(hidden)] +#[macro_export] +macro_rules! __pin_project_enum_make_proj_method { + ([] $($variant:tt)*) => {}; + ( + [$proj_ty_ident:ident] + [$proj_vis:vis] + [$method_ident:ident $get_method:ident $($mut:ident)?] + [$($ty_generics:tt)*] + { + $( + $variant:ident $({ + $( + $(#[$pin:ident])? + $field:ident + ),+ + })? + ),+ + } + ) => { + $proj_vis fn $method_ident<'__pin>( + self: $crate::__private::Pin<&'__pin $($mut)? Self>, + ) -> $proj_ty_ident <'__pin, $($ty_generics)*> { + unsafe { + match self.$get_method() { + $( + Self::$variant $({ + $($field),+ + })? => { + $proj_ty_ident::$variant $({ + $( + $field: $crate::__pin_project_make_unsafe_field_proj!( + $(#[$pin])? $field + ) + ),+ + })? + } + ),+ + } + } + } + }; +} + +#[doc(hidden)] +#[macro_export] +macro_rules! __pin_project_enum_make_proj_replace_method { + ([] $($field:tt)*) => {}; + ( + [$proj_ty_ident:ident] + [$proj_vis:vis] + [$($ty_generics:tt)*] + { + $( + $variant:ident $({ + $( + $(#[$pin:ident])? + $field:ident + ),+ + })? + ),+ + } + ) => { + $proj_vis fn project_replace( + self: $crate::__private::Pin<&mut Self>, + replacement: Self, + ) -> $proj_ty_ident <$($ty_generics)*> { + unsafe { + let __self_ptr: *mut Self = self.get_unchecked_mut(); + + // Destructors will run in reverse order, so next create a guard to overwrite + // `self` with the replacement value without calling destructors. + let __guard = $crate::__private::UnsafeOverwriteGuard::new(__self_ptr, replacement); + + match &mut *__self_ptr { + $( + Self::$variant $({ + $($field),+ + })? => { + $crate::__pin_project_make_proj_replace_block! { + [$proj_ty_ident :: $variant] + $({ + $( + $(#[$pin])? + $field + ),+ + })? + } + } + ),+ + } + } + } + }; +} + +#[doc(hidden)] +#[macro_export] +macro_rules! __pin_project_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 Unpin for Struct where T: Unpin {} + // ``` + // + // However, if struct is public and there is a private type field, + // this would cause an E0446 (private type in public interface). + // + // When RFC 2145 is implemented (rust-lang/rust#48054), + // this will become a lint, rather then a hard error. + // + // As a workaround for this, we generate a new struct, containing all of the pinned + // fields from our #[pin_project] type. This struct is declared within + // a function, which makes it impossible to be named by user code. + // This guarantees that it will use the default auto-trait impl for Unpin - + // that is, it will implement Unpin iff all of its fields implement Unpin. + // This type can be safely declared as 'public', satisfying the privacy + // checker without actually allowing user code to access it. + // + // This allows users to apply the #[pin_project] attribute to types + // regardless of the privacy of the types of their fields. + // + // See also https://github.com/taiki-e/pin-project/pull/53. + #[allow(non_snake_case)] + $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)*)? + { + } + }; +} + +#[doc(hidden)] +#[macro_export] +macro_rules! __pin_project_make_drop_impl { + ( + [$_ident:ident] + [$($_impl_generics:tt)*] [$($_ty_generics:tt)*] [$(where $($_where_clause:tt)*)?] + impl $(< + $( $lifetime:lifetime $(: $lifetime_bound:lifetime)? ),* $(,)? + $( $generics:ident + $(: $generics_bound:path)? + $(: ?$generics_unsized_bound:path)? + $(: $generics_lifetime_bound:lifetime)? + ),* + >)? PinnedDrop for $self_ty:ty + $(where + $( $where_clause_ty:ty + $(: $where_clause_bound:path)? + $(: ?$where_clause_unsized_bound:path)? + $(: $where_clause_lifetime_bound:lifetime)? + ),* $(,)? + )? + { + fn drop($($arg:ident)+: Pin<&mut Self>) { + $($tt:tt)* + } + } + ) => { + impl $(< + $( $lifetime $(: $lifetime_bound)? ,)* + $( $generics + $(: $generics_bound)? + $(: ?$generics_unsized_bound)? + $(: $generics_lifetime_bound)? + ),* + >)? $crate::__private::Drop for $self_ty + $(where + $( $where_clause_ty + $(: $where_clause_bound)? + $(: ?$where_clause_unsized_bound)? + $(: $where_clause_lifetime_bound)? + ),* + )? + { + fn drop(&mut self) { + // Implementing `__DropInner::__drop_inner` is safe, but calling it is not safe. + // This is because destructors can be called multiple times in safe code and + // [double dropping is unsound](https://github.com/rust-lang/rust/pull/62360). + // + // `__drop_inner` is defined as a safe method, but this is fine since + // `__drop_inner` is not accessible by the users and we call `__drop_inner` only + // once. + // + // Users can implement [`Drop`] safely using `pin_project!` and can drop a + // type that implements `PinnedDrop` using the [`drop`] function safely. + fn __drop_inner $(< + $( $lifetime $(: $lifetime_bound)? ,)* + $( $generics + $(: $generics_bound)? + $(: ?$generics_unsized_bound)? + $(: $generics_lifetime_bound)? + ),* + >)? ( + $($arg)+: $crate::__private::Pin<&mut $self_ty>, + ) + $(where + $( $where_clause_ty + $(: $where_clause_bound)? + $(: ?$where_clause_unsized_bound)? + $(: $where_clause_lifetime_bound)? + ),* + )? + { + // A dummy `__drop_inner` function to prevent users call outer `__drop_inner`. + fn __drop_inner() {} + $($tt)* + } + + // Safety - we're in 'drop', so we know that 'self' will + // never move again. + let pinned_self: $crate::__private::Pin<&mut Self> + = unsafe { $crate::__private::Pin::new_unchecked(self) }; + // We call `__drop_inner` only once. Since `__DropInner::__drop_inner` + // is not accessible by the users, it is never called again. + __drop_inner(pinned_self); + } + } + }; + ( + [$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 conflict with the explicit MustNotImplDrop impl below. + // This will result in a compilation error, which is exactly what we want. + trait MustNotImplDrop {} + #[allow(clippy::drop_bounds, drop_bounds)] + impl MustNotImplDrop for T {} + impl <$($impl_generics)*> MustNotImplDrop for $ident <$($ty_generics)*> + $(where + $($where_clause)*)? + { + } + }; +} + +#[doc(hidden)] +#[macro_export] +macro_rules! __pin_project_make_unpin_bound { + (#[pin] $field_ty:ty) => { + $field_ty + }; + ($field_ty:ty) => { + $crate::__private::AlwaysUnpin<$field_ty> + }; +} + +#[doc(hidden)] +#[macro_export] +macro_rules! __pin_project_make_unsafe_field_proj { + (#[pin] $field:ident) => { + $crate::__private::Pin::new_unchecked($field) + }; + ($field:ident) => { + $field + }; +} + +#[doc(hidden)] +#[macro_export] +macro_rules! __pin_project_make_replace_field_proj { + (#[pin] $field:ident) => { + $crate::__private::PhantomData + }; + ($field:ident) => { + $crate::__private::ptr::read($field) + }; +} + +#[doc(hidden)] +#[macro_export] +macro_rules! __pin_project_make_unsafe_drop_in_place_guard { + (#[pin] $field:ident) => { + $crate::__private::UnsafeDropInPlaceGuard::new($field) + }; + ($field:ident) => { + () + }; +} + +#[doc(hidden)] +#[macro_export] +macro_rules! __pin_project_make_proj_field_mut { + (#[pin] $field_ty:ty) => { + $crate::__private::Pin<&'__pin mut ($field_ty)> + }; + ($field_ty:ty) => { + &'__pin mut ($field_ty) + }; +} + +#[doc(hidden)] +#[macro_export] +macro_rules! __pin_project_make_proj_field_ref { + (#[pin] $field_ty:ty) => { + $crate::__private::Pin<&'__pin ($field_ty)> + }; + ($field_ty:ty) => { + &'__pin ($field_ty) + }; +} + +#[doc(hidden)] +#[macro_export] +macro_rules! __pin_project_make_proj_field_replace { + (#[pin] $field_ty:ty) => { + $crate::__private::PhantomData<$field_ty> + }; + ($field_ty:ty) => { + $field_ty + }; +} + +#[doc(hidden)] +#[macro_export] +macro_rules! __pin_project_internal { + // parsing proj_mut_ident + ( + [] + [$($proj_ref_ident:ident)?] + [$($proj_replace_ident:ident)?] + [$($attrs:tt)*] + + #[project = $proj_mut_ident:ident] + $($tt:tt)* + ) => { + $crate::__pin_project_internal! { + [$proj_mut_ident] + [$($proj_ref_ident)?] + [$($proj_replace_ident)?] + [$($attrs)*] + $($tt)* + } + }; + // parsing proj_ref_ident + ( + [$($proj_mut_ident:ident)?] + [] + [$($proj_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)* + } + }; + // parsing proj_replace_ident + ( + [$($proj_mut_ident:ident)?] + [$($proj_ref_ident:ident)?] + [] + [$($attrs:tt)*] + + #[project_replace = $proj_replace_ident:ident] + $($tt:tt)* + ) => { + $crate::__pin_project_internal! { + [$($proj_mut_ident)?] + [$($proj_ref_ident)?] + [$proj_replace_ident] + [$($attrs)*] + $($tt)* + } + }; + // this is actually part of a recursive step that picks off a single non-`pin_project_lite` attribute + // there could be more to parse + ( + [$($proj_mut_ident:ident)?] + [$($proj_ref_ident:ident)?] + [$($proj_replace_ident:ident)?] + [$($attrs:tt)*] + + #[$($attr:tt)*] + $($tt:tt)* + ) => { + $crate::__pin_project_internal! { + [$($proj_mut_ident)?] + [$($proj_ref_ident)?] + [$($proj_replace_ident)?] + [$($attrs)* #[$($attr)*]] + $($tt)* + } + }; + // now determine visibility + // if public, downgrade + ( + [$($proj_mut_ident:ident)?] + [$($proj_ref_ident:ident)?] + [$($proj_replace_ident:ident)?] + [$($attrs:tt)*] + pub $struct_ty_ident:ident $ident:ident + $($tt:tt)* + ) => { + $crate::__pin_project_parse_generics! { + [$($proj_mut_ident)?] + [$($proj_ref_ident)?] + [$($proj_replace_ident)?] + [$($attrs)*] + [pub $struct_ty_ident $ident pub(crate)] + $($tt)* + } + }; + ( + [$($proj_mut_ident:ident)?] + [$($proj_ref_ident:ident)?] + [$($proj_replace_ident:ident)?] + [$($attrs:tt)*] + $vis:vis $struct_ty_ident:ident $ident:ident + $($tt:tt)* + ) => { + $crate::__pin_project_parse_generics! { + [$($proj_mut_ident)?] + [$($proj_ref_ident)?] + [$($proj_replace_ident)?] + [$($attrs)*] + [$vis $struct_ty_ident $ident $vis] + $($tt)* + } + }; +} + +#[doc(hidden)] +#[macro_export] +macro_rules! __pin_project_parse_generics { + ( + [$($proj_mut_ident:ident)?] + [$($proj_ref_ident:ident)?] + [$($proj_replace_ident:ident)?] + [$($attrs:tt)*] + [$vis:vis $struct_ty_ident:ident $ident:ident $proj_ty_vis:vis] + $(< + $( $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)? + ),* $(,)? + )? + { + $($body_data:tt)* + } + $(impl $($pinned_drop:tt)*)? + ) => { + $crate::__pin_project_expand! { + [$($proj_mut_ident)?] + [$($proj_ref_ident)?] + [$($proj_replace_ident)?] + [$proj_ty_vis] + [$($attrs)* $vis $struct_ty_ident $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)? + ),* )?] + { + $($body_data)* + } + $(impl $($pinned_drop)*)? + } + }; +} + +#[doc(hidden)] +pub mod __private { + use core::mem::ManuallyDrop; + #[doc(hidden)] + pub use core::{ + marker::{PhantomData, Unpin}, + ops::Drop, + pin::Pin, + ptr, + }; + + // This is an internal helper struct used by `pin_project!`. + #[doc(hidden)] + pub struct AlwaysUnpin(PhantomData); + + impl Unpin for AlwaysUnpin {} + + // This is an internal helper used to ensure a value is dropped. + #[doc(hidden)] + pub struct UnsafeDropInPlaceGuard(*mut T); + + impl UnsafeDropInPlaceGuard { + #[doc(hidden)] + pub unsafe fn new(ptr: *mut T) -> Self { + Self(ptr) + } + } + + impl Drop for UnsafeDropInPlaceGuard { + fn drop(&mut self) { + unsafe { + ptr::drop_in_place(self.0); + } + } + } + + // This is an internal helper used to ensure a value is overwritten without + // its destructor being called. + #[doc(hidden)] + pub struct UnsafeOverwriteGuard { + target: *mut T, + value: ManuallyDrop, + } + + impl UnsafeOverwriteGuard { + #[doc(hidden)] + pub unsafe fn new(target: *mut T, value: T) -> Self { + Self { target, value: ManuallyDrop::new(value) } + } + } + + impl Drop for UnsafeOverwriteGuard { + fn drop(&mut self) { + unsafe { + ptr::write(self.target, ptr::read(&*self.value)); + } + } + } +} diff --git a/third_party/rust/pin-project-lite/tests/README.md b/third_party/rust/pin-project-lite/tests/README.md new file mode 100644 index 0000000000..47216165df --- /dev/null +++ b/third_party/rust/pin-project-lite/tests/README.md @@ -0,0 +1,46 @@ +# Tests + +Many of the tests in this repository are based on [pin-project's tests](https://github.com/taiki-e/pin-project/tree/HEAD/tests). + +To run all tests, run the following command: + +```sh +cargo +nightly test --all +``` + +## UI tests (`ui`, `compiletest.rs`) + +This checks errors detected by the macro or the Rust compiler in the resulting +expanded code. + +To run this test, run the following command: + +```sh +cargo +nightly test --test compiletest +``` + +Locally, this test updates the files in the `ui` directory if there are +changes to the generated code. If there are any changes to the files in the +`ui` directory after running the test, please commit them. + +See also [`trybuild` documentation](https://docs.rs/trybuild). + +## Expansion tests (`expand`, `expandtest.rs`) + +Similar to ui tests, but instead of checking the compiler output, this checks +the code generated by macros. + +See pin-project's [examples](https://github.com/taiki-e/pin-project/tree/HEAD/examples) +for descriptions of what the generated code does, and why it needs to be generated. + +To run this test, run the following command: + +```sh +cargo +nightly test --test expandtest +``` + +Locally, this test updates the files in the `expand` directory if there are +changes to the generated code. If there are any changes to the files in the +`expand` directory after running the test, please commit them. + +See also [`macrotest` documentation](https://docs.rs/macrotest). diff --git a/third_party/rust/pin-project-lite/tests/auxiliary/mod.rs b/third_party/rust/pin-project-lite/tests/auxiliary/mod.rs new file mode 100644 index 0000000000..1457099160 --- /dev/null +++ b/third_party/rust/pin-project-lite/tests/auxiliary/mod.rs @@ -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); + }; +} diff --git a/third_party/rust/pin-project-lite/tests/compiletest.rs b/third_party/rust/pin-project-lite/tests/compiletest.rs new file mode 100644 index 0000000000..70d2358943 --- /dev/null +++ b/third_party/rust/pin-project-lite/tests/compiletest.rs @@ -0,0 +1,15 @@ +#![cfg(not(miri))] +#![warn(rust_2018_idioms, single_use_lifetimes)] + +use std::env; + +#[rustversion::attr(not(nightly), ignore)] +#[test] +fn ui() { + if env::var_os("CI").is_none() { + env::set_var("TRYBUILD", "overwrite"); + } + + let t = trybuild::TestCases::new(); + t.compile_fail("tests/ui/**/*.rs"); +} diff --git a/third_party/rust/pin-project-lite/tests/drop_order.rs b/third_party/rust/pin-project-lite/tests/drop_order.rs new file mode 100644 index 0000000000..6e5deaf154 --- /dev/null +++ b/third_party/rust/pin-project-lite/tests/drop_order.rs @@ -0,0 +1,169 @@ +#![warn(rust_2018_idioms, single_use_lifetimes)] + +// Refs: https://doc.rust-lang.org/reference/destructors.html + +use std::{cell::Cell, panic, pin::Pin, thread}; + +use pin_project_lite::pin_project; + +struct D<'a>(&'a Cell, usize); + +impl Drop for D<'_> { + fn drop(&mut self) { + if !thread::panicking() { + let old = self.0.replace(self.1); + assert_eq!(old, self.1 - 1); + } + } +} + +pin_project! { +#[project = StructPinnedProj] +#[project_ref = StructPinnedProjRef] +#[project_replace = StructPinnedProjReplace] +struct StructPinned<'a> { + #[pin] + f1: D<'a>, + #[pin] + f2: D<'a>, +} +} + +pin_project! { +#[project = StructUnpinnedProj] +#[project_ref = StructUnpinnedProjRef] +#[project_replace = StructUnpinnedProjReplace] +struct StructUnpinned<'a> { + f1: D<'a>, + f2: D<'a>, +} +} + +pin_project! { +#[project_replace = EnumProjReplace] +enum Enum<'a> { + #[allow(dead_code)] // false positive that fixed in Rust 1.38 + StructPinned { + #[pin] + f1: D<'a>, + #[pin] + f2: D<'a>, + }, + #[allow(dead_code)] // false positive that fixed in Rust 1.38 + StructUnpinned { + f1: D<'a>, + f2: D<'a>, + }, +} +} + +#[test] +fn struct_pinned() { + { + let c = Cell::new(0); + let _x = StructPinned { f1: D(&c, 1), f2: D(&c, 2) }; + } + { + let c = Cell::new(0); + let mut x = StructPinned { f1: D(&c, 1), f2: D(&c, 2) }; + let y = Pin::new(&mut x); + let _z = y.project_replace(StructPinned { f1: D(&c, 3), f2: D(&c, 4) }); + } +} + +#[test] +fn struct_unpinned() { + { + let c = Cell::new(0); + let _x = StructUnpinned { f1: D(&c, 1), f2: D(&c, 2) }; + } + { + let c = Cell::new(0); + let mut x = StructUnpinned { f1: D(&c, 1), f2: D(&c, 2) }; + let y = Pin::new(&mut x); + let _z = y.project_replace(StructUnpinned { f1: D(&c, 3), f2: D(&c, 4) }); + } +} + +#[test] +fn enum_struct() { + { + let c = Cell::new(0); + let _x = Enum::StructPinned { f1: D(&c, 1), f2: D(&c, 2) }; + } + { + let c = Cell::new(0); + let mut x = Enum::StructPinned { f1: D(&c, 1), f2: D(&c, 2) }; + let y = Pin::new(&mut x); + let _z = y.project_replace(Enum::StructPinned { f1: D(&c, 3), f2: D(&c, 4) }); + } + + { + let c = Cell::new(0); + let _x = Enum::StructUnpinned { f1: D(&c, 1), f2: D(&c, 2) }; + } + { + let c = Cell::new(0); + let mut x = Enum::StructUnpinned { f1: D(&c, 1), f2: D(&c, 2) }; + let y = Pin::new(&mut x); + let _z = y.project_replace(Enum::StructUnpinned { f1: D(&c, 3), f2: D(&c, 4) }); + } +} + +// https://github.com/rust-lang/rust/issues/47949 +// https://github.com/taiki-e/pin-project/pull/194#discussion_r419098111 +#[allow(clippy::many_single_char_names)] +#[test] +fn project_replace_panic() { + pin_project! { + #[project_replace = SProjReplace] + struct S { + #[pin] + pinned: T, + unpinned: U, + } + } + + struct D<'a>(&'a mut bool, bool); + impl Drop for D<'_> { + fn drop(&mut self) { + *self.0 = true; + if self.1 { + panic!(); + } + } + } + + let (mut a, mut b, mut c, mut d) = (false, false, false, false); + let res = panic::catch_unwind(panic::AssertUnwindSafe(|| { + let mut x = S { pinned: D(&mut a, true), unpinned: D(&mut b, false) }; + let _y = Pin::new(&mut x) + .project_replace(S { pinned: D(&mut c, false), unpinned: D(&mut d, false) }); + // Previous `x.pinned` was dropped and panicked when `project_replace` is + // called, so this is unreachable. + unreachable!(); + })); + assert!(res.is_err()); + assert!(a); + assert!(b); + assert!(c); + assert!(d); + + let (mut a, mut b, mut c, mut d) = (false, false, false, false); + let res = panic::catch_unwind(panic::AssertUnwindSafe(|| { + let mut x = S { pinned: D(&mut a, false), unpinned: D(&mut b, true) }; + { + let _y = Pin::new(&mut x) + .project_replace(S { pinned: D(&mut c, false), unpinned: D(&mut d, false) }); + // `_y` (previous `x.unpinned`) live to the end of this scope, so + // this is not unreachable. + // unreachable!(); + } + unreachable!(); + })); + assert!(res.is_err()); + assert!(a); + assert!(b); + assert!(c); + assert!(d); +} diff --git a/third_party/rust/pin-project-lite/tests/expand/default/enum.expanded.rs b/third_party/rust/pin-project-lite/tests/expand/default/enum.expanded.rs new file mode 100644 index 0000000000..eae0aac85e --- /dev/null +++ b/third_party/rust/pin-project-lite/tests/expand/default/enum.expanded.rs @@ -0,0 +1,127 @@ +use pin_project_lite::pin_project; +enum Enum { + 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: '__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: '__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 { + Struct { + pinned: ::pin_project_lite::__private::PhantomData, + unpinned: U, + }, + Unit, +} +#[allow(single_use_lifetimes)] +#[allow(clippy::unknown_clippy_lints)] +#[allow(clippy::used_underscore_binding)] +const _: () = { + impl Enum { + 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 { + unsafe { + let __self_ptr: *mut Self = self.get_unchecked_mut(); + let __guard = ::pin_project_lite::__private::UnsafeOverwriteGuard::new( + __self_ptr, + replacement, + ); + match &mut *__self_ptr { + Self::Struct { pinned, unpinned } => { + let result = EnumProjReplace::Struct { + pinned: ::pin_project_lite::__private::PhantomData, + unpinned: ::pin_project_lite::__private::ptr::read(unpinned), + }; + { + ( + ::pin_project_lite::__private::UnsafeDropInPlaceGuard::new(pinned), + (), + ); + } + result + } + Self::Unit => EnumProjReplace::Unit, + } + } + } + } + #[allow(non_snake_case)] + struct __Origin<'__pin, T, U> { + __dummy_lifetime: ::pin_project_lite::__private::PhantomData<&'__pin ()>, + Struct: (T, ::pin_project_lite::__private::AlwaysUnpin), + Unit: (), + } + impl<'__pin, T, U> ::pin_project_lite::__private::Unpin for Enum where + __Origin<'__pin, T, U>: ::pin_project_lite::__private::Unpin + { + } + trait MustNotImplDrop {} + #[allow(clippy::drop_bounds, drop_bounds)] + impl MustNotImplDrop for T {} + impl MustNotImplDrop for Enum {} +}; +fn main() {} diff --git a/third_party/rust/pin-project-lite/tests/expand/default/enum.rs b/third_party/rust/pin-project-lite/tests/expand/default/enum.rs new file mode 100644 index 0000000000..90d6860a81 --- /dev/null +++ b/third_party/rust/pin-project-lite/tests/expand/default/enum.rs @@ -0,0 +1,17 @@ +use pin_project_lite::pin_project; + +pin_project! { + #[project = EnumProj] + #[project_ref = EnumProjRef] + #[project_replace = EnumProjReplace] + enum Enum { + Struct { + #[pin] + pinned: T, + unpinned: U, + }, + Unit, + } +} + +fn main() {} diff --git a/third_party/rust/pin-project-lite/tests/expand/default/struct.expanded.rs b/third_party/rust/pin-project-lite/tests/expand/default/struct.expanded.rs new file mode 100644 index 0000000000..8ab318cfb8 --- /dev/null +++ b/third_party/rust/pin-project-lite/tests/expand/default/struct.expanded.rs @@ -0,0 +1,84 @@ +use pin_project_lite::pin_project; +struct Struct { + 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: '__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: '__pin, + { + pinned: ::pin_project_lite::__private::Pin<&'__pin (T)>, + unpinned: &'__pin (U), + } + impl Struct { + 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, + } + impl<'__pin, T, U> ::pin_project_lite::__private::Unpin for Struct where + __Origin<'__pin, T, U>: ::pin_project_lite::__private::Unpin + { + } + trait MustNotImplDrop {} + #[allow(clippy::drop_bounds, drop_bounds)] + impl MustNotImplDrop for T {} + impl MustNotImplDrop for Struct {} + #[forbid(unaligned_references, safe_packed_borrows)] + fn __assert_not_repr_packed(this: &Struct) { + let _ = &this.pinned; + let _ = &this.unpinned; + } +}; +fn main() {} diff --git a/third_party/rust/pin-project-lite/tests/expand/default/struct.rs b/third_party/rust/pin-project-lite/tests/expand/default/struct.rs new file mode 100644 index 0000000000..e5447c70a6 --- /dev/null +++ b/third_party/rust/pin-project-lite/tests/expand/default/struct.rs @@ -0,0 +1,11 @@ +use pin_project_lite::pin_project; + +pin_project! { + struct Struct { + #[pin] + pinned: T, + unpinned: U, + } +} + +fn main() {} diff --git a/third_party/rust/pin-project-lite/tests/expand/multifields/enum.expanded.rs b/third_party/rust/pin-project-lite/tests/expand/multifields/enum.expanded.rs new file mode 100644 index 0000000000..fca0febcda --- /dev/null +++ b/third_party/rust/pin-project-lite/tests/expand/multifields/enum.expanded.rs @@ -0,0 +1,88 @@ +use pin_project_lite::pin_project; +enum Enum { + 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 { + Struct { + pinned1: ::pin_project_lite::__private::PhantomData, + pinned2: ::pin_project_lite::__private::PhantomData, + unpinned1: U, + unpinned2: U, + }, + Unit, +} +#[allow(single_use_lifetimes)] +#[allow(clippy::unknown_clippy_lints)] +#[allow(clippy::used_underscore_binding)] +const _: () = { + impl Enum { + fn project_replace( + self: ::pin_project_lite::__private::Pin<&mut Self>, + replacement: Self, + ) -> EnumProjReplace { + unsafe { + let __self_ptr: *mut Self = self.get_unchecked_mut(); + let __guard = ::pin_project_lite::__private::UnsafeOverwriteGuard::new( + __self_ptr, + replacement, + ); + match &mut *__self_ptr { + Self::Struct { + pinned1, + pinned2, + unpinned1, + unpinned2, + } => { + let result = EnumProjReplace::Struct { + pinned1: ::pin_project_lite::__private::PhantomData, + pinned2: ::pin_project_lite::__private::PhantomData, + unpinned1: ::pin_project_lite::__private::ptr::read(unpinned1), + unpinned2: ::pin_project_lite::__private::ptr::read(unpinned2), + }; + { + ( + ::pin_project_lite::__private::UnsafeDropInPlaceGuard::new(pinned1), + ::pin_project_lite::__private::UnsafeDropInPlaceGuard::new(pinned2), + (), + (), + ); + } + result + } + Self::Unit => EnumProjReplace::Unit, + } + } + } + } + #[allow(non_snake_case)] + struct __Origin<'__pin, T, U> { + __dummy_lifetime: ::pin_project_lite::__private::PhantomData<&'__pin ()>, + Struct: ( + T, + T, + ::pin_project_lite::__private::AlwaysUnpin, + ::pin_project_lite::__private::AlwaysUnpin, + ), + Unit: (), + } + impl<'__pin, T, U> ::pin_project_lite::__private::Unpin for Enum where + __Origin<'__pin, T, U>: ::pin_project_lite::__private::Unpin + { + } + trait MustNotImplDrop {} + #[allow(clippy::drop_bounds, drop_bounds)] + impl MustNotImplDrop for T {} + impl MustNotImplDrop for Enum {} +}; +fn main() {} diff --git a/third_party/rust/pin-project-lite/tests/expand/multifields/enum.rs b/third_party/rust/pin-project-lite/tests/expand/multifields/enum.rs new file mode 100644 index 0000000000..c713362ad6 --- /dev/null +++ b/third_party/rust/pin-project-lite/tests/expand/multifields/enum.rs @@ -0,0 +1,18 @@ +use pin_project_lite::pin_project; + +pin_project! { +#[project_replace = EnumProjReplace] +enum Enum { + Struct { + #[pin] + pinned1: T, + #[pin] + pinned2: T, + unpinned1: U, + unpinned2: U, + }, + Unit, +} +} + +fn main() {} diff --git a/third_party/rust/pin-project-lite/tests/expand/multifields/struct.expanded.rs b/third_party/rust/pin-project-lite/tests/expand/multifields/struct.expanded.rs new file mode 100644 index 0000000000..4320f68438 --- /dev/null +++ b/third_party/rust/pin-project-lite/tests/expand/multifields/struct.expanded.rs @@ -0,0 +1,152 @@ +use pin_project_lite::pin_project; +struct Struct { + 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 { + pinned1: ::pin_project_lite::__private::PhantomData, + pinned2: ::pin_project_lite::__private::PhantomData, + 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: '__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: '__pin, + { + pinned1: ::pin_project_lite::__private::Pin<&'__pin (T)>, + pinned2: ::pin_project_lite::__private::Pin<&'__pin (T)>, + unpinned1: &'__pin (U), + unpinned2: &'__pin (U), + } + impl Struct { + 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 { + unsafe { + let __self_ptr: *mut Self = self.get_unchecked_mut(); + let __guard = ::pin_project_lite::__private::UnsafeOverwriteGuard::new( + __self_ptr, + replacement, + ); + let Self { + pinned1, + pinned2, + unpinned1, + unpinned2, + } = &mut *__self_ptr; + let result = StructProjReplace { + pinned1: ::pin_project_lite::__private::PhantomData, + pinned2: ::pin_project_lite::__private::PhantomData, + unpinned1: ::pin_project_lite::__private::ptr::read(unpinned1), + unpinned2: ::pin_project_lite::__private::ptr::read(unpinned2), + }; + { + ( + ::pin_project_lite::__private::UnsafeDropInPlaceGuard::new(pinned1), + ::pin_project_lite::__private::UnsafeDropInPlaceGuard::new(pinned2), + (), + (), + ); + } + result + } + } + } + #[allow(non_snake_case)] + struct __Origin<'__pin, T, U> { + __dummy_lifetime: ::pin_project_lite::__private::PhantomData<&'__pin ()>, + pinned1: T, + pinned2: T, + unpinned1: ::pin_project_lite::__private::AlwaysUnpin, + unpinned2: ::pin_project_lite::__private::AlwaysUnpin, + } + impl<'__pin, T, U> ::pin_project_lite::__private::Unpin for Struct where + __Origin<'__pin, T, U>: ::pin_project_lite::__private::Unpin + { + } + trait MustNotImplDrop {} + #[allow(clippy::drop_bounds, drop_bounds)] + impl MustNotImplDrop for T {} + impl MustNotImplDrop for Struct {} + #[forbid(unaligned_references, safe_packed_borrows)] + fn __assert_not_repr_packed(this: &Struct) { + let _ = &this.pinned1; + let _ = &this.pinned2; + let _ = &this.unpinned1; + let _ = &this.unpinned2; + } +}; +fn main() {} diff --git a/third_party/rust/pin-project-lite/tests/expand/multifields/struct.rs b/third_party/rust/pin-project-lite/tests/expand/multifields/struct.rs new file mode 100644 index 0000000000..a1d45d168e --- /dev/null +++ b/third_party/rust/pin-project-lite/tests/expand/multifields/struct.rs @@ -0,0 +1,15 @@ +use pin_project_lite::pin_project; + +pin_project! { +#[project_replace = StructProjReplace] +struct Struct { + #[pin] + pinned1: T, + #[pin] + pinned2: T, + unpinned1: U, + unpinned2: U, +} +} + +fn main() {} diff --git a/third_party/rust/pin-project-lite/tests/expand/naming/enum-all.expanded.rs b/third_party/rust/pin-project-lite/tests/expand/naming/enum-all.expanded.rs new file mode 100644 index 0000000000..eae0aac85e --- /dev/null +++ b/third_party/rust/pin-project-lite/tests/expand/naming/enum-all.expanded.rs @@ -0,0 +1,127 @@ +use pin_project_lite::pin_project; +enum Enum { + 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: '__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: '__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 { + Struct { + pinned: ::pin_project_lite::__private::PhantomData, + unpinned: U, + }, + Unit, +} +#[allow(single_use_lifetimes)] +#[allow(clippy::unknown_clippy_lints)] +#[allow(clippy::used_underscore_binding)] +const _: () = { + impl Enum { + 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 { + unsafe { + let __self_ptr: *mut Self = self.get_unchecked_mut(); + let __guard = ::pin_project_lite::__private::UnsafeOverwriteGuard::new( + __self_ptr, + replacement, + ); + match &mut *__self_ptr { + Self::Struct { pinned, unpinned } => { + let result = EnumProjReplace::Struct { + pinned: ::pin_project_lite::__private::PhantomData, + unpinned: ::pin_project_lite::__private::ptr::read(unpinned), + }; + { + ( + ::pin_project_lite::__private::UnsafeDropInPlaceGuard::new(pinned), + (), + ); + } + result + } + Self::Unit => EnumProjReplace::Unit, + } + } + } + } + #[allow(non_snake_case)] + struct __Origin<'__pin, T, U> { + __dummy_lifetime: ::pin_project_lite::__private::PhantomData<&'__pin ()>, + Struct: (T, ::pin_project_lite::__private::AlwaysUnpin), + Unit: (), + } + impl<'__pin, T, U> ::pin_project_lite::__private::Unpin for Enum where + __Origin<'__pin, T, U>: ::pin_project_lite::__private::Unpin + { + } + trait MustNotImplDrop {} + #[allow(clippy::drop_bounds, drop_bounds)] + impl MustNotImplDrop for T {} + impl MustNotImplDrop for Enum {} +}; +fn main() {} diff --git a/third_party/rust/pin-project-lite/tests/expand/naming/enum-all.rs b/third_party/rust/pin-project-lite/tests/expand/naming/enum-all.rs new file mode 100644 index 0000000000..90d6860a81 --- /dev/null +++ b/third_party/rust/pin-project-lite/tests/expand/naming/enum-all.rs @@ -0,0 +1,17 @@ +use pin_project_lite::pin_project; + +pin_project! { + #[project = EnumProj] + #[project_ref = EnumProjRef] + #[project_replace = EnumProjReplace] + enum Enum { + Struct { + #[pin] + pinned: T, + unpinned: U, + }, + Unit, + } +} + +fn main() {} diff --git a/third_party/rust/pin-project-lite/tests/expand/naming/enum-mut.expanded.rs b/third_party/rust/pin-project-lite/tests/expand/naming/enum-mut.expanded.rs new file mode 100644 index 0000000000..7c4d6afbf9 --- /dev/null +++ b/third_party/rust/pin-project-lite/tests/expand/naming/enum-mut.expanded.rs @@ -0,0 +1,57 @@ +use pin_project_lite::pin_project; +enum Enum { + 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: '__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 Enum { + 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), + Unit: (), + } + impl<'__pin, T, U> ::pin_project_lite::__private::Unpin for Enum where + __Origin<'__pin, T, U>: ::pin_project_lite::__private::Unpin + { + } + trait MustNotImplDrop {} + #[allow(clippy::drop_bounds, drop_bounds)] + impl MustNotImplDrop for T {} + impl MustNotImplDrop for Enum {} +}; +fn main() {} diff --git a/third_party/rust/pin-project-lite/tests/expand/naming/enum-mut.rs b/third_party/rust/pin-project-lite/tests/expand/naming/enum-mut.rs new file mode 100644 index 0000000000..69beecd1d9 --- /dev/null +++ b/third_party/rust/pin-project-lite/tests/expand/naming/enum-mut.rs @@ -0,0 +1,15 @@ +use pin_project_lite::pin_project; + +pin_project! { + #[project = EnumProj] + enum Enum { + Struct { + #[pin] + pinned: T, + unpinned: U, + }, + Unit, + } +} + +fn main() {} diff --git a/third_party/rust/pin-project-lite/tests/expand/naming/enum-none.expanded.rs b/third_party/rust/pin-project-lite/tests/expand/naming/enum-none.expanded.rs new file mode 100644 index 0000000000..28ce97da7b --- /dev/null +++ b/third_party/rust/pin-project-lite/tests/expand/naming/enum-none.expanded.rs @@ -0,0 +1,26 @@ +use pin_project_lite::pin_project; +enum Enum { + Struct { pinned: T, unpinned: U }, + Unit, +} +#[allow(single_use_lifetimes)] +#[allow(clippy::unknown_clippy_lints)] +#[allow(clippy::used_underscore_binding)] +const _: () = { + impl Enum {} + #[allow(non_snake_case)] + struct __Origin<'__pin, T, U> { + __dummy_lifetime: ::pin_project_lite::__private::PhantomData<&'__pin ()>, + Struct: (T, ::pin_project_lite::__private::AlwaysUnpin), + Unit: (), + } + impl<'__pin, T, U> ::pin_project_lite::__private::Unpin for Enum where + __Origin<'__pin, T, U>: ::pin_project_lite::__private::Unpin + { + } + trait MustNotImplDrop {} + #[allow(clippy::drop_bounds, drop_bounds)] + impl MustNotImplDrop for T {} + impl MustNotImplDrop for Enum {} +}; +fn main() {} diff --git a/third_party/rust/pin-project-lite/tests/expand/naming/enum-none.rs b/third_party/rust/pin-project-lite/tests/expand/naming/enum-none.rs new file mode 100644 index 0000000000..b2e3f9d76a --- /dev/null +++ b/third_party/rust/pin-project-lite/tests/expand/naming/enum-none.rs @@ -0,0 +1,14 @@ +use pin_project_lite::pin_project; + +pin_project! { + enum Enum { + Struct { + #[pin] + pinned: T, + unpinned: U, + }, + Unit, + } +} + +fn main() {} diff --git a/third_party/rust/pin-project-lite/tests/expand/naming/enum-ref.expanded.rs b/third_party/rust/pin-project-lite/tests/expand/naming/enum-ref.expanded.rs new file mode 100644 index 0000000000..a1a013bda4 --- /dev/null +++ b/third_party/rust/pin-project-lite/tests/expand/naming/enum-ref.expanded.rs @@ -0,0 +1,57 @@ +use pin_project_lite::pin_project; +enum Enum { + 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: '__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 Enum { + 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), + Unit: (), + } + impl<'__pin, T, U> ::pin_project_lite::__private::Unpin for Enum where + __Origin<'__pin, T, U>: ::pin_project_lite::__private::Unpin + { + } + trait MustNotImplDrop {} + #[allow(clippy::drop_bounds, drop_bounds)] + impl MustNotImplDrop for T {} + impl MustNotImplDrop for Enum {} +}; +fn main() {} diff --git a/third_party/rust/pin-project-lite/tests/expand/naming/enum-ref.rs b/third_party/rust/pin-project-lite/tests/expand/naming/enum-ref.rs new file mode 100644 index 0000000000..480d592d68 --- /dev/null +++ b/third_party/rust/pin-project-lite/tests/expand/naming/enum-ref.rs @@ -0,0 +1,15 @@ +use pin_project_lite::pin_project; + +pin_project! { + #[project_ref = EnumProjRef] + enum Enum { + Struct { + #[pin] + pinned: T, + unpinned: U, + }, + Unit, + } +} + +fn main() {} diff --git a/third_party/rust/pin-project-lite/tests/expand/naming/struct-all.expanded.rs b/third_party/rust/pin-project-lite/tests/expand/naming/struct-all.expanded.rs new file mode 100644 index 0000000000..b91c24eb2a --- /dev/null +++ b/third_party/rust/pin-project-lite/tests/expand/naming/struct-all.expanded.rs @@ -0,0 +1,117 @@ +use pin_project_lite::pin_project; +struct Struct { + 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: '__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: '__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 { + pinned: ::pin_project_lite::__private::PhantomData, + 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 Struct { + 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 { + unsafe { + let __self_ptr: *mut Self = self.get_unchecked_mut(); + let __guard = ::pin_project_lite::__private::UnsafeOverwriteGuard::new( + __self_ptr, + replacement, + ); + let Self { pinned, unpinned } = &mut *__self_ptr; + let result = StructProjReplace { + pinned: ::pin_project_lite::__private::PhantomData, + unpinned: ::pin_project_lite::__private::ptr::read(unpinned), + }; + { + ( + ::pin_project_lite::__private::UnsafeDropInPlaceGuard::new(pinned), + (), + ); + } + result + } + } + } + #[allow(non_snake_case)] + struct __Origin<'__pin, T, U> { + __dummy_lifetime: ::pin_project_lite::__private::PhantomData<&'__pin ()>, + pinned: T, + unpinned: ::pin_project_lite::__private::AlwaysUnpin, + } + impl<'__pin, T, U> ::pin_project_lite::__private::Unpin for Struct where + __Origin<'__pin, T, U>: ::pin_project_lite::__private::Unpin + { + } + trait MustNotImplDrop {} + #[allow(clippy::drop_bounds, drop_bounds)] + impl MustNotImplDrop for T {} + impl MustNotImplDrop for Struct {} + #[forbid(unaligned_references, safe_packed_borrows)] + fn __assert_not_repr_packed(this: &Struct) { + let _ = &this.pinned; + let _ = &this.unpinned; + } +}; +fn main() {} diff --git a/third_party/rust/pin-project-lite/tests/expand/naming/struct-all.rs b/third_party/rust/pin-project-lite/tests/expand/naming/struct-all.rs new file mode 100644 index 0000000000..cb087530fe --- /dev/null +++ b/third_party/rust/pin-project-lite/tests/expand/naming/struct-all.rs @@ -0,0 +1,14 @@ +use pin_project_lite::pin_project; + +pin_project! { + #[project = StructProj] + #[project_ref = StructProjRef] + #[project_replace = StructProjReplace] + struct Struct { + #[pin] + pinned: T, + unpinned: U, + } +} + +fn main() {} diff --git a/third_party/rust/pin-project-lite/tests/expand/naming/struct-mut.expanded.rs b/third_party/rust/pin-project-lite/tests/expand/naming/struct-mut.expanded.rs new file mode 100644 index 0000000000..aaa41cd080 --- /dev/null +++ b/third_party/rust/pin-project-lite/tests/expand/naming/struct-mut.expanded.rs @@ -0,0 +1,84 @@ +use pin_project_lite::pin_project; +struct Struct { + 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: '__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: '__pin, + { + pinned: ::pin_project_lite::__private::Pin<&'__pin (T)>, + unpinned: &'__pin (U), + } + impl Struct { + 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, + } + impl<'__pin, T, U> ::pin_project_lite::__private::Unpin for Struct where + __Origin<'__pin, T, U>: ::pin_project_lite::__private::Unpin + { + } + trait MustNotImplDrop {} + #[allow(clippy::drop_bounds, drop_bounds)] + impl MustNotImplDrop for T {} + impl MustNotImplDrop for Struct {} + #[forbid(unaligned_references, safe_packed_borrows)] + fn __assert_not_repr_packed(this: &Struct) { + let _ = &this.pinned; + let _ = &this.unpinned; + } +}; +fn main() {} diff --git a/third_party/rust/pin-project-lite/tests/expand/naming/struct-mut.rs b/third_party/rust/pin-project-lite/tests/expand/naming/struct-mut.rs new file mode 100644 index 0000000000..59db44530a --- /dev/null +++ b/third_party/rust/pin-project-lite/tests/expand/naming/struct-mut.rs @@ -0,0 +1,12 @@ +use pin_project_lite::pin_project; + +pin_project! { + #[project = StructProj] + struct Struct { + #[pin] + pinned: T, + unpinned: U, + } +} + +fn main() {} diff --git a/third_party/rust/pin-project-lite/tests/expand/naming/struct-none.expanded.rs b/third_party/rust/pin-project-lite/tests/expand/naming/struct-none.expanded.rs new file mode 100644 index 0000000000..8ab318cfb8 --- /dev/null +++ b/third_party/rust/pin-project-lite/tests/expand/naming/struct-none.expanded.rs @@ -0,0 +1,84 @@ +use pin_project_lite::pin_project; +struct Struct { + 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: '__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: '__pin, + { + pinned: ::pin_project_lite::__private::Pin<&'__pin (T)>, + unpinned: &'__pin (U), + } + impl Struct { + 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, + } + impl<'__pin, T, U> ::pin_project_lite::__private::Unpin for Struct where + __Origin<'__pin, T, U>: ::pin_project_lite::__private::Unpin + { + } + trait MustNotImplDrop {} + #[allow(clippy::drop_bounds, drop_bounds)] + impl MustNotImplDrop for T {} + impl MustNotImplDrop for Struct {} + #[forbid(unaligned_references, safe_packed_borrows)] + fn __assert_not_repr_packed(this: &Struct) { + let _ = &this.pinned; + let _ = &this.unpinned; + } +}; +fn main() {} diff --git a/third_party/rust/pin-project-lite/tests/expand/naming/struct-none.rs b/third_party/rust/pin-project-lite/tests/expand/naming/struct-none.rs new file mode 100644 index 0000000000..e5447c70a6 --- /dev/null +++ b/third_party/rust/pin-project-lite/tests/expand/naming/struct-none.rs @@ -0,0 +1,11 @@ +use pin_project_lite::pin_project; + +pin_project! { + struct Struct { + #[pin] + pinned: T, + unpinned: U, + } +} + +fn main() {} diff --git a/third_party/rust/pin-project-lite/tests/expand/naming/struct-ref.expanded.rs b/third_party/rust/pin-project-lite/tests/expand/naming/struct-ref.expanded.rs new file mode 100644 index 0000000000..3d97ab8fae --- /dev/null +++ b/third_party/rust/pin-project-lite/tests/expand/naming/struct-ref.expanded.rs @@ -0,0 +1,84 @@ +use pin_project_lite::pin_project; +struct Struct { + 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: '__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: '__pin, + { + pinned: ::pin_project_lite::__private::Pin<&'__pin mut (T)>, + unpinned: &'__pin mut (U), + } + impl Struct { + 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, + } + impl<'__pin, T, U> ::pin_project_lite::__private::Unpin for Struct where + __Origin<'__pin, T, U>: ::pin_project_lite::__private::Unpin + { + } + trait MustNotImplDrop {} + #[allow(clippy::drop_bounds, drop_bounds)] + impl MustNotImplDrop for T {} + impl MustNotImplDrop for Struct {} + #[forbid(unaligned_references, safe_packed_borrows)] + fn __assert_not_repr_packed(this: &Struct) { + let _ = &this.pinned; + let _ = &this.unpinned; + } +}; +fn main() {} diff --git a/third_party/rust/pin-project-lite/tests/expand/naming/struct-ref.rs b/third_party/rust/pin-project-lite/tests/expand/naming/struct-ref.rs new file mode 100644 index 0000000000..6821af8274 --- /dev/null +++ b/third_party/rust/pin-project-lite/tests/expand/naming/struct-ref.rs @@ -0,0 +1,12 @@ +use pin_project_lite::pin_project; + +pin_project! { + #[project_ref = StructProjRef] + struct Struct { + #[pin] + pinned: T, + unpinned: U, + } +} + +fn main() {} diff --git a/third_party/rust/pin-project-lite/tests/expand/pinned_drop/enum.expanded.rs b/third_party/rust/pin-project-lite/tests/expand/pinned_drop/enum.expanded.rs new file mode 100644 index 0000000000..665ff63386 --- /dev/null +++ b/third_party/rust/pin-project-lite/tests/expand/pinned_drop/enum.expanded.rs @@ -0,0 +1,95 @@ +use pin_project_lite::pin_project; +use std::pin::Pin; +enum Enum { + 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: '__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: '__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 Enum { + fn project<'__pin>( + self: ::pin_project_lite::__private::Pin<&'__pin mut Self>, + ) -> EnumProj<'__pin, T, U> { + unsafe { + match self.get_unchecked_mut() { + Self::Struct { pinned, unpinned } => EnumProj::Struct { + pinned: ::pin_project_lite::__private::Pin::new_unchecked(pinned), + unpinned: unpinned, + }, + Self::Unit => EnumProj::Unit, + } + } + } + fn project_ref<'__pin>( + self: ::pin_project_lite::__private::Pin<&'__pin Self>, + ) -> EnumProjRef<'__pin, T, U> { + unsafe { + match self.get_ref() { + Self::Struct { pinned, unpinned } => EnumProjRef::Struct { + pinned: ::pin_project_lite::__private::Pin::new_unchecked(pinned), + unpinned: unpinned, + }, + Self::Unit => EnumProjRef::Unit, + } + } + } + } + #[allow(non_snake_case)] + struct __Origin<'__pin, T, U> { + __dummy_lifetime: ::pin_project_lite::__private::PhantomData<&'__pin ()>, + Struct: (T, ::pin_project_lite::__private::AlwaysUnpin), + Unit: (), + } + impl<'__pin, T, U> ::pin_project_lite::__private::Unpin for Enum where + __Origin<'__pin, T, U>: ::pin_project_lite::__private::Unpin + { + } + impl ::pin_project_lite::__private::Drop for Enum { + fn drop(&mut self) { + fn __drop_inner(this: ::pin_project_lite::__private::Pin<&mut Enum>) { + fn __drop_inner() {} + let _ = this; + } + let pinned_self: ::pin_project_lite::__private::Pin<&mut Self> = + unsafe { ::pin_project_lite::__private::Pin::new_unchecked(self) }; + __drop_inner(pinned_self); + } + } +}; +fn main() {} diff --git a/third_party/rust/pin-project-lite/tests/expand/pinned_drop/enum.rs b/third_party/rust/pin-project-lite/tests/expand/pinned_drop/enum.rs new file mode 100644 index 0000000000..1855cb7a16 --- /dev/null +++ b/third_party/rust/pin-project-lite/tests/expand/pinned_drop/enum.rs @@ -0,0 +1,22 @@ +use pin_project_lite::pin_project; +use std::pin::Pin; + +pin_project! { + #[project = EnumProj] + #[project_ref = EnumProjRef] + enum Enum { + Struct { + #[pin] + pinned: T, + unpinned: U, + }, + Unit, + } + impl PinnedDrop for Enum { + fn drop(this: Pin<&mut Self>) { + let _ = this; + } + } +} + +fn main() {} diff --git a/third_party/rust/pin-project-lite/tests/expand/pinned_drop/struct.expanded.rs b/third_party/rust/pin-project-lite/tests/expand/pinned_drop/struct.expanded.rs new file mode 100644 index 0000000000..5b82b7a19c --- /dev/null +++ b/third_party/rust/pin-project-lite/tests/expand/pinned_drop/struct.expanded.rs @@ -0,0 +1,92 @@ +use pin_project_lite::pin_project; +use std::pin::Pin; +struct Struct { + 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: '__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: '__pin, + { + pinned: ::pin_project_lite::__private::Pin<&'__pin (T)>, + unpinned: &'__pin (U), + } + impl Struct { + 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, + } + impl<'__pin, T, U> ::pin_project_lite::__private::Unpin for Struct where + __Origin<'__pin, T, U>: ::pin_project_lite::__private::Unpin + { + } + impl ::pin_project_lite::__private::Drop for Struct { + fn drop(&mut self) { + fn __drop_inner(this: ::pin_project_lite::__private::Pin<&mut Struct>) { + fn __drop_inner() {} + let _ = this; + } + let pinned_self: ::pin_project_lite::__private::Pin<&mut Self> = + unsafe { ::pin_project_lite::__private::Pin::new_unchecked(self) }; + __drop_inner(pinned_self); + } + } + #[forbid(unaligned_references, safe_packed_borrows)] + fn __assert_not_repr_packed(this: &Struct) { + let _ = &this.pinned; + let _ = &this.unpinned; + } +}; +fn main() {} diff --git a/third_party/rust/pin-project-lite/tests/expand/pinned_drop/struct.rs b/third_party/rust/pin-project-lite/tests/expand/pinned_drop/struct.rs new file mode 100644 index 0000000000..0cc7567690 --- /dev/null +++ b/third_party/rust/pin-project-lite/tests/expand/pinned_drop/struct.rs @@ -0,0 +1,17 @@ +use pin_project_lite::pin_project; +use std::pin::Pin; + +pin_project! { + struct Struct { + #[pin] + pinned: T, + unpinned: U, + } + impl PinnedDrop for Struct { + fn drop(this: Pin<&mut Self>) { + let _ = this; + } + } +} + +fn main() {} diff --git a/third_party/rust/pin-project-lite/tests/expand/pub/enum.expanded.rs b/third_party/rust/pin-project-lite/tests/expand/pub/enum.expanded.rs new file mode 100644 index 0000000000..6f190cba08 --- /dev/null +++ b/third_party/rust/pin-project-lite/tests/expand/pub/enum.expanded.rs @@ -0,0 +1,87 @@ +use pin_project_lite::pin_project; +pub enum Enum { + 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: '__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: '__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 Enum { + 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), + Unit: (), + } + impl<'__pin, T, U> ::pin_project_lite::__private::Unpin for Enum where + __Origin<'__pin, T, U>: ::pin_project_lite::__private::Unpin + { + } + trait MustNotImplDrop {} + #[allow(clippy::drop_bounds, drop_bounds)] + impl MustNotImplDrop for T {} + impl MustNotImplDrop for Enum {} +}; +fn main() {} diff --git a/third_party/rust/pin-project-lite/tests/expand/pub/enum.rs b/third_party/rust/pin-project-lite/tests/expand/pub/enum.rs new file mode 100644 index 0000000000..d3968afdf2 --- /dev/null +++ b/third_party/rust/pin-project-lite/tests/expand/pub/enum.rs @@ -0,0 +1,16 @@ +use pin_project_lite::pin_project; + +pin_project! { + #[project = EnumProj] + #[project_ref = EnumProjRef] + pub enum Enum { + Struct { + #[pin] + pinned: T, + unpinned: U, + }, + Unit, + } +} + +fn main() {} diff --git a/third_party/rust/pin-project-lite/tests/expand/pub/struct.expanded.rs b/third_party/rust/pin-project-lite/tests/expand/pub/struct.expanded.rs new file mode 100644 index 0000000000..7b5826d149 --- /dev/null +++ b/third_party/rust/pin-project-lite/tests/expand/pub/struct.expanded.rs @@ -0,0 +1,84 @@ +use pin_project_lite::pin_project; +pub struct Struct { + 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: '__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: '__pin, + { + pub pinned: ::pin_project_lite::__private::Pin<&'__pin (T)>, + pub unpinned: &'__pin (U), + } + impl Struct { + 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, + } + impl<'__pin, T, U> ::pin_project_lite::__private::Unpin for Struct where + __Origin<'__pin, T, U>: ::pin_project_lite::__private::Unpin + { + } + trait MustNotImplDrop {} + #[allow(clippy::drop_bounds, drop_bounds)] + impl MustNotImplDrop for T {} + impl MustNotImplDrop for Struct {} + #[forbid(unaligned_references, safe_packed_borrows)] + fn __assert_not_repr_packed(this: &Struct) { + let _ = &this.pinned; + let _ = &this.unpinned; + } +}; +fn main() {} diff --git a/third_party/rust/pin-project-lite/tests/expand/pub/struct.rs b/third_party/rust/pin-project-lite/tests/expand/pub/struct.rs new file mode 100644 index 0000000000..6659096909 --- /dev/null +++ b/third_party/rust/pin-project-lite/tests/expand/pub/struct.rs @@ -0,0 +1,11 @@ +use pin_project_lite::pin_project; + +pin_project! { + pub struct Struct { + #[pin] + pub pinned: T, + pub unpinned: U, + } +} + +fn main() {} diff --git a/third_party/rust/pin-project-lite/tests/expandtest.rs b/third_party/rust/pin-project-lite/tests/expandtest.rs new file mode 100644 index 0000000000..3f0d5c1121 --- /dev/null +++ b/third_party/rust/pin-project-lite/tests/expandtest.rs @@ -0,0 +1,43 @@ +#![cfg(not(miri))] +#![warn(rust_2018_idioms, single_use_lifetimes)] + +use std::{ + env, + process::{Command, ExitStatus, Stdio}, +}; + +const PATH: &str = "tests/expand/**/*.rs"; + +#[rustversion::attr(not(nightly), ignore)] +#[test] +fn expandtest() { + let is_ci = env::var_os("CI").is_some(); + let cargo = &*env::var("CARGO").unwrap_or_else(|_| "cargo".into()); + if !has_command(&[cargo, "expand"]) || !has_command(&[cargo, "fmt"]) { + if is_ci { + panic!("expandtest requires rustfmt and cargo-expand"); + } + return; + } + + let args = &["--all-features"]; + if is_ci { + macrotest::expand_without_refresh_args(PATH, args); + } else { + env::set_var("MACROTEST", "overwrite"); + macrotest::expand_args(PATH, args); + } +} + +fn has_command(command: &[&str]) -> bool { + Command::new(command[0]) + .args(&command[1..]) + .arg("--version") + .stdin(Stdio::null()) + .stdout(Stdio::null()) + .stderr(Stdio::null()) + .status() + .as_ref() + .map(ExitStatus::success) + .unwrap_or(false) +} diff --git a/third_party/rust/pin-project-lite/tests/include/basic.rs b/third_party/rust/pin-project-lite/tests/include/basic.rs new file mode 100644 index 0000000000..25121f210b --- /dev/null +++ b/third_party/rust/pin-project-lite/tests/include/basic.rs @@ -0,0 +1,35 @@ +// default pin_project! is completely safe. + +::pin_project_lite::pin_project! { + #[derive(Debug)] + pub struct DefaultStruct { + #[pin] + pub pinned: T, + pub unpinned: U, + } +} + +::pin_project_lite::pin_project! { + #[project = DefaultStructProj] + #[project_ref = DefaultStructProjRef] + #[derive(Debug)] + pub struct DefaultStructNamed { + #[pin] + pub pinned: T, + pub unpinned: U, + } +} + +::pin_project_lite::pin_project! { + #[project = DefaultEnumProj] + #[project_ref = DefaultEnumProjRef] + #[derive(Debug)] + pub enum DefaultEnum { + Struct { + #[pin] + pinned: T, + unpinned: U, + }, + Unit, + } +} diff --git a/third_party/rust/pin-project-lite/tests/lint.rs b/third_party/rust/pin-project-lite/tests/lint.rs new file mode 100644 index 0000000000..852f940bcf --- /dev/null +++ b/third_party/rust/pin-project-lite/tests/lint.rs @@ -0,0 +1,263 @@ +// Check interoperability with rustc and clippy lints. + +#![forbid(unsafe_code)] +// for old compilers +#![allow(unknown_lints)] +#![warn(nonstandard_style, rust_2018_idioms, unused)] +// Note: This does not guarantee compatibility with forbidding these lints in the future. +// If rustc adds a new lint, we may not be able to keep this. +#![forbid(future_incompatible, rust_2018_compatibility, rust_2021_compatibility)] +// lints forbidden as a part of future_incompatible, rust_2018_compatibility, and rust_2021_compatibility are not included in the list below. +// elided_lifetimes_in_paths, explicit_outlives_requirements, unused_extern_crates: as a part of rust_2018_idioms +// unsafe_op_in_unsafe_fn: requires Rust 1.52. and, we don't generate unsafe fn. +// non_exhaustive_omitted_patterns: unstable +// unstable_features: no way to generate #![feature(..)] by macros, expect for unstable inner attribute. and this lint is deprecated: https://doc.rust-lang.org/rustc/lints/listing/allowed-by-default.html#unstable-features +// unused_crate_dependencies, must_not_suspend: unrelated +// unsafe_code: checked in forbid_unsafe module +#![warn( + box_pointers, + deprecated_in_future, + fuzzy_provenance_casts, + lossy_provenance_casts, + macro_use_extern_crate, + meta_variable_misuse, + missing_abi, + missing_copy_implementations, + missing_debug_implementations, + missing_docs, + non_ascii_idents, + noop_method_call, + single_use_lifetimes, + trivial_casts, + trivial_numeric_casts, + unreachable_pub, + unused_import_braces, + unused_lifetimes, + unused_qualifications, + unused_results, + variant_size_differences +)] +#![warn(clippy::all, clippy::pedantic, clippy::nursery, clippy::restriction)] +#![allow(clippy::blanket_clippy_restriction_lints)] // this is a test, so enable all restriction lints intentionally. +#![allow(clippy::exhaustive_structs, clippy::exhaustive_enums, clippy::single_char_lifetime_names)] // TODO + +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, + pub u: Box, + } + } + + pin_project! { + #[project = EnumProj] + #[project_ref = EnumProjRef] + #[derive(Debug)] + pub enum Enum { + Struct { + #[pin] + p: Box, + u: Box, + }, + Unit, + } + } +} + +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, + } + } + + pin_project! { + #[project = EnumProj] + #[project_ref = EnumProjRef] + #[derive(Debug)] + pub enum Enum<'a, T, U> + where + T: ?Sized, + U: ?Sized, + { + Struct { + #[pin] + pinned: &'a mut T, + unpinned: &'a mut U, + }, + Unit, + } + } +} + +pub mod variant_size_differences { + use pin_project_lite::pin_project; + + pin_project! { + #[project = EnumProj] + #[project_ref = EnumProjRef] + #[allow(missing_debug_implementations, missing_copy_implementations)] // https://github.com/rust-lang/rust/pull/74060 + #[allow(variant_size_differences)] // for the type itself + #[allow(clippy::large_enum_variant)] // for the type itself + pub enum Enum { + V1 { f: u8 }, + V2 { f: [u8; 1024] }, + } + } +} + +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, + } + } + + pin_project! { + #[project = EnumProj] + #[project_ref = EnumProjRef] + #[derive(Debug)] + pub enum Enum<'a, T, U> { + Struct { + #[pin] + pinned: &'a mut T, + unpinned: &'a mut U, + }, + Unit, + } + } +} + +#[allow(unreachable_pub)] +mod clippy_redundant_pub_crate { + use pin_project_lite::pin_project; + + pin_project! { + #[derive(Debug)] + pub struct Struct { + #[pin] + pub pinned: T, + pub unpinned: U, + } + } + + pin_project! { + #[project = EnumProj] + #[project_ref = EnumProjRef] + #[derive(Debug)] + pub enum Enum { + Struct { + #[pin] + pinned: T, + unpinned: U, + }, + Unit, + } + } +} + +#[allow(clippy::use_self)] +pub mod clippy_type_repetition_in_bounds { + use pin_project_lite::pin_project; + + pin_project! { + #[derive(Debug)] + pub struct Struct + where + Struct: Sized, + { + #[pin] + pub pinned: T, + pub unpinned: U, + } + } + + pin_project! { + #[project = EnumProj] + #[project_ref = EnumProjRef] + #[derive(Debug)] + pub enum Enum + where + Enum: Sized, + { + Struct { + #[pin] + pinned: T, + unpinned: U, + }, + Unit, + } + } +} + +pub mod clippy_used_underscore_binding { + use pin_project_lite::pin_project; + + pin_project! { + #[derive(Debug)] + pub struct Struct { + #[pin] + pub _pinned: T, + pub _unpinned: U, + } + } + + pin_project! { + #[project = EnumProj] + #[project_ref = EnumProjRef] + #[derive(Debug)] + pub enum Enum { + Struct { + #[pin] + _pinned: T, + _unpinned: U, + }, + } + } +} + +pub mod clippy_ref_option_ref { + use pin_project_lite::pin_project; + + pin_project! { + pub struct Struct<'a> { + #[pin] + pub _pinned: Option<&'a ()>, + pub _unpinned: Option<&'a ()>, + } + } + + pin_project! { + #[project = EnumProj] + #[project_ref = EnumProjRef] + pub enum Enum<'a> { + Struct { + #[pin] + _pinned: Option<&'a ()>, + _unpinned: Option<&'a ()>, + }, + } + } +} diff --git a/third_party/rust/pin-project-lite/tests/proper_unpin.rs b/third_party/rust/pin-project-lite/tests/proper_unpin.rs new file mode 100644 index 0000000000..668e975ba9 --- /dev/null +++ b/third_party/rust/pin-project-lite/tests/proper_unpin.rs @@ -0,0 +1,67 @@ +#![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 { + f: T, + } + + assert_unpin!(Inner<()>); + assert_not_unpin!(Inner); + + pin_project! { + struct Struct { + #[pin] + f1: Inner, + f2: U, + } + } + + assert_unpin!(Struct<(), ()>); + assert_unpin!(Struct<(), PhantomPinned>); + assert_not_unpin!(Struct); + assert_not_unpin!(Struct); + + pin_project! { + #[project = EnumProj] + #[project_ref = EnumProjRef] + enum Enum { + V1 { + #[pin] + f1: Inner, + f2: U, + }, + } + } + + assert_unpin!(Enum<(), ()>); + assert_unpin!(Enum<(), PhantomPinned>); + assert_not_unpin!(Enum); + assert_not_unpin!(Enum); + + pin_project! { + struct TrivialBounds { + #[pin] + f: PhantomPinned, + } + } + + assert_not_unpin!(TrivialBounds); + + pin_project! { + struct PinRef<'a, T, U> { + #[pin] + f1: &'a mut Inner, + f2: U, + } + } + + assert_unpin!(PinRef<'_, PhantomPinned, PhantomPinned>); +} diff --git a/third_party/rust/pin-project-lite/tests/test.rs b/third_party/rust/pin-project-lite/tests/test.rs new file mode 100644 index 0000000000..ed9b75c42c --- /dev/null +++ b/third_party/rust/pin-project-lite/tests/test.rs @@ -0,0 +1,695 @@ +#![warn(rust_2018_idioms, single_use_lifetimes)] +#![allow(dead_code)] + +#[macro_use] +mod auxiliary; + +use core::{ + marker::{PhantomData, PhantomPinned}, + pin::Pin, +}; + +use pin_project_lite::pin_project; + +#[test] +fn projection() { + pin_project! { + #[project = StructProj] + #[project_ref = StructProjRef] + #[project_replace = StructProjReplace] + #[derive(Default)] + struct Struct { + #[pin] + f1: T, + f2: U, + } + } + + let mut s = Struct { f1: 1, f2: 2 }; + let mut s_orig = Pin::new(&mut s); + let s = s_orig.as_mut().project(); + + let _: Pin<&mut i32> = s.f1; + assert_eq!(*s.f1, 1); + let _: &mut i32 = s.f2; + assert_eq!(*s.f2, 2); + + assert_eq!(s_orig.as_ref().f1, 1); + assert_eq!(s_orig.as_ref().f2, 2); + + let mut s = Struct { f1: 1, f2: 2 }; + let mut s = Pin::new(&mut s); + { + let StructProj { f1, f2 } = s.as_mut().project(); + let _: Pin<&mut i32> = f1; + let _: &mut i32 = f2; + } + { + let StructProjRef { f1, f2 } = s.as_ref().project_ref(); + let _: Pin<&i32> = f1; + let _: &i32 = f2; + } + + { + let StructProjReplace { f1: PhantomData, f2 } = + s.as_mut().project_replace(Struct::default()); + assert_eq!(f2, 2); + let StructProj { f1, f2 } = s.project(); + assert_eq!(*f1, 0); + assert_eq!(*f2, 0); + } + + pin_project! { + #[project = EnumProj] + #[project_ref = EnumProjRef] + #[project_replace = EnumProjReplace] + #[derive(Eq, PartialEq, Debug)] + enum Enum { + Struct { + #[pin] + f1: C, + f2: D, + }, + Unit, + } + } + + let mut e = Enum::Struct { f1: 1, f2: 2 }; + let mut e = Pin::new(&mut e); + + match e.as_mut().project() { + EnumProj::Struct { f1, f2 } => { + let _: Pin<&mut i32> = f1; + assert_eq!(*f1, 1); + let _: &mut i32 = f2; + assert_eq!(*f2, 2); + } + EnumProj::Unit => unreachable!(), + } + + assert_eq!(&*e, &Enum::Struct { f1: 1, f2: 2 }); + + if let EnumProj::Struct { f1, f2 } = e.as_mut().project() { + let _: Pin<&mut i32> = f1; + assert_eq!(*f1, 1); + let _: &mut i32 = f2; + assert_eq!(*f2, 2); + } + + if let EnumProjReplace::Struct { f1: PhantomData, f2 } = e.as_mut().project_replace(Enum::Unit) + { + assert_eq!(f2, 2); + } +} + +#[test] +fn enum_project_set() { + pin_project! { + #[project = EnumProj] + #[project_ref = EnumProjRef] + #[derive(Eq, PartialEq, Debug)] + enum Enum { + V1 { #[pin] f: u8 }, + V2 { f: bool }, + } + } + + let mut e = Enum::V1 { f: 25 }; + let mut e_orig = Pin::new(&mut e); + let e_proj = e_orig.as_mut().project(); + + match e_proj { + EnumProj::V1 { f } => { + let new_e = Enum::V2 { f: f.as_ref().get_ref() == &25 }; + e_orig.set(new_e); + } + EnumProj::V2 { .. } => unreachable!(), + } + + assert_eq!(e, Enum::V2 { f: true }); +} + +#[test] +fn where_clause() { + pin_project! { + struct Struct + where + T: Copy, + { + f: T, + } + } + + pin_project! { + #[project = EnumProj] + #[project_ref = EnumProjRef] + enum Enum + where + T: Copy, + { + V { f: T }, + } + } +} + +#[test] +fn where_clause_and_associated_type_field() { + pin_project! { + struct Struct1 + where + I: Iterator, + { + #[pin] + f1: I, + f2: I::Item, + } + } + + pin_project! { + struct Struct2 + where + I: Iterator, + { + #[pin] + f1: I, + f2: J, + } + } + + pin_project! { + pub struct Struct3 + where + T: 'static, + { + f: T, + } + } + + trait Static: 'static {} + + impl Static for Struct3 {} + + pin_project! { + #[project = EnumProj] + #[project_ref = EnumProjRef] + enum Enum + where + I: Iterator, + { + V1 { #[pin] f: I }, + V2 { f: I::Item }, + } + } +} + +#[test] +fn derive_copy() { + pin_project! { + #[derive(Clone, Copy)] + struct Struct { + f: T, + } + } + + fn is_copy() {} + + is_copy::>(); +} + +#[test] +fn move_out() { + struct NotCopy; + + pin_project! { + struct Struct { + f: NotCopy, + } + } + + let x = Struct { f: NotCopy }; + let _val: NotCopy = x.f; + + pin_project! { + #[project = EnumProj] + #[project_ref = EnumProjRef] + enum Enum { + V { f: NotCopy }, + } + } + + let x = Enum::V { f: NotCopy }; + #[allow(clippy::infallible_destructuring_match)] + let _val: NotCopy = match x { + Enum::V { f } => f, + }; +} + +#[test] +fn trait_bounds_on_type_generics() { + pin_project! { + pub struct Struct1<'a, T: ?Sized> { + f: &'a mut T, + } + } + + pin_project! { + pub struct Struct2<'a, T: ::core::fmt::Debug> { + f: &'a mut T, + } + } + + pin_project! { + pub struct Struct3<'a, T: core::fmt::Debug> { + f: &'a mut T, + } + } + + // pin_project! { + // pub struct Struct4<'a, T: core::fmt::Debug + core::fmt::Display> { + // f: &'a mut T, + // } + // } + + // pin_project! { + // pub struct Struct5<'a, T: core::fmt::Debug + ?Sized> { + // f: &'a mut T, + // } + // } + + pin_project! { + pub struct Struct6<'a, T: core::fmt::Debug = [u8; 16]> { + f: &'a mut T, + } + } + + let _: Struct6<'_> = Struct6 { f: &mut [0_u8; 16] }; + + pin_project! { + pub struct Struct7 { + f: T, + } + } + + trait Static: 'static {} + + impl Static for Struct7 {} + + pin_project! { + pub struct Struct8<'a, 'b: 'a> { + f1: &'a u8, + f2: &'b u8, + } + } + + pin_project! { + #[project = EnumProj] + #[project_ref = EnumProjRef] + enum Enum<'a, T: ?Sized> { + V { f: &'a mut T }, + } + } +} + +#[test] +fn private_type_in_public_type() { + pin_project! { + pub struct PublicStruct { + #[pin] + inner: PrivateStruct, + } + } + + struct PrivateStruct(T); +} + +#[allow(clippy::needless_lifetimes)] +#[test] +fn lifetime_project() { + pin_project! { + struct Struct1 { + #[pin] + pinned: T, + unpinned: U, + } + } + + pin_project! { + struct Struct2<'a, T, U> { + #[pin] + pinned: &'a T, + unpinned: U, + } + } + + pin_project! { + #[project = EnumProj] + #[project_ref = EnumProjRef] + enum Enum { + V { + #[pin] + pinned: T, + unpinned: U, + }, + } + } + + impl Struct1 { + fn get_pin_ref<'a>(self: Pin<&'a Self>) -> Pin<&'a T> { + self.project_ref().pinned + } + fn get_pin_mut<'a>(self: Pin<&'a mut Self>) -> Pin<&'a mut T> { + self.project().pinned + } + 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> { + fn get_pin_ref<'a>(self: Pin<&'a Self>) -> Pin<&'a &'b T> { + self.project_ref().pinned + } + fn get_pin_mut<'a>(self: Pin<&'a mut Self>) -> Pin<&'a mut &'b T> { + self.project().pinned + } + fn get_pin_ref_elided(self: Pin<&Self>) -> Pin<&&'b T> { + self.project_ref().pinned + } + fn get_pin_mut_elided(self: Pin<&mut Self>) -> Pin<&mut &'b T> { + self.project().pinned + } + } + + impl Enum { + fn get_pin_ref<'a>(self: Pin<&'a Self>) -> Pin<&'a T> { + match self.project_ref() { + EnumProjRef::V { pinned, .. } => pinned, + } + } + fn get_pin_mut<'a>(self: Pin<&'a mut Self>) -> Pin<&'a mut T> { + match self.project() { + EnumProj::V { pinned, .. } => pinned, + } + } + fn get_pin_ref_elided(self: Pin<&Self>) -> Pin<&T> { + match self.project_ref() { + EnumProjRef::V { pinned, .. } => pinned, + } + } + fn get_pin_mut_elided(self: Pin<&mut Self>) -> Pin<&mut T> { + match self.project() { + EnumProj::V { pinned, .. } => pinned, + } + } + } +} + +mod visibility { + use pin_project_lite::pin_project; + + pin_project! { + pub(crate) struct S { + pub f: u8, + } + } +} + +#[test] +fn visibility() { + let mut x = visibility::S { f: 0 }; + let x = Pin::new(&mut x); + let y = x.as_ref().project_ref(); + let _: &u8 = y.f; + let y = x.project(); + let _: &mut u8 = y.f; +} + +#[test] +fn trivial_bounds() { + pin_project! { + pub struct NoGenerics { + #[pin] + f: PhantomPinned, + } + } + + assert_not_unpin!(NoGenerics); +} + +#[test] +fn dst() { + pin_project! { + pub struct Struct1 { + f: T, + } + } + + let mut x = Struct1 { f: 0_u8 }; + let x: Pin<&mut Struct1> = Pin::new(&mut x as _); + let _: &mut (dyn core::fmt::Debug) = x.project().f; + + pin_project! { + pub struct Struct2 { + #[pin] + f: T, + } + } + + let mut x = Struct2 { f: 0_u8 }; + let x: Pin<&mut Struct2> = Pin::new(&mut x as _); + let _: Pin<&mut (dyn core::fmt::Debug + Unpin)> = x.project().f; + + pin_project! { + struct Struct3 + where + T: ?Sized, + { + f: T, + } + } + + pin_project! { + struct Struct4 + where + T: ?Sized, + { + #[pin] + f: T, + } + } + + pin_project! { + struct Struct11<'a, T: ?Sized, U: ?Sized> { + f1: &'a mut T, + f2: U, + } + } +} + +#[test] +fn dyn_type() { + pin_project! { + struct Struct1 { + f: dyn core::fmt::Debug, + } + } + + pin_project! { + struct Struct2 { + #[pin] + f: dyn core::fmt::Debug, + } + } + + pin_project! { + struct Struct3 { + f: dyn core::fmt::Debug + Send, + } + } + + pin_project! { + struct Struct4 { + #[pin] + f: dyn core::fmt::Debug + Send, + } + } +} + +#[test] +fn no_infer_outlives() { + trait Trait { + type Y; + } + + struct Struct1(A); + + impl Trait for Struct1 { + type Y = Option; + } + + pin_project! { + struct Struct2 { + _f: as Trait>::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 (), + // } + // } +} + +#[test] +fn attrs() { + pin_project! { + /// dox1 + #[derive(Clone)] + #[project = StructProj] + #[project_ref = StructProjRef] + /// dox2 + #[derive(Debug)] + /// dox3 + struct Struct { + // TODO + // /// dox4 + f: () + } + } + + pin_project! { + #[project = Enum1Proj] + #[project_ref = Enum1ProjRef] + enum Enum1 { + #[cfg(not(any()))] + V { + f: () + }, + } + } + + pin_project! { + /// dox1 + #[derive(Clone)] + #[project = Enum2Proj] + #[project_ref = Enum2ProjRef] + /// dox2 + #[derive(Debug)] + /// dox3 + enum Enum2 { + /// dox4 + V1 { + // TODO + // /// dox5 + f: () + }, + /// dox6 + V2, + } + } +} + +#[test] +fn pinned_drop() { + pin_project! { + pub struct Struct1<'a> { + was_dropped: &'a mut bool, + #[pin] + field: u8, + } + impl PinnedDrop for Struct1<'_> { + fn drop(this: Pin<&mut Self>) { + **this.project().was_dropped = true; + } + } + } + + let mut was_dropped = false; + drop(Struct1 { was_dropped: &mut was_dropped, field: 42 }); + assert!(was_dropped); + + pin_project! { + pub struct Struct2<'a> { + was_dropped: &'a mut bool, + #[pin] + field: u8, + } + impl PinnedDrop for Struct2<'_> { + fn drop(mut this: Pin<&mut Self>) { + **this.as_mut().project().was_dropped = true; + } + } + } + + trait Service { + type Error; + } + + pin_project! { + struct Struct3<'a, T, Request> + where + T: Service, + T::Error: std::error::Error, + { + was_dropped: &'a mut bool, + #[pin] + field: T, + req: Request, + } + + impl PinnedDrop for Struct3<'_, T, Request> + where + T: Service, + T::Error: std::error::Error, + { + fn drop(mut this: Pin<&mut Self>) { + **this.as_mut().project().was_dropped = true; + } + } + } +} diff --git a/third_party/rust/pin-project-lite/tests/ui/pin_project/conflict-drop.rs b/third_party/rust/pin-project-lite/tests/ui/pin_project/conflict-drop.rs new file mode 100644 index 0000000000..870059d62f --- /dev/null +++ b/third_party/rust/pin-project-lite/tests/ui/pin_project/conflict-drop.rs @@ -0,0 +1,15 @@ +use pin_project_lite::pin_project; + +pin_project! { //~ ERROR E0119 + struct Foo { + #[pin] + future: T, + field: U, + } +} + +impl Drop for Foo { + fn drop(&mut self) {} +} + +fn main() {} diff --git a/third_party/rust/pin-project-lite/tests/ui/pin_project/conflict-drop.stderr b/third_party/rust/pin-project-lite/tests/ui/pin_project/conflict-drop.stderr new file mode 100644 index 0000000000..66872bd4bd --- /dev/null +++ b/third_party/rust/pin-project-lite/tests/ui/pin_project/conflict-drop.stderr @@ -0,0 +1,16 @@ +error[E0119]: conflicting implementations of trait `_::MustNotImplDrop` for type `Foo<_, _>` + --> tests/ui/pin_project/conflict-drop.rs:3:1 + | +3 | / pin_project! { //~ ERROR E0119 +4 | | struct Foo { +5 | | #[pin] +6 | | future: T, +7 | | field: U, +8 | | } +9 | | } + | | ^ + | | | + | |_first implementation here + | conflicting implementation for `Foo<_, _>` + | + = note: this error originates in the macro `$crate::__pin_project_make_drop_impl` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/third_party/rust/pin-project-lite/tests/ui/pin_project/conflict-unpin.rs b/third_party/rust/pin-project-lite/tests/ui/pin_project/conflict-unpin.rs new file mode 100644 index 0000000000..f702f064de --- /dev/null +++ b/third_party/rust/pin-project-lite/tests/ui/pin_project/conflict-unpin.rs @@ -0,0 +1,40 @@ +use pin_project_lite::pin_project; + +// The same implementation. + +pin_project! { //~ ERROR E0119 + struct Foo { + #[pin] + future: T, + field: U, + } +} + +// conflicting implementations +impl Unpin for Foo where T: Unpin {} // Conditional Unpin impl + +// The implementation that under different conditions. + +pin_project! { //~ ERROR E0119 + struct Bar { + #[pin] + future: T, + field: U, + } +} + +// conflicting implementations +impl Unpin for Bar {} // Non-conditional Unpin impl + +pin_project! { //~ ERROR E0119 + struct Baz { + #[pin] + future: T, + field: U, + } +} + +// conflicting implementations +impl Unpin for Baz {} // Conditional Unpin impl + +fn main() {} diff --git a/third_party/rust/pin-project-lite/tests/ui/pin_project/conflict-unpin.stderr b/third_party/rust/pin-project-lite/tests/ui/pin_project/conflict-unpin.stderr new file mode 100644 index 0000000000..bd30fafdd3 --- /dev/null +++ b/third_party/rust/pin-project-lite/tests/ui/pin_project/conflict-unpin.stderr @@ -0,0 +1,50 @@ +error[E0119]: conflicting implementations of trait `std::marker::Unpin` for type `Foo<_, _>` + --> tests/ui/pin_project/conflict-unpin.rs:5:1 + | +5 | / pin_project! { //~ ERROR E0119 +6 | | struct Foo { +7 | | #[pin] +8 | | future: T, +9 | | field: U, +10 | | } +11 | | } + | |_^ conflicting implementation for `Foo<_, _>` +... +14 | impl Unpin for Foo where T: Unpin {} // Conditional Unpin impl + | --------------------------------------------- first implementation here + | + = note: this error originates in the macro `$crate::__pin_project_make_unpin_impl` (in Nightly builds, run with -Z macro-backtrace for more info) + +error[E0119]: conflicting implementations of trait `std::marker::Unpin` for type `Bar<_, _>` + --> tests/ui/pin_project/conflict-unpin.rs:18:1 + | +18 | / pin_project! { //~ ERROR E0119 +19 | | struct Bar { +20 | | #[pin] +21 | | future: T, +22 | | field: U, +23 | | } +24 | | } + | |_^ conflicting implementation for `Bar<_, _>` +... +27 | impl Unpin for Bar {} // Non-conditional Unpin impl + | ------------------------------ first implementation here + | + = note: this error originates in the macro `$crate::__pin_project_make_unpin_impl` (in Nightly builds, run with -Z macro-backtrace for more info) + +error[E0119]: conflicting implementations of trait `std::marker::Unpin` for type `Baz<_, _>` + --> tests/ui/pin_project/conflict-unpin.rs:29:1 + | +29 | / pin_project! { //~ ERROR E0119 +30 | | struct Baz { +31 | | #[pin] +32 | | future: T, +33 | | field: U, +34 | | } +35 | | } + | |_^ conflicting implementation for `Baz<_, _>` +... +38 | impl Unpin for Baz {} // Conditional Unpin impl + | -------------------------------------------- first implementation here + | + = note: this error originates in the macro `$crate::__pin_project_make_unpin_impl` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/third_party/rust/pin-project-lite/tests/ui/pin_project/invalid-bounds.rs b/third_party/rust/pin-project-lite/tests/ui/pin_project/invalid-bounds.rs new file mode 100644 index 0000000000..64b397a37e --- /dev/null +++ b/third_party/rust/pin-project-lite/tests/ui/pin_project/invalid-bounds.rs @@ -0,0 +1,93 @@ +use pin_project_lite::pin_project; + +pin_project! { + struct Generics1 { //~ ERROR no rules expected the token `:` + field: T, + } +} + +pin_project! { + struct Generics2 { //~ ERROR no rules expected the token `:` + field: T, + } +} + +pin_project! { + struct Generics3 { //~ ERROR expected one of `+`, `,`, `=`, or `>`, found `:` + field: T, + } +} + +pin_project! { + struct Generics4 { //~ ERROR expected one of `+`, `,`, `=`, or `>`, found `:` + field: T, + } +} + +pin_project! { + struct Generics5 { //~ ERROR expected one of `+`, `,`, `=`, or `>`, found `:` + field: T, + } +} + +pin_project! { + struct Generics6 { //~ ERROR no rules expected the token `Sized` + field: T, + } +} + +pin_project! { + struct WhereClause1 + where + T: 'static : Sized //~ ERROR no rules expected the token `:` + { + field: T, + } +} + +pin_project! { + struct WhereClause2 + where + T: 'static : ?Sized //~ ERROR no rules expected the token `:` + { + field: T, + } +} + +pin_project! { + struct WhereClause3 + where + T: Sized : 'static //~ ERROR expected `where`, or `{` after struct name, found `:` + { + field: T, + } +} + +pin_project! { + struct WhereClause4 + where + T: ?Sized : 'static //~ ERROR expected `where`, or `{` after struct name, found `:` + { + field: T, + } +} + +pin_project! { + struct WhereClause5 + where + T: Sized : ?Sized //~ ERROR expected `where`, or `{` after struct name, found `:` + { + field: T, + } +} + +pin_project! { + struct WhereClause6 + where + T: ?Sized : Sized //~ ERROR no rules expected the token `Sized` + { + field: T, + } +} + +fn main() {} diff --git a/third_party/rust/pin-project-lite/tests/ui/pin_project/invalid-bounds.stderr b/third_party/rust/pin-project-lite/tests/ui/pin_project/invalid-bounds.stderr new file mode 100644 index 0000000000..40e79bf928 --- /dev/null +++ b/third_party/rust/pin-project-lite/tests/ui/pin_project/invalid-bounds.stderr @@ -0,0 +1,428 @@ +error: no rules expected the token `:` + --> tests/ui/pin_project/invalid-bounds.rs:4:33 + | +4 | struct Generics1 { //~ ERROR no rules expected the token `:` + | ^ no rules expected this token in macro call + +error: no rules expected the token `:` + --> tests/ui/pin_project/invalid-bounds.rs:10:33 + | +10 | struct Generics2 { //~ ERROR no rules expected the token `:` + | ^ no rules expected this token in macro call + +error: expected one of `+`, `,`, `=`, or `>`, found `:` + --> tests/ui/pin_project/invalid-bounds.rs:15:1 + | +15 | / pin_project! { +16 | | struct Generics3 { //~ ERROR expected one of `+`, `,`, `=`, or `>`, found `:` +17 | | field: T, +18 | | } +19 | | } + | | ^ + | | | + | | expected one of `+`, `,`, `=`, or `>` + | |_unexpected token + | in this macro invocation + | + = note: this error originates in the macro `$crate::__pin_project_parse_generics` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: expected one of `+`, `,`, `=`, or `>`, found `:` + --> tests/ui/pin_project/invalid-bounds.rs:15:1 + | +15 | / pin_project! { +16 | | struct Generics3 { //~ ERROR expected one of `+`, `,`, `=`, or `>`, found `:` +17 | | field: T, +18 | | } +19 | | } + | | ^ + | | | + | |_expected one of `+`, `,`, `=`, or `>` + | unexpected token + | + = note: this error originates in the macro `$crate::__pin_project_parse_generics` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: expected one of `+`, `,`, `=`, or `>`, found `:` + --> tests/ui/pin_project/invalid-bounds.rs:15:1 + | +15 | / pin_project! { +16 | | struct Generics3 { //~ ERROR expected one of `+`, `,`, `=`, or `>`, found `:` +17 | | field: T, +18 | | } +19 | | } + | | ^ + | | | + | | expected one of `+`, `,`, `=`, or `>` + | |_unexpected token + | in this macro invocation + | + = note: this error originates in the macro `$crate::__pin_project_parse_generics` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: expected one of `+`, `,`, `=`, or `>`, found `:` + --> tests/ui/pin_project/invalid-bounds.rs:15:1 + | +15 | / pin_project! { +16 | | struct Generics3 { //~ ERROR expected one of `+`, `,`, `=`, or `>`, found `:` +17 | | field: T, +18 | | } +19 | | } + | | ^ + | | | + | | expected one of `+`, `,`, `=`, or `>` + | |_unexpected token + | in this macro invocation + | + = note: this error originates in the macro `$crate::__pin_project_parse_generics` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: expected one of `+`, `,`, `=`, or `>`, found `:` + --> tests/ui/pin_project/invalid-bounds.rs:21:1 + | +21 | / pin_project! { +22 | | struct Generics4 { //~ ERROR expected one of `+`, `,`, `=`, or `>`, found `:` +23 | | field: T, +24 | | } +25 | | } + | | ^ + | | | + | | expected one of `+`, `,`, `=`, or `>` + | |_unexpected token + | in this macro invocation + | + = note: this error originates in the macro `$crate::__pin_project_parse_generics` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: expected one of `+`, `,`, `=`, or `>`, found `:` + --> tests/ui/pin_project/invalid-bounds.rs:21:1 + | +21 | / pin_project! { +22 | | struct Generics4 { //~ ERROR expected one of `+`, `,`, `=`, or `>`, found `:` +23 | | field: T, +24 | | } +25 | | } + | | ^ + | | | + | |_expected one of `+`, `,`, `=`, or `>` + | unexpected token + | + = note: this error originates in the macro `$crate::__pin_project_parse_generics` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: expected one of `+`, `,`, `=`, or `>`, found `:` + --> tests/ui/pin_project/invalid-bounds.rs:21:1 + | +21 | / pin_project! { +22 | | struct Generics4 { //~ ERROR expected one of `+`, `,`, `=`, or `>`, found `:` +23 | | field: T, +24 | | } +25 | | } + | | ^ + | | | + | | expected one of `+`, `,`, `=`, or `>` + | |_unexpected token + | in this macro invocation + | + = note: this error originates in the macro `$crate::__pin_project_parse_generics` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: expected one of `+`, `,`, `=`, or `>`, found `:` + --> tests/ui/pin_project/invalid-bounds.rs:21:1 + | +21 | / pin_project! { +22 | | struct Generics4 { //~ ERROR expected one of `+`, `,`, `=`, or `>`, found `:` +23 | | field: T, +24 | | } +25 | | } + | | ^ + | | | + | | expected one of `+`, `,`, `=`, or `>` + | |_unexpected token + | in this macro invocation + | + = note: this error originates in the macro `$crate::__pin_project_parse_generics` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: expected one of `+`, `,`, `=`, or `>`, found `:` + --> tests/ui/pin_project/invalid-bounds.rs:27:1 + | +27 | / pin_project! { +28 | | struct Generics5 { //~ ERROR expected one of `+`, `,`, `=`, or `>`, found `:` +29 | | field: T, +30 | | } +31 | | } + | | ^ + | | | + | | expected one of `+`, `,`, `=`, or `>` + | |_unexpected token + | in this macro invocation + | + = note: this error originates in the macro `$crate::__pin_project_parse_generics` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: expected one of `+`, `,`, `=`, or `>`, found `:` + --> tests/ui/pin_project/invalid-bounds.rs:27:1 + | +27 | / pin_project! { +28 | | struct Generics5 { //~ ERROR expected one of `+`, `,`, `=`, or `>`, found `:` +29 | | field: T, +30 | | } +31 | | } + | | ^ + | | | + | |_expected one of `+`, `,`, `=`, or `>` + | unexpected token + | + = note: this error originates in the macro `$crate::__pin_project_parse_generics` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: expected one of `+`, `,`, `=`, or `>`, found `:` + --> tests/ui/pin_project/invalid-bounds.rs:27:1 + | +27 | / pin_project! { +28 | | struct Generics5 { //~ ERROR expected one of `+`, `,`, `=`, or `>`, found `:` +29 | | field: T, +30 | | } +31 | | } + | | ^ + | | | + | | expected one of `+`, `,`, `=`, or `>` + | |_unexpected token + | in this macro invocation + | + = note: this error originates in the macro `$crate::__pin_project_parse_generics` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: expected one of `+`, `,`, `=`, or `>`, found `:` + --> tests/ui/pin_project/invalid-bounds.rs:27:1 + | +27 | / pin_project! { +28 | | struct Generics5 { //~ ERROR expected one of `+`, `,`, `=`, or `>`, found `:` +29 | | field: T, +30 | | } +31 | | } + | | ^ + | | | + | | expected one of `+`, `,`, `=`, or `>` + | |_unexpected token + | in this macro invocation + | + = note: this error originates in the macro `$crate::__pin_project_parse_generics` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: no rules expected the token `Sized` + --> tests/ui/pin_project/invalid-bounds.rs:34:34 + | +34 | struct Generics6 { //~ ERROR no rules expected the token `Sized` + | ^^^^^ no rules expected this token in macro call + +error: no rules expected the token `:` + --> tests/ui/pin_project/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 `:` + --> tests/ui/pin_project/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 `{` after struct name, found `:` + --> tests/ui/pin_project/invalid-bounds.rs:57:1 + | +57 | / pin_project! { +58 | | struct WhereClause3 +59 | | where +60 | | T: Sized : 'static //~ ERROR expected `where`, or `{` after struct name, found `:` +... | +63 | | } +64 | | } + | | ^ + | | | + | |_expected `{` after struct name + | in this macro invocation + | + = note: this error originates in the macro `$crate::__pin_project_parse_generics` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: expected one of `+`, `,`, or `{`, found `:` + --> tests/ui/pin_project/invalid-bounds.rs:57:1 + | +57 | / pin_project! { +58 | | struct WhereClause3 +59 | | where +60 | | T: Sized : 'static //~ ERROR expected `where`, or `{` after struct name, found `:` +... | +63 | | } +64 | | } + | | ^ + | | | + | |_expected one of `+`, `,`, or `{` + | unexpected token + | + = note: this error originates in the macro `$crate::__pin_project_parse_generics` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: expected `{` after struct name, found `:` + --> tests/ui/pin_project/invalid-bounds.rs:57:1 + | +57 | / pin_project! { +58 | | struct WhereClause3 +59 | | where +60 | | T: Sized : 'static //~ ERROR expected `where`, or `{` after struct name, found `:` +... | +63 | | } +64 | | } + | | ^ + | | | + | |_expected `{` after struct name + | in this macro invocation + | + = note: this error originates in the macro `$crate::__pin_project_parse_generics` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: expected `{` after struct name, found `:` + --> tests/ui/pin_project/invalid-bounds.rs:57:1 + | +57 | / pin_project! { +58 | | struct WhereClause3 +59 | | where +60 | | T: Sized : 'static //~ ERROR expected `where`, or `{` after struct name, found `:` +... | +63 | | } +64 | | } + | | ^ + | | | + | |_expected `{` after struct name + | in this macro invocation + | + = note: this error originates in the macro `$crate::__pin_project_parse_generics` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: expected `{` after struct name, found `:` + --> tests/ui/pin_project/invalid-bounds.rs:66:1 + | +66 | / pin_project! { +67 | | struct WhereClause4 +68 | | where +69 | | T: ?Sized : 'static //~ ERROR expected `where`, or `{` after struct name, found `:` +... | +72 | | } +73 | | } + | | ^ + | | | + | |_expected `{` after struct name + | in this macro invocation + | + = note: this error originates in the macro `$crate::__pin_project_parse_generics` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: expected one of `+`, `,`, or `{`, found `:` + --> tests/ui/pin_project/invalid-bounds.rs:66:1 + | +66 | / pin_project! { +67 | | struct WhereClause4 +68 | | where +69 | | T: ?Sized : 'static //~ ERROR expected `where`, or `{` after struct name, found `:` +... | +72 | | } +73 | | } + | | ^ + | | | + | |_expected one of `+`, `,`, or `{` + | unexpected token + | + = note: this error originates in the macro `$crate::__pin_project_parse_generics` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: expected `{` after struct name, found `:` + --> tests/ui/pin_project/invalid-bounds.rs:66:1 + | +66 | / pin_project! { +67 | | struct WhereClause4 +68 | | where +69 | | T: ?Sized : 'static //~ ERROR expected `where`, or `{` after struct name, found `:` +... | +72 | | } +73 | | } + | | ^ + | | | + | |_expected `{` after struct name + | in this macro invocation + | + = note: this error originates in the macro `$crate::__pin_project_parse_generics` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: expected `{` after struct name, found `:` + --> tests/ui/pin_project/invalid-bounds.rs:66:1 + | +66 | / pin_project! { +67 | | struct WhereClause4 +68 | | where +69 | | T: ?Sized : 'static //~ ERROR expected `where`, or `{` after struct name, found `:` +... | +72 | | } +73 | | } + | | ^ + | | | + | |_expected `{` after struct name + | in this macro invocation + | + = note: this error originates in the macro `$crate::__pin_project_parse_generics` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: expected `{` after struct name, found `:` + --> tests/ui/pin_project/invalid-bounds.rs:75:1 + | +75 | / pin_project! { +76 | | struct WhereClause5 +77 | | where +78 | | T: Sized : ?Sized //~ ERROR expected `where`, or `{` after struct name, found `:` +... | +81 | | } +82 | | } + | | ^ + | | | + | |_expected `{` after struct name + | in this macro invocation + | + = note: this error originates in the macro `$crate::__pin_project_parse_generics` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: expected one of `+`, `,`, or `{`, found `:` + --> tests/ui/pin_project/invalid-bounds.rs:75:1 + | +75 | / pin_project! { +76 | | struct WhereClause5 +77 | | where +78 | | T: Sized : ?Sized //~ ERROR expected `where`, or `{` after struct name, found `:` +... | +81 | | } +82 | | } + | | ^ + | | | + | |_expected one of `+`, `,`, or `{` + | unexpected token + | + = note: this error originates in the macro `$crate::__pin_project_parse_generics` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: expected `{` after struct name, found `:` + --> tests/ui/pin_project/invalid-bounds.rs:75:1 + | +75 | / pin_project! { +76 | | struct WhereClause5 +77 | | where +78 | | T: Sized : ?Sized //~ ERROR expected `where`, or `{` after struct name, found `:` +... | +81 | | } +82 | | } + | | ^ + | | | + | |_expected `{` after struct name + | in this macro invocation + | + = note: this error originates in the macro `$crate::__pin_project_parse_generics` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: expected `{` after struct name, found `:` + --> tests/ui/pin_project/invalid-bounds.rs:75:1 + | +75 | / pin_project! { +76 | | struct WhereClause5 +77 | | where +78 | | T: Sized : ?Sized //~ ERROR expected `where`, or `{` after struct name, found `:` +... | +81 | | } +82 | | } + | | ^ + | | | + | |_expected `{` after struct name + | in this macro invocation + | + = note: this error originates in the macro `$crate::__pin_project_parse_generics` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: no rules expected the token `Sized` + --> tests/ui/pin_project/invalid-bounds.rs:87:21 + | +87 | T: ?Sized : Sized //~ ERROR no rules expected the token `Sized` + | ^^^^^ no rules expected this token in macro call diff --git a/third_party/rust/pin-project-lite/tests/ui/pin_project/invalid.rs b/third_party/rust/pin-project-lite/tests/ui/pin_project/invalid.rs new file mode 100644 index 0000000000..e0ea61d4f7 --- /dev/null +++ b/third_party/rust/pin-project-lite/tests/ui/pin_project/invalid.rs @@ -0,0 +1,25 @@ +use pin_project_lite::pin_project; + +pin_project! { + struct A { + #[pin()] //~ ERROR no rules expected the token `(` + pinned: T, + } +} + +pin_project! { + #[pin] //~ ERROR cannot find attribute `pin` in this scope + struct B { + pinned: T, + } +} + +pin_project! { + struct C { + #[pin] + #[pin] //~ ERROR no rules expected the token `#` + pinned: T, + } +} + +fn main() {} diff --git a/third_party/rust/pin-project-lite/tests/ui/pin_project/invalid.stderr b/third_party/rust/pin-project-lite/tests/ui/pin_project/invalid.stderr new file mode 100644 index 0000000000..623a886722 --- /dev/null +++ b/third_party/rust/pin-project-lite/tests/ui/pin_project/invalid.stderr @@ -0,0 +1,59 @@ +error: no rules expected the token `struct` + --> tests/ui/pin_project/invalid.rs:3:1 + | +3 | / pin_project! { +4 | | struct A { +5 | | #[pin()] //~ ERROR no rules expected the token `(` +6 | | pinned: T, +7 | | } +8 | | } + | |_^ no rules expected this token in macro call + | + = note: this error originates in the macro `$crate::__pin_project_expand` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: no rules expected the token `struct` + --> tests/ui/pin_project/invalid.rs:3:1 + | +3 | / pin_project! { +4 | | struct A { +5 | | #[pin()] //~ ERROR no rules expected the token `(` +6 | | pinned: T, +7 | | } +8 | | } + | |_^ no rules expected this token in macro call + | + = note: this error originates in the macro `$crate::__pin_project_expand` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: no rules expected the token `struct` + --> tests/ui/pin_project/invalid.rs:17:1 + | +17 | / pin_project! { +18 | | struct C { +19 | | #[pin] +20 | | #[pin] //~ ERROR no rules expected the token `#` +21 | | pinned: T, +22 | | } +23 | | } + | |_^ no rules expected this token in macro call + | + = note: this error originates in the macro `$crate::__pin_project_expand` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: no rules expected the token `struct` + --> tests/ui/pin_project/invalid.rs:17:1 + | +17 | / pin_project! { +18 | | struct C { +19 | | #[pin] +20 | | #[pin] //~ ERROR no rules expected the token `#` +21 | | pinned: T, +22 | | } +23 | | } + | |_^ no rules expected this token in macro call + | + = note: this error originates in the macro `$crate::__pin_project_expand` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: cannot find attribute `pin` in this scope + --> tests/ui/pin_project/invalid.rs:11:7 + | +11 | #[pin] //~ ERROR cannot find attribute `pin` in this scope + | ^^^ diff --git a/third_party/rust/pin-project-lite/tests/ui/pin_project/overlapping_lifetime_names.rs b/third_party/rust/pin-project-lite/tests/ui/pin_project/overlapping_lifetime_names.rs new file mode 100644 index 0000000000..117c18d74c --- /dev/null +++ b/third_party/rust/pin-project-lite/tests/ui/pin_project/overlapping_lifetime_names.rs @@ -0,0 +1,10 @@ +use pin_project_lite::pin_project; + +pin_project! { //~ ERROR E0263,E0496 + pub struct Foo<'__pin, T> { + #[pin] + field: &'__pin mut T, + } +} + +fn main() {} diff --git a/third_party/rust/pin-project-lite/tests/ui/pin_project/overlapping_lifetime_names.stderr b/third_party/rust/pin-project-lite/tests/ui/pin_project/overlapping_lifetime_names.stderr new file mode 100644 index 0000000000..35074d0753 --- /dev/null +++ b/third_party/rust/pin-project-lite/tests/ui/pin_project/overlapping_lifetime_names.stderr @@ -0,0 +1,75 @@ +error[E0263]: lifetime name `'__pin` declared twice in the same scope + --> tests/ui/pin_project/overlapping_lifetime_names.rs:4:20 + | +3 | / pin_project! { //~ ERROR E0263,E0496 +4 | | pub struct Foo<'__pin, T> { + | | ^^^^^^ declared twice +5 | | #[pin] +6 | | field: &'__pin mut T, +7 | | } +8 | | } + | |_- previous declaration here + +error[E0263]: lifetime name `'__pin` declared twice in the same scope + --> tests/ui/pin_project/overlapping_lifetime_names.rs:4:20 + | +3 | / pin_project! { //~ ERROR E0263,E0496 +4 | | pub struct Foo<'__pin, T> { + | | ^^^^^^ declared twice +5 | | #[pin] +6 | | field: &'__pin mut T, +7 | | } +8 | | } + | |_- previous declaration here + +error[E0263]: lifetime name `'__pin` declared twice in the same scope + --> tests/ui/pin_project/overlapping_lifetime_names.rs:4:20 + | +3 | / pin_project! { //~ ERROR E0263,E0496 +4 | | pub struct Foo<'__pin, T> { + | | ^^^^^^ declared twice +5 | | #[pin] +6 | | field: &'__pin mut T, +7 | | } +8 | | } + | |_- previous declaration here + +error[E0496]: lifetime name `'__pin` shadows a lifetime name that is already in scope + --> tests/ui/pin_project/overlapping_lifetime_names.rs:3:1 + | +3 | / pin_project! { //~ ERROR E0263,E0496 +4 | | pub struct Foo<'__pin, T> { + | | ------ first declared here +5 | | #[pin] +6 | | field: &'__pin mut T, +7 | | } +8 | | } + | |_^ lifetime `'__pin` already in scope + | + = note: this error originates in the macro `$crate::__pin_project_struct_make_proj_method` (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 + --> tests/ui/pin_project/overlapping_lifetime_names.rs:3:1 + | +3 | / pin_project! { //~ ERROR E0263,E0496 +4 | | pub struct Foo<'__pin, T> { + | | ------ first declared here +5 | | #[pin] +6 | | field: &'__pin mut T, +7 | | } +8 | | } + | |_^ lifetime `'__pin` already in scope + | + = note: this error originates in the macro `$crate::__pin_project_struct_make_proj_method` (in Nightly builds, run with -Z macro-backtrace for more info) + +error[E0263]: lifetime name `'__pin` declared twice in the same scope + --> tests/ui/pin_project/overlapping_lifetime_names.rs:4:20 + | +3 | / pin_project! { //~ ERROR E0263,E0496 +4 | | pub struct Foo<'__pin, T> { + | | ^^^^^^ declared twice +5 | | #[pin] +6 | | field: &'__pin mut T, +7 | | } +8 | | } + | |_- previous declaration here diff --git a/third_party/rust/pin-project-lite/tests/ui/pin_project/overlapping_unpin_struct.rs b/third_party/rust/pin-project-lite/tests/ui/pin_project/overlapping_unpin_struct.rs new file mode 100644 index 0000000000..25131d17d1 --- /dev/null +++ b/third_party/rust/pin-project-lite/tests/ui/pin_project/overlapping_unpin_struct.rs @@ -0,0 +1,20 @@ +use std::marker::PhantomPinned; + +use pin_project_lite::pin_project; + +pin_project! { + struct Foo { + #[pin] + inner: T, + } +} + +struct __Origin {} + +impl Unpin for __Origin {} + +fn is_unpin() {} + +fn main() { + is_unpin::>(); //~ ERROR E0277 +} diff --git a/third_party/rust/pin-project-lite/tests/ui/pin_project/overlapping_unpin_struct.stderr b/third_party/rust/pin-project-lite/tests/ui/pin_project/overlapping_unpin_struct.stderr new file mode 100644 index 0000000000..303e7cbb58 --- /dev/null +++ b/third_party/rust/pin-project-lite/tests/ui/pin_project/overlapping_unpin_struct.stderr @@ -0,0 +1,33 @@ +error[E0277]: `PhantomPinned` cannot be unpinned + --> tests/ui/pin_project/overlapping_unpin_struct.rs:19:5 + | +19 | is_unpin::>(); //~ ERROR E0277 + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ within `_::__Origin<'_, PhantomPinned>`, the trait `Unpin` is not implemented for `PhantomPinned` + | + = note: consider using `Box::pin` +note: required because it appears within the type `_::__Origin<'_, PhantomPinned>` + --> tests/ui/pin_project/overlapping_unpin_struct.rs:5:1 + | +5 | / pin_project! { +6 | | struct Foo { +7 | | #[pin] +8 | | inner: T, +9 | | } +10 | | } + | |_^ +note: required because of the requirements on the impl of `Unpin` for `Foo` + --> tests/ui/pin_project/overlapping_unpin_struct.rs:5:1 + | +5 | / pin_project! { +6 | | struct Foo { +7 | | #[pin] +8 | | inner: T, +9 | | } +10 | | } + | |_^ +note: required by a bound in `is_unpin` + --> tests/ui/pin_project/overlapping_unpin_struct.rs:16:16 + | +16 | fn is_unpin() {} + | ^^^^^ required by this bound in `is_unpin` + = note: this error originates in the macro `$crate::__pin_project_make_unpin_impl` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/third_party/rust/pin-project-lite/tests/ui/pin_project/packed.rs b/third_party/rust/pin-project-lite/tests/ui/pin_project/packed.rs new file mode 100644 index 0000000000..50afb118c8 --- /dev/null +++ b/third_party/rust/pin-project-lite/tests/ui/pin_project/packed.rs @@ -0,0 +1,21 @@ +#![allow(unaligned_references)] + +use pin_project_lite::pin_project; + +pin_project! { //~ ERROR reference to packed field is unaligned + #[repr(packed, C)] + struct Packed { + #[pin] + field: u16, + } +} + +pin_project! { //~ ERROR reference to packed field is unaligned + #[repr(packed(2))] + struct PackedN { + #[pin] + field: u32, + } +} + +fn main() {} diff --git a/third_party/rust/pin-project-lite/tests/ui/pin_project/packed.stderr b/third_party/rust/pin-project-lite/tests/ui/pin_project/packed.stderr new file mode 100644 index 0000000000..81fb4f1fcc --- /dev/null +++ b/third_party/rust/pin-project-lite/tests/ui/pin_project/packed.stderr @@ -0,0 +1,57 @@ +error: reference to packed field is unaligned + --> tests/ui/pin_project/packed.rs:5:1 + | +5 | / pin_project! { //~ ERROR reference to packed field is unaligned +6 | | #[repr(packed, C)] +7 | | struct Packed { +8 | | #[pin] +9 | | field: u16, +10 | | } +11 | | } + | |_^ + | +note: the lint level is defined here + --> tests/ui/pin_project/packed.rs:5:1 + | +5 | / pin_project! { //~ ERROR reference to packed field is unaligned +6 | | #[repr(packed, C)] +7 | | struct Packed { +8 | | #[pin] +9 | | field: u16, +10 | | } +11 | | } + | |_^ + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #82523 + = note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced) + = help: copy the field contents to a local variable, or replace the reference with a raw pointer and use `read_unaligned`/`write_unaligned` (loads and stores via `*p` must be properly aligned even when using raw pointers) + = note: this error originates in the macro `$crate::__pin_project_constant` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: reference to packed field is unaligned + --> tests/ui/pin_project/packed.rs:13:1 + | +13 | / pin_project! { //~ ERROR reference to packed field is unaligned +14 | | #[repr(packed(2))] +15 | | struct PackedN { +16 | | #[pin] +17 | | field: u32, +18 | | } +19 | | } + | |_^ + | +note: the lint level is defined here + --> tests/ui/pin_project/packed.rs:13:1 + | +13 | / pin_project! { //~ ERROR reference to packed field is unaligned +14 | | #[repr(packed(2))] +15 | | struct PackedN { +16 | | #[pin] +17 | | field: u32, +18 | | } +19 | | } + | |_^ + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #82523 + = note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced) + = help: copy the field contents to a local variable, or replace the reference with a raw pointer and use `read_unaligned`/`write_unaligned` (loads and stores via `*p` must be properly aligned even when using raw pointers) + = note: this error originates in the macro `$crate::__pin_project_constant` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/third_party/rust/pin-project-lite/tests/ui/pin_project/unpin_sneaky.rs b/third_party/rust/pin-project-lite/tests/ui/pin_project/unpin_sneaky.rs new file mode 100644 index 0000000000..984cc2a219 --- /dev/null +++ b/third_party/rust/pin-project-lite/tests/ui/pin_project/unpin_sneaky.rs @@ -0,0 +1,12 @@ +use pin_project_lite::pin_project; + +pin_project! { + struct Foo { + #[pin] + inner: u8, + } +} + +impl Unpin for __Origin {} //~ ERROR E0412,E0321 + +fn main() {} diff --git a/third_party/rust/pin-project-lite/tests/ui/pin_project/unpin_sneaky.stderr b/third_party/rust/pin-project-lite/tests/ui/pin_project/unpin_sneaky.stderr new file mode 100644 index 0000000000..4eb6eff96f --- /dev/null +++ b/third_party/rust/pin-project-lite/tests/ui/pin_project/unpin_sneaky.stderr @@ -0,0 +1,11 @@ +error[E0412]: cannot find type `__Origin` in this scope + --> tests/ui/pin_project/unpin_sneaky.rs:10:16 + | +10 | impl Unpin for __Origin {} //~ ERROR E0412,E0321 + | ^^^^^^^^ not found in this scope + +error[E0321]: cross-crate traits with a default impl, like `Unpin`, can only be implemented for a struct/enum type, not `[type error]` + --> tests/ui/pin_project/unpin_sneaky.rs:10:1 + | +10 | impl Unpin for __Origin {} //~ ERROR E0412,E0321 + | ^^^^^^^^^^^^^^^^^^^^^^^ can't implement cross-crate trait with a default impl for non-struct/enum type diff --git a/third_party/rust/pin-project-lite/tests/ui/pin_project/unsupported.rs b/third_party/rust/pin-project-lite/tests/ui/pin_project/unsupported.rs new file mode 100644 index 0000000000..2f80836275 --- /dev/null +++ b/third_party/rust/pin-project-lite/tests/ui/pin_project/unsupported.rs @@ -0,0 +1,27 @@ +use pin_project_lite::pin_project; + +pin_project! { + struct Struct1 {} //~ ERROR no rules expected the token `}` +} + +pin_project! { + struct Struct2(); //~ ERROR no rules expected the token `(` +} + +pin_project! { + struct Struct3; //~ ERROR no rules expected the token `;` +} + +pin_project! { + enum Enum { //~ ERROR no rules expected the token `enum` + A(u8) + } +} + +pin_project! { + union Union { //~ ERROR no rules expected the token `union` + x: u8, + } +} + +fn main() {} diff --git a/third_party/rust/pin-project-lite/tests/ui/pin_project/unsupported.stderr b/third_party/rust/pin-project-lite/tests/ui/pin_project/unsupported.stderr new file mode 100644 index 0000000000..a7d215a43e --- /dev/null +++ b/third_party/rust/pin-project-lite/tests/ui/pin_project/unsupported.stderr @@ -0,0 +1,79 @@ +error: no rules expected the token `}` + --> tests/ui/pin_project/unsupported.rs:3:1 + | +3 | / pin_project! { +4 | | struct Struct1 {} //~ ERROR no rules expected the token `}` +5 | | } + | |_^ no rules expected this token in macro call + | + = note: this error originates in the macro `$crate::__pin_project_expand` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: no rules expected the token `}` + --> tests/ui/pin_project/unsupported.rs:3:1 + | +3 | / pin_project! { +4 | | struct Struct1 {} //~ ERROR no rules expected the token `}` +5 | | } + | |_^ no rules expected this token in macro call + | + = note: this error originates in the macro `$crate::__pin_project_expand` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: no rules expected the token `(` + --> tests/ui/pin_project/unsupported.rs:8:19 + | +8 | struct Struct2(); //~ ERROR no rules expected the token `(` + | ^ no rules expected this token in macro call + +error: no rules expected the token `;` + --> tests/ui/pin_project/unsupported.rs:12:19 + | +12 | struct Struct3; //~ ERROR no rules expected the token `;` + | ^ no rules expected this token in macro call + +error: no rules expected the token `enum` + --> tests/ui/pin_project/unsupported.rs:15:1 + | +15 | / pin_project! { +16 | | enum Enum { //~ ERROR no rules expected the token `enum` +17 | | A(u8) +18 | | } +19 | | } + | |_^ no rules expected this token in macro call + | + = note: this error originates in the macro `$crate::__pin_project_expand` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: no rules expected the token `enum` + --> tests/ui/pin_project/unsupported.rs:15:1 + | +15 | / pin_project! { +16 | | enum Enum { //~ ERROR no rules expected the token `enum` +17 | | A(u8) +18 | | } +19 | | } + | |_^ no rules expected this token in macro call + | + = note: this error originates in the macro `$crate::__pin_project_expand` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: no rules expected the token `union` + --> tests/ui/pin_project/unsupported.rs:21:1 + | +21 | / pin_project! { +22 | | union Union { //~ ERROR no rules expected the token `union` +23 | | x: u8, +24 | | } +25 | | } + | |_^ no rules expected this token in macro call + | + = note: this error originates in the macro `$crate::__pin_project_expand` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: no rules expected the token `union` + --> tests/ui/pin_project/unsupported.rs:21:1 + | +21 | / pin_project! { +22 | | union Union { //~ ERROR no rules expected the token `union` +23 | | x: u8, +24 | | } +25 | | } + | |_^ no rules expected this token in macro call + | + = note: this error originates in the macro `$crate::__pin_project_expand` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/third_party/rust/pin-project-lite/tests/ui/pinned_drop/call-drop-inner.rs b/third_party/rust/pin-project-lite/tests/ui/pinned_drop/call-drop-inner.rs new file mode 100644 index 0000000000..609b3bebad --- /dev/null +++ b/third_party/rust/pin-project-lite/tests/ui/pinned_drop/call-drop-inner.rs @@ -0,0 +1,17 @@ +use pin_project_lite::pin_project; + +pin_project! { + pub struct S { + #[pin] + field: u8, + } + impl PinnedDrop for S { + fn drop(this: Pin<&mut Self>) { + __drop_inner(this); + } + } +} + +fn main() { + let _x = S { field: 0 }; +} diff --git a/third_party/rust/pin-project-lite/tests/ui/pinned_drop/call-drop-inner.stderr b/third_party/rust/pin-project-lite/tests/ui/pinned_drop/call-drop-inner.stderr new file mode 100644 index 0000000000..597f67c84f --- /dev/null +++ b/third_party/rust/pin-project-lite/tests/ui/pinned_drop/call-drop-inner.stderr @@ -0,0 +1,22 @@ +error[E0061]: this function takes 0 arguments but 1 argument was supplied + --> tests/ui/pinned_drop/call-drop-inner.rs:10:13 + | +10 | __drop_inner(this); + | ^^^^^^^^^^^^ ---- argument unexpected + | +note: function defined here + --> tests/ui/pinned_drop/call-drop-inner.rs:3:1 + | +3 | / pin_project! { +4 | | pub struct S { +5 | | #[pin] +6 | | field: u8, +... | +12 | | } +13 | | } + | |_^ + = note: this error originates in the macro `$crate::__pin_project_make_drop_impl` (in Nightly builds, run with -Z macro-backtrace for more info) +help: remove the extra argument + | +10 | __drop_inner(); + | ~~~~~~~~~~~~~~ diff --git a/third_party/rust/pin-project-lite/tests/ui/pinned_drop/conditional-drop-impl.rs b/third_party/rust/pin-project-lite/tests/ui/pinned_drop/conditional-drop-impl.rs new file mode 100644 index 0000000000..68b01b265e --- /dev/null +++ b/third_party/rust/pin-project-lite/tests/ui/pinned_drop/conditional-drop-impl.rs @@ -0,0 +1,26 @@ +use pin_project_lite::pin_project; + +// In `Drop` impl, the implementor must specify the same requirement as type definition. + +struct DropImpl { + f: T, +} + +impl Drop for DropImpl { + //~^ ERROR E0367 + fn drop(&mut self) {} +} + +pin_project! { + //~^ ERROR E0367 + struct PinnedDropImpl { + #[pin] + f: T, + } + + impl PinnedDrop for PinnedDropImpl { + fn drop(_this: Pin<&mut Self>) {} + } +} + +fn main() {} diff --git a/third_party/rust/pin-project-lite/tests/ui/pinned_drop/conditional-drop-impl.stderr b/third_party/rust/pin-project-lite/tests/ui/pinned_drop/conditional-drop-impl.stderr new file mode 100644 index 0000000000..d70009c97a --- /dev/null +++ b/third_party/rust/pin-project-lite/tests/ui/pinned_drop/conditional-drop-impl.stderr @@ -0,0 +1,38 @@ +error[E0367]: `Drop` impl requires `T: Unpin` but the struct it is implemented for does not + --> tests/ui/pinned_drop/conditional-drop-impl.rs:9:9 + | +9 | impl Drop for DropImpl { + | ^^^^^ + | +note: the implementor must specify the same requirement + --> tests/ui/pinned_drop/conditional-drop-impl.rs:5:1 + | +5 | / struct DropImpl { +6 | | f: T, +7 | | } + | |_^ + +error[E0367]: `Drop` impl requires `T: Unpin` but the struct it is implemented for does not + --> tests/ui/pinned_drop/conditional-drop-impl.rs:14:1 + | +14 | / pin_project! { +15 | | //~^ ERROR E0367 +16 | | struct PinnedDropImpl { +17 | | #[pin] +... | +23 | | } +24 | | } + | |_^ + | +note: the implementor must specify the same requirement + --> tests/ui/pinned_drop/conditional-drop-impl.rs:14:1 + | +14 | / pin_project! { +15 | | //~^ ERROR E0367 +16 | | struct PinnedDropImpl { +17 | | #[pin] +... | +23 | | } +24 | | } + | |_^ + = note: this error originates in the macro `$crate::__pin_project_make_drop_impl` (in Nightly builds, run with -Z macro-backtrace for more info) -- cgit v1.2.3