Closed jswrenn closed 2 years ago
I get that this error is unexpected, but 'spurious' sounds like a claim that this is a false positive?
Here's a version that avoids unsafe, and it also makes Miri happy.
The original code is probably just buggy -- each time you write &mut future
, that claims that this is the only pointer to future
that will be used henceforth. And that claim is just wrong since the future is self-referential. Once it is pinned, you must never create a mutable reference directly to a future, since that would invalidate the self-referential references.
Though I admit I don't entirely understand why the !Unpin
exception is insufficient.
I did some more investigation, see IRLO for details. But Miri is right, the original code is buggy -- pinned
is in fact an Unpin
future with a by-value self-referential generator, which is not kosher. A slight variant of this causes a use-after-free, so it's not just aliasing rules that are violated.
Running this code snippet (playground) with miri:
...results in this diagnostic:
I'm using the miri packaged with
rustc 1.66.0-nightly (ce7f0f1aa 2022-09-28)
.Discussion on Zulip here: https://rust-lang.zulipchat.com/#narrow/stream/269128-miri/topic/Diagnosing.20retag.20in.20.60.2Eawait.60