Additional let bindings needed to avoid Sync
#94843
Labels
A-async-await
Area: Async & Await
A-borrow-checker
Area: The borrow checker
C-bug
Category: This is a bug.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
I tried this code:
(playground)
I expected to see this happen:
It should compile.
Instead, this happened:
Note that following the suggestion using an additional
let
binding fixes the issue:What is kinda weird (from my PoV) is the explanation: adding an additional
let
binding doesn't really shorted the borrowing ofx
, we're still just calling.clone()
and then callf
.You might wonder why someone would clone
x
here, but let's assume we needx
after callingf
and I didn't want to make the example more complicated.The
spawn
function above was chosen because it is similar totokio::spawn
, for which this issue was observed originally.I think this might be another instance of #69663 but I'm not sure.
Meta
rustc --version --verbose
:Bug is also reproducible on nightly.
The text was updated successfully, but these errors were encountered: