Skip to content

Commit 6adce70

Browse files
m-ou-senikomatsakis
authored andcommitted
Improve comments for reserved prefixes.
Co-authored-by: Niko Matsakis <niko@alum.mit.edu>
1 parent 3b18e21 commit 6adce70

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

compiler/rustc_lexer/src/lib.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,12 @@ pub enum TokenKind {
6666
Ident,
6767
/// "r#ident"
6868
RawIdent,
69-
/// `foo#`, `foo'`, `foo"`. Note the tailer is not included.
69+
/// An unknown prefix like `foo#`, `foo'`, `foo"`. Note that only the
70+
/// prefix (`foo`) is included in the token, not the separator (which is
71+
/// lexed as its own distinct token). In Rust 2021 and later, reserved
72+
/// prefixes are reported as errors; in earlier editions, they result in a
73+
/// (allowed by default) lint, and are treated as regular identifier
74+
/// tokens.
7075
BadPrefix,
7176
/// "12_u8", "1.0e-40", "b"123"". See `LiteralKind` for more details.
7277
Literal { kind: LiteralKind, suffix_start: usize },
@@ -493,7 +498,7 @@ impl Cursor<'_> {
493498
debug_assert!(is_id_start(self.prev()));
494499
// Start is already eaten, eat the rest of identifier.
495500
self.eat_while(is_id_continue);
496-
// Good prefixes must have been handled eariler. So if
501+
// Good prefixes must have been handled earlier. So if
497502
// we see a prefix here, it is definitely a bad prefix.
498503
match self.first() {
499504
'#' | '"' | '\'' => BadPrefix,

compiler/rustc_parse/src/lexer/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,10 @@ impl<'a> StringReader<'a> {
500500
FatalError.raise()
501501
}
502502

503-
// See RFC 3101.
503+
// RFC 3101 introduced the idea of (reserved) prefixes. As of Rust 2021,
504+
// using a (unknown) prefix is an error. In earlier editions, however, they
505+
// only result in a (allowed by default) lint, and are treated as regular
506+
// identifier tokens.
504507
fn report_reserved_prefix(&self, start: BytePos) {
505508
let prefix_span = self.mk_sp(start, self.pos);
506509
let msg = format!("prefix `{}` is unknown", self.str_from_to(start, self.pos));

0 commit comments

Comments
 (0)