@@ -6,8 +6,7 @@ use crate::tokenstream::TokenTree;
6
6
7
7
use rustc_data_structures:: sync:: Lrc ;
8
8
use rustc_lexer:: unescape:: { unescape_byte, unescape_char} ;
9
- use rustc_lexer:: unescape:: { unescape_byte_str, unescape_str} ;
10
- use rustc_lexer:: unescape:: { unescape_raw_byte_str, unescape_raw_str} ;
9
+ use rustc_lexer:: unescape:: { unescape_byte_literal, unescape_literal, Mode } ;
11
10
use rustc_span:: symbol:: { kw, sym, Symbol } ;
12
11
use rustc_span:: Span ;
13
12
@@ -59,45 +58,53 @@ impl LitKind {
59
58
// new symbol because the string in the LitKind is different to the
60
59
// string in the token.
61
60
let s = symbol. as_str ( ) ;
62
- let symbol = if s. contains ( & [ '\\' , '\r' ] [ ..] ) {
63
- let mut buf = String :: with_capacity ( s. len ( ) ) ;
64
- let mut error = Ok ( ( ) ) ;
65
- unescape_str ( & s, & mut |_, unescaped_char| match unescaped_char {
66
- Ok ( c) => buf. push ( c) ,
67
- Err ( _) => error = Err ( LitError :: LexerError ) ,
68
- } ) ;
69
- error?;
70
- Symbol :: intern ( & buf)
71
- } else {
72
- symbol
73
- } ;
61
+ let symbol =
62
+ if s. contains ( & [ '\\' , '\r' ] [ ..] ) {
63
+ let mut buf = String :: with_capacity ( s. len ( ) ) ;
64
+ let mut error = Ok ( ( ) ) ;
65
+ unescape_literal ( & s, Mode :: Str , & mut |_, unescaped_char| {
66
+ match unescaped_char {
67
+ Ok ( c) => buf. push ( c) ,
68
+ Err ( _) => error = Err ( LitError :: LexerError ) ,
69
+ }
70
+ } ) ;
71
+ error?;
72
+ Symbol :: intern ( & buf)
73
+ } else {
74
+ symbol
75
+ } ;
74
76
LitKind :: Str ( symbol, ast:: StrStyle :: Cooked )
75
77
}
76
78
token:: StrRaw ( n) => {
77
79
// Ditto.
78
80
let s = symbol. as_str ( ) ;
79
- let symbol = if s. contains ( '\r' ) {
80
- let mut buf = String :: with_capacity ( s. len ( ) ) ;
81
- let mut error = Ok ( ( ) ) ;
82
- unescape_raw_str ( & s, & mut |_, unescaped_char| match unescaped_char {
83
- Ok ( c) => buf. push ( c) ,
84
- Err ( _) => error = Err ( LitError :: LexerError ) ,
85
- } ) ;
86
- error?;
87
- buf. shrink_to_fit ( ) ;
88
- Symbol :: intern ( & buf)
89
- } else {
90
- symbol
91
- } ;
81
+ let symbol =
82
+ if s. contains ( '\r' ) {
83
+ let mut buf = String :: with_capacity ( s. len ( ) ) ;
84
+ let mut error = Ok ( ( ) ) ;
85
+ unescape_literal ( & s, Mode :: RawStr , & mut |_, unescaped_char| {
86
+ match unescaped_char {
87
+ Ok ( c) => buf. push ( c) ,
88
+ Err ( _) => error = Err ( LitError :: LexerError ) ,
89
+ }
90
+ } ) ;
91
+ error?;
92
+ buf. shrink_to_fit ( ) ;
93
+ Symbol :: intern ( & buf)
94
+ } else {
95
+ symbol
96
+ } ;
92
97
LitKind :: Str ( symbol, ast:: StrStyle :: Raw ( n) )
93
98
}
94
99
token:: ByteStr => {
95
100
let s = symbol. as_str ( ) ;
96
101
let mut buf = Vec :: with_capacity ( s. len ( ) ) ;
97
102
let mut error = Ok ( ( ) ) ;
98
- unescape_byte_str ( & s, & mut |_, unescaped_byte| match unescaped_byte {
99
- Ok ( c) => buf. push ( c) ,
100
- Err ( _) => error = Err ( LitError :: LexerError ) ,
103
+ unescape_byte_literal ( & s, Mode :: ByteStr , & mut |_, unescaped_byte| {
104
+ match unescaped_byte {
105
+ Ok ( c) => buf. push ( c) ,
106
+ Err ( _) => error = Err ( LitError :: LexerError ) ,
107
+ }
101
108
} ) ;
102
109
error?;
103
110
buf. shrink_to_fit ( ) ;
@@ -108,9 +115,11 @@ impl LitKind {
108
115
let bytes = if s. contains ( '\r' ) {
109
116
let mut buf = Vec :: with_capacity ( s. len ( ) ) ;
110
117
let mut error = Ok ( ( ) ) ;
111
- unescape_raw_byte_str ( & s, & mut |_, unescaped_byte| match unescaped_byte {
112
- Ok ( c) => buf. push ( c) ,
113
- Err ( _) => error = Err ( LitError :: LexerError ) ,
118
+ unescape_byte_literal ( & s, Mode :: RawByteStr , & mut |_, unescaped_byte| {
119
+ match unescaped_byte {
120
+ Ok ( c) => buf. push ( c) ,
121
+ Err ( _) => error = Err ( LitError :: LexerError ) ,
122
+ }
114
123
} ) ;
115
124
error?;
116
125
buf. shrink_to_fit ( ) ;
0 commit comments