rusterlium / rustler

Safe Rust bridge for creating Erlang NIF functions
https://docs.rs/crate/rustler
Apache License 2.0
4.38k stars 225 forks source link

rustler::resource! no longer warning-free with 1.83 #665

Closed liamwhite closed 5 hours ago

liamwhite commented 6 hours ago
warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item
  --> src/zip.rs:22:5
   |
21 | pub fn load(env: Env, _: Term) -> bool {
   | -------------------------------------- move the `impl` block outside of this function `load`
22 |     rustler::resource!(WriterResource, env);
   |     ^^^^^^^^^^^^^^^^^^^--------------^^^^^^
   |     |                  |
   |     |                  `WriterResource` is not local
   |     `ResourceTypeProvider` is not local
   |
   = note: the macro `rustler::resource` defines the non-local `impl`, and may need to be changed
   = note: the macro `rustler::resource` may come from an old version of the `rustler` crate, try updating your dependency with `cargo update -p rustler`
   = note: an `impl` is never scoped, even when it is nested inside an item, as it may impact type checking outside of that item, which can be the case if neither the trait or the self type are at the same nesting level as the `impl`
   = note: `#[warn(non_local_definitions)]` on by default
   = note: this warning originates in the macro `rustler::resource` (in Nightly builds, run with -Z macro-backtrace for more info)

The macro likely should be deprecated and a new version added to define a function and the top-level impl block separately.

filmor commented 5 hours ago

There is already a solution for this since 0.34, see https://github.com/rusterlium/rustler/blob/master/UPGRADE.md#033---034.