{"record":{"id":"10002a85551840c3","repo":"neon-bindings/neon","slug":"neon-class-can-only-contain-const-and-fn-items","errorCode":null,"errorMessage":"`neon::class` can only contain `const` and `fn` items.","messagePattern":"`neon::class` can only contain `const` and `fn` items\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/neon-macros/src/class/mod.rs","lineNumber":808,"sourceCode":"                        return Err(syn::Error::new(span, msg));\n                    }\n                    constructor = Some(f);\n                    continue; // Skip adding to fns\n                } else if f.sig.ident == \"finalize\" {\n                    if has_finalizer {\n                        let span = syn::spanned::Spanned::span(&f);\n                        let msg = \"Only one `finalize` method is allowed in a class.\";\n                        return Err(syn::Error::new(span, msg));\n                    }\n                    has_finalizer = true;\n                    continue; // Skip adding to fns\n                }\n                fns.push(f)\n            }\n            _ => {\n                let span = syn::spanned::Spanned::span(&item);\n                let msg = \"`neon::class` can only contain `const` and `fn` items.\";\n                return Err(syn::Error::new(span, msg));\n            }\n        }\n    }\n\n    Ok(ClassItems {\n        consts,\n        fns,\n        constructor,\n        has_finalizer,\n    })\n}\n\npub(crate) fn class(\n    _attr: proc_macro::TokenStream,\n    item: proc_macro::TokenStream,\n) -> proc_macro::TokenStream {\n    class_with_name(_attr, item, None)\n}","sourceCodeStart":790,"sourceCodeEnd":826,"githubUrl":"https://github.com/neon-bindings/neon/blob/38960e4381d9ad13b551cdf2d261f609167c9bc2/crates/neon-macros/src/class/mod.rs#L790-L826","documentation":"Items inside a `#[neon] impl` block processed by the class macro must be either `const` items or `fn` items. Any other item kind (type aliases, associated types, macros, use statements, etc.) causes this error pointing at that item.","triggerScenarios":"Placing a `type` alias, `use` statement, macro invocation, or other non-fn/non-const associated item inside a `#[neon]`-annotated impl block grouped by group_class_items.","commonSituations":"Pasting an associated type into the exported impl block; adding a helper `use` inside the impl; procedural macro items or trait associated types written directly into the class impl block.","solutions":["Move the offending item (type alias, use, etc.) outside the #[neon] impl block into the module scope","Convert helper code into a plain `fn` if it was meant to be a method","Remove the item if it is not needed for the exported class"],"exampleFix":"// before\n#[neon]\nimpl Greet {\n    type Alias = String; // not allowed\n    fn new(cx: &mut FunctionContext) -> JsResult<JsGreet> { ... }\n}\n// after\ntype Alias = String; // moved to module scope\n#[neon]\nimpl Greet {\n    fn new(cx: &mut FunctionContext) -> JsResult<JsGreet> { ... }\n}","handlingStrategy":"validation","validationCode":"// keep the #[neon] impl block limited to fn/const items\nconst ALLOWED: fn(&str) -> bool = |item| {\n    let t = item.trim();\n    t.starts_with(\"fn \") || t.starts_with(\"const \")\n};","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Put type aliases, use statements, and macros outside the #[neon] impl block","Only declare methods and consts in exported class impls","Review the impl block contents whenever refactoring items into it"],"tags":["rust","proc-macro","neon","unsupported-item","compile-time"],"backgroundTag":"unsupported-operation","analyzedSha":"38960e4381d9ad13b551cdf2d261f609167c9bc2","analyzedAt":"2026-09-13T09:05:33.640Z","contentChangedAt":"2026-09-13T09:05:33.640Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}