.. default-domain:: spec
.. informational-section::
:dp:`fls_pqwpf87b84tr` The text of a Rust program consists of [module]s organized into [source file]s. The text of a source file is a sequence of [lexical element]s, each composed of characters, whose rules are presented in this chapter.
:dp:`fls_itcth8292ud6` The program text of a Rust program is written using the Unicode character set.
Syntax
:dp:`fls_vfx8byq5zo8t` A character is defined by this document for each cell in the coding space described by Unicode, regardless of whether or not Unicode allocates a character to that cell.
:dp:`fls_pvslhm3chtlb` A :dt:`whitespace character` is one of the following characters:
- :dp:`fls_a5ec9cpn4sc8` 0x09 (horizontal tabulation)
- :dp:`fls_dgyrj49y3c7c` 0x0A (new line)
- :dp:`fls_5ocmngyur7by` 0x0B (vertical tabulation)
- :dp:`fls_1aj0rgi9kpib` 0x0C (form feed)
- :dp:`fls_bfzdxsbq2c2q` 0x0D (carriage return)
- :dp:`fls_vw0kq2y1o63m` 0x20 (space)
- :dp:`fls_ao296bmamwzh` 0x85 (next line)
- :dp:`fls_6kymhq7embdh` 0x200E (left-to-right mark)
- :dp:`fls_8mxmrxvhn3by` 0x200F (right-to-left mark)
- :dp:`fls_bc6D1ATvmJJr` 0x2028 (line separator)
- :dp:`fls_zfs15iel08y0` 0x2029 (paragraph separator)
:dp:`fls_7eifv4ksunu1` A whitespace string is a string that consists of one or more [whitespace character]s.
:dp:`fls_PIDKEm8GiLNL` An :ds:`AsciiCharacter` is any Unicode character in the range 0x00 - 0x7F, both inclusive.
Legality Rules
:dp:`fls_2brw13n9ldgy` The coded representation of a character is tool-defined.
Syntax
.. syntax:: LexicalElement ::= Comment | Identifier | Keyword | Literal | Punctuation Punctuation ::= Delimiter | $$+$$ | $$-$$ | $$*$$ | $$/$$ | $$%$$ | $$^$$ | $$!$$ | $$&$$ | $$|$$ | $$&&$$ | $$||$$ | $$<<$$ | $$>>$$ | $$+=$$ | $$-=$$ | $$*=$$ | $$/=$$ | $$%=$$ | $$^=$$ | $$&=$$ | $$|=$$ | $$<<=$$ | $$>>=$$ | $$=$$ | $$==$$ | $$!=$$ | $$>$$ | $$<$$ | $$>=$$ | $$<=$$ | $$@$$ | $$_$$ | $$.$$ | $$..$$ | $$...$$ | $$..=$$ | $$,$$ | $$;$$ | $$:$$ | $$::$$ | $$->$$ | $$=>$$ | $$#$$ | $$$$$ | $$?$$ Delimiter ::= $${$$ | $$}$$ | $$[$$ | $$]$$ | $$($$ | $$)$$
Legality Rules
:dp:`fls_d4nvxsvxj537` The text of a source file is a sequence of separate [lexical element]s. The meaning of a program depends only on the particular sequence of [lexical element]s, excluding non-[doc comment]s.
:dp:`fls_a1zylpqha73x` A lexical element is the most basic syntactic element in program text.
:dp:`fls_jy6wifn5r2bu` The text of a source file is divided into [line]s.
:dp:`fls_efdfq9nhpmp5` A line is a sequence of zero or more characters followed by an end of line.
:dp:`fls_go25sisi5fdp` The representation of an end of line is tool-defined.
:dp:`fls_a6t53o8h1vdk` A separator is a character or a string that separates adjacent [lexical element]s. A whitespace string is a separator.
:dp:`fls_8fv63w6f4udl` A :dt:`simple punctuator` is one of the following special characters:
.. syntax:: $$+$$ $$-$$ $$*$$ $$/$$ $$%$$ $$^$$ $$!$$ $$&$$ $$|$$ $$=$$ $$>$$ $$<$$ $$@$$ $$_$$ $$.$$ $$,$$ $$;$$ $$:$$ $$#$$ $$$$$ $$?$$ $${$$ $$}$$ $$[$$ $$]$$ $$($$ $$)$$
:dp:`fls_es0tz1q9cmoo` A :dt:`compound punctuator` is one of the following two or more adjacent special characters:
.. syntax:: $$&&$$ $$||$$ $$<<$$ $$>>$$ $$+=$$ $$-=$$ $$*=$$ $$/=$$ $$%=$$ $$^=$$ $$&=$$ $$|=$$ $$<<=$$ $$>>=$$ $$==$$ $$!=$$ $$>=$$ $$<=$$ $$..$$ $$...$$ $$..=$$ $$::$$ $$->$$ $$=>$$
:dp:`fls_vm86olkeecer` The following [compound punctuator]s are :dt:`[flexible compound punctuator]s`.
.. syntax:: $$&&$$ $$||$$ $$<<$$ $$>>$$
:dp:`fls_5zxdgxy8tjrq` A flexible compound punctuator may be treated as a single compound punctuator or two adjacent [simple punctuator]s.
:dp:`fls_x89vkq9rwlyt` Each of the special characters listed for single character punctuator is a simple punctuator except if this character is used as a character of a compound punctuator, or a character of a character literal, a comment, a numeric literal, or a string literal.
:dp:`fls_bo3xh8r60ji1` The following names are used when referring to [punctuator]s:
Syntax
.. syntax:: Identifier ::= NonKeywordIdentifier | RawIdentifier IdentifierList ::= Identifier ($$,$$ Identifier)* $$,$$? NonKeywordIdentifier ::= PureIdentifier | WeakKeyword RawIdentifier ::= $$r#$$ (PureIdentifier | RawIdentifierKeyword) PureIdentifier ::= XID_Start XID_Continue* | $$_$$ XID_Continue+ IdentifierOrUnderscore ::= Identifier | $$_$$ Renaming ::= $$as$$ IdentifierOrUnderscore
:dp:`fls_ls7ymvgd5kfa`
A :ds:`RawIdentifierKeyword` is any keyword in category :s:`Keyword`,
except crate
, self
, Self
, and super
.
:dp:`fls_aqj9aguczgqs` :ds:`XID_Start` and :ds:`XID_Continue` are defined in Unicode Standard Annex #31.
Legality Rules
:dp:`fls_xsdmun5uqy4c` An identifier is a lexical element that refers to a name.
:dp:`fls_ktnf6zkrdy45` A pure identifier is an identifier that does not include [weak keyword]s.
:dp:`fls_jpecw46eh061` A pure identifier shall follow the specification in Unicode Standard Annex #31 for Unicode version 13.0, with the following profile:
- :dp:`fls_lwcflgezgs5z`
Start
=XID_Start
, plus character 0x5F (low line). - :dp:`fls_uts0hywaw1rq`
Continue
=XID_Continue
- :dp:`fls_lju1avcn0pfd`
Medial
= empty
:dp:`fls_cs6cbw625np1` Characters 0x200C (zero width non-joiner) and 0x200D (zero width joiner) shall not appear in a pure identifier.
:dp:`fls_irwcldiotei2` A pure identifier shall be restricted to characters in category :s:`AsciiCharacter` in the following contexts:
- :dp:`fls_g72rxs2z5960` [Crate import]s,
- :dp:`fls_w473jevurlt1`
[Name]s of external [crate]s represented in a simple path, when
the simple path starts with namespace qualifier
::
, - :dp:`fls_mt1u4m3simhc` [Name]s of [outline module]s that lack attribute :c:`path`,
- :dp:`fls_e2v58o233lvd` [Name]s of [item]s that are subject to attribute :c:`no_mangle`,
- :dp:`fls_op0lp1i065di` [Name]s of [item]s within [external block]s.
:dp:`fls_vde7gev5rz4q` [Identifier]s are normalized using Normalization Form C as defined in Unicode Standard Annex #15.
:dp:`fls_j9yh8j8jgdeu` Two [identifier]s are considered the same if they consist of the same sequence of characters after performing normalization.
:dp:`fls_jejt5z8m1yew` [Declarative macro]s and [procedural macro]s shall receive normalized [identifier]s in their input.
Examples
foo
_identifier
r#true
Москва
東京
Syntax
.. syntax:: Literal ::= BooleanLiteral | ByteLiteral | ByteStringLiteral | CStringLiteral | CharacterLiteral | NumericLiteral | StringLiteral
Legality Rules
:dp:`fls_s76un78zyd0j` A literal is a fixed value in program text.
Syntax
.. syntax:: ByteLiteral ::= $$b'$$ ByteContent $$'$$ ByteContent ::= ByteCharacter | ByteEscape ByteEscape ::= | $$\0$$ | $$\"$$ | $$\'$$ | $$\t$$ | $$\n$$ | $$\r$$ | $$\\$$ | $$\x$$ OctalDigit HexadecimalDigit
:dp:`fls_3hpzf12h60u4` A :ds:`ByteCharacter` is any character in category :s:`AsciiCharacter` except characters 0x09 (horizontal tabulation), 0x0A (new line), 0x0D (carriage return), 0x27 (apostrophe), and 0x5C (reverse solidus).
Legality Rules
:dp:`fls_q0qwr83frszx` A byte literal is a literal that denotes a fixed byte value.
:dp:`fls_fggytrv5jvw0` The type of a byte literal is :c:`u8`.
Examples
b'h'
b'\n'
b'\x1B'
Syntax
.. syntax:: ByteStringLiteral ::= RawByteStringLiteral | SimpleByteStringLiteral
Legality Rules
:dp:`fls_t63zfv5JdUhj` A byte string literal is a literal that consists of multiple :s:`[AsciiCharacter]s`.
:dp:`fls_Xd6LnfzMb7t7` The character sequence 0x0D 0x0A (carriage return, new line) is replaced by 0x0A (new line) inside of a byte string literal.
Syntax
.. syntax:: SimpleByteStringLiteral ::= $$b"$$ SimpleByteStringContent* $$"$$ SimpleByteStringContent ::= ByteEscape | SimpleByteStringCharacter | StringContinuation
:dp:`fls_3dcqhuosqb84` A :ds:`SimpleByteStringCharacter` is any character in category :s:`AsciiCharacter` except characters 0x0D (carriage return), 0x22 (quotation mark), and 0x5C (reverse solidus).
Legality Rules
:dp:`fls_moe3zfx39ox2` A simple byte string literal is a byte string literal that consists of multiple :s:`[AsciiCharacter]s`.
:dp:`fls_vffxb6arj9jf`
The type of a simple byte string literal of size N
is &'static [u8;
N]
.
Examples
b""
b"a\tb"
b"Multi\
line"
Syntax
.. syntax:: RawByteStringLiteral ::= $$br$$ RawByteStringContent RawByteStringContent ::= NestedRawByteStringContent | $$"$$ AsciiCharacter* $$"$$ NestedRawByteStringContent ::= $$#$$ RawByteStringContent $$#$$
Legality Rules
:dp:`fls_yyw7nv651580` A raw byte string literal is a simple byte string literal that does not recognize [escaped character]s.
:dp:`fls_5ybq0euwya42`
The type of a raw byte string literal of size N
is &'static
[u8; N]
.
Examples
br""
br#""#
br##"left #"# right"##
Syntax
.. syntax:: CStringLiteral ::= RawCStringLiteral | SimpleCStringLiteral
Legality Rules
:dp:`fls_VKCW830CzhhN` A c string literal is a literal that consists of multiple characters with an implicit 0x00 byte appended to it.
:dp:`fls_XJprzaEn82Xs` The character sequence 0x0D 0x0A (carriage return, new line) is replaced by 0x0A (new line) inside of a c string literal.
Syntax
.. syntax:: SimpleCStringLiteral ::= $$c"$$ SimpleCStringContent* $$"$$ SimpleCStringContent ::= AsciiEscape | SimpleStringCharacter | StringContinuation | UnicodeEscape
:dp:`fls_fnwQHo7twAom` A simple c string literal is any Unicode character except characters 0x0D (carriage return), 0x22 (quotation mark), 0x5C (reverse solidus) and 0x00 (null byte).
Legality Rules
:dp:`fls_nPI7j0siGP8G` A simple c string literal is a c string literal where the characters are Unicode characters.
:dp:`fls_Ae7LM4Wg0NA7` The type of a simple string literal is :std:`&'static [core::ffi::CStr]`.
Examples
c""
c"cat"
c"\tcol\nrow"
c"bell\x07"
c"\u{B80a}"
c"\
multi\
line\
string"
Syntax
.. syntax:: RawCStringLiteral ::= $$cr$$ RawCStringContent RawCStringContent ::= NestedRawCStringContent | $$"$$ ~[$$\r$$]* $$"$$ NestedRawCStringContent ::= $$#$$ RawCStringContent $$#$$
Legality Rules
:dp:`fls_gLrei65i8Uzq` A raw c string literal is a simple c string literal that does not recognize [escaped character]s.
:dp:`fls_9nJHsg9dCi66` The type of a simple string literal is :std:`&'static [core::ffi::CStr]`.
Examples
cr""
cr#""#
cr##"left #"# right"##
Syntax
.. syntax:: NumericLiteral ::= FloatLiteral | IntegerLiteral
Legality Rules
:dp:`fls_fqpqnku27v99` A numeric literal is a literal that denotes a number.
Syntax
.. syntax:: IntegerLiteral ::= IntegerContent IntegerSuffix? IntegerContent ::= BinaryLiteral | DecimalLiteral | HexadecimalLiteral | OctalLiteral BinaryLiteral ::= $$0b$$ BinaryDigitOrUnderscore* BinaryDigit BinaryDigitOrUnderscore* BinaryDigitOrUnderscore ::= BinaryDigit | $$_$$ BinaryDigit ::= [$$0$$-$$1$$] DecimalLiteral ::= DecimalDigit DecimalDigitOrUnderscore* DecimalDigitOrUnderscore ::= DecimalDigit | $$_$$ DecimalDigit ::= [$$0$$-$$9$$] HexadecimalLiteral ::= $$0x$$ HexadecimalDigitOrUnderscore* HexadecimalDigit HexadecimalDigitOrUnderscore* HexadecimalDigitOrUnderscore ::= HexadecimalDigit | $$_$$ HexadecimalDigit ::= [$$0$$-$$9$$ $$a$$-$$f$$ $$A$$-$$F$$] OctalLiteral ::= $$0o$$ OctalDigitOrUnderscore* OctalDigit OctalDigitOrUnderscore* OctalDigitOrUnderscore ::= OctalDigit | $$_$$ OctalDigit ::= [$$0$$-$$7$$] IntegerSuffix ::= SignedIntegerSuffix | UnsignedIntegerSuffix SignedIntegerSuffix ::= $$i8$$ | $$i16$$ | $$i32$$ | $$i64$$ | $$i128$$ | $$isize$$ UnsignedIntegerSuffix ::= $$u8$$ | $$u16$$ | $$u32$$ | $$u64$$ | $$u128$$ | $$usize$$
Legality Rules
:dp:`fls_vkk2krfn93ry` An integer literal is a numeric literal that denotes a whole number.
:dp:`fls_nxqncu5yq4eu` A binary literal is an integer literal in base 2.
:dp:`fls_rn8xfd66yvst` A decimal literal is an integer literal in base 10.
:dp:`fls_2268lchxkzjp` A hexadecimal literal is an integer literal in base 16.
:dp:`fls_4v7awnutbpoe` An octal literal is an integer literal in base 8.
:dp:`fls_f1e29aj0sqvl` An integer suffix is a component of an integer literal that specifies an explicit integer type.
:dp:`fls_u83mffscqm6` A suffixed integer is an integer literal with an integer suffix.
:dp:`fls_g10nuv14q4jn` An unsuffixed integer is an integer literal without an integer suffix.
:dp:`fls_hpkkvuj1z1ez` The type of a suffixed integer is determined by its integer suffix as follows:
- :dp:`fls_7yq2fep848ky`
Suffix
i8
specifies type :c:`i8`. - :dp:`fls_bzm8lwq3qlat`
Suffix
i16
specifies type :c:`i16`. - :dp:`fls_l4cx36brc1r5`
Suffix
i32
specifies type :c:`i32`. - :dp:`fls_wthchinwx996`
Suffix
i64
specifies type :c:`i64`. - :dp:`fls_7uoaet2pm3am`
Suffix
i128
specifies type :c:`i128`. - :dp:`fls_p4rw583o2qbi`
Suffix
isize
specifies type :c:`isize`. - :dp:`fls_xrv4q56lmoo3`
Suffix
u8
specifies type :c:`u8`. - :dp:`fls_66e3q5um6cwc`
Suffix
u16
specifies type :c:`u16`. - :dp:`fls_5asyk66y7c9d`
Suffix
u32
specifies type :c:`u32`. - :dp:`fls_76fifqjka0lx`
Suffix
u64
specifies type :c:`u64`. - :dp:`fls_fsaimo419gf0`
Suffix
u128
specifies type :c:`u128`. - :dp:`fls_hvzacbu7yiwc`
Suffix
usize
specifies type :c:`usize`.
:dp:`fls_50qipwqi3arw` The type of an unsuffixed integer is determined by type inference as follows:
- :dp:`fls_idzhusp2l908` If an integer type can be uniquely determined from the surrounding program context, then the unsuffixed integer has that type.
- :dp:`fls_qqrqyc6uhol` If the program context under-constrains the type, then the inferred type is :c:`i32`.
- :dp:`fls_pexi5jazthq6` If the program context over-constrains the type, then this is considered a static error.
Examples
0b0010_1110_u8
1___2_3
0x4D8a
0o77_52i128
Syntax
.. syntax:: FloatLiteral ::= DecimalLiteral $$.$$ | DecimalLiteral FloatExponent | DecimalLiteral $$.$$ DecimalLiteral FloatExponent? | DecimalLiteral ($$.$$ DecimalLiteral)? FloatExponent? FloatSuffix FloatExponent ::= ExponentLetter ExponentSign? ExponentMagnitude ExponentLetter ::= $$e$$ | $$E$$ ExponentSign ::= $$+$$ | $$-$$ ExponentMagnitude ::= DecimalDigitOrUnderscore* DecimalDigit DecimalDigitOrUnderscore* FloatSuffix ::= $$f32$$ | $$f64$$
Legality Rules
:dp:`fls_rzi7oeqokd6e` A float literal is a numeric literal that denotes a fractional number.
:dp:`fls_2ru1zyrykd37` A float suffix is a component of a float literal that specifies an explicit floating-point type.
:dp:`fls_21mhnhplzam7` A suffixed float is a float literal with a float suffix.
:dp:`fls_drqh80k0sfkb` An unsuffixed float is a float literal without a float suffix.
:dp:`fls_cbs7j9pjpusw` The type of a suffixed float is determined by the float suffix as follows:
- :dp:`fls_b9w7teaw1f8f`
Suffix
f32
specifies type :c:`f32`. - :dp:`fls_eawxng4ndhv0`
Suffix
f64
specifies type :c:`f64`.
:dp:`fls_yuhza1muo7o` The type of an unsuffixed float is determined by type inference as follows:
- :dp:`fls_4sxt1ct7fyen` If a floating-point type can be uniquely determined from the surrounding program context, then the unsuffixed float has that type.
- :dp:`fls_wa72rssp0jnt` If the program context under-constrains the type, then the inferred type is :c:`f64`.
- :dp:`fls_x2cw7g8g56f8` If the program context over-constrains the type, then this is considered a static error.
Examples
45.
8E+1_820
3.14e5
8_031.4_e-12f64
Syntax
.. syntax:: CharacterLiteral ::= $$'$$ CharacterContent $$'$$ CharacterContent ::= AsciiEscape | CharacterLiteralCharacter | UnicodeEscape AsciiEscape ::= | $$\0$$ | $$\"$$ | $$\'$$ | $$\t$$ | $$\n$$ | $$\r$$ | $$\\$$ | $$\x$$ OctalDigit HexadecimalDigit
:dp:`fls_j9q9ton57rvl` A :ds:`CharacterLiteralCharacter` is any Unicode character except characters 0x09 (horizontal tabulation), 0x0A (new line), 0x0D (carriage return), 0x27 (apostrophe), and 0x5c (reverse solidus).
:dp:`fls_5v9gx22g5wPm`
A :ds:`UnicodeEscape` starts with a \u{
literal, followed by 1 to 6
instances of a :s:`HexadecimalDigit`, inclusive, followed by a }
character.
It can represent any Unicode codepoint between U+00000 and U+10FFFF,
inclusive, except Unicode surrogate codepoints, which exist between
the range of U+D800 and U+DFFF, inclusive.
Legality Rules
:dp:`fls_vag2oy4q7d4n` A character literal is a literal that denotes a fixed Unicode character.
:dp:`fls_n8z6p6g564r2` The type of a character literal is :c:`char`.
Examples
'a'
'\t'
'\x1b'
'\u{1F30}'
Syntax
.. syntax:: StringLiteral ::= RawStringLiteral | SimpleStringLiteral
Legality Rules
:dp:`fls_7fuctvtvdi7x` A string literal is a literal that consists of multiple characters.
:dp:`fls_NyiCpU2tzJlQ` The character sequence 0x0D 0x0A (carriage return, new line) is replaced by 0x0A (new line) inside of a string literal.
Syntax
.. syntax:: SimpleStringLiteral ::= $$"$$ SimpleStringContent* $$"$$ SimpleStringContent ::= AsciiEscape | SimpleStringCharacter | StringContinuation | UnicodeEscape
:dp:`fls_1pdzwkt5txfj` A :ds:`SimpleStringCharacter` is any Unicode character except characters 0x0D (carriage return), 0x22 (quotation mark), and 0x5C (reverse solidus).
:dp:`fls_wawtu6j3fiqn` :ds:`StringContinuation` is the character sequence 0x5C 0x0A (reverse solidus, new line).
Legality Rules
:dp:`fls_ycy5ee6orjx` A simple string literal is a string literal where the characters are Unicode characters.
:dp:`fls_6nt5kls21xes`
The type of a simple string literal is &'static str
.
Examples
""
"cat"
"\tcol\nrow"
"bell\x07"
"\u{B80a}"
"\
multi\
line\
string"
Syntax
.. syntax:: RawStringLiteral ::= $$r$$ RawStringContent RawStringContent ::= NestedRawStringContent | $$"$$ ~[$$\r$$]* $$"$$ NestedRawStringContent ::= $$#$$ RawStringContent $$#$$
Legality Rules
:dp:`fls_36suwhbwmq1t` A raw string literal is a simple string literal that does not recognize [escaped character]s.
:dp:`fls_ms43w1towz40`
The type of a raw string literal is &'static str
.
Examples
r""
r#""#
r##"left #"# right"##
Syntax
.. syntax:: BooleanLiteral ::= $$false$$ | $$true$$
Legality Rules
:dp:`fls_1lll64ftupjd` A boolean literal is a literal that denotes the truth [value]s of logic and Boolean algebra.
:dp:`fls_pgngble3ilyx` The type of a boolean literal is :c:`bool`.
Examples
true
Syntax
.. syntax:: Comment ::= BlockCommentOrDoc | LineCommentOrDoc BlockCommentOrDoc ::= BlockComment | InnerBlockDoc | OuterBlockDoc LineCommentOrDoc ::= LineComment | InnerLineDoc | OuterLineDoc LineComment ::= $$//$$ | $$//$$ (~[$$!$$ $$/$$] | $$//$$) ~[$$\n$$]* BlockComment ::= $$/*$$ (~[$$!$$ $$*$$] | $$**$$ | BlockCommentOrDoc) (BlockCommentOrDoc | ~[$$*/$$])* $$*/$$ | $$/**/$$ | $$/***/$$ InnerBlockDoc ::= $$/*!$$ (BlockCommentOrDoc | ~[$$*/$$ $$\r$$])* $$*/$$ InnerLineDoc ::= $$//!$$ ~[$$\n$$ $$\r$$]* OuterBlockDoc ::= $$/**$$ (~[$$*$$] | BlockCommentOrDoc) (BlockCommentOrDoc | ~[$$*/$$ $$\r$$])* $$*/$$ OuterLineDoc ::= $$///$$ (~[$$/$$] ~[$$\n$$ $$\r$$]*)?
Legality Rules
:dp:`fls_8obn3dtzpe5f` A comment is a lexical element that acts as an annotation or an explanation in program text.
:dp:`fls_qsbnl11be35s` A block comment is a comment that spans one or more [line]s.
:dp:`fls_nayisy85kyq2` A line comment is a comment that spans exactly one line.
:dp:`fls_k3hj30hjkdhw` An inner block doc is a block comment that applies to an enclosing non-[comment] construct.
:dp:`fls_tspijl68lduc` An inner line doc is a line comment that applies to an enclosing non-[comment] construct.
:dp:`fls_KZp0yiFLTqxb` An inner doc comment is either an inner block doc or an inner line doc.
:dp:`fls_63gzofa9ktic` An outer block doc is a block comment that applies to a subsequent non-[comment] construct.
:dp:`fls_scko7crha0um` An outer line doc is a line comment that applies to a subsequent non-[comment] construct.
:dp:`fls_RYVL9KgaxKvl` An outer doc comment is either an outer block doc or an outer line doc.
:dp:`fls_7n6d3jx61ose` A doc comment is a comment class that includes [inner block doc]s, [inner line doc]s, [outer block doc]s, and [outer line doc]s.
:dp:`fls_6fxcs17n4kw` Character 0x0D (carriage return) shall not appear in a comment.
:dp:`fls_uze7l7cxonk1` [Block comment]s, [inner block doc]s, and [outer block doc]s shall extend one or more [line]s.
:dp:`fls_gy23lwlqw2mc` [Line comment]s, [inner line doc]s, and [outer line doc]s shall extend exactly one line.
:dp:`fls_w7d0skpov1is` [Outer block doc]s and [outer line doc]s shall apply to a subsequent non-[comment] construct.
:dp:`fls_32ncjvj2kn7z` [Inner block doc]s and [inner line doc]s shall apply to an enclosing non-[comment] construct.
:dp:`fls_ok0zvo9vcmzo`
[Inner block doc]s and [inner line doc]s are equivalent to
attribute :c:`doc` of the form #![doc = content]
, where content
is a string literal form of the comment without the leading //!
,
/*!
amd trailing */
characters.
:dp:`fls_nWtKuPi8Fw6v`
[Outer block doc]s and [outer line doc]s are equivalent to
attribute :c:`doc` of the form #[doc = content]
, where content
is a string literal form of the comment without the leading ///
,
/**
and trailing */
characters.
Examples
// This is a stand-alone line comment. So is the next line.
////
/* This is a stand-alone
block comment. */
/*
/* This is a nested block comment */
*/
/// This outer line comment applies to commented_module.
/** This outer block comment applies to commented_module,
and is considered documentation. */
pub mod commented_module {
//! This inner line comment applies to commented_mode.
/*! This inner block comment applies to commented_module,
and is considered documentation. */
}
Syntax
.. syntax:: Keyword ::= ReservedKeyword | StrictKeyword | WeakKeyword
Legality Rules
:dp:`fls_dti0uu7rz81w` A keyword is a word in program text that has special meaning.
:dp:`fls_sxg1o4oxql51` [Keyword]s are case sensitive.
Syntax
.. syntax:: StrictKeyword ::= $$as$$ | $$async$$ | $$await$$ | $$break$$ | $$const$$ | $$continue$$ | $$crate$$ | $$dyn$$ | $$enum$$ | $$extern$$ | $$false$$ | $$fn$$ | $$for$$ | $$if$$ | $$impl$$ | $$in$$ | $$let$$ | $$loop$$ | $$match$$ | $$mod$$ | $$move$$ | $$mut$$ | $$pub$$ | $$ref$$ | $$return$$ | $$self$$ | $$Self$$ | $$static$$ | $$struct$$ | $$super$$ | $$trait$$ | $$true$$ | $$type$$ | $$unsafe$$ | $$use$$ | $$where$$ | $$while$$
Legality Rules
:dp:`fls_bsh7qsyvox21` A strict keyword is a keyword that always holds its special meaning.
Syntax
.. syntax:: ReservedKeyword ::= $$abstract$$ | $$become$$ | $$box$$ | $$do$$ | $$final$$ | $$macro$$ | $$override$$ | $$priv$$ | $$try$$ | $$typeof$$ | $$unsized$$ | $$virtual$$ | $$yield$$
Legality Rules
:dp:`fls_w4b97ewwnql` A reserved keyword is a keyword that is not yet in use.
Syntax
.. syntax:: WeakKeyword ::= $$macro_rules$$ | $$'static$$ | $$union$$ | $$safe$$
Legality Rules
:dp:`fls_bv87t1gvj7bz` A weak keyword is a keyword whose special meaning depends on the context.
:dp:`fls_bl55g03jmayf`
Word macro_rules
acts as a keyword only when used in the context of a
:s:`MacroRulesDefinition`.
:dp:`fls_c354oryv513p`
Word 'static
acts as a keyword only when used in the context of a
:s:`LifetimeIndication`.
:dp:`fls_r9fhuiq1ys1p`
Word union
acts as a keyword only when used in the context of a
:s:`UnionDeclaration`.
:dp:`fls_g0JEluWqBpNc`
Word safe
acts as a keyword only when used as a qualifier of :s:`Function` or :s:`Static` in the context of a :s:`ExternalBlock`.