You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Incorrect "implementation of Send is not general enough" error with lifetimed Send impl used in async fn #96865
A-async-awaitArea: Async & AwaitA-coroutinesArea: CoroutinesAsyncAwait-TriagedAsync-await issues that have been triaged during a working group meeting.C-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
structFoo<'a,F>{func:F,data:&'au32,}unsafeimpl<'a,F:Send + Callback<&'au32>>SendforFoo<'a,F>{}traitCallback<I>{}structImplementor<'a>(&'au32);impl<'a>Callback<&'au32>forImplementor<'a>{}fnassert_send<T:Send>(v:T) -> T{ v }asyncfnasync_function<'a>(data:&'au32){let data = assert_send(Foo{func:Implementor(data),
data,});
std::future::ready(5).await;}fnwrapper(data:&u32){assert_send(async_function(data));}
I expected to see this happen: No error
Instead, this happened:
error: implementation of `std::marker::Send` is not general enough
--> src/main.rs:23:5
|
23 | assert_send(async_function(data));
| ^^^^^^^^^^^ implementation of `std::marker::Send` is not general enough
|
= note: `std::marker::Send` would have to be implemented for the type `Foo<'0, Implementor<'1>>`, for any two lifetimes `'0` and `'1`...
= note: ...but `std::marker::Send` is actually implemented for the type `Foo<'2, Implementor<'_>>`, for some specific lifetime `'2`
It looks like we are incorrectly replacing regions with inference variables. In generator_interior, it looks like we replace regions with variables in a couple of places for convenience, so maybe we are being sloppy with that? Here are a couple of places that might be relevant:
Please, bump up this bug report.
All the problematic code presented here still show the same errors in Rust 1.71, 1.3 years after.
This bug bit me nowadays, preventing my progress on a nice & flexible generic async code using references for zero-copying things around.
I'll either have to write inneficient code or chase an as-efficient-as-possible workaround for my specific case for hours and hours...
I ended up using the alternative notation -- described here: #102211 (comment) -- to avoid this type inference compiler bug when GATs are involved.
Other zero-cost workarounds are possible as well:
@rvolosatovs my project has been stalled for about a year due to this bug, your solution has at least solved the problem that I'm hitting after a complete rewrite, I cannot thank you enough!
Also another interesting tidbit, at least my variation of this bug was fixed by using the "higher ranked assumptions" flag on the nightly compiler some 9-12 months ago. That said, this no longer works, prompting said rewrite.
A-async-awaitArea: Async & AwaitA-coroutinesArea: CoroutinesAsyncAwait-TriagedAsync-await issues that have been triaged during a working group meeting.C-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
Activity
aliemjay commentedon May 10, 2022
Minimized: https://play.rust-lang.org/?version=nightly&mode=release&edition=2021&gist=87d7f794697776f806158ef6b9880bdb
@rustbot label A-generators A-async-await T-compiler
SabrinaJewson commentedon May 11, 2022
Another instance of what I think is the same bug, this time with
dyn Traits and associated types: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=6d632d153fdfebd3cb7348a0ec15326a (discovered by @LegionMammal978 on Discord)The fix there is to wrap the
dyn Traitin another type:eholk commentedon May 23, 2022
It looks like we are incorrectly replacing regions with inference variables. In generator_interior, it looks like we replace regions with variables in a couple of places for convenience, so maybe we are being sloppy with that? Here are a couple of places that might be relevant:
rust/compiler/rustc_typeck/src/check/generator_interior.rs
Lines 224 to 227 in ef9b498
@rustbot label AsyncAwait-Triaged
carols10cents commentedon Aug 17, 2022
Is this related to/duplicate of #64552?
emersonford commentedon Apr 12, 2023
@carols10cents @eholk yeah this is definitely the same issue as #102211. fixing that bug should fix all related issues.
zertyz commentedon Aug 19, 2023
Please, bump up this bug report.
All the problematic code presented here still show the same errors in Rust 1.71, 1.3 years after.
This bug bit me nowadays, preventing my progress on a nice & flexible generic async code using references for zero-copying things around.
I'll either have to write inneficient code or chase an as-efficient-as-possible workaround for my specific case for hours and hours...
zertyz commentedon Aug 21, 2023
I ended up using the alternative notation -- described here: #102211 (comment) -- to avoid this type inference compiler bug when GATs are involved.
Other zero-cost workarounds are possible as well:
Other workarounds exist in the first link, but they involve paying extra costs for boxing / dynamic dispatching.
lukaszwojtow commentedon Feb 17, 2024
I think this: https://github.com/qpackt/qpackt/blob/b4f20dd9f0273ee0c1c33e7b994e7bf8e046cf2d/qpackt-backend/src/main.rs#L93 is also wrong. Should I report it separately or is it the same bug?
16 remaining items
refactor(sdk): replace #[async_trait] with explicit BoxFuture on SDK …
fix(sdk): replace #[async_trait] with #[box_async] to fix HRTB Send i…
chore: update dash-sdk to latest platform v3.1-dev
chore: update dash-sdk to latest platform v3.1-dev
chore: update dash-sdk to latest platform v3.1-dev
chore: update dash-sdk to latest platform v3.1-dev
chore: update dash-sdk to latest platform v3.1-dev
chore: update dash-sdk to latest platform v3.1-dev
chore: update dash-sdk to latest platform v3.1-dev
chore: update dash-sdk to latest platform v3.1-dev
chore: update dash-sdk to latest platform v3.1-dev
chore: update dash-sdk to latest platform v3.1-dev (#806)
feat(web): replace sync subprocess execution with direct service disp…
feat(web): replace sync subprocess execution with direct service disp…
Kulasko commentedon Nov 29, 2026
@rvolosatovs my project has been stalled for about a year due to this bug, your solution has at least solved the problem that I'm hitting after a complete rewrite, I cannot thank you enough!
Also another interesting tidbit, at least my variation of this bug was fixed by using the "higher ranked assumptions" flag on the nightly compiler some 9-12 months ago. That said, this no longer works, prompting said rewrite.