{"record":{"id":"bdcd2ecd36e7e9a3","repo":"GitoxideLabs/gitoxide","slug":"expect-a-function","errorCode":null,"errorMessage":"expect a function","messagePattern":"expect a function","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"gix-macros/src/momo.rs","lineNumber":95,"sourceCode":"            quote!(#new_item #new_inner_item)\n        } else {\n            // Put the new inner function within the function block\n            // to avoid duplicate function name and support associated\n            // function that doesn't use `self` or `Self`.\n            let new_item = Item::Fn(ItemFn {\n                attrs: item_fn.attrs,\n                vis: item_fn.vis,\n                sig: outer_sig,\n                block: parse_quote!({\n                    #new_inner_item\n\n                    #inner_ident(#argexprs)\n                }),\n            });\n            quote!(#new_item)\n        }\n    } else {\n        Error::new(fn_item.span(), \"expect a function\").to_compile_error()\n    }\n}\n\n#[derive(Copy, Clone)]\n// All conversions we support. Check references to this type for an idea how to add more.\nenum Conversion {\n    Into,\n    AsRef,\n    AsMut,\n}\n\nimpl Conversion {\n    fn conversion_expr(&self, i: &Ident) -> Expr {\n        match *self {\n            Conversion::Into => parse_quote!(#i.into()),\n            Conversion::AsRef => parse_quote!(#i.as_ref()),\n            Conversion::AsMut => parse_quote!(#i.as_mut()),\n        }","sourceCodeStart":77,"sourceCodeEnd":113,"githubUrl":"https://github.com/GitoxideLabs/gitoxide/blob/e73179060badf27222d790981fac3f84c1830a7e/gix-macros/src/momo.rs#L77-L113","documentation":"The `momo` proc-macro can only transform function items. When the annotated item is anything else (struct, impl block, etc.), it cannot proceed and emits this compile error at the item's span. This is a usage constraint of the attribute, not a runtime failure.","triggerScenarios":"Applying the momo-based attribute macro to a non-function item such as a struct, enum, module, or impl block.","commonSituations":"Placement mistakes — attribute attached to the wrong item after refactoring; editor auto-import adding the attribute at the wrong scope level.","solutions":["Move the attribute to the function item it is meant to transform.","Remove the attribute entirely if no function should be transformed.","Check that the macro isn't accidentally applied to a mod/impl due to indentation or placement errors."],"exampleFix":"// before: attribute on a non-function\n#[momo]\nstruct Repo { ... }\n\n// after: attribute on a function\nstruct Repo { ... }\n#[momo]\nfn open(path: impl Into<PathBuf>) -> Repo { ... }","handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["Attach the momo attribute only to `fn` items.","After refactors, verify attribute placement moved with the function.","Let rust-analyzer's attribute diagnostics flag misplaced attributes early."],"tags":["proc-macro","compile-time","rust","gix-macros"],"backgroundTag":"incompatible-source-type","analyzedSha":"e73179060badf27222d790981fac3f84c1830a7e","analyzedAt":"2026-09-08T11:26:50.865Z","contentChangedAt":"2026-09-08T11:26:50.865Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}