`async extern fn` is accepted

I was initially going to file an issue about the reference not making it clear this is not allowed, but a quick test on the playground shows this actually compiles with a warning about impl Future not being ffi-safe.

1 Like

async fn has an opaque return type, so it shouldn't be callable by FFI even with extern "Rust". And there correctly are errors issued if you try to declare async fn or fn -> impl Future in an extern block.

#[no_mangle]
async extern "Rust" fn hello_async() { // Allowed without warnings
    println!("Hello world");
}

extern "Rust" {
    async fn hello_async();  // functions in `extern` blocks cannot have qualifiers
    fn hello_async() -> impl Future; // [E0562]: `impl Trait` is not allowed in `extern fn` return types
}

I don't think it's a bug as such that you can request a C-like calling convention for an async function. It's just not very useful.

3 Likes