diesel-rs/diesel · error · syn::Error
, the correct format is `#[aggregate]
Error message
{e}, the correct format is `#[aggregate]` What it means
When parsing a `#[sql_function]` attribute list, the `#[aggregate]` attribute must be a bare path with a simple identifier. If `path.require_ident()` fails (e.g. the attribute path contains arguments, generics, or segments), the error is wrapped with the hint that the correct format is `#[aggregate]`.
Solutions
- Write the attribute as a bare `#[aggregate]` with no arguments or values.
- Remove any `= value` assignment or parenthesized arguments after `aggregate`.
- Check diesel documentation for configuration this attribute does (it does not accept parameters in this form).
Example fix
// before #[sql_function] #[aggregate = true] fn sum(x: Integer) -> Integer; // after #[sql_function] #[aggregate] fn sum(x: Integer) -> Integer;
Defensive patterns
Strategy: validation
Validate before calling
// Attribute must be a bare path: #[aggregate] let attr_src = "#[aggregate]"; assert!(attr_src == "#[aggregate]"); // no args, no assignment
Prevention
- Treat diesel sql_function attributes as bare flags unless docs show a parameter form.
- Do not apply serde/clap-style key=value syntax to diesel attributes.
- Consult the diesel docs page for #[sql_function] for the accepted attribute list.
When it happens
Trigger: Writing `#[aggregate(...)]`, `#[aggregate = true]`, or a multi-segment path like `#[foo::aggregate]` where an identifier is expected, inside a `#[sql_function(...)]` attribute.
Common situations: Assuming `aggregate` takes a boolean or configuration value; copying serde-style attribute syntax into diesel attributes.
Understand the failure class
Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.
Related errors
- , the correct format is `#[skip_return_type_helper]
- invalid variadic argument count: not enough function…
- cannot find argument corresponding to the generic
- expect `SQL` as ABI
- expect `SQL` function blocks to be safe
AI-assisted analysis of diesel-rs/diesel@6fa6ed01b2 (2026-09-07).
Data as JSON: /api/errors/a64621f43193ef96.
Report an issue: GitHub.
Appendix: source
Thrown at diesel_derives/src/sql_function.rs:1361
..
}),
..
}) if path.is_ident("sql_name") => Ok(AttributeSpanWrapper {
attribute_span: attr.span(),
ident_span: sql_name.span(),
item: SqlFunctionAttribute::SqlName {
ident: path.require_ident()?.clone(),
value: sql_name.clone(),
},
}),
syn::Meta::Path(path) if path.is_ident("aggregate") => Ok(AttributeSpanWrapper {
attribute_span: attr.span(),
ident_span: path.span(),
item: SqlFunctionAttribute::Aggregate {
ident: path
.require_ident()
.map_err(|e| {
syn::Error::new(
e.span(),
format!("{e}, the correct format is `#[aggregate]`"),
)
})?
.clone(),
},
}),
syn::Meta::Path(path) if path.is_ident("skip_return_type_helper") => {
Ok(AttributeSpanWrapper {
ident_span: attr.span(),
attribute_span: path.span(),
item: SqlFunctionAttribute::SkipReturnTypeHelper {
ident: path
.require_ident()
.map_err(|e| {
syn::Error::new(
e.span(),
format!("{e}, the correct format is `#[skip_return_type_helper]`"),View on GitHub (pinned to 6fa6ed01b2)