1- use std:: ops:: Range ;
2-
31use rustc_ast:: ast:: { self , AttrStyle } ;
42use rustc_ast:: token:: { self , CommentKind , Delimiter , IdentIsRaw , Token , TokenKind } ;
53use rustc_ast:: tokenstream:: TokenStream ;
@@ -525,7 +523,7 @@ impl<'psess, 'src> Lexer<'psess, 'src> {
525523 }
526524 err. emit ( )
527525 }
528- self . cook_unicode ( token:: Char , Mode :: Char , start, end, 1 , 1 ) // ' '
526+ self . cook_quoted ( token:: Char , Mode :: Char , start, end, 1 , 1 ) // ' '
529527 }
530528 rustc_lexer:: LiteralKind :: Byte { terminated } => {
531529 if !terminated {
@@ -537,7 +535,7 @@ impl<'psess, 'src> Lexer<'psess, 'src> {
537535 . with_code ( E0763 )
538536 . emit ( )
539537 }
540- self . cook_unicode ( token:: Byte , Mode :: Byte , start, end, 2 , 1 ) // b' '
538+ self . cook_quoted ( token:: Byte , Mode :: Byte , start, end, 2 , 1 ) // b' '
541539 }
542540 rustc_lexer:: LiteralKind :: Str { terminated } => {
543541 if !terminated {
@@ -549,7 +547,7 @@ impl<'psess, 'src> Lexer<'psess, 'src> {
549547 . with_code ( E0765 )
550548 . emit ( )
551549 }
552- self . cook_unicode ( token:: Str , Mode :: Str , start, end, 1 , 1 ) // " "
550+ self . cook_quoted ( token:: Str , Mode :: Str , start, end, 1 , 1 ) // " "
553551 }
554552 rustc_lexer:: LiteralKind :: ByteStr { terminated } => {
555553 if !terminated {
@@ -561,7 +559,7 @@ impl<'psess, 'src> Lexer<'psess, 'src> {
561559 . with_code ( E0766 )
562560 . emit ( )
563561 }
564- self . cook_unicode ( token:: ByteStr , Mode :: ByteStr , start, end, 2 , 1 ) // b" "
562+ self . cook_quoted ( token:: ByteStr , Mode :: ByteStr , start, end, 2 , 1 ) // b" "
565563 }
566564 rustc_lexer:: LiteralKind :: CStr { terminated } => {
567565 if !terminated {
@@ -573,13 +571,13 @@ impl<'psess, 'src> Lexer<'psess, 'src> {
573571 . with_code ( E0767 )
574572 . emit ( )
575573 }
576- self . cook_mixed ( token:: CStr , Mode :: CStr , start, end, 2 , 1 ) // c" "
574+ self . cook_quoted ( token:: CStr , Mode :: CStr , start, end, 2 , 1 ) // c" "
577575 }
578576 rustc_lexer:: LiteralKind :: RawStr { n_hashes } => {
579577 if let Some ( n_hashes) = n_hashes {
580578 let n = u32:: from ( n_hashes) ;
581579 let kind = token:: StrRaw ( n_hashes) ;
582- self . cook_unicode ( kind, Mode :: RawStr , start, end, 2 + n, 1 + n) // r##" "##
580+ self . cook_quoted ( kind, Mode :: RawStr , start, end, 2 + n, 1 + n) // r##" "##
583581 } else {
584582 self . report_raw_str_error ( start, 1 ) ;
585583 }
@@ -588,7 +586,7 @@ impl<'psess, 'src> Lexer<'psess, 'src> {
588586 if let Some ( n_hashes) = n_hashes {
589587 let n = u32:: from ( n_hashes) ;
590588 let kind = token:: ByteStrRaw ( n_hashes) ;
591- self . cook_unicode ( kind, Mode :: RawByteStr , start, end, 3 + n, 1 + n) // br##" "##
589+ self . cook_quoted ( kind, Mode :: RawByteStr , start, end, 3 + n, 1 + n) // br##" "##
592590 } else {
593591 self . report_raw_str_error ( start, 2 ) ;
594592 }
@@ -597,7 +595,7 @@ impl<'psess, 'src> Lexer<'psess, 'src> {
597595 if let Some ( n_hashes) = n_hashes {
598596 let n = u32:: from ( n_hashes) ;
599597 let kind = token:: CStrRaw ( n_hashes) ;
600- self . cook_unicode ( kind, Mode :: RawCStr , start, end, 3 + n, 1 + n) // cr##" "##
598+ self . cook_quoted ( kind, Mode :: RawCStr , start, end, 3 + n, 1 + n) // cr##" "##
601599 } else {
602600 self . report_raw_str_error ( start, 2 ) ;
603601 }
@@ -913,40 +911,36 @@ impl<'psess, 'src> Lexer<'psess, 'src> {
913911 self . dcx ( ) . emit_fatal ( errors:: TooManyHashes { span : self . mk_sp ( start, self . pos ) , num } ) ;
914912 }
915913
916- fn cook_common (
914+ fn cook_quoted (
917915 & self ,
918916 mut kind : token:: LitKind ,
919917 mode : Mode ,
920918 start : BytePos ,
921919 end : BytePos ,
922920 prefix_len : u32 ,
923921 postfix_len : u32 ,
924- unescape : fn ( & str , Mode , & mut dyn FnMut ( Range < usize > , Result < ( ) , EscapeError > ) ) ,
925922 ) -> ( token:: LitKind , Symbol ) {
926923 let content_start = start + BytePos ( prefix_len) ;
927924 let content_end = end - BytePos ( postfix_len) ;
928925 let lit_content = self . str_from_to ( content_start, content_end) ;
929- unescape ( lit_content, mode, & mut |range, result| {
930- // Here we only check for errors. The actual unescaping is done later.
931- if let Err ( err) = result {
932- let span_with_quotes = self . mk_sp ( start, end) ;
933- let ( start, end) = ( range. start as u32 , range. end as u32 ) ;
934- let lo = content_start + BytePos ( start) ;
935- let hi = lo + BytePos ( end - start) ;
936- let span = self . mk_sp ( lo, hi) ;
937- let is_fatal = err. is_fatal ( ) ;
938- if let Some ( guar) = emit_unescape_error (
939- self . dcx ( ) ,
940- lit_content,
941- span_with_quotes,
942- span,
943- mode,
944- range,
945- err,
946- ) {
947- assert ! ( is_fatal) ;
948- kind = token:: Err ( guar) ;
949- }
926+ unescape:: unescape_for_errors ( lit_content, mode, |range, err| {
927+ let span_with_quotes = self . mk_sp ( start, end) ;
928+ let ( start, end) = ( range. start as u32 , range. end as u32 ) ;
929+ let lo = content_start + BytePos ( start) ;
930+ let hi = lo + BytePos ( end - start) ;
931+ let span = self . mk_sp ( lo, hi) ;
932+ let is_fatal = err. is_fatal ( ) ;
933+ if let Some ( guar) = emit_unescape_error (
934+ self . dcx ( ) ,
935+ lit_content,
936+ span_with_quotes,
937+ span,
938+ mode,
939+ range,
940+ err,
941+ ) {
942+ assert ! ( is_fatal) ;
943+ kind = token:: Err ( guar) ;
950944 }
951945 } ) ;
952946
@@ -959,36 +953,6 @@ impl<'psess, 'src> Lexer<'psess, 'src> {
959953 } ;
960954 ( kind, sym)
961955 }
962-
963- fn cook_unicode (
964- & self ,
965- kind : token:: LitKind ,
966- mode : Mode ,
967- start : BytePos ,
968- end : BytePos ,
969- prefix_len : u32 ,
970- postfix_len : u32 ,
971- ) -> ( token:: LitKind , Symbol ) {
972- self . cook_common ( kind, mode, start, end, prefix_len, postfix_len, |src, mode, callback| {
973- unescape:: unescape_unicode ( src, mode, & mut |span, result| {
974- callback ( span, result. map ( drop) )
975- } )
976- } )
977- }
978-
979- fn cook_mixed (
980- & self ,
981- kind : token:: LitKind ,
982- mode : Mode ,
983- start : BytePos ,
984- end : BytePos ,
985- prefix_len : u32 ,
986- postfix_len : u32 ,
987- ) -> ( token:: LitKind , Symbol ) {
988- self . cook_common ( kind, mode, start, end, prefix_len, postfix_len, |src, _mode, callback| {
989- unescape:: unescape_cstr ( src, & mut |span, result| callback ( span, result. map ( drop) ) )
990- } )
991- }
992956}
993957
994958pub fn nfc_normalize ( string : & str ) -> Symbol {
0 commit comments