{"record":{"id":"3caf61c8516882c2","repo":"diesel-rs/diesel","slug":"only-single-feature-cfg-attr-attributes-are-supp","errorCode":null,"errorMessage":"only single feature `cfg_attr` attributes are supported. Got `{ident}` but expected `feature = \"foo\"`","messagePattern":"only single feature `cfg_attr` attributes are supported\\. Got `(.+?)` but expected `feature = \"foo\"`","errorType":"exception","errorClass":"syn::Error","httpStatus":null,"severity":"error","filePath":"diesel_derives/src/sql_function.rs","lineNumber":1939,"sourceCode":"            ident.span(),\n            format!(\"Expected `require_order` but got `{ident}`\"),\n        ))\n    }\n}\n\nimpl SqlFunctionAttribute {\n    fn parse_attr(\n        name: Ident,\n        input: &syn::parse::ParseBuffer<'_>,\n        attr: Attribute,\n        attribute_span: proc_macro2::Span,\n    ) -> Result<AttributeSpanWrapper<Self>> {\n        // rustc doesn't resolve cfg attrs for us :(\n        // This is hacky, but mostly for internal use\n        if name == \"cfg_attr\" {\n            let ident = input.parse::<Ident>()?;\n            if ident != \"feature\" {\n                return Err(syn::Error::new(\n                    ident.span(),\n                    format!(\n                        \"only single feature `cfg_attr` attributes are supported. \\\n                             Got `{ident}` but expected `feature = \\\"foo\\\"`\"\n                    ),\n                ));\n            }\n            let _ = input.parse::<Token![=]>()?;\n            let feature = input.parse::<LitStr>()?;\n            let feature_value = feature.value();\n            let _ = input.parse::<Token![,]>()?;\n            let wrap_macro = match feature_value.as_str() {\n                \"postgres_backend\" => Some(syn::parse_quote!(\n                    diesel::internal::sql_functions::expand_pg\n                )),\n                \"sqlite\" | \"__sqlite_shared\" => Some(syn::parse_quote!(\n                    diesel::internal::sql_functions::expand_sqlite\n                )),","sourceCodeStart":1921,"sourceCodeEnd":1957,"githubUrl":"https://github.com/diesel-rs/diesel/blob/6fa6ed01b24b24248ab2a611698d0a7c6a2e9120/diesel_derives/src/sql_function.rs#L1921-L1957","documentation":"The `cfg_attr` option of `#[sql_function]` supports only single-feature conditions of the form `feature = \"foo\"`. If the first token inside `cfg_attr(...)` is not the identifier `feature`, the macro rejects it with this message.","triggerScenarios":"Using `#[sql_function(cfg_attr(...))]` where the predicate does not start with `feature`, e.g. `cfg_attr(unix, ...)` or `cfg_attr(target_os = \"...\", ...)` or a misspelled `features = \"foo\"`.","commonSituations":"Copying general `#[cfg_attr]` conditions into the proc-macro attribute, which only implements a small subset of cfg syntax; trying multi-feature or `all()` conditions.","solutions":["Use exactly `feature = \"foo\"` as the cfg_attr predicate: `cfg_attr(feature = \"foo\", ...)`","Fix typos like `features` or `feat`","Move complex cfg conditions outside the macro and gate the function definition itself with a normal `#[cfg_attr]`"],"exampleFix":"// before\n#[sql_function(cfg_attr(unix, prefix = \"pg_\"))]\n// after\n#[sql_function(cfg_attr(feature = \"postgres\", prefix = \"pg_\"))]","handlingStrategy":"validation","validationCode":"fn validate_cfg_attr_predicate(pred: &str) -> Result<(), String> {\n    if pred.starts_with(\"feature = \\\"\") && pred.ends_with(\"\\\"\") { Ok(()) } else { Err(format!(\"cfg_attr predicate must be feature = \\\"foo\\\", got: {}\", pred)) }\n}","typeGuard":"fn is_single_feature_cfg(pred: &str) -> bool { pred.starts_with(\"feature = \\\"\") && pred.ends_with(\"\\\"\") }","tryCatchPattern":null,"preventionTips":["Only single-feature cfg_attr is supported: use feature = \"foo\"","Never use target_os, unix, all(), or multi-feature conditions inside the macro","Gate complex cfg logic on the item with a normal #[cfg_attr] instead"],"tags":["proc-macro","rust","cfg","attribute-parsing","diesel"],"backgroundTag":"invalid-argument-format","analyzedSha":"6fa6ed01b24b24248ab2a611698d0a7c6a2e9120","analyzedAt":"2026-09-07T01:50:13.074Z","contentChangedAt":"2026-09-07T01:50:13.074Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}