{"record":{"id":"3b30689c8d342b2a","repo":"rust-lang/rust","slug":"expected-a-string-literal","errorCode":null,"errorMessage":"Expected a string literal","messagePattern":"Expected a string literal","errorType":"exception","errorClass":"syn::Error","httpStatus":null,"severity":"error","filePath":"compiler/rustc_macros/src/query.rs","lineNumber":316,"sourceCode":"        eval_always: #eval_always,\n        feedable: #feedable,\n        handle_cycle_error: #handle_cycle_error,\n        no_force: #no_force,\n        no_hash: #no_hash,\n        returns_error_guaranteed: #returns_error_guaranteed,\n        separate_provide_extern: #separate_provide_extern,\n        // tidy-alphabetical-end\n    }\n}\n\nfn doc_comment_from_desc(list: &Punctuated<Expr, token::Comma>) -> Result<Attribute> {\n    use ::syn::*;\n    let mut iter = list.iter();\n    let format_str: String = match iter.next() {\n        Some(&Expr::Lit(ExprLit { lit: Lit::Str(ref lit_str), .. })) => {\n            lit_str.value().replace(\"`{}`\", \"{}\") // We add them later anyways for consistency\n        }\n        _ => return Err(Error::new(list.span(), \"Expected a string literal\")),\n    };\n    let mut fmt_fragments = format_str.split(\"{}\");\n    let mut doc_string = fmt_fragments.next().unwrap().to_string();\n    iter.map(::quote::ToTokens::to_token_stream).zip(fmt_fragments).for_each(\n        |(tts, next_fmt_fragment)| {\n            use ::core::fmt::Write;\n            write!(\n                &mut doc_string,\n                \" `{}` {}\",\n                tts.to_string().replace(\" . \", \".\"),\n                next_fmt_fragment,\n            )\n            .unwrap();\n        },\n    );\n    let doc_string = format!(\"[query description - consider adding a doc-comment!] {doc_string}\");\n    Ok(parse_quote! { #[doc = #doc_string] })\n}","sourceCodeStart":298,"sourceCodeEnd":334,"githubUrl":"https://github.com/rust-lang/rust/blob/7088e4b63a9516ebfbfe2ab2d999cf01a528ac14/compiler/rustc_macros/src/query.rs#L298-L334","documentation":"Emitted by doc_comment_from_desc in the rustc_queries! macro. When a query has no explicit doc comment (///), the macro auto-generates one from the desc modifier's expression list. The first expression must be a string literal (a format string like \"computes type of {}\"). If the first expression is not an Expr::Lit containing a Lit::Str, this error fires at the span of the entire expression list. This only happens when no manual doc comment is provided — if you add ///, doc_comment_from_desc is never called.","triggerScenarios":"Writing a query without a /// doc comment where the desc block's first element is not a string literal. For example: desc { 42, key } or desc { tcx.item_name(key), key } or an empty desc { }. The first token must be a quoted string.","commonSituations":"Writing a desc block that starts with a format_args! macro call or an expression instead of a plain string literal; forgetting the format string and only putting expression arguments.","solutions":["Ensure the desc block starts with a string literal: desc { \"description for `{}`\", key }.","Alternatively, add a /// doc comment above the query — then desc's format is not inspected for auto-doc generation, though desc still requires a string literal for the query description closure.","Remember that desc's first element is always a format string; subsequent comma-separated expressions are the format arguments."],"exampleFix":"// before (no doc comment, desc doesn't start with a string literal):\nquery foo(key: DefId) -> Ty<'tcx> { desc { key, \"foo\" } }\n// after: start with a string literal format string\nquery foo(key: DefId) -> Ty<'tcx> { desc { \"foo for `{}`\", key } }\n// or add a manual doc comment:\n/// Computes foo for the given definition.\nquery foo(key: DefId) -> Ty<'tcx> { desc { \"foo for `{}`\", key } }","handlingStrategy":"validation","validationCode":"// Ensure every desc block starts with a string literal, or add a doc comment.\n// Static check in your editor: verify the first token inside desc { } is a \"...\".\n// If you add a /// comment above the query, doc_comment_from_desc is bypassed\n// and this error won't fire (though desc still needs a string literal for the description).","typeGuard":null,"tryCatchPattern":"// Compile-time error from the proc macro — cannot be caught at runtime.\n// Fix by making the first element of desc { } a string literal.","preventionTips":["Always start the desc block with a quoted format string: desc { \"description for `{}`\", key }.","If you add a /// doc comment, the auto-generation path is skipped, but still use a string literal.","Remember the desc format: first element is the format string, rest are comma-separated arguments."],"tags":["rustc","proc-macro","query","compiler-internals","documentation"],"backgroundTag":null,"analyzedSha":"7088e4b63a9516ebfbfe2ab2d999cf01a528ac14","analyzedAt":"2026-08-10T14:17:03.603Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}