Comments
@root COMMENT ->
LINE_COMMENT
| INNER_LINE_DOC
| OUTER_LINE_DOC
| INNER_BLOCK_DOC
| OUTER_BLOCK_DOC
| BLOCK_COMMENT
LINE_COMMENT ->
`//` (~[`/` `!` LF] | `//`) ~LF*
| `//` EOF
| `//` _immediately followed by LF_
BLOCK_COMMENT ->
`/*` !(`!` | `*` ![`*` `/`]) ^
( BLOCK_COMMENT_OR_DOC | (!`*/` CHAR) )*
`*/`
INNER_LINE_DOC ->
`//!` ^ LINE_DOC_COMMENT_CONTENT (LF | EOF)
LINE_DOC_COMMENT_CONTENT -> (!CR ~LF)*
INNER_BLOCK_DOC ->
`/*!` ^ ( BLOCK_COMMENT_OR_DOC | BLOCK_CHAR )* `*/`
OUTER_LINE_DOC ->
`///` ^ LINE_DOC_COMMENT_CONTENT (LF | EOF)
OUTER_BLOCK_DOC ->
`/**` ![`*` `/`]
^
( ~[`*` CR] | BLOCK_COMMENT_OR_DOC )
( BLOCK_COMMENT_OR_DOC | BLOCK_CHAR )*
`*/`
BLOCK_CHAR -> (!(`*/` | CR) CHAR)
BLOCK_COMMENT_OR_DOC ->
INNER_BLOCK_DOC
| OUTER_BLOCK_DOC
| BLOCK_COMMENT
Non-doc comments
Comments follow the general C++ style of line (//) and block (/* ... */) comment forms. Nested block comments are supported.
Non-doc comments are interpreted as a form of whitespace.
Doc comments
Line doc comments beginning with exactly three slashes (///), and block doc comments (/** ... */), both outer doc comments, are interpreted as a special syntax for doc attributes.
That is, they are equivalent to writing #[doc="..."] around the body of the comment, i.e., /// Foo turns into #[doc=" Foo"] and /** Bar */ turns into #[doc=" Bar "]. They must therefore appear before something that accepts an outer attribute.
Line comments beginning with //! and block comments /*! ... */ are doc comments that apply to the parent of the comment, rather than the item that follows.
That is, they are equivalent to writing #![doc="..."] around the body of the comment. //! comments are usually used to document modules that occupy a source file.
The character U+000D (CR) is not allowed in doc comments.
Note
It is conventional for doc comments to contain Markdown, as expected by
rustdoc. However, the comment syntax does not respect any internal Markdown./** `glob = "*/*.rs";` */terminates the comment at the first*/, and the remaining code would cause a syntax error. This slightly limits the content of block doc comments compared to line doc comments.
Note
The sequence
U+000D(CR) immediately followed byU+000A(LF) would have been previously transformed into a singleU+000A(LF).
Examples
//! A doc comment that applies to the implicit anonymous module of this crate