Skip to content

#[napi(constructor)] is failing to expand behind a #[cfg_attr] #1194

@Hywan

Description

@Hywan

Hello,

This issue is similar to #1120. The following code is working:

#[cfg_attr(feature = "nodejs", napi)]
pub struct Bar {}

#[cfg_attr(feature = "nodejs", napi)]
impl Bar {
    #[napi(constructor)]
    pub fn new() -> Self {
        Self {}
    }
}

but changing #[napi(constructor)] to #[cfg_attr(feature = "nodejs", napi(constructor))] will fail:

error: associated `static` items are not allowed
  --> ….rs:13:36
   |
13 |     #[cfg_attr(feature = "nodejs", napi(constructor))]
   |                                    ^^^^^^^^^^^^^^^^^
   |
   = note: this error originates in the attribute macro `napi::bindgen_prelude::ctor` (in Nightly builds, run with -Z macro-backtrace for more info)

etc.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions