confusing "lifetime mismatch" error when spawning task #86487
Labels
A-async-await
Area: Async & Await
A-diagnostics
Area: Messages for errors, warnings, and lints
AsyncAwait-Triaged
Async-await issues that have been triaged during a working group meeting.
C-bug
Category: This is a bug.
D-confusing
Diagnostics: Confusing error or lint that should be reworked.
E-needs-mcve
Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example
requires-nightly
This issue requires a nightly compiler in some way.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
suggested labels: A-diagnostics, A-async-await, D-confusing, requires-nightly
Introduction
Hey diagnostics team. I'm currently helping a pal debug some code, and we're experiencing a particularly gnarly error. We haven't been able to figure out what's going wrong, so we can't provide a repro either. So I'm opening this issue so folks can come along on the journey we're on, and maybe we can figure out both what the root error is -- and how to improve the error messages -- together!
Setting the scene
The current project lives on the
spawn
branch of thepeermap-ingest
project. To get started do:The following code is where our error points us to. We're pushing
async-std
task::JoinHandle
into aVec
so we can await all handles together later on. Each task processes a command, which interacts with a backing store asynchronously in the background. If an error occurs, we log it. Theasync move {}
block's generated future returns a()
.Running the code generates the following output:
What are we looking at?
The main error describes a: "lifetime mismatch". It then points to a call site, highlights the type signatures, and finally points to where the requirement was defined. However this has some issues:
note: expected type
do not carry any explicit lifetimes, and look otherwise identical to each othernote: the lifetime requirement is introduced here
points to theSend
param inasync_std::task::spawn
. That's not a lifetime, which makes it confusing.'static
lifetime inasync_std::task::spawn
, but we cannot know for sure.Send
is highlighted in the second output makes it unclear whether the issue actually is that we are trying to pass a!Send
item to a function which required the item isSend
.Result<_, Box<dyn Error + ...>>
is odd, since the return type of theFuture
is()
. What error is being referred to here? It's unclear!What have we tried so far?
+ 'static
notations to everyError
definition in the code (and dependencies) to no changeasync move {}
block with anasync fn
to no change!Send
or non-'static
(after having done the error type fix as well)What could be done to help solve this?
Send
or an issue with a lifetime (if so: which lifetime?). Clearing that up would be a first step.hint: expected type
should not be identical. If a lifetime is different, it should probably show up.async_std::task::spawn
in the source, and the error in thehint: expected type
is unclear. It'd be nice to know whichError
type is being referred to -- even if it's only shown with--verbose
output. Needing to manually step through code takes a lot of time, where supposedly the compiler already knows this information (even if not displayed in the output).Conclusion
I hope this is enough information for someone to take a look at this. I think we're hitting a particularly gnarly combination of diagnostics failures here, which when put together make it hard to debug. Thanks heaps!
cc/ @substack
The text was updated successfully, but these errors were encountered: