Improve comments for reserved prefixes.

Co-authored-by: Niko Matsakis <niko@alum.mit.edu>
This commit is contained in:
Mara Bos 2021-06-14 16:46:46 +00:00 committed by lrh2000
parent 3b18e215a3
commit 6adce70a58
2 changed files with 11 additions and 3 deletions

View File

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

View File

@ -500,7 +500,10 @@ impl<'a> StringReader<'a> {
FatalError.raise()
}
// See RFC 3101.
// RFC 3101 introduced the idea of (reserved) prefixes. As of Rust 2021,
// using a (unknown) prefix is an error. In earlier editions, however, they
// only result in a (allowed by default) lint, and are treated as regular
// identifier tokens.
fn report_reserved_prefix(&self, start: BytePos) {
let prefix_span = self.mk_sp(start, self.pos);
let msg = format!("prefix `{}` is unknown", self.str_from_to(start, self.pos));