cxx-async icon indicating copy to clipboard operation
cxx-async copied to clipboard

C++ compilation error when returning `RustFutureVoid` from Rust to C++

Open emersonford opened this issue 3 years ago • 0 comments

I have the following defined:

mod ffi {
    unsafe extern "C++" {
        include!("cxx_rs_future_defs.h");
        
        type RustFutureVoid = super::RustFutureVoid;
    }

    extern "Rust" {
        fn foo() -> RustFutureVoid;
    }
}

unsafe impl Future for RustFutureVoid {
    type Output = ();
}

pub fn foo() -> RustFutureVoid {
    RustFutureVoid::fallible(async { Ok(()) })
}

with cxx_rs_future_defs.h:

#pragma once

#define CXXASYNC_HAVE_COROUTINE_HEADER

#include "cxx-async/include/rust/cxx_async.h"
#include "cxx-async/include/rust/cxx_async_folly.h"
#include "rust/cxx.h"

CXXASYNC_DEFINE_FUTURE(
    void,
    RustFutureVoid);

and C++ code that calls this Rust method, e.g.

folly::coro::Task<void> calls_foo() {
    co_await foo();
}

however this does not compile due to the following:

cxx-async/include/rust/cxx_async.h:590:14: error: cannot form a reference to 'void'
  YieldResult&& await_resume() {
             ^
folly/experimental/coro/Traits.h:78:36: note: in instantiation of template class 'rust::async::RustAwaiter<RustFutureVoid>' requested here
        decltype(std::declval<T&>().await_ready()),
...

seems to be a unique case with void specifically?

emersonford avatar Sep 14 '22 23:09 emersonford