Skip to content
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

Function pointer with function pointer arg needs diagnostic #815

Open
dtolnay opened this issue Apr 9, 2021 · 0 comments
Open

Function pointer with function pointer arg needs diagnostic #815

dtolnay opened this issue Apr 9, 2021 · 0 comments

Comments

@dtolnay
Copy link
Owner

dtolnay commented Apr 9, 2021

// src/lib.rs

#[cxx::bridge]
mod ffi {
    unsafe extern "C++" {
        include!("example/include/header.h");

        fn f(x: fn(y: fn()));
    }
}
// include/header.h

#pragma once
#include "rust/cxx.h"

void f(rust::Fn<void(rust::Fn<void()> y)> x);

This currently emits a warning but otherwise compiles (and probably does the wrong thing). It needs to error instead because we don't yet fully support function pointers getting passed in the C++-to-Rust direction -- tracked in #52.

warning: `extern` fn uses type `fn()`, which is not FFI-safe
 --> src/lib.rs:6:23
  |
6 |         fn f(x: fn(y: fn()));
  |                       ^^^^ not FFI-safe
  |
  = note: `#[warn(improper_ctypes_definitions)]` on by default
  = help: consider using an `extern fn(...) -> ...` function pointer instead
  = note: this function pointer has Rust-specific calling convention
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant