-
-
Notifications
You must be signed in to change notification settings - Fork 14.8k
Unexpected "the parameter type X may not live long enough" error in asynchronous functions #95719
Copy link
Copy link
Open
Labels
A-GATsArea: Generic associated types (GATs)Area: Generic associated types (GATs)A-async-awaitArea: Async & AwaitArea: Async & AwaitA-lifetimesArea: Lifetimes / regionsArea: Lifetimes / regionsA-trait-systemArea: Trait systemArea: Trait systemAsyncAwait-TriagedAsync-await issues that have been triaged during a working group meeting.Async-await issues that have been triaged during a working group meeting.E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.Call for participation: An issue has been fixed and does not reproduce, but no test has been added.F-impl_trait_in_assoc_type`#![feature(impl_trait_in_assoc_type)]``#![feature(impl_trait_in_assoc_type)]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-typesRelevant to the types team, which will review and decide on the PR/issue.Relevant to the types team, which will review and decide on the PR/issue.WG-asyncWorking group: Async & awaitWorking group: Async & await
Metadata
Metadata
Assignees
Labels
A-GATsArea: Generic associated types (GATs)Area: Generic associated types (GATs)A-async-awaitArea: Async & AwaitArea: Async & AwaitA-lifetimesArea: Lifetimes / regionsArea: Lifetimes / regionsA-trait-systemArea: Trait systemArea: Trait systemAsyncAwait-TriagedAsync-await issues that have been triaged during a working group meeting.Async-await issues that have been triaged during a working group meeting.E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.Call for participation: An issue has been fixed and does not reproduce, but no test has been added.F-impl_trait_in_assoc_type`#![feature(impl_trait_in_assoc_type)]``#![feature(impl_trait_in_assoc_type)]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-typesRelevant to the types team, which will review and decide on the PR/issue.Relevant to the types team, which will review and decide on the PR/issue.WG-asyncWorking group: Async & awaitWorking group: Async & await
Type
Fields
Give feedbackNo fields configured for issues without a type.
When a
Futureis wrapped in anasyncblock or anasyncfunction, some of its traits are lost, e.g., Send, thus causing various issues.I tried this code:
I expected to see no compiler errors: the returned
Futurefromasync fn wrapshould beSend, becauseg.get()isSendandasync fn wraponly wraps the code in an asynchronous code block.Instead, this happened: the returned
Futurefromasync fn wrapis not anymoreSend. Note that the error manifests differently if another lifetime bounds are involved in the trait -lifetime bound not satisfiedwhen assertingis_send(&fut). It's even strange to seelifetime boundsormay not live long enougherrors when checking theSendbound.Meta
rustc --version --verbose:Error