@@ -7,7 +7,6 @@ use rustc_lexer::{Base, DocStyle, RawStrError};
7
7
use rustc_session:: lint:: builtin:: RESERVED_PREFIX ;
8
8
use rustc_session:: lint:: BuiltinLintDiagnostics ;
9
9
use rustc_session:: parse:: ParseSess ;
10
- use rustc_span:: edition:: Edition ;
11
10
use rustc_span:: symbol:: { sym, Symbol } ;
12
11
use rustc_span:: { BytePos , Pos , Span } ;
13
12
@@ -508,28 +507,30 @@ impl<'a> StringReader<'a> {
508
507
let prefix_span = self . mk_sp ( start, self . pos ) ;
509
508
let msg = format ! ( "prefix `{}` is unknown" , self . str_from_to( start, self . pos) ) ;
510
509
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.
512
526
self . sess . buffer_lint_with_diagnostic (
513
527
& RESERVED_PREFIX ,
514
528
prefix_span,
515
529
ast:: CRATE_NODE_ID ,
516
530
& msg,
517
531
BuiltinLintDiagnostics :: ReservedPrefix ( prefix_span) ,
518
532
) ;
519
- return ;
520
533
}
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 ( ) ;
533
534
}
534
535
535
536
/// Note: It was decided to not add a test case, because it would be too big.
0 commit comments