@@ -8,7 +8,7 @@ use rustc_session::lint::builtin::RESERVED_PREFIX;
88use rustc_session:: lint:: BuiltinLintDiagnostics ;
99use rustc_session:: parse:: ParseSess ;
1010use rustc_span:: symbol:: { sym, Symbol } ;
11- use rustc_span:: { BytePos , Pos , Span } ;
11+ use rustc_span:: { edition :: Edition , BytePos , Pos , Span } ;
1212
1313use tracing:: debug;
1414
@@ -507,20 +507,22 @@ impl<'a> StringReader<'a> {
507507 let prefix_span = self . mk_sp ( start, self . pos ) ;
508508 let msg = format ! ( "prefix `{}` is unknown" , self . str_from_to( start, self . pos) ) ;
509509
510- if prefix_span. rust_2021 ( ) {
510+ let expn_data = prefix_span. ctxt ( ) . outer_expn_data ( ) ;
511+
512+ if expn_data. edition >= Edition :: Edition2021 {
511513 // 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 ( ) ,
518519 "consider inserting whitespace here" ,
519520 " " . into ( ) ,
520521 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 ( ) ;
524526 } else {
525527 // Before Rust 2021, only emit a lint for migration.
526528 self . sess . buffer_lint_with_diagnostic (
0 commit comments