1- use std:: ops:: Range ;
2-
31use diagnostics:: make_unclosed_delims_error;
42use rustc_ast:: ast:: { self , AttrStyle } ;
53use rustc_ast:: token:: { self , CommentKind , Delimiter , IdentIsRaw , Token , TokenKind } ;
@@ -8,7 +6,7 @@ use rustc_ast::util::unicode::contains_text_flow_control_chars;
86use rustc_errors:: codes:: * ;
97use rustc_errors:: { Applicability , Diag , DiagCtxtHandle , StashKey } ;
108use rustc_lexer:: { Base , Cursor , DocStyle , LiteralKind , RawStrError } ;
11- use rustc_literal_escaper:: { EscapeError , Mode , unescape_mixed , unescape_unicode } ;
9+ use rustc_literal_escaper:: { EscapeError , Mode , unescape_for_errors } ;
1210use rustc_session:: lint:: BuiltinLintDiag ;
1311use rustc_session:: lint:: builtin:: {
1412 RUST_2021_PREFIXES_INCOMPATIBLE_SYNTAX , RUST_2024_GUARDED_STRING_INCOMPATIBLE_SYNTAX ,
@@ -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 }
@@ -914,40 +912,36 @@ impl<'psess, 'src> Lexer<'psess, 'src> {
914912 self . dcx ( ) . emit_fatal ( errors:: TooManyHashes { span : self . mk_sp ( start, self . pos ) , num } ) ;
915913 }
916914
917- fn cook_common (
915+ fn cook_quoted (
918916 & self ,
919917 mut kind : token:: LitKind ,
920918 mode : Mode ,
921919 start : BytePos ,
922920 end : BytePos ,
923921 prefix_len : u32 ,
924922 postfix_len : u32 ,
925- unescape : fn ( & str , Mode , & mut dyn FnMut ( Range < usize > , Result < ( ) , EscapeError > ) ) ,
926923 ) -> ( token:: LitKind , Symbol ) {
927924 let content_start = start + BytePos ( prefix_len) ;
928925 let content_end = end - BytePos ( postfix_len) ;
929926 let lit_content = self . str_from_to ( content_start, content_end) ;
930- unescape ( lit_content, mode, & mut |range, result| {
931- // Here we only check for errors. The actual unescaping is done later.
932- if let Err ( err) = result {
933- let span_with_quotes = self . mk_sp ( start, end) ;
934- let ( start, end) = ( range. start as u32 , range. end as u32 ) ;
935- let lo = content_start + BytePos ( start) ;
936- let hi = lo + BytePos ( end - start) ;
937- let span = self . mk_sp ( lo, hi) ;
938- let is_fatal = err. is_fatal ( ) ;
939- if let Some ( guar) = emit_unescape_error (
940- self . dcx ( ) ,
941- lit_content,
942- span_with_quotes,
943- span,
944- mode,
945- range,
946- err,
947- ) {
948- assert ! ( is_fatal) ;
949- kind = token:: Err ( guar) ;
950- }
927+ unescape_for_errors ( lit_content, mode, |range, err| {
928+ let span_with_quotes = self . mk_sp ( start, end) ;
929+ let ( start, end) = ( range. start as u32 , range. end as u32 ) ;
930+ let lo = content_start + BytePos ( start) ;
931+ let hi = lo + BytePos ( end - start) ;
932+ let span = self . mk_sp ( lo, hi) ;
933+ let is_fatal = err. is_fatal ( ) ;
934+ if let Some ( guar) = emit_unescape_error (
935+ self . dcx ( ) ,
936+ lit_content,
937+ span_with_quotes,
938+ span,
939+ mode,
940+ range,
941+ err,
942+ ) {
943+ assert ! ( is_fatal) ;
944+ kind = token:: Err ( guar) ;
951945 }
952946 } ) ;
953947
@@ -960,34 +954,6 @@ impl<'psess, 'src> Lexer<'psess, 'src> {
960954 } ;
961955 ( kind, sym)
962956 }
963-
964- fn cook_unicode (
965- & self ,
966- kind : token:: LitKind ,
967- mode : Mode ,
968- start : BytePos ,
969- end : BytePos ,
970- prefix_len : u32 ,
971- postfix_len : u32 ,
972- ) -> ( token:: LitKind , Symbol ) {
973- self . cook_common ( kind, mode, start, end, prefix_len, postfix_len, |src, mode, callback| {
974- unescape_unicode ( src, mode, & mut |span, result| callback ( span, result. map ( drop) ) )
975- } )
976- }
977-
978- fn cook_mixed (
979- & self ,
980- kind : token:: LitKind ,
981- mode : Mode ,
982- start : BytePos ,
983- end : BytePos ,
984- prefix_len : u32 ,
985- postfix_len : u32 ,
986- ) -> ( token:: LitKind , Symbol ) {
987- self . cook_common ( kind, mode, start, end, prefix_len, postfix_len, |src, mode, callback| {
988- unescape_mixed ( src, mode, & mut |span, result| callback ( span, result. map ( drop) ) )
989- } )
990- }
991957}
992958
993959pub fn nfc_normalize ( string : & str ) -> Symbol {
0 commit comments