@@ -3,9 +3,7 @@ use rustc_ast::ast::{self, AttrStyle};
33use rustc_ast:: token:: { self , CommentKind , Token , TokenKind } ;
44use rustc_ast:: tokenstream:: { Spacing , TokenStream } ;
55use 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 } ;
97use rustc_lexer:: unescape:: { self , Mode } ;
108use rustc_lexer:: { Base , DocStyle , RawStrError } ;
119use rustc_session:: lint:: builtin:: {
@@ -104,7 +102,7 @@ impl<'a> StringReader<'a> {
104102 }
105103
106104 /// 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 ) -> ! {
108106 self . sess . span_diagnostic . span_fatal ( sp, m)
109107 }
110108
@@ -114,7 +112,7 @@ impl<'a> StringReader<'a> {
114112 }
115113
116114 /// 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 ) -> ! {
118116 self . fatal_span ( self . mk_sp ( from_pos, to_pos) , m)
119117 }
120118
@@ -129,12 +127,24 @@ impl<'a> StringReader<'a> {
129127 to_pos : BytePos ,
130128 m : & str ,
131129 c : char ,
132- ) -> DiagnosticBuilder < ' a , ErrorGuaranteed > {
130+ ) -> DiagnosticBuilder < ' a , ! > {
133131 self . sess
134132 . span_diagnostic
135133 . struct_span_fatal ( self . mk_sp ( from_pos, to_pos) , & format ! ( "{}: {}" , m, escaped_char( c) ) )
136134 }
137135
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+
138148 /// Detect usages of Unicode codepoints changing the direction of the text on screen and loudly
139149 /// complain about it.
140150 fn lint_unicode_text_flow ( & self , start : BytePos ) {
@@ -311,7 +321,7 @@ impl<'a> StringReader<'a> {
311321 rustc_lexer:: TokenKind :: Unknown | rustc_lexer:: TokenKind :: InvalidIdent => {
312322 let c = self . str_from ( start) . chars ( ) . next ( ) . unwrap ( ) ;
313323 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) ;
315325 // FIXME: the lexer could be used to turn the ASCII version of unicode homoglyphs,
316326 // instead of keeping a table in `check_for_substitution`into the token. Ideally,
317327 // this should be inside `rustc_lexer`. However, we should first remove compound
@@ -503,8 +513,7 @@ impl<'a> StringReader<'a> {
503513 "found invalid character; only `#` is allowed in raw string delimitation" ,
504514 bad_char,
505515 )
506- . emit ( ) ;
507- FatalError . raise ( )
516+ . emit ( )
508517 }
509518
510519 fn report_unterminated_raw_string (
@@ -541,8 +550,7 @@ impl<'a> StringReader<'a> {
541550 ) ;
542551 }
543552
544- err. emit ( ) ;
545- FatalError . raise ( )
553+ err. emit ( )
546554 }
547555
548556 // RFC 3101 introduced the idea of (reserved) prefixes. As of Rust 2021,
@@ -601,7 +609,6 @@ impl<'a> StringReader<'a> {
601609 found
602610 ) ,
603611 )
604- . raise ( ) ;
605612 }
606613
607614 fn validate_literal_escape (
0 commit comments