1
- use std:: ops:: Range ;
2
-
3
1
use rustc_ast:: ast:: { self , AttrStyle } ;
4
2
use rustc_ast:: token:: { self , CommentKind , Delimiter , IdentIsRaw , Token , TokenKind } ;
5
3
use rustc_ast:: tokenstream:: TokenStream ;
@@ -525,7 +523,7 @@ impl<'psess, 'src> Lexer<'psess, 'src> {
525
523
}
526
524
err. emit ( )
527
525
}
528
- self . cook_unicode ( token:: Char , Mode :: Char , start, end, 1 , 1 ) // ' '
526
+ self . cook_quoted ( token:: Char , Mode :: Char , start, end, 1 , 1 ) // ' '
529
527
}
530
528
rustc_lexer:: LiteralKind :: Byte { terminated } => {
531
529
if !terminated {
@@ -537,7 +535,7 @@ impl<'psess, 'src> Lexer<'psess, 'src> {
537
535
. with_code ( E0763 )
538
536
. emit ( )
539
537
}
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' '
541
539
}
542
540
rustc_lexer:: LiteralKind :: Str { terminated } => {
543
541
if !terminated {
@@ -549,7 +547,7 @@ impl<'psess, 'src> Lexer<'psess, 'src> {
549
547
. with_code ( E0765 )
550
548
. emit ( )
551
549
}
552
- self . cook_unicode ( token:: Str , Mode :: Str , start, end, 1 , 1 ) // " "
550
+ self . cook_quoted ( token:: Str , Mode :: Str , start, end, 1 , 1 ) // " "
553
551
}
554
552
rustc_lexer:: LiteralKind :: ByteStr { terminated } => {
555
553
if !terminated {
@@ -561,7 +559,7 @@ impl<'psess, 'src> Lexer<'psess, 'src> {
561
559
. with_code ( E0766 )
562
560
. emit ( )
563
561
}
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" "
565
563
}
566
564
rustc_lexer:: LiteralKind :: CStr { terminated } => {
567
565
if !terminated {
@@ -573,13 +571,13 @@ impl<'psess, 'src> Lexer<'psess, 'src> {
573
571
. with_code ( E0767 )
574
572
. emit ( )
575
573
}
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" "
577
575
}
578
576
rustc_lexer:: LiteralKind :: RawStr { n_hashes } => {
579
577
if let Some ( n_hashes) = n_hashes {
580
578
let n = u32:: from ( n_hashes) ;
581
579
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##" "##
583
581
} else {
584
582
self . report_raw_str_error ( start, 1 ) ;
585
583
}
@@ -588,7 +586,7 @@ impl<'psess, 'src> Lexer<'psess, 'src> {
588
586
if let Some ( n_hashes) = n_hashes {
589
587
let n = u32:: from ( n_hashes) ;
590
588
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##" "##
592
590
} else {
593
591
self . report_raw_str_error ( start, 2 ) ;
594
592
}
@@ -597,7 +595,7 @@ impl<'psess, 'src> Lexer<'psess, 'src> {
597
595
if let Some ( n_hashes) = n_hashes {
598
596
let n = u32:: from ( n_hashes) ;
599
597
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##" "##
601
599
} else {
602
600
self . report_raw_str_error ( start, 2 ) ;
603
601
}
@@ -913,40 +911,36 @@ impl<'psess, 'src> Lexer<'psess, 'src> {
913
911
self . dcx ( ) . emit_fatal ( errors:: TooManyHashes { span : self . mk_sp ( start, self . pos ) , num } ) ;
914
912
}
915
913
916
- fn cook_common (
914
+ fn cook_quoted (
917
915
& self ,
918
916
mut kind : token:: LitKind ,
919
917
mode : Mode ,
920
918
start : BytePos ,
921
919
end : BytePos ,
922
920
prefix_len : u32 ,
923
921
postfix_len : u32 ,
924
- unescape : fn ( & str , Mode , & mut dyn FnMut ( Range < usize > , Result < ( ) , EscapeError > ) ) ,
925
922
) -> ( token:: LitKind , Symbol ) {
926
923
let content_start = start + BytePos ( prefix_len) ;
927
924
let content_end = end - BytePos ( postfix_len) ;
928
925
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) ;
950
944
}
951
945
} ) ;
952
946
@@ -959,36 +953,6 @@ impl<'psess, 'src> Lexer<'psess, 'src> {
959
953
} ;
960
954
( kind, sym)
961
955
}
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
- }
992
956
}
993
957
994
958
pub fn nfc_normalize ( string : & str ) -> Symbol {
0 commit comments