diesel-rs/diesel · error
` ` must be in the form `#[ ="something"]
Error message
`{}` must be in the form `#[{}="something"]` What it means
Helper `str_value_of_meta_item` in diesel's migrations macros expects an attribute in the exact string-literal form `#[name = "something"]`. If the attribute exists but is not a `Meta::NameValue` with a `Lit::Str` (e.g. a path/flag-style attribute or a non-string literal), the macro panics with this message naming the expected attribute.
Solutions
- Quote the attribute value: `#[migration_name = "my_migration"]`.
- Ensure the attribute is a key = "string literal" pair, not a bare flag or path segment.
- Remove non-string literals (numbers, bools) and wrap them in string form if the option accepts them.
- Check the diesel version's documented attribute names for the macro you use.
Example fix
// before #[migration_name = create_users] mod migrations; // after #[migration_name = "create_users"] mod migrations;
Defensive patterns
Strategy: validation
Validate before calling
// attribute values must be string literals
// bad: #[migration_name = foo] or #[migration_name]
// good:
#[migration_name = "create_users"]
mod migrations {} Prevention
- Always write macro attributes as `#[name = "string literal"]`.
- Copy attribute syntax from diesel docs/tests, not other crates.
- Let rustfmt/rust-analyzer surface macro attribute syntax errors early.
When it happens
Trigger: Writing `#[migration_name = something]` (non-string literal), `#[migration_name]` (flag without value), or `#[migration_name = 42]` on a module used with `embed_migrations!` / `import_migrations!` style attributes (e.g. `migration_name`, `migration_version`).
Common situations: Copy-pasting attribute syntax from other crates; forgetting quotes around the value; using `=` with an identifier instead of a string literal; typos creating duplicate 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
- unexpected token after positional `#[variadic(..)]`
- expect `last_arguments`
- Can't get file name from path
- Invalid migration directory: the directory's name should be
- unexpected end of input, expected `=` help: the correct…
AI-assisted analysis of diesel-rs/diesel@6fa6ed01b2 (2026-09-07).
Data as JSON: /api/errors/ca6c57de60cf89af.
Report an issue: GitHub.
Appendix: source
Thrown at diesel_migrations/migrations_macros/src/util.rs:9
use syn::*;
pub fn str_value_of_meta_item(item: &Meta, name: &str) -> String {
match *item {
Meta::NameValue(MetaNameValue {
lit: Lit::Str(ref value),
..
}) => value.value(),
_ => panic!(
r#"`{}` must be in the form `#[{}="something"]`"#,
name, name
),
}
}
pub fn get_options_from_input(
name: &Path,
attrs: &[Attribute],
on_bug: fn() -> !,
) -> Option<Vec<Meta>> {
let options = attrs
.iter()
.find(|a| &a.path == name)
.map(Attribute::parse_meta);
match options {
Some(Ok(Meta::List(MetaList { ref nested, .. }))) => Some(
nestedView on GitHub (pinned to 6fa6ed01b2)