@@ -167,7 +167,7 @@ impl<'a> StringReader<'a> {
167167
168168 fn fail_unterminated_raw_string ( & self , start : Span , hash_count : u16 , spans : Vec < Span > ) -> ! {
169169 const SPAN_THRESHOLD : usize = 3 ;
170- const MSG_STR : & str = "Raw string could be meant to end here" ;
170+ const MSG_STR : & str = "you might have meant to end the raw string here" ;
171171 let hash_str = format ! ( "\" {}" , "#" . repeat( hash_count as usize ) ) ;
172172 let spans_len = spans. len ( ) ;
173173
@@ -176,15 +176,19 @@ impl<'a> StringReader<'a> {
176176
177177 for s in spans {
178178 if spans_len < SPAN_THRESHOLD {
179- err. span_suggestion ( s,
180- MSG_STR ,
181- hash_str. clone ( ) ,
182- Applicability :: MaybeIncorrect ) ;
179+ err. span_suggestion (
180+ s,
181+ MSG_STR ,
182+ hash_str. clone ( ) ,
183+ Applicability :: MaybeIncorrect
184+ ) ;
183185 } else {
184- err. tool_only_span_suggestion ( s,
185- MSG_STR ,
186- hash_str. clone ( ) ,
187- Applicability :: MaybeIncorrect ) ;
186+ err. tool_only_span_suggestion (
187+ s,
188+ MSG_STR ,
189+ hash_str. clone ( ) ,
190+ Applicability :: MaybeIncorrect
191+ ) ;
188192 }
189193 }
190194
@@ -1329,28 +1333,39 @@ impl<'a> StringReader<'a> {
13291333 while self . ch_is ( '#' ) {
13301334 if hash_count == 65535 {
13311335 let bpos = self . next_pos ;
1332- self . fatal_span_ ( start_bpos,
1333- bpos,
1334- "too many `#` symbols: raw strings may be \
1335- delimited by up to 65535 `#` symbols") . raise ( ) ;
1336+ let msg = match raw_type {
1337+ RawStringType :: Unicode => "too many `#` symbols: raw strings may be \
1338+ delimited by up to 65535 `#` symbols",
1339+ RawStringType :: Byte => "too many `#` symbols: raw byte strings may be \
1340+ delimited by up to 65535 `#` symbols",
1341+ } ;
1342+ self . fatal_span_ (
1343+ start_bpos,
1344+ bpos,
1345+ msg
1346+ ) . raise ( ) ;
13361347 }
13371348 self . bump ( ) ;
13381349 hash_count += 1 ;
13391350 }
13401351 let bpos_span = self . mk_sp ( start_bpos, self . pos ) ;
13411352
13421353 match self . ch {
1343- None => self . fail_unterminated_raw_string ( bpos_span,
1344- hash_count,
1345- vec ! [ self . mk_sp( self . pos, self . pos) ] ) ,
1354+ None => self . fail_unterminated_raw_string (
1355+ bpos_span,
1356+ hash_count,
1357+ vec ! [ self . mk_sp( self . pos, self . pos) ]
1358+ ) ,
13461359 Some ( '"' ) => { } ,
13471360 Some ( c) => {
13481361 let last_bpos = self . pos ;
1349- self . fatal_span_char ( start_bpos,
1350- last_bpos,
1351- "found invalid character; only `#` is allowed \
1352- in raw string delimitation",
1353- c) . raise ( ) ;
1362+ self . fatal_span_char (
1363+ start_bpos,
1364+ last_bpos,
1365+ "found invalid character; only `#` is allowed \
1366+ in raw string delimitation",
1367+ c
1368+ ) . raise ( ) ;
13541369 }
13551370 }
13561371
@@ -1363,7 +1378,6 @@ impl<'a> StringReader<'a> {
13631378 ' outer: loop {
13641379 match ( self . ch , raw_type) {
13651380 ( None , _) => {
1366- spans. push ( self . mk_sp ( self . pos , self . pos ) ) ;
13671381 self . fail_unterminated_raw_string ( bpos_span, hash_count, spans) ;
13681382 } ,
13691383 ( Some ( '"' ) , _) => {
@@ -1380,10 +1394,11 @@ impl<'a> StringReader<'a> {
13801394 ( Some ( '\r' ) , RawStringType :: Unicode ) => {
13811395 if !self . nextch_is ( '\n' ) {
13821396 let last_bpos = self . pos ;
1383- self . err_span_ ( start_bpos,
1384- last_bpos,
1385- "bare CR not allowed in raw string, use \\ r \
1386- instead") ;
1397+ self . err_span_ (
1398+ start_bpos,
1399+ last_bpos,
1400+ "bare CR not allowed in raw string, use \\ r instead"
1401+ ) ;
13871402 valid = false ;
13881403 }
13891404 }
@@ -1412,10 +1427,13 @@ impl<'a> StringReader<'a> {
14121427
14131428 let mut err = self . sess
14141429 . span_diagnostic . struct_span_err ( sp, "too many `#` when terminating raw string" ) ;
1415- err. span_label ( sp_beg, format ! ( "The raw string has {} leading `#`..." , hash_count) ) ;
1416- err. span_label ( sp_end,
1417- format ! ( "...but is closed with {}." ,
1418- self . pos. 0 - lo. 0 + hash_count as u32 ) ) ;
1430+ err. span_label ( sp_beg, format ! ( "this raw string has {} leading `#`..." , hash_count) ) ;
1431+ err. span_label (
1432+ sp_end,
1433+ format ! ( "...but is closed with {}." ,
1434+ self . pos. 0 - lo. 0 + hash_count as u32
1435+ )
1436+ ) ;
14191437 err. span_suggestion_hidden (
14201438 self . mk_sp ( lo, self . pos ) ,
14211439 "remove the unneeded `#`" ,
0 commit comments