@@ -132,6 +132,18 @@ impl<'a> StringReader<'a> {
132
132
self . advance_token ( ) ?;
133
133
Ok ( ret_val)
134
134
}
135
+
136
+ fn fail_unterminated_raw_string ( & self , pos : BytePos , hash_count : usize ) {
137
+ let mut err = self . struct_span_fatal ( pos, pos, "unterminated raw string" ) ;
138
+ err. span_label ( self . mk_sp ( pos, pos) , "unterminated raw string" ) ;
139
+ if hash_count > 0 {
140
+ err. note ( & format ! ( "this raw string should be terminated with `\" {}`" ,
141
+ "#" . repeat( hash_count) ) ) ;
142
+ }
143
+ err. emit ( ) ;
144
+ FatalError . raise ( ) ;
145
+ }
146
+
135
147
fn fatal ( & self , m : & str ) -> FatalError {
136
148
self . fatal_span ( self . peek_span , m)
137
149
}
@@ -269,6 +281,15 @@ impl<'a> StringReader<'a> {
269
281
Self :: push_escaped_char_for_msg ( & mut m, c) ;
270
282
self . fatal_span_ ( from_pos, to_pos, & m[ ..] )
271
283
}
284
+
285
+ fn struct_span_fatal ( & self ,
286
+ from_pos : BytePos ,
287
+ to_pos : BytePos ,
288
+ m : & str )
289
+ -> DiagnosticBuilder < ' a > {
290
+ self . sess . span_diagnostic . struct_span_fatal ( self . mk_sp ( from_pos, to_pos) , m)
291
+ }
292
+
272
293
fn struct_fatal_span_char ( & self ,
273
294
from_pos : BytePos ,
274
295
to_pos : BytePos ,
@@ -1404,8 +1425,7 @@ impl<'a> StringReader<'a> {
1404
1425
}
1405
1426
1406
1427
if self . is_eof ( ) {
1407
- let last_bpos = self . pos ;
1408
- self . fatal_span_ ( start_bpos, last_bpos, "unterminated raw string" ) . raise ( ) ;
1428
+ self . fail_unterminated_raw_string ( start_bpos, hash_count) ;
1409
1429
} else if !self . ch_is ( '"' ) {
1410
1430
let last_bpos = self . pos ;
1411
1431
let curr_char = self . ch . unwrap ( ) ;
@@ -1421,8 +1441,7 @@ impl<'a> StringReader<'a> {
1421
1441
let mut valid = true ;
1422
1442
' outer: loop {
1423
1443
if self . is_eof ( ) {
1424
- let last_bpos = self . pos ;
1425
- self . fatal_span_ ( start_bpos, last_bpos, "unterminated raw string" ) . raise ( ) ;
1444
+ self . fail_unterminated_raw_string ( start_bpos, hash_count) ;
1426
1445
}
1427
1446
// if self.ch_is('"') {
1428
1447
// content_end_bpos = self.pos;
@@ -1636,8 +1655,7 @@ impl<'a> StringReader<'a> {
1636
1655
}
1637
1656
1638
1657
if self . is_eof ( ) {
1639
- let pos = self . pos ;
1640
- self . fatal_span_ ( start_bpos, pos, "unterminated raw string" ) . raise ( ) ;
1658
+ self . fail_unterminated_raw_string ( start_bpos, hash_count) ;
1641
1659
} else if !self . ch_is ( '"' ) {
1642
1660
let pos = self . pos ;
1643
1661
let ch = self . ch . unwrap ( ) ;
@@ -1653,8 +1671,7 @@ impl<'a> StringReader<'a> {
1653
1671
' outer: loop {
1654
1672
match self . ch {
1655
1673
None => {
1656
- let pos = self . pos ;
1657
- self . fatal_span_ ( start_bpos, pos, "unterminated raw string" ) . raise ( )
1674
+ self . fail_unterminated_raw_string ( start_bpos, hash_count) ;
1658
1675
}
1659
1676
Some ( '"' ) => {
1660
1677
content_end_bpos = self . pos ;
0 commit comments