-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Incorrect "implementation of Send
is not general enough" error with lifetimed Send
impl used in async fn
#96865
Comments
struct Foo<'a>(&'a str);
unsafe impl Send for Foo<'static> {}
fn assert_send_future() -> impl Send {
async {
let data: Foo<'static> = Foo("");
std::future::ready(()).await;
}
} @rustbot label A-generators A-async-await T-compiler |
Another instance of what I think is the same bug, this time with trait Funnel {
type This;
}
impl<T: 'static> Funnel for T {
type This = T;
}
async fn bar<T: Funnel>() {
let _x: T::This = todo!();
std::future::ready(()).await;
}
pub fn test() -> impl Send {
async { bar::<Box<dyn Send>>().await }
} The fix there is to wrap the #[repr(transparent)]
struct DynSendWrapper(dyn Send);
pub fn test() -> impl Send {
async { bar::<Box<DynSendWrapper>>().await }
} |
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:
@rustbot label AsyncAwait-Triaged |
Is this related to/duplicate of #64552? |
@carols10cents @eholk yeah this is definitely the same issue as #102211. fixing that bug should fix all related issues. |
Please, bump up this bug report. |
I ended up using the alternative notation -- described here: #102211 (comment) -- to avoid this type inference compiler bug when GATs are involved.
Other workarounds exist in the first link, but they involve paying extra costs for boxing / dynamic dispatching. |
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? |
- Changing parser trait to async caused an error in the DLT parser because it returns type has a reference in it. Because of that we got a compiler error about that the results doesn't implements Send trait enough. - This Error is possible to be a bug in rust that would be fixed in the future. See issues: - rust-lang/rust#64552 - rust-lang/rust#96865 - For now I replaced the references with Arcs in the results of DLT-Parser
…in hosts - Changing parser trait to async caused an error in the DLT parser because it returns type has a reference in it. Because of that we got a compiler error about that the results doesn't implements Send trait enough. - This Error is possible to be a bug in rust that would be fixed in the future. See issues: - rust-lang/rust#64552 - rust-lang/rust#96865 - For now I replaced the references with Arcs in the results of DLT-Parser - implements for parser Plugin hosts now awaits on the async call from the plugin instead of using `futures::executer::block_on()`. However, this change didn't improve the performance of the plugins
…in hosts - Changing parser trait to async caused an error in the DLT parser because it returns type has a reference in it. Because of that we got a compiler error about that the results doesn't implements Send trait enough. - This Error is possible to be a bug in rust that would be fixed in the future. See issues: - rust-lang/rust#64552 - rust-lang/rust#96865 - For now I replaced the references with Arcs in the results of DLT-Parser - implements for parser Plugin hosts now awaits on the async call from the plugin instead of using `futures::executer::block_on()`. However, this change didn't improve the performance of the plugins
I also meet this error with code: #[allow(unused)]
#[async_trait::async_trait]
pub trait MyTrait {
async fn do_something(&self);
}
pub struct MyStruct<'a> {
a: &'a str,
}
unsafe impl Send for MyStruct<'static> {}
pub struct TestStruct;
impl TestStruct {
async fn function4(_a: &String, _b: MyStruct<'static>) {
// if not the following line, will get error, but why?
let _b: MyStruct<'static> = _b;
}
}
#[async_trait::async_trait]
impl MyTrait for TestStruct {
async fn do_something(&self) {
let s: &'static str = "hello world";
let my_struct: MyStruct<'static> = MyStruct::<'static> { a: s };
let a = "xxx".to_string();
Self::function4(&a, my_struct).await;
}
} but it can be solved by adding |
Encountered this issue with rustc 1.78.0 and fixed it using a very simple workaround trait like so: I've distilled this from observation in #100013 (comment) that calling pub trait SendFuture: core::future::Future {
fn send(self) -> impl core::future::Future<Output = Self::Output> + Send
where
Self: Sized + Send,
{
self
}
}
impl<T: core::future::Future> SendFuture for T {} I've published the fix in a |
fix rust-lang/rust#96865 in bindgen Signed-off-by: Roman Volosatovs <rvolosatovs@riseup.net>
fix rust-lang/rust#96865 in bindgen Signed-off-by: Roman Volosatovs <rvolosatovs@riseup.net>
The original minimized versions no longer errors on rustc 1.80.1 However, I just ran into an error like this one with a seemingly benign use of async fn in trait. ENOTIME to minimize it, here's the commit that has the error. @rvolosatovs 's |
I tried this code:
I expected to see this happen: No error
Instead, this happened:
Meta
rustc --version --verbose
:Also happens with Nightly:
The text was updated successfully, but these errors were encountered: