Skip to content

Commit 2c7c369

Browse files
committed
Improve TokenKind comments.
- Improve wording. - Use backticks consistently for examples.
1 parent df29f9b commit 2c7c369

File tree

1 file changed

+39
-41
lines changed
  • compiler/rustc_lexer/src

1 file changed

+39
-41
lines changed

compiler/rustc_lexer/src/lib.rs

Lines changed: 39 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,10 @@ impl Token {
5757
/// Enum representing common lexeme types.
5858
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
5959
pub enum TokenKind {
60-
// Multi-char tokens:
61-
/// "// comment"
60+
/// A line comment, e.g. `// comment`.
6261
LineComment { doc_style: Option<DocStyle> },
6362

64-
/// `/* block comment */`
63+
/// A block comment, e.g. `/* block comment */`.
6564
///
6665
/// Block comments can be recursive, so a sequence like `/* /* */`
6766
/// will not be considered terminated and will result in a parsing error.
@@ -70,18 +69,17 @@ pub enum TokenKind {
7069
/// Any whitespace character sequence.
7170
Whitespace,
7271

73-
/// "ident" or "continue"
74-
///
75-
/// At this step, keywords are also considered identifiers.
72+
/// An identifier or keyword, e.g. `ident` or `continue`.
7673
Ident,
7774

78-
/// Like the above, but containing invalid unicode codepoints.
75+
/// An identifier that is invalid because it contains emoji.
7976
InvalidIdent,
8077

81-
/// "r#ident"
78+
/// A raw identifier, e.g. "r#ident".
8279
RawIdent,
8380

84-
/// An unknown prefix, like `foo#`, `foo'`, `foo"`.
81+
/// An unknown literal prefix, like `foo#`, `foo'`, `foo"`. Excludes
82+
/// literal prefixes that contain emoji, which are considered "invalid".
8583
///
8684
/// Note that only the
8785
/// prefix (`foo`) is included in the token, not the separator (which is
@@ -93,11 +91,12 @@ pub enum TokenKind {
9391

9492
/// An unknown prefix in a lifetime, like `'foo#`.
9593
///
96-
/// Note that like above, only the `'` and prefix are included in the token
94+
/// Like `UnknownPrefix`, only the `'` and prefix are included in the token
9795
/// and not the separator.
9896
UnknownPrefixLifetime,
9997

100-
/// `'r#lt`, which in edition < 2021 is split into several tokens: `'r # lt`.
98+
/// A raw lifetime, e.g. `'r#foo`. In edition < 2021 it will be split into
99+
/// several tokens: `'r` and `#` and `foo`.
101100
RawLifetime,
102101

103102
/// Similar to the above, but *always* an error on every edition. This is used
@@ -110,70 +109,69 @@ pub enum TokenKind {
110109
/// Split into the component tokens on older editions.
111110
GuardedStrPrefix,
112111

113-
/// Examples: `12u8`, `1.0e-40`, `b"123"`. Note that `_` is an invalid
112+
/// Literals, e.g. `12u8`, `1.0e-40`, `b"123"`. Note that `_` is an invalid
114113
/// suffix, but may be present here on string and float literals. Users of
115114
/// this type will need to check for and reject that case.
116115
///
117116
/// See [LiteralKind] for more details.
118117
Literal { kind: LiteralKind, suffix_start: u32 },
119118

120-
/// "'a"
119+
/// A lifetime, e.g. `'a`.
121120
Lifetime { starts_with_number: bool },
122121

123-
// One-char tokens:
124-
/// ";"
122+
/// `;`
125123
Semi,
126-
/// ","
124+
/// `,`
127125
Comma,
128-
/// "."
126+
/// `.`
129127
Dot,
130-
/// "("
128+
/// `(`
131129
OpenParen,
132-
/// ")"
130+
/// `)`
133131
CloseParen,
134-
/// "{"
132+
/// `{`
135133
OpenBrace,
136-
/// "}"
134+
/// `}`
137135
CloseBrace,
138-
/// "["
136+
/// `[`
139137
OpenBracket,
140-
/// "]"
138+
/// `]`
141139
CloseBracket,
142-
/// "@"
140+
/// `@`
143141
At,
144-
/// "#"
142+
/// `#`
145143
Pound,
146-
/// "~"
144+
/// `~`
147145
Tilde,
148-
/// "?"
146+
/// `?`
149147
Question,
150-
/// ":"
148+
/// `:`
151149
Colon,
152-
/// "$"
150+
/// `$`
153151
Dollar,
154-
/// "="
152+
/// `=`
155153
Eq,
156-
/// "!"
154+
/// `!`
157155
Bang,
158-
/// "<"
156+
/// `<`
159157
Lt,
160-
/// ">"
158+
/// `>`
161159
Gt,
162-
/// "-"
160+
/// `-`
163161
Minus,
164-
/// "&"
162+
/// `&`
165163
And,
166-
/// "|"
164+
/// `|`
167165
Or,
168-
/// "+"
166+
/// `+`
169167
Plus,
170-
/// "*"
168+
/// `*`
171169
Star,
172-
/// "/"
170+
/// `/`
173171
Slash,
174-
/// "^"
172+
/// `^`
175173
Caret,
176-
/// "%"
174+
/// `%`
177175
Percent,
178176

179177
/// Unknown token, not expected by the lexer, e.g. "№"

0 commit comments

Comments
 (0)