diesel-rs/diesel · error
unknown attribute, expected
Error message
unknown attribute, expected{prefix} `{}` What it means
Generic error emitted by diesel's attribute parser utilities when an unrecognized attribute key is encountered. It lists the set of valid keys expected at that position, formatted as a backtick-joined list. If exactly one key is valid, the message omits the 'one of' prefix.
Solutions
- Use one of the valid keys listed in the error message
- Fix typos in the attribute name
- Check the diesel version's documentation for supported keys on that derive
Example fix
// before #[diesel(table_name = users, primary_key(id, extra_key))] // after #[diesel(table_name = users, primary_key(id))]
Defensive patterns
Strategy: validation
Validate before calling
const VALID_KEYS: &[&str] = &["sqlite_type", "table_name", "primary_key"];
assert!(VALID_KEYS.contains(&key), "unknown diesel attribute key: {}", key); Prevention
- Verify attribute keys against the current diesel version's docs
- Watch for typos in long key names like `treat_none_as_null`
- Don't copy attribute keys between different derives
When it happens
Trigger: Passing any key to a `#[diesel(...)]` attribute that is not in the valid list for that derive/position, e.g. `#[diesel(treat_nane_as_null = true)]` (typo) or a key valid on one derive but not another.
Common situations: Typos in attribute names; copying attributes between derives where the key isn't supported; using attributes from an older/newer diesel version that renamed keys.
Understand the failure class
Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.
Related errors
- expected attribute `name` help: the correct format looks…
- expect `skip_zero_argument_variant`
- , the correct format is `#[variadic(last_arguments = 3)]`…
- , the correct format is `#[variadic(3)]
- unexpected option
AI-assisted analysis of diesel-rs/diesel@6fa6ed01b2 (2026-09-07).
Data as JSON: /api/errors/e7be5a8ee701543c.
Report an issue: GitHub.
Appendix: source
Thrown at diesel_attribute_parser/src/util.rs:8
use syn::parse::{Parse, ParseStream, Peek, Result};
use syn::token::Eq;
use syn::{Ident, Type, parenthesized};
pub fn unknown_attribute(name: &Ident, valid: &[&str]) -> syn::Error {
let prefix = if valid.len() == 1 { "" } else { " one of" };
syn::Error::new(
name.span(),
format!(
"unknown attribute, expected{prefix} `{}`",
valid.join("`, `")
),
)
}
pub fn parse_eq<T: Parse>(input: ParseStream, help: &str) -> Result<T> {
if input.is_empty() {
return Err(syn::Error::new(
input.span(),
format!(
"unexpected end of input, expected `=`\n\
help: the correct format looks like `#[diesel({help})]`",
),
));
}View on GitHub (pinned to 6fa6ed01b2)