@@ -8,7 +8,7 @@ use rustc_ast::token::{self, CommentKind, Delimiter, Token, TokenKind};
8
8
use rustc_ast:: tokenstream:: TokenStream ;
9
9
use rustc_ast:: util:: unicode:: contains_text_flow_control_chars;
10
10
use rustc_errors:: {
11
- error_code, Applicability , Diagnostic , DiagnosticBuilder , FatalAbort , StashKey ,
11
+ error_code, Applicability , DiagCtxt , Diagnostic , DiagnosticBuilder , FatalAbort , StashKey ,
12
12
} ;
13
13
use rustc_lexer:: unescape:: { self , EscapeError , Mode } ;
14
14
use rustc_lexer:: { Base , DocStyle , RawStrError } ;
@@ -110,6 +110,10 @@ struct StringReader<'a> {
110
110
}
111
111
112
112
impl < ' a > StringReader < ' a > {
113
+ pub fn dcx ( & self ) -> & ' a DiagCtxt {
114
+ & self . sess . dcx
115
+ }
116
+
113
117
fn mk_sp ( & self , lo : BytePos , hi : BytePos ) -> Span {
114
118
self . override_span . unwrap_or_else ( || Span :: with_root_ctxt ( lo, hi) )
115
119
}
@@ -176,7 +180,7 @@ impl<'a> StringReader<'a> {
176
180
let span = self . mk_sp ( start, self . pos ) ;
177
181
self . sess . symbol_gallery . insert ( sym, span) ;
178
182
if !sym. can_be_raw ( ) {
179
- self . sess . emit_err ( errors:: CannotBeRawIdent { span, ident : sym } ) ;
183
+ self . dcx ( ) . emit_err ( errors:: CannotBeRawIdent { span, ident : sym } ) ;
180
184
}
181
185
self . sess . raw_identifier_spans . push ( span) ;
182
186
token:: Ident ( sym, true )
@@ -247,7 +251,7 @@ impl<'a> StringReader<'a> {
247
251
let lifetime_name = self . str_from ( start) ;
248
252
if starts_with_number {
249
253
let span = self . mk_sp ( start, self . pos ) ;
250
- let mut diag = self . sess . struct_err ( "lifetimes cannot start with a number" ) ;
254
+ let mut diag = self . dcx ( ) . struct_err ( "lifetimes cannot start with a number" ) ;
251
255
diag. set_span ( span) ;
252
256
diag. stash ( span, StashKey :: LifetimeIsChar ) ;
253
257
}
@@ -308,7 +312,7 @@ impl<'a> StringReader<'a> {
308
312
// fancier error recovery to it, as there will be less overall work to do this
309
313
// way.
310
314
let ( token, sugg) = unicode_chars:: check_for_substitution ( self , start, c, repeats+1 ) ;
311
- self . sess . emit_err ( errors:: UnknownTokenStart {
315
+ self . dcx ( ) . emit_err ( errors:: UnknownTokenStart {
312
316
span : self . mk_sp ( start, self . pos + Pos :: from_usize ( repeats * c. len_utf8 ( ) ) ) ,
313
317
escaped : escaped_char ( c) ,
314
318
sugg,
@@ -384,7 +388,7 @@ impl<'a> StringReader<'a> {
384
388
content_start + BytePos ( idx as u32 + 1 ) ,
385
389
) ;
386
390
let block = matches ! ( comment_kind, CommentKind :: Block ) ;
387
- self . sess . emit_err ( errors:: CrDocComment { span, block } ) ;
391
+ self . dcx ( ) . emit_err ( errors:: CrDocComment { span, block } ) ;
388
392
}
389
393
}
390
394
@@ -483,7 +487,7 @@ impl<'a> StringReader<'a> {
483
487
rustc_lexer:: LiteralKind :: Int { base, empty_int } => {
484
488
if empty_int {
485
489
let span = self . mk_sp ( start, end) ;
486
- self . sess . emit_err ( errors:: NoDigitsLiteral { span } ) ;
490
+ self . dcx ( ) . emit_err ( errors:: NoDigitsLiteral { span } ) ;
487
491
( token:: Integer , sym:: integer ( 0 ) )
488
492
} else {
489
493
if matches ! ( base, Base :: Binary | Base :: Octal ) {
@@ -495,7 +499,7 @@ impl<'a> StringReader<'a> {
495
499
start + BytePos :: from_usize ( 2 + idx + c. len_utf8 ( ) ) ,
496
500
) ;
497
501
if c != '_' && c. to_digit ( base) . is_none ( ) {
498
- self . sess . emit_err ( errors:: InvalidDigitLiteral { span, base } ) ;
502
+ self . dcx ( ) . emit_err ( errors:: InvalidDigitLiteral { span, base } ) ;
499
503
}
500
504
}
501
505
}
@@ -505,7 +509,7 @@ impl<'a> StringReader<'a> {
505
509
rustc_lexer:: LiteralKind :: Float { base, empty_exponent } => {
506
510
if empty_exponent {
507
511
let span = self . mk_sp ( start, self . pos ) ;
508
- self . sess . emit_err ( errors:: EmptyExponentFloat { span } ) ;
512
+ self . dcx ( ) . emit_err ( errors:: EmptyExponentFloat { span } ) ;
509
513
}
510
514
let base = match base {
511
515
Base :: Hexadecimal => Some ( "hexadecimal" ) ,
@@ -515,7 +519,7 @@ impl<'a> StringReader<'a> {
515
519
} ;
516
520
if let Some ( base) = base {
517
521
let span = self . mk_sp ( start, end) ;
518
- self . sess . emit_err ( errors:: FloatLiteralUnsupportedBase { span, base } ) ;
522
+ self . dcx ( ) . emit_err ( errors:: FloatLiteralUnsupportedBase { span, base } ) ;
519
523
}
520
524
( token:: Float , self . symbol_from_to ( start, end) )
521
525
}
@@ -678,7 +682,7 @@ impl<'a> StringReader<'a> {
678
682
} else {
679
683
None
680
684
} ;
681
- self . sess . emit_err ( errors:: UnknownPrefix { span : prefix_span, prefix, sugg } ) ;
685
+ self . dcx ( ) . emit_err ( errors:: UnknownPrefix { span : prefix_span, prefix, sugg } ) ;
682
686
} else {
683
687
// Before Rust 2021, only emit a lint for migration.
684
688
self . sess . buffer_lint_with_diagnostic (
@@ -692,7 +696,7 @@ impl<'a> StringReader<'a> {
692
696
}
693
697
694
698
fn report_too_many_hashes ( & self , start : BytePos , num : u32 ) -> ! {
695
- self . sess . emit_fatal ( errors:: TooManyHashes { span : self . mk_sp ( start, self . pos ) , num } ) ;
699
+ self . dcx ( ) . emit_fatal ( errors:: TooManyHashes { span : self . mk_sp ( start, self . pos ) , num } ) ;
696
700
}
697
701
698
702
fn cook_common (
0 commit comments