@@ -132,6 +132,18 @@ impl<'a> StringReader<'a> {
132132 self . advance_token ( ) ?;
133133 Ok ( ret_val)
134134 }
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+
135147 fn fatal ( & self , m : & str ) -> FatalError {
136148 self . fatal_span ( self . peek_span , m)
137149 }
@@ -269,6 +281,15 @@ impl<'a> StringReader<'a> {
269281 Self :: push_escaped_char_for_msg ( & mut m, c) ;
270282 self . fatal_span_ ( from_pos, to_pos, & m[ ..] )
271283 }
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+
272293 fn struct_fatal_span_char ( & self ,
273294 from_pos : BytePos ,
274295 to_pos : BytePos ,
@@ -1404,8 +1425,7 @@ impl<'a> StringReader<'a> {
14041425 }
14051426
14061427 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) ;
14091429 } else if !self . ch_is ( '"' ) {
14101430 let last_bpos = self . pos ;
14111431 let curr_char = self . ch . unwrap ( ) ;
@@ -1421,8 +1441,7 @@ impl<'a> StringReader<'a> {
14211441 let mut valid = true ;
14221442 ' outer: loop {
14231443 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) ;
14261445 }
14271446 // if self.ch_is('"') {
14281447 // content_end_bpos = self.pos;
@@ -1636,8 +1655,7 @@ impl<'a> StringReader<'a> {
16361655 }
16371656
16381657 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) ;
16411659 } else if !self . ch_is ( '"' ) {
16421660 let pos = self . pos ;
16431661 let ch = self . ch . unwrap ( ) ;
@@ -1653,8 +1671,7 @@ impl<'a> StringReader<'a> {
16531671 ' outer: loop {
16541672 match self . ch {
16551673 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) ;
16581675 }
16591676 Some ( '"' ) => {
16601677 content_end_bpos = self . pos ;
0 commit comments