about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMara Bos <m-ou.se@m-ou.se>2021-06-14 16:46:46 +0000
committerlrh2000 <lrh2000@pku.edu.cn>2021-06-26 23:11:13 +0800
commit6adce70a58808426753fa8e74068dcb959c004a6 (patch)
tree119b5c5e56f86f635445cc25c36de62f93af2849
parent3b18e215a3517bf32cc598b6e14743b14e4a928e (diff)
downloadrust-6adce70a58808426753fa8e74068dcb959c004a6.tar.gz
rust-6adce70a58808426753fa8e74068dcb959c004a6.zip
Improve comments for reserved prefixes.
Co-authored-by: Niko Matsakis <niko@alum.mit.edu>
-rw-r--r--compiler/rustc_lexer/src/lib.rs9
-rw-r--r--compiler/rustc_parse/src/lexer/mod.rs5
2 files changed, 11 insertions, 3 deletions
diff --git a/compiler/rustc_lexer/src/lib.rs b/compiler/rustc_lexer/src/lib.rs
index 5f3e245bf99..4a8f34e2815 100644
--- a/compiler/rustc_lexer/src/lib.rs
+++ b/compiler/rustc_lexer/src/lib.rs
@@ -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,
diff --git a/compiler/rustc_parse/src/lexer/mod.rs b/compiler/rustc_parse/src/lexer/mod.rs
index f50e8a8db01..b694217b58a 100644
--- a/compiler/rustc_parse/src/lexer/mod.rs
+++ b/compiler/rustc_parse/src/lexer/mod.rs
@@ -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));