{"record":{"id":"15693d3d9405aa0b","repo":"diesel-rs/diesel","slug":"ident-attribute-form-is-deprecated","errorCode":null,"errorMessage":"#[{ident}] attribute form is deprecated","messagePattern":"#\\[(.+?)\\] attribute form is deprecated","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"diesel_attribute_parser/src/deprecated/mod.rs","lineNumber":54,"sourceCode":"#[cfg(all(not(feature = \"without-deprecated\"), feature = \"with-deprecated\"))]\nmod impl_deprecated {\n    use super::{ParseDeprecated, ParseStream, Result};\n    use crate::deprecated::belongs_to::parse_belongs_to;\n    use crate::deprecated::changeset_options::parse_changeset_options;\n    use crate::deprecated::postgres_type::parse_postgres_type;\n    use crate::deprecated::primary_key::parse_primary_key;\n    use crate::deprecated::utils::parse_eq_and_lit_str;\n    use crate::notes::{\n        COLUMN_NAME_NOTE, MYSQL_TYPE_NOTE, SQL_TYPE_NOTE, SQLITE_TYPE_NOTE, TABLE_NAME_NOTE,\n    };\n    use crate::parsers::{MysqlType, PostgresType, SqliteType};\n    use crate::{FieldAttr, StructAttr};\n    use proc_macro2::Span;\n    use syn::Ident;\n\n    macro_rules! warn {\n        ($ident: expr_2021, $help: expr_2021) => {\n            warn(\n                $ident.span(),\n                &format!(\"#[{}] attribute form is deprecated\", $ident),\n                $help,\n            );\n        };\n    }\n\n    impl ParseDeprecated for StructAttr {\n        fn parse_deprecated(input: ParseStream) -> Result<Option<Self>> {\n            let name: Ident = input.parse()?;\n            let name_str = name.to_string();\n\n            match &*name_str {\n                \"table_name\" => {\n                    let lit_str = parse_eq_and_lit_str(name.clone(), input, TABLE_NAME_NOTE)?;\n                    warn!(\n                        name,\n                        &format!(\"use `#[diesel(table_name = {})]` instead\", lit_str.value())","sourceCodeStart":36,"sourceCodeEnd":72,"githubUrl":"https://github.com/diesel-rs/diesel/blob/6fa6ed01b24b24248ab2a611698d0a7c6a2e9120/diesel_attribute_parser/src/deprecated/mod.rs#L36-L72","documentation":"This is a deprecation warning emitted by diesel's attribute parser during a `#[derive(Queryable, Identifiable, ...)]` expansion. Diesel used to accept bare attributes like `#[table_name = \"users\"]` / `#[primary_key(id)]` directly on the derived struct; these now must be namespaced as `#[diesel(table_name = \"users\")]`. The `warn!` macro wraps the identifier's span and message so the compiler points at the exact offending attribute. It does not fail the build — the old form still works until removed.","triggerScenarios":"Deriving diesel traits on a struct that still uses the old un-namespaced attribute syntax, e.g. `#[table_name = \"posts\"]`, `#[primary_key(id)]`, `#[belongs_to(User, foreign_key = \"user_id\")]`, `#[column_name = \"x\"]` without the `#[diesel(...)]` prefix. Occurs during `cargo build`/`cargo check` whenever the parser hits such an attribute.","commonSituations":"Upgrading diesel from 1.x/early 2.0 to 2.x where attribute namespacing became required by convention; code generated by older tutorials or books; copy-pasted derive structs from older projects; lint-clean CI builds surfacing the warnings after a dependency bump.","solutions":["Prefix every diesel attribute with `diesel::`, e.g. change `#[table_name = \"users\"]` to `#[diesel(table_name = \"users\")]`","Do the same for related attributes: `#[diesel(primary_key(id))]`, `#[diesel(belongs_to(User))]`, `#[diesel(column_name = x)]`","Read the `= help:` note attached to the warning — it states the exact replacement form for that attribute","Run `cargo fix` or manually sweep the crate with `cargo build 2>&1 | grep deprecated` to find all occurrences"],"exampleFix":"// before\n#[derive(Queryable, Identifiable)]\n#[table_name = \"users\"]\n#[primary_key(id)]\npub struct User { pub id: i32, pub name: String }\n// after\n#[derive(Queryable, Identifiable)]\n#[diesel(table_name = users)]\n#[diesel(primary_key(id))]\npub struct User { pub id: i32, pub name: String }","handlingStrategy":"validation","validationCode":"// grep-style check a team can run in CI to catch old attribute forms before building\ngrep -rnE '#\\[(table_name|primary_key|belongs_to|column_name|foreign_key|select_expression)[ (=]' src/ \\\n  && echo 'Deprecated diesel attribute form found — namespace with #[diesel(...)]' && exit 1 || true","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always namespace diesel derive attributes as `#[diesel(...)]` in new code","Upgrade-prepare: sweep the codebase for bare `#[table_name]`, `#[primary_key]`, `#[belongs_to]`, `#[column_name]` after bumping diesel","Add the CI grep/lint above to reject legacy attribute forms at PR time","Copy derive structs from the current diesel docs/examples, not old tutorials"],"tags":["rust","diesel","deprecation","proc-macro","attributes"],"backgroundTag":"deprecated-api-usage","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"}