@@ -8,7 +8,7 @@ use rustc_session::lint::builtin::RESERVED_PREFIX;
8
8
use rustc_session:: lint:: BuiltinLintDiagnostics ;
9
9
use rustc_session:: parse:: ParseSess ;
10
10
use rustc_span:: symbol:: { sym, Symbol } ;
11
- use rustc_span:: { BytePos , Pos , Span } ;
11
+ use rustc_span:: { edition :: Edition , BytePos , Pos , Span } ;
12
12
13
13
use tracing:: debug;
14
14
@@ -507,20 +507,22 @@ impl<'a> StringReader<'a> {
507
507
let prefix_span = self . mk_sp ( start, self . pos ) ;
508
508
let msg = format ! ( "prefix `{}` is unknown" , self . str_from_to( start, self . pos) ) ;
509
509
510
- if prefix_span. rust_2021 ( ) {
510
+ let expn_data = prefix_span. ctxt ( ) . outer_expn_data ( ) ;
511
+
512
+ if expn_data. edition >= Edition :: Edition2021 {
511
513
// 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 ) ,
514
+ let mut err = self . sess . span_diagnostic . struct_span_err ( prefix_span, & msg) ;
515
+ err. span_label ( prefix_span, "unknown prefix" ) ;
516
+ if expn_data. is_root ( ) {
517
+ err. span_suggestion_verbose (
518
+ prefix_span. shrink_to_hi ( ) ,
518
519
"consider inserting whitespace here" ,
519
520
" " . into ( ) ,
520
521
Applicability :: MachineApplicable ,
521
- )
522
- . note ( "prefixed identifiers and literals are reserved since Rust 2021" )
523
- . emit ( ) ;
522
+ ) ;
523
+ }
524
+ err. note ( "prefixed identifiers and literals are reserved since Rust 2021" ) ;
525
+ err. emit ( ) ;
524
526
} else {
525
527
// Before Rust 2021, only emit a lint for migration.
526
528
self . sess . buffer_lint_with_diagnostic (
0 commit comments