Skip to content

Commit d40be0f

Browse files
m-ou-selrh2000
authored andcommitted
Check the span's edition for the reserved prefixes.
1 parent 6adce70 commit d40be0f

File tree

1 file changed

+16
-15
lines changed
  • compiler/rustc_parse/src/lexer

1 file changed

+16
-15
lines changed

compiler/rustc_parse/src/lexer/mod.rs

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use rustc_lexer::{Base, DocStyle, RawStrError};
77
use rustc_session::lint::builtin::RESERVED_PREFIX;
88
use rustc_session::lint::BuiltinLintDiagnostics;
99
use rustc_session::parse::ParseSess;
10-
use rustc_span::edition::Edition;
1110
use rustc_span::symbol::{sym, Symbol};
1211
use rustc_span::{BytePos, Pos, Span};
1312

@@ -508,28 +507,30 @@ impl<'a> StringReader<'a> {
508507
let prefix_span = self.mk_sp(start, self.pos);
509508
let msg = format!("prefix `{}` is unknown", self.str_from_to(start, self.pos));
510509

511-
if self.sess.edition < Edition::Edition2021 {
510+
if prefix_span.rust_2021() {
511+
// In Rust 2021, this is a hard error.
512+
self.sess
513+
.span_diagnostic
514+
.struct_span_err(prefix_span, &msg)
515+
.span_label(prefix_span, "unknown prefix")
516+
.span_suggestion_verbose(
517+
self.mk_sp(self.pos, self.pos),
518+
"consider inserting whitespace here",
519+
" ".into(),
520+
Applicability::MachineApplicable,
521+
)
522+
.note("prefixed identifiers and literals are reserved since Rust 2021")
523+
.emit();
524+
} else {
525+
// Before Rust 2021, only emit a lint for migration.
512526
self.sess.buffer_lint_with_diagnostic(
513527
&RESERVED_PREFIX,
514528
prefix_span,
515529
ast::CRATE_NODE_ID,
516530
&msg,
517531
BuiltinLintDiagnostics::ReservedPrefix(prefix_span),
518532
);
519-
return;
520533
}
521-
522-
let mut err = self.sess.span_diagnostic.struct_span_err(prefix_span, &msg);
523-
err.span_label(prefix_span, "unknown prefix");
524-
err.span_suggestion_verbose(
525-
self.mk_sp(self.pos, self.pos),
526-
"consider inserting whitespace here",
527-
" ".into(),
528-
Applicability::MachineApplicable,
529-
);
530-
err.note("prefixed identifiers and literals are reserved since Rust 2021");
531-
532-
err.emit();
533534
}
534535

535536
/// Note: It was decided to not add a test case, because it would be too big.

0 commit comments

Comments
 (0)