Flecs-Rust icon indicating copy to clipboard operation
Flecs-Rust copied to clipboard

nightly warning: function pointer comparisons do not produce meaningful results since their addresses are not guaranteed to be unique

Open waywardmonkeys opened this issue 10 months ago • 3 comments

Build with a current nightly and you'll get this:

warning: function pointer comparisons do not produce meaningful results since their addresses are not guaranteed to be unique
   --> flecs_ecs/src/core/utility/functions.rs:521:9
    |
521 |         ctor_hooks != sys::flecs_default_ctor
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = note: the address of the same function can vary between different codegen units
    = note: furthermore, different functions could have the same address after being merged together
    = note: for more information visit <https://doc.rust-lang.org/nightly/core/ptr/fn.fn_addr_eq.html>
    = note: `#[warn(unpredictable_function_pointer_comparisons)]` on by default
help: refactor your code, or use `std::ptr::fn_addr_eq` to suppress the lint
    |
521 |         !std::ptr::fn_addr_eq(ctor_hooks, sys::flecs_default_ctor as unsafe extern "C-unwind" fn(*mut std::ffi::c_void, i32, *const ecs_type_info_t))
    |         ++++++++++++++++++++++          ~                         +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

waywardmonkeys avatar Feb 12 '25 14:02 waywardmonkeys

The suggested workaround isn't great since on some targets, you tend to do more LTO and function merging (like wasm32).

waywardmonkeys avatar Feb 12 '25 14:02 waywardmonkeys

I would opt for fn_addr_eq unless you have another solution.

Indra-db avatar Feb 12 '25 15:02 Indra-db

You can, but like I said, in the presence of LTO and function merging, it may well lead to very difficult to detect bugs. But that's up to you.

waywardmonkeys avatar Mar 05 '25 16:03 waywardmonkeys