{"record":{"id":"0eee84e703bab76e","repo":"rust-lang/rust","slug":"attributes-must-be-outer-attributes-not-i","errorCode":null,"errorMessage":"attributes must be outer attributes (`///`), not inner attributes","messagePattern":"attributes must be outer attributes \\(`///`\\), not inner attributes","errorType":"exception","errorClass":"syn::Error","httpStatus":null,"severity":"error","filePath":"compiler/rustc_macros/src/query.rs","lineNumber":23,"sourceCode":"use 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 }\n/// //    ^^^^^^^^                               name\n/// //             ^^^                           key_pat","sourceCodeStart":5,"sourceCodeEnd":41,"githubUrl":"https://github.com/rust-lang/rust/blob/7088e4b63a9516ebfbfe2ab2d999cf01a528ac14/compiler/rustc_macros/src/query.rs#L5-L41","documentation":"Emitted by check_attributes in the rustc_queries! macro when a #[doc] attribute uses inner-attribute syntax (//! or #[doc = ...] with AttrStyle::Inner) instead of outer-attribute syntax (/// or #[doc = ...] with AttrStyle::Outer). Only outer doc comments are allowed on individual query declarations. Inner doc comments (which document the enclosing item/module) don't make semantic sense on individual query entries.","triggerScenarios":"Writing //! instead of /// in front of a query or non_query declaration inside a rustc_queries! { } block. For example, accidentally using a module-level doc comment style on a query.","commonSituations":"Editor auto-completing //! because the query block is inside a module; copy-paste from module-level documentation; unfamiliarity with the difference between /// and //! in this context.","solutions":["Change the inner doc comment //! to an outer doc comment /// on the query line.","If documenting the query group as a whole, place the //! comment outside the rustc_queries! invocation, not inside it on individual queries."],"exampleFix":"// before\nrustc_queries! {\n    //! Computes the type of an expression.\n    query type_of(key: DefId) -> Ty<'tcx> { desc { \"type of `{}`\", key } }\n}\n// after: use /// (outer) instead of //! (inner)\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":"// Lint: check that query declarations don't use inner doc comments.\n// In your editor, search for '//!' lines inside rustc_queries! blocks.\n// Or programmatically:\n//   rg '//!' -B2 -A5 --type rust | grep -B5 'query \\|non_query '\n// Any match likely indicates an inner doc comment on a query.","typeGuard":null,"tryCatchPattern":"// Compile-time error from the proc macro — cannot be caught.\n// Fix by changing //! to ///.","preventionTips":["Use /// (outer doc comments) on individual query declarations, not //! (inner).","Configure your editor to not auto-suggest //! for item-level comments.","Review the doc comment style guide in the rustc compiler contributors' guide."],"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"}