# Surprising soundness trouble around \`PollFn\`

**URL:** <https://internals.rust-lang.org/t/surprising-soundness-trouble-around-pollfn/17484>\
**Category:** Uncategorized\
**Created:** [October 4, 2022, 11:09am UTC](https://internals.rust-lang.org/t/surprising-soundness-trouble-around-pollfn/17484 "2022-10-04T11:09:11Z")\
**Posts on this page:** 1\
**Showing post:** 15

<div class="post-metadata">

**Author:** ![comex](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/comex/32/2587_2.png) [@comex](https://internals.rust-lang.org/u/comex)\
**Post date:** [October 6, 2022, 3:45am UTC](https://internals.rust-lang.org/t/surprising-soundness-trouble-around-pollfn/17484/15 "2022-10-06T03:45:13Z")

</div>

For what it's worth: `tokio::join!` and `futures::join!` are unsound, but `std::future::join!` is not. `tokio::join!` [moves the input futures into a lambda](https://docs.rs/tokio/latest/src/tokio/macros/join.rs.html#113), similar to the original example, and so does `futures::join!` (whose implementation is more complicated). In contrast, `std::future::join` [pins the input futures outside the lambda](https://doc.rust-lang.org/src/core/future/join.rs.html#109) and only moves `Pin<&mut T>` objects into the lambda.

[Here is a playground link](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=00233b71340fdece6efdd72b547a8dda), pieced together from some of the previous snippets, that triggers a Miri error using `tokio::join!` and no `unsafe`. If you change `tokio::join!` to `futures::join!` it also triggers an error.

And... [here is a playground link](https://play.rust-lang.org/?version=nightly&mode=release&edition=2021&gist=57db0d7837edb1a47c556dca8fdc2a91) that actually triggers a miscompilation using `futures::join!`. The code should print 44, but in release mode it prints 43. This doesn't work with `tokio::join!` simply because it generates more complicated control flow that confuses LLVM.

---

_[View the full topic](https://internals.rust-lang.org/t/surprising-soundness-trouble-around-pollfn/17484)._
