@@ -3,9 +3,7 @@ use rustc_ast::ast::{self, AttrStyle};
3
3
use rustc_ast:: token:: { self , CommentKind , Token , TokenKind } ;
4
4
use rustc_ast:: tokenstream:: { Spacing , TokenStream } ;
5
5
use rustc_ast:: util:: unicode:: contains_text_flow_control_chars;
6
- use rustc_errors:: {
7
- error_code, Applicability , DiagnosticBuilder , ErrorGuaranteed , FatalError , PResult ,
8
- } ;
6
+ use rustc_errors:: { error_code, Applicability , DiagnosticBuilder , ErrorGuaranteed , PResult } ;
9
7
use rustc_lexer:: unescape:: { self , Mode } ;
10
8
use rustc_lexer:: { Base , DocStyle , RawStrError } ;
11
9
use rustc_session:: lint:: builtin:: {
@@ -104,7 +102,7 @@ impl<'a> StringReader<'a> {
104
102
}
105
103
106
104
/// Report a fatal lexical error with a given span.
107
- fn fatal_span ( & self , sp : Span , m : & str ) -> FatalError {
105
+ fn fatal_span ( & self , sp : Span , m : & str ) -> ! {
108
106
self . sess . span_diagnostic . span_fatal ( sp, m)
109
107
}
110
108
@@ -114,7 +112,7 @@ impl<'a> StringReader<'a> {
114
112
}
115
113
116
114
/// Report a fatal error spanning [`from_pos`, `to_pos`).
117
- fn fatal_span_ ( & self , from_pos : BytePos , to_pos : BytePos , m : & str ) -> FatalError {
115
+ fn fatal_span_ ( & self , from_pos : BytePos , to_pos : BytePos , m : & str ) -> ! {
118
116
self . fatal_span ( self . mk_sp ( from_pos, to_pos) , m)
119
117
}
120
118
@@ -129,12 +127,24 @@ impl<'a> StringReader<'a> {
129
127
to_pos : BytePos ,
130
128
m : & str ,
131
129
c : char ,
132
- ) -> DiagnosticBuilder < ' a , ErrorGuaranteed > {
130
+ ) -> DiagnosticBuilder < ' a , ! > {
133
131
self . sess
134
132
. span_diagnostic
135
133
. struct_span_fatal ( self . mk_sp ( from_pos, to_pos) , & format ! ( "{}: {}" , m, escaped_char( c) ) )
136
134
}
137
135
136
+ fn struct_err_span_char (
137
+ & self ,
138
+ from_pos : BytePos ,
139
+ to_pos : BytePos ,
140
+ m : & str ,
141
+ c : char ,
142
+ ) -> DiagnosticBuilder < ' a , ErrorGuaranteed > {
143
+ self . sess
144
+ . span_diagnostic
145
+ . struct_span_err ( self . mk_sp ( from_pos, to_pos) , & format ! ( "{}: {}" , m, escaped_char( c) ) )
146
+ }
147
+
138
148
/// Detect usages of Unicode codepoints changing the direction of the text on screen and loudly
139
149
/// complain about it.
140
150
fn lint_unicode_text_flow ( & self , start : BytePos ) {
@@ -311,7 +321,7 @@ impl<'a> StringReader<'a> {
311
321
rustc_lexer:: TokenKind :: Unknown | rustc_lexer:: TokenKind :: InvalidIdent => {
312
322
let c = self . str_from ( start) . chars ( ) . next ( ) . unwrap ( ) ;
313
323
let mut err =
314
- self . struct_fatal_span_char ( start, self . pos , "unknown start of token" , c) ;
324
+ self . struct_err_span_char ( start, self . pos , "unknown start of token" , c) ;
315
325
// FIXME: the lexer could be used to turn the ASCII version of unicode homoglyphs,
316
326
// instead of keeping a table in `check_for_substitution`into the token. Ideally,
317
327
// this should be inside `rustc_lexer`. However, we should first remove compound
@@ -503,8 +513,7 @@ impl<'a> StringReader<'a> {
503
513
"found invalid character; only `#` is allowed in raw string delimitation" ,
504
514
bad_char,
505
515
)
506
- . emit ( ) ;
507
- FatalError . raise ( )
516
+ . emit ( )
508
517
}
509
518
510
519
fn report_unterminated_raw_string (
@@ -541,8 +550,7 @@ impl<'a> StringReader<'a> {
541
550
) ;
542
551
}
543
552
544
- err. emit ( ) ;
545
- FatalError . raise ( )
553
+ err. emit ( )
546
554
}
547
555
548
556
// RFC 3101 introduced the idea of (reserved) prefixes. As of Rust 2021,
@@ -601,7 +609,6 @@ impl<'a> StringReader<'a> {
601
609
found
602
610
) ,
603
611
)
604
- . raise ( ) ;
605
612
}
606
613
607
614
fn validate_literal_escape (
0 commit comments