about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMara Bos <m-ou.se@m-ou.se>2021-06-14 16:48:07 +0000
committerlrh2000 <lrh2000@pku.edu.cn>2021-06-26 23:11:13 +0800
commitd40be0fc6418affeeb765a9b6a99315e90aa57c8 (patch)
treebb231629cba958563844965de1eda2cbd257c897
parent6adce70a58808426753fa8e74068dcb959c004a6 (diff)
downloadrust-d40be0fc6418affeeb765a9b6a99315e90aa57c8.tar.gz
rust-d40be0fc6418affeeb765a9b6a99315e90aa57c8.zip
Check the span's edition for the reserved prefixes.
-rw-r--r--compiler/rustc_parse/src/lexer/mod.rs31
1 files changed, 16 insertions, 15 deletions
diff --git a/compiler/rustc_parse/src/lexer/mod.rs b/compiler/rustc_parse/src/lexer/mod.rs
index b694217b58a..21a6ace7cf4 100644
--- a/compiler/rustc_parse/src/lexer/mod.rs
+++ b/compiler/rustc_parse/src/lexer/mod.rs
@@ -7,7 +7,6 @@ use rustc_lexer::{Base, DocStyle, RawStrError};
 use rustc_session::lint::builtin::RESERVED_PREFIX;
 use rustc_session::lint::BuiltinLintDiagnostics;
 use rustc_session::parse::ParseSess;
-use rustc_span::edition::Edition;
 use rustc_span::symbol::{sym, Symbol};
 use rustc_span::{BytePos, Pos, Span};
 
@@ -508,7 +507,22 @@ impl<'a> StringReader<'a> {
         let prefix_span = self.mk_sp(start, self.pos);
         let msg = format!("prefix `{}` is unknown", self.str_from_to(start, self.pos));
 
-        if self.sess.edition < Edition::Edition2021 {
+        if prefix_span.rust_2021() {
+            // In Rust 2021, this is a hard error.
+            self.sess
+                .span_diagnostic
+                .struct_span_err(prefix_span, &msg)
+                .span_label(prefix_span, "unknown prefix")
+                .span_suggestion_verbose(
+                    self.mk_sp(self.pos, self.pos),
+                    "consider inserting whitespace here",
+                    " ".into(),
+                    Applicability::MachineApplicable,
+                )
+                .note("prefixed identifiers and literals are reserved since Rust 2021")
+                .emit();
+        } else {
+            // Before Rust 2021, only emit a lint for migration.
             self.sess.buffer_lint_with_diagnostic(
                 &RESERVED_PREFIX,
                 prefix_span,
@@ -516,20 +530,7 @@ impl<'a> StringReader<'a> {
                 &msg,
                 BuiltinLintDiagnostics::ReservedPrefix(prefix_span),
             );
-            return;
         }
-
-        let mut err = self.sess.span_diagnostic.struct_span_err(prefix_span, &msg);
-        err.span_label(prefix_span, "unknown prefix");
-        err.span_suggestion_verbose(
-            self.mk_sp(self.pos, self.pos),
-            "consider inserting whitespace here",
-            " ".into(),
-            Applicability::MachineApplicable,
-        );
-        err.note("prefixed identifiers and literals are reserved since Rust 2021");
-
-        err.emit();
     }
 
     /// Note: It was decided to not add a test case, because it would be too big.