11
11
use ast;
12
12
use codemap:: { BytePos , CharPos , CodeMap , Pos , Span } ;
13
13
use codemap;
14
+ use diagnostic:: FatalError ;
14
15
use diagnostic:: SpanHandler ;
15
16
use ext:: tt:: transcribe:: tt_next_token;
16
17
use parse:: token:: str_to_ident;
@@ -30,7 +31,7 @@ pub trait Reader {
30
31
fn is_eof ( & self ) -> bool ;
31
32
fn next_token ( & mut self ) -> TokenAndSpan ;
32
33
/// Report a fatal error with the current span.
33
- fn fatal ( & self , & str ) -> ! ;
34
+ fn fatal ( & self , & str ) -> FatalError ;
34
35
/// Report a non-fatal error with the current span.
35
36
fn err ( & self , & str ) ;
36
37
fn peek ( & self ) -> TokenAndSpan ;
@@ -86,7 +87,7 @@ impl<'a> Reader for StringReader<'a> {
86
87
self . advance_token ( ) ;
87
88
ret_val
88
89
}
89
- fn fatal ( & self , m : & str ) -> ! {
90
+ fn fatal ( & self , m : & str ) -> FatalError {
90
91
self . fatal_span ( self . peek_span , m)
91
92
}
92
93
fn err ( & self , m : & str ) {
@@ -110,8 +111,8 @@ impl<'a> Reader for TtReader<'a> {
110
111
debug ! ( "TtReader: r={:?}" , r) ;
111
112
r
112
113
}
113
- fn fatal ( & self , m : & str ) -> ! {
114
- panic ! ( self . sp_diag. span_fatal( self . cur_span, m) ) ;
114
+ fn fatal ( & self , m : & str ) -> FatalError {
115
+ self . sp_diag . span_fatal ( self . cur_span , m)
115
116
}
116
117
fn err ( & self , m : & str ) {
117
118
self . sp_diag . span_err ( self . cur_span , m) ;
@@ -163,8 +164,8 @@ impl<'a> StringReader<'a> {
163
164
}
164
165
165
166
/// Report a fatal lexical error with a given span.
166
- pub fn fatal_span ( & self , sp : Span , m : & str ) -> ! {
167
- panic ! ( self . span_diagnostic. span_fatal( sp, m) )
167
+ pub fn fatal_span ( & self , sp : Span , m : & str ) -> FatalError {
168
+ self . span_diagnostic . span_fatal ( sp, m)
168
169
}
169
170
170
171
/// Report a lexical error with a given span.
@@ -178,7 +179,7 @@ impl<'a> StringReader<'a> {
178
179
}
179
180
180
181
/// Report a fatal error spanning [`from_pos`, `to_pos`).
181
- fn fatal_span_ ( & self , from_pos : BytePos , to_pos : BytePos , m : & str ) -> ! {
182
+ fn fatal_span_ ( & self , from_pos : BytePos , to_pos : BytePos , m : & str ) -> FatalError {
182
183
self . fatal_span ( codemap:: mk_sp ( from_pos, to_pos) , m)
183
184
}
184
185
@@ -194,11 +195,11 @@ impl<'a> StringReader<'a> {
194
195
195
196
/// Report a lexical error spanning [`from_pos`, `to_pos`), appending an
196
197
/// escaped character to the error message
197
- fn fatal_span_char ( & self , from_pos : BytePos , to_pos : BytePos , m : & str , c : char ) -> ! {
198
+ fn fatal_span_char ( & self , from_pos : BytePos , to_pos : BytePos , m : & str , c : char ) -> FatalError {
198
199
let mut m = m. to_string ( ) ;
199
200
m. push_str ( ": " ) ;
200
201
for c in c. escape_default ( ) { m. push ( c) }
201
- self . fatal_span_ ( from_pos, to_pos, & m[ ..] ) ;
202
+ self . fatal_span_ ( from_pos, to_pos, & m[ ..] )
202
203
}
203
204
204
205
/// Report a lexical error spanning [`from_pos`, `to_pos`), appending an
@@ -212,12 +213,12 @@ impl<'a> StringReader<'a> {
212
213
213
214
/// Report a lexical error spanning [`from_pos`, `to_pos`), appending the
214
215
/// offending string to the error message
215
- fn fatal_span_verbose ( & self , from_pos : BytePos , to_pos : BytePos , mut m : String ) -> ! {
216
+ fn fatal_span_verbose ( & self , from_pos : BytePos , to_pos : BytePos , mut m : String ) -> FatalError {
216
217
m. push_str ( ": " ) ;
217
218
let from = self . byte_offset ( from_pos) . to_usize ( ) ;
218
219
let to = self . byte_offset ( to_pos) . to_usize ( ) ;
219
220
m. push_str ( & self . source_text [ from..to] ) ;
220
- self . fatal_span_ ( from_pos, to_pos, & m[ ..] ) ;
221
+ self . fatal_span_ ( from_pos, to_pos, & m[ ..] )
221
222
}
222
223
223
224
/// Advance peek_tok and peek_span to refer to the next token, and
@@ -538,7 +539,7 @@ impl<'a> StringReader<'a> {
538
539
"unterminated block comment"
539
540
} ;
540
541
let last_bpos = self . last_pos ;
541
- self . fatal_span_ ( start_bpos, last_bpos, msg) ;
542
+ panic ! ( self . fatal_span_( start_bpos, last_bpos, msg) ) ;
542
543
}
543
544
let n = self . curr . unwrap ( ) ;
544
545
match n {
@@ -682,7 +683,9 @@ impl<'a> StringReader<'a> {
682
683
for _ in 0 ..n_digits {
683
684
if self . is_eof ( ) {
684
685
let last_bpos = self . last_pos ;
685
- self . fatal_span_ ( start_bpos, last_bpos, "unterminated numeric character escape" ) ;
686
+ panic ! ( self . fatal_span_( start_bpos,
687
+ last_bpos,
688
+ "unterminated numeric character escape" ) ) ;
686
689
}
687
690
if self . curr_is ( delim) {
688
691
let last_bpos = self . last_pos ;
@@ -835,15 +838,15 @@ impl<'a> StringReader<'a> {
835
838
let c = match self . curr {
836
839
Some ( c) => c,
837
840
None => {
838
- self . fatal_span_ ( start_bpos, self . last_pos ,
839
- "unterminated unicode escape (found EOF)" ) ;
841
+ panic ! ( self . fatal_span_( start_bpos, self . last_pos,
842
+ "unterminated unicode escape (found EOF)" ) ) ;
840
843
}
841
844
} ;
842
845
accum_int *= 16 ;
843
846
accum_int += c. to_digit ( 16 ) . unwrap_or_else ( || {
844
847
if c == delim {
845
- self . fatal_span_ ( self . last_pos , self . pos ,
846
- "unterminated unicode escape (needed a `}`)" ) ;
848
+ panic ! ( self . fatal_span_( self . last_pos, self . pos,
849
+ "unterminated unicode escape (needed a `}`)" ) ) ;
847
850
} else {
848
851
self . err_span_char ( self . last_pos , self . pos ,
849
852
"invalid character in unicode escape" , c) ;
@@ -1077,12 +1080,12 @@ impl<'a> StringReader<'a> {
1077
1080
let valid = self . scan_char_or_byte ( start, c2, /* ascii_only = */ false , '\'' ) ;
1078
1081
if !self . curr_is ( '\'' ) {
1079
1082
let last_bpos = self . last_pos ;
1080
- self . fatal_span_verbose (
1083
+ panic ! ( self . fatal_span_verbose(
1081
1084
// Byte offsetting here is okay because the
1082
1085
// character before position `start` is an
1083
1086
// ascii single quote.
1084
1087
start - BytePos ( 1 ) , last_bpos,
1085
- "unterminated character constant" . to_string ( ) ) ;
1088
+ "unterminated character constant" . to_string( ) ) ) ;
1086
1089
}
1087
1090
let id = if valid { self . name_from ( start) } else { token:: intern ( "0" ) } ;
1088
1091
self . bump ( ) ; // advance curr past token
@@ -1107,7 +1110,9 @@ impl<'a> StringReader<'a> {
1107
1110
while !self . curr_is ( '"' ) {
1108
1111
if self . is_eof ( ) {
1109
1112
let last_bpos = self . last_pos ;
1110
- self . fatal_span_ ( start_bpos, last_bpos, "unterminated double quote string" ) ;
1113
+ panic ! ( self . fatal_span_( start_bpos,
1114
+ last_bpos,
1115
+ "unterminated double quote string" ) ) ;
1111
1116
}
1112
1117
1113
1118
let ch_start = self . last_pos ;
@@ -1133,14 +1138,14 @@ impl<'a> StringReader<'a> {
1133
1138
1134
1139
if self . is_eof ( ) {
1135
1140
let last_bpos = self . last_pos ;
1136
- self . fatal_span_ ( start_bpos, last_bpos, "unterminated raw string" ) ;
1141
+ panic ! ( self . fatal_span_( start_bpos, last_bpos, "unterminated raw string" ) ) ;
1137
1142
} else if !self . curr_is ( '"' ) {
1138
1143
let last_bpos = self . last_pos ;
1139
1144
let curr_char = self . curr . unwrap ( ) ;
1140
- self . fatal_span_char ( start_bpos, last_bpos,
1145
+ panic ! ( self . fatal_span_char( start_bpos, last_bpos,
1141
1146
"found invalid character; \
1142
1147
only `#` is allowed in raw string delimitation",
1143
- curr_char) ;
1148
+ curr_char) ) ;
1144
1149
}
1145
1150
self . bump ( ) ;
1146
1151
let content_start_bpos = self . last_pos ;
@@ -1149,7 +1154,7 @@ impl<'a> StringReader<'a> {
1149
1154
' outer: loop {
1150
1155
if self . is_eof ( ) {
1151
1156
let last_bpos = self . last_pos ;
1152
- self . fatal_span_ ( start_bpos, last_bpos, "unterminated raw string" ) ;
1157
+ panic ! ( self . fatal_span_( start_bpos, last_bpos, "unterminated raw string" ) ) ;
1153
1158
}
1154
1159
//if self.curr_is('"') {
1155
1160
//content_end_bpos = self.last_pos;
@@ -1218,7 +1223,7 @@ impl<'a> StringReader<'a> {
1218
1223
c => {
1219
1224
let last_bpos = self . last_pos ;
1220
1225
let bpos = self . pos ;
1221
- self . fatal_span_char ( last_bpos, bpos, "unknown start of token" , c) ;
1226
+ panic ! ( self . fatal_span_char( last_bpos, bpos, "unknown start of token" , c) ) ;
1222
1227
}
1223
1228
}
1224
1229
}
@@ -1271,9 +1276,9 @@ impl<'a> StringReader<'a> {
1271
1276
// character before position `start` are an
1272
1277
// ascii single quote and ascii 'b'.
1273
1278
let last_pos = self . last_pos ;
1274
- self . fatal_span_verbose (
1279
+ panic ! ( self . fatal_span_verbose(
1275
1280
start - BytePos ( 2 ) , last_pos,
1276
- "unterminated byte constant" . to_string ( ) ) ;
1281
+ "unterminated byte constant" . to_string( ) ) ) ;
1277
1282
}
1278
1283
1279
1284
let id = if valid { self . name_from ( start) } else { token:: intern ( "?" ) } ;
@@ -1293,8 +1298,7 @@ impl<'a> StringReader<'a> {
1293
1298
while !self . curr_is ( '"' ) {
1294
1299
if self . is_eof ( ) {
1295
1300
let last_pos = self . last_pos ;
1296
- self . fatal_span_ ( start, last_pos,
1297
- "unterminated double quote byte string" ) ;
1301
+ panic ! ( self . fatal_span_( start, last_pos, "unterminated double quote byte string" ) ) ;
1298
1302
}
1299
1303
1300
1304
let ch_start = self . last_pos ;
@@ -1318,14 +1322,14 @@ impl<'a> StringReader<'a> {
1318
1322
1319
1323
if self . is_eof ( ) {
1320
1324
let last_pos = self . last_pos ;
1321
- self . fatal_span_ ( start_bpos, last_pos, "unterminated raw string" ) ;
1325
+ panic ! ( self . fatal_span_( start_bpos, last_pos, "unterminated raw string" ) ) ;
1322
1326
} else if !self . curr_is ( '"' ) {
1323
1327
let last_pos = self . last_pos ;
1324
1328
let ch = self . curr . unwrap ( ) ;
1325
- self . fatal_span_char ( start_bpos, last_pos,
1329
+ panic ! ( self . fatal_span_char( start_bpos, last_pos,
1326
1330
"found invalid character; \
1327
1331
only `#` is allowed in raw string delimitation",
1328
- ch) ;
1332
+ ch) ) ;
1329
1333
}
1330
1334
self . bump ( ) ;
1331
1335
let content_start_bpos = self . last_pos ;
@@ -1334,7 +1338,7 @@ impl<'a> StringReader<'a> {
1334
1338
match self . curr {
1335
1339
None => {
1336
1340
let last_pos = self . last_pos ;
1337
- self . fatal_span_ ( start_bpos, last_pos, "unterminated raw string" )
1341
+ panic ! ( self . fatal_span_( start_bpos, last_pos, "unterminated raw string" ) )
1338
1342
} ,
1339
1343
Some ( '"' ) => {
1340
1344
content_end_bpos = self . last_pos ;
0 commit comments