neon-bindings / neon

Rust bindings for writing safe and fast native Node.js modules.
https://www.neon-bindings.com/
Apache License 2.0
8k stars 283 forks source link

`register_module!` is unhygenic #981

Closed ranile closed 1 year ago

ranile commented 1 year ago

The following code should compile just fine but it fails:

fn funcmut cx: neon::prelude::FunctionContext) -> neon::prelude::JsResult<neon::prelude::JsValue> {
    todo!()
}

neon::register_module!(mut m, {
    m.export_function("func", func)?;
});
Error message ``` error: cannot find macro `register_module` in this scope --> src/lib.rs:65:9 | 65 | / neon::register_module!(mut m, { 66 | | m.export_function("make_num_77", make_num_77)?; 67 | | }); | |__________^ | = help: consider importing one of these items: crate::tests::register_module neon::register_module = note: this error originates in the macro `neon::register_module` (in Nightly builds, run with -Z macro-backtrace for more info) ```

This is because the macro assumes itself to be in scope, which isn't the case if a qualified path is used. See https://docs.rs/neon/latest/src/neon/lib.rs.html#121

kjvalencik commented 1 year ago

Thanks for reporting. Unless this is causing you issues, I'm going to close this issue for a couple of reasons:

Let me know if this is an issue you can't workaround and I can re-open. Cheers!