{"record":{"id":"0662efebdee5d35f","repo":"rust-lang/rust","slug":"attributes-not-supported-on-queries","errorCode":null,"errorMessage":"attributes not supported on queries","messagePattern":"attributes not supported on queries","errorType":"exception","errorClass":"syn::Error","httpStatus":null,"severity":"error","filePath":"compiler/rustc_macros/src/query.rs","lineNumber":21,"sourceCode":"use quote::{quote, quote_spanned};\nuse syn::parse::{Parse, ParseStream, Result};\nuse syn::punctuated::Punctuated;\nuse syn::spanned::Spanned;\nuse syn::{\n    AttrStyle, Attribute, Error, Expr, Ident, Pat, ReturnType, Token, Type, braced, parenthesized,\n    parse_macro_input, token,\n};\n\nmod kw {\n    syn::custom_keyword!(non_query);\n    syn::custom_keyword!(query);\n}\n\n/// Ensures only doc comment attributes are used\nfn check_attributes(attrs: Vec<Attribute>) -> Result<Vec<Attribute>> {\n    let inner = |attr: Attribute| {\n        if !attr.path().is_ident(\"doc\") {\n            Err(Error::new(attr.span(), \"attributes not supported on queries\"))\n        } else if attr.style != AttrStyle::Outer {\n            Err(Error::new(\n                attr.span(),\n                \"attributes must be outer attributes (`///`), not inner attributes\",\n            ))\n        } else {\n            Ok(attr)\n        }\n    };\n    attrs.into_iter().map(inner).collect()\n}\n\n/// Declaration of a compiler query.\n///\n/// ```ignore (illustrative)\n/// /// Doc comment for `my_query`.\n/// //  ^^^^^^^^^^^^^^^^^^^^^^^^^^^              doc_comments\n/// query my_query(key: DefId) -> Value { anon }","sourceCodeStart":3,"sourceCodeEnd":39,"githubUrl":"https://github.com/rust-lang/rust/blob/7088e4b63a9516ebfbfe2ab2d999cf01a528ac14/compiler/rustc_macros/src/query.rs#L3-L39","documentation":"Emitted by the check_attributes function inside the rustc_queries! proc macro (rustc_macros/src/query.rs). The macro validates every attribute on a query or non_query declaration and only permits #[doc] attributes (doc comments). If any other attribute is present (e.g., #[inline], #[cfg(...)], #[allow(...)]), this syn::Error is produced at that attribute's span. The error surfaces as a compile-time error in the crate invoking rustc_queries!.","triggerScenarios":"A compiler developer adds a query declaration inside a rustc_queries! { } block and annotates it with a non-doc attribute such as #[inline], #[allow(dead_code)], #[cfg(feature = \"x\")], or any other helper attribute.","commonSituations":"Adding a new query to rustc and trying to suppress a lint or add an optimization hint via attributes; copy-pasting from a non-query context where attributes are allowed.","solutions":["Remove the non-doc attribute from the query declaration — query modifiers (eval_always, arena_cache, etc.) go inside the { } modifier block, not as attributes.","If you need conditional compilation, apply it at a higher level (the module or the rustc_queries! invocation site), not on individual queries.","Move lint allows to the enclosing module with #[allow(...)] on the mod or use #![allow(...)] at crate level."],"exampleFix":"// before\nrustc_queries! {\n    #[inline]\n    /// Computes the type of an expression.\n    query type_of(key: DefId) -> Ty<'tcx> { desc { \"type of `{}`\", key } }\n}\n// after: remove the non-doc attribute\nrustc_queries! {\n    /// Computes the type of an expression.\n    query type_of(key: DefId) -> Ty<'tcx> { desc { \"type of `{}`\", key } }\n}","handlingStrategy":"validation","validationCode":"// In a test or CI lint, verify that query declarations only have #[doc] attributes.\n// This is a code-review/lint concern — the proc macro itself enforces it at compile time.\n// You can grep your query declarations:\n//   rg -A5 'query |non_query ' --type rust | grep -v 'doc\\|//' | grep '#\\['\n// Any hit indicates a non-doc attribute on a query.","typeGuard":null,"tryCatchPattern":"// This is a compile-time error from a proc macro. It cannot be caught.\n// Fix by removing the offending attribute from the query declaration.\n// The error points to the exact attribute span.","preventionTips":["Only use /// doc comments on query and non_query declarations inside rustc_queries!.","Query behavior modifiers go inside the { } block, not as attributes.","Add a code review checklist item: 'no non-doc attributes on queries'.","Use rust-analyzer or rustdoc to preview the macro expansion if unsure."],"tags":["rustc","proc-macro","query","compiler-internals"],"backgroundTag":null,"analyzedSha":"7088e4b63a9516ebfbfe2ab2d999cf01a528ac14","analyzedAt":"2026-08-10T14:17:03.603Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}