rust-lang / rust-bindgen

Automatically generates Rust FFI bindings to C (and some C++) libraries.
https://rust-lang.github.io/rust-bindgen/
BSD 3-Clause "New" or "Revised" License
4.23k stars 679 forks source link

`static mut` deprecation #2801

Open wmmc88 opened 3 months ago

wmmc88 commented 3 months ago

There is a current pre-RFC for deprecating static mut in Rust 2024, in favor of better alternatives. I think bindgen should start using some of these alternatives instead of generating code that will become deprecated in the near-term. My understanding of the pre-RFC is that we should be using SyncUnsafeCell in these FFI scenarios instead of static mut

Input C/C++ Header

extern const void* FOO;

Bindgen Invocation

bindgen::Builder::default()
    .header("input.h")
    .generate()
    .unwrap()

Actual Results

extern "C" {
    pub static mut Foo: *const ::core::ffi::c_void;
}

Expected Results

pvdrz commented 3 months ago

SyncUnsafeCell is unstable which means we would have to implement this change and gate it behind nightly.