Inner documentation comments in Rust are annotations used to document the enclosing item that contains the comment itself, rather than the item immediately following it. They are parsed by theDocumentation Index
Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
Use this file to discover all available pages before exploring further.
rustdoc tool to generate HTML documentation for any item that contains a block, such as the root scope of a crate, a module, a function body, or a method.
Syntax
Rust supports two syntactic forms for inner documentation comments: line comments and block comments. Line Comments Line comments begin with//! and continue to the end of the line. Multiple consecutive //! lines are concatenated into a single documentation block.
/*! and end with */. They can span multiple lines and contain internal formatting.
Compiler Desugaring
At the Abstract Syntax Tree (AST) level, the Rust compiler desugars inner documentation comments into innerdoc attributes. Specifically, //! and /*! ... */ are translated into #![doc = "..."].
! in #![...]), they apply to the AST node they are inside, not the node they precede.
Placement and Parsing Rules
Inner documentation comments are subject to strict placement rules within the Rust module system and block structures:- Scope: They must be placed at the top of the enclosing scope. This can be at the very beginning of a file (like
main.rsorlib.rs), or immediately after the opening brace ({) of a block-containing item (likemod { ... },fn { ... }, orimpl { ... }). - Ordering: They must appear before any declarations, statements, or items within that scope. Placing an inner documentation comment after an item or statement will cause
rustcto intercept the misplaced comment and emit the compiler errorexpected outer doc comment. - Markdown Support: The text within the comment is parsed as CommonMark Markdown by
rustdoc, supporting standard Markdown elements like headings, code blocks, and links.
Master Rust with Deep Grasping Methodology!Learn More





