3 > **<sup>Lexer</sup>**\
5 > `//` (~\[`/` `!` `\n`] | `//`) ~`\n`<sup>\*</sup>\
9 > `/*` (~\[`*` `!`] | `**` | _BlockCommentOrDoc_)
10 > (_BlockCommentOrDoc_ | ~`*/`)<sup>\*</sup> `*/`\
11 > | `/**/`\
12 > | `/***/`
15 > `//!` ~\[`\n` _IsolatedCR_]<sup>\*</sup>
18 > `/*!` ( _BlockCommentOrDoc_ | ~\[`*/` _IsolatedCR_] )<sup>\*</sup> `*/`
21 > `///` (~`/` ~\[`\n` _IsolatedCR_]<sup>\*</sup>)<sup>?</sup>
24 > `/**` (~`*` | _BlockCommentOrDoc_ )
25 > (_BlockCommentOrDoc_ | ~\[`*/` _IsolatedCR_])<sup>\*</sup> `*/`
27 > _BlockCommentOrDoc_ :\
28 > BLOCK_COMMENT\
29 > | OUTER_BLOCK_DOC\
30 > | INNER_BLOCK_DOC
33 > _A `\r` not followed by a `\n`_
37 Comments follow the general C++ style of line (`//`) and
38 block (`/* ... */`) comment forms. Nested block comments are supported.
40 Non-doc comments are interpreted as a form of whitespace.
44 Line doc comments beginning with exactly _three_ slashes (`///`), and block
45 doc comments (`/** ... */`), both outer doc comments, are interpreted as a
46 special syntax for [`doc` attributes]. That is, they are equivalent to writing
47 `#[doc="..."]` around the body of the comment, i.e., `/// Foo` turns into
48 `#[doc="Foo"]` and `/** Bar */` turns into `#[doc="Bar"]`.
50 Line comments beginning with `//!` and block comments `/*! ... */` are
51 doc comments that apply to the parent of the comment, rather than the item
52 that follows. That is, they are equivalent to writing `#![doc="..."]` around
53 the body of the comment. `//!` comments are usually used to document
54 modules that occupy a source file.
56 Isolated CRs (`\r`), i.e. not followed by LF (`\n`), are not allowed in doc
62 //! A doc comment that applies to the implicit anonymous module of this crate
64 pub mod outer_module {
67 //!! - Still an inner line doc (but with a bang at the beginning)
69 /*! - Inner block doc */
70 /*!! - Still an inner block doc (but with a bang at the beginning) */
73 /// - Outer line doc (exactly 3 slashes)
76 /* - Only a comment */
77 /** - Outer block doc (exactly) 2 asterisks */
78 /*** - Only a comment */
80 pub mod inner_module {}
82 pub mod nested_comments {
83 /* In Rust /* we can /* nest comments */ */ */
85 // All three types of block comments can contain or be nested inside
88 /* /* */ /** */ /*! */ */
89 /*! /* */ /** */ /*! */ */
90 /** /* */ /** */ /*! */ */
94 pub mod degenerate_cases {
95 // empty inner line doc
98 // empty inner block doc
101 // empty line comment
104 // empty outer line doc
107 // empty block comment
110 pub mod dummy_item {}
112 // empty 2-asterisk block isn't a doc block, it is a block comment
117 /* The next one isn't allowed because outer doc comments
118 require an item that will receive the doc */
120 /// Where is my item?
125 [`doc` attributes]: ../rustdoc/the-doc-attribute.html