{"record":{"id":"057d25761521d202","repo":"diesel-rs/diesel","slug":"expected-type","errorCode":null,"errorMessage":"expected type","messagePattern":"expected type","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"diesel_attribute_parser/src/util.rs","lineNumber":48,"sourceCode":"}\n\n/// Specialized version of `parse_eq` for `syn::Type` with a customized error message for readability.\n/// This is useful because a great variety of tokens would be valid to parse as a `syn::Type`.\npub fn parse_eq_type(input: ParseStream, help: &str) -> Result<syn::Type> {\n    if input.is_empty() {\n        return Err(syn::Error::new(\n            input.span(),\n            format!(\n                \"unexpected end of input, expected `=`\\n\\\n                 help: the correct format looks like `#[diesel({help})]`\",\n            ),\n        ));\n    }\n\n    input.parse::<Eq>()?;\n    input\n        .parse::<Type>()\n        .map_err(|e| syn::Error::new(e.span(), \"expected type\"))\n}\n\npub fn parse_paren<T: Parse>(input: ParseStream, help: &str) -> Result<T> {\n    if input.is_empty() {\n        return Err(syn::Error::new(\n            input.span(),\n            format!(\n                \"unexpected end of input, expected parentheses\\n\\\n                 help: the correct format looks like `#[diesel({help})]`\",\n            ),\n        ));\n    }\n\n    let content;\n    parenthesized!(content in input);\n    content.parse()\n}\n","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/diesel-rs/diesel/blob/6fa6ed01b24b24248ab2a611698d0a7c6a2e9120/diesel_attribute_parser/src/util.rs#L30-L66","documentation":"After the `=` token is consumed, `parse_eq_type` tries to parse a `syn::Type`. If that parse fails, the underlying syn error (which can be vague since many tokens could start a type) is replaced with this clearer 'expected type' message at the same span.","triggerScenarios":"Writing `#[diesel(sql_type = 42)]`, `#[diesel(sql_type = ,)]`, or any tokens after `=` that are not valid Rust type syntax.","commonSituations":"Passing a literal or expression where a type is required; forgetting to import/qualify a path correctly is usually OK syntactically, but garbage tokens are not.","solutions":["Replace the text after `=` with a valid Rust type (path or generic)","Quote generic types correctly if using turbofish-like syntax in paths","Check the token after `=` for stray commas or literals"],"exampleFix":"// before\n#[diesel(sql_type = \"text\")]\n// after\n#[diesel(sql_type = Text)]","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"fn is_valid_type_token(s: &str) -> bool {\n    syn::parse_str::<syn::Type>(s).is_ok()\n}","tryCatchPattern":"match syn::parse_str::<syn::Type>(src) {\n    Ok(t) => t,\n    Err(e) => panic!(\"#[diesel(...)] expected a Rust type after `=`: {}\", e),\n}","preventionTips":["Use a real type path (e.g. MyType) after `=`, not strings or numbers","Compile-check types by importing them at the call site","Keep generic syntax valid Rust"],"tags":["rust","proc-macro","diesel","type-syntax"],"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"}