Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 858f4ac

Browse files
committed
Rename the unescaping functions.
`unescape_literal` becomes `unescape_unicode`, and `unescape_c_string` becomes `unescape_mixed`. Because rfc3349 will mean that C string literals will no longer be the only mixed utf8 literals.
1 parent 5651407 commit 858f4ac

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed

crates/parser/src/lexed_str.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -379,14 +379,14 @@ fn unescape_string_error_message(text: &str, mode: Mode) -> &'static str {
379379
let mut error_message = "";
380380
match mode {
381381
Mode::CStr => {
382-
rustc_lexer::unescape::unescape_c_string(text, mode, &mut |_, res| {
382+
rustc_lexer::unescape::unescape_mixed(text, mode, &mut |_, res| {
383383
if let Err(e) = res {
384384
error_message = error_to_diagnostic_message(e, mode);
385385
}
386386
});
387387
}
388388
Mode::ByteStr | Mode::Str => {
389-
rustc_lexer::unescape::unescape_literal(text, mode, &mut |_, res| {
389+
rustc_lexer::unescape::unescape_unicode(text, mode, &mut |_, res| {
390390
if let Err(e) = res {
391391
error_message = error_to_diagnostic_message(e, mode);
392392
}

crates/syntax/src/ast/token_ext.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::{
66
};
77

88
use rustc_lexer::unescape::{
9-
unescape_byte, unescape_c_string, unescape_char, unescape_literal, MixedUnit, Mode,
9+
unescape_byte, unescape_char, unescape_mixed, unescape_unicode, MixedUnit, Mode,
1010
};
1111

1212
use crate::{
@@ -193,7 +193,7 @@ pub trait IsString: AstToken {
193193
let text = &self.text()[text_range_no_quotes - start];
194194
let offset = text_range_no_quotes.start() - start;
195195

196-
unescape_literal(text, Self::MODE, &mut |range, unescaped_char| {
196+
unescape_unicode(text, Self::MODE, &mut |range, unescaped_char| {
197197
let text_range =
198198
TextRange::new(range.start.try_into().unwrap(), range.end.try_into().unwrap());
199199
cb(text_range + offset, unescaped_char);
@@ -226,7 +226,7 @@ impl ast::String {
226226
let mut buf = String::new();
227227
let mut prev_end = 0;
228228
let mut has_error = false;
229-
unescape_literal(text, Self::MODE, &mut |char_range, unescaped_char| match (
229+
unescape_unicode(text, Self::MODE, &mut |char_range, unescaped_char| match (
230230
unescaped_char,
231231
buf.capacity() == 0,
232232
) {
@@ -270,7 +270,7 @@ impl ast::ByteString {
270270
let mut buf: Vec<u8> = Vec::new();
271271
let mut prev_end = 0;
272272
let mut has_error = false;
273-
unescape_literal(text, Self::MODE, &mut |char_range, unescaped_char| match (
273+
unescape_unicode(text, Self::MODE, &mut |char_range, unescaped_char| match (
274274
unescaped_char,
275275
buf.capacity() == 0,
276276
) {
@@ -311,7 +311,7 @@ impl IsString for ast::CString {
311311
let text = &self.text()[text_range_no_quotes - start];
312312
let offset = text_range_no_quotes.start() - start;
313313

314-
unescape_c_string(text, Self::MODE, &mut |range, unescaped_char| {
314+
unescape_mixed(text, Self::MODE, &mut |range, unescaped_char| {
315315
let text_range =
316316
TextRange::new(range.start.try_into().unwrap(), range.end.try_into().unwrap());
317317
// XXX: This method should only be used for highlighting ranges. The unescaped
@@ -340,7 +340,7 @@ impl ast::CString {
340340
MixedUnit::Char(c) => buf.extend(c.encode_utf8(&mut [0; 4]).as_bytes()),
341341
MixedUnit::HighByte(b) => buf.push(b),
342342
};
343-
unescape_c_string(text, Self::MODE, &mut |char_range, unescaped| match (
343+
unescape_mixed(text, Self::MODE, &mut |char_range, unescaped| match (
344344
unescaped,
345345
buf.capacity() == 0,
346346
) {

crates/syntax/src/validation.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
mod block;
66

77
use rowan::Direction;
8-
use rustc_lexer::unescape::{self, unescape_c_string, unescape_literal, Mode};
8+
use rustc_lexer::unescape::{self, unescape_mixed, unescape_unicode, Mode};
99

1010
use crate::{
1111
algo,
@@ -140,7 +140,7 @@ fn validate_literal(literal: ast::Literal, acc: &mut Vec<SyntaxError>) {
140140
ast::LiteralKind::String(s) => {
141141
if !s.is_raw() {
142142
if let Some(without_quotes) = unquote(text, 1, '"') {
143-
unescape_literal(without_quotes, Mode::Str, &mut |range, char| {
143+
unescape_unicode(without_quotes, Mode::Str, &mut |range, char| {
144144
if let Err(err) = char {
145145
push_err(1, range.start, err);
146146
}
@@ -151,7 +151,7 @@ fn validate_literal(literal: ast::Literal, acc: &mut Vec<SyntaxError>) {
151151
ast::LiteralKind::ByteString(s) => {
152152
if !s.is_raw() {
153153
if let Some(without_quotes) = unquote(text, 2, '"') {
154-
unescape_literal(without_quotes, Mode::ByteStr, &mut |range, char| {
154+
unescape_unicode(without_quotes, Mode::ByteStr, &mut |range, char| {
155155
if let Err(err) = char {
156156
push_err(1, range.start, err);
157157
}
@@ -162,7 +162,7 @@ fn validate_literal(literal: ast::Literal, acc: &mut Vec<SyntaxError>) {
162162
ast::LiteralKind::CString(s) => {
163163
if !s.is_raw() {
164164
if let Some(without_quotes) = unquote(text, 2, '"') {
165-
unescape_c_string(without_quotes, Mode::CStr, &mut |range, char| {
165+
unescape_mixed(without_quotes, Mode::CStr, &mut |range, char| {
166166
if let Err(err) = char {
167167
push_err(1, range.start, err);
168168
}
@@ -172,7 +172,7 @@ fn validate_literal(literal: ast::Literal, acc: &mut Vec<SyntaxError>) {
172172
}
173173
ast::LiteralKind::Char(_) => {
174174
if let Some(without_quotes) = unquote(text, 1, '\'') {
175-
unescape_literal(without_quotes, Mode::Char, &mut |range, char| {
175+
unescape_unicode(without_quotes, Mode::Char, &mut |range, char| {
176176
if let Err(err) = char {
177177
push_err(1, range.start, err);
178178
}
@@ -181,7 +181,7 @@ fn validate_literal(literal: ast::Literal, acc: &mut Vec<SyntaxError>) {
181181
}
182182
ast::LiteralKind::Byte(_) => {
183183
if let Some(without_quotes) = unquote(text, 2, '\'') {
184-
unescape_literal(without_quotes, Mode::Byte, &mut |range, char| {
184+
unescape_unicode(without_quotes, Mode::Byte, &mut |range, char| {
185185
if let Err(err) = char {
186186
push_err(2, range.start, err);
187187
}

0 commit comments

Comments
 (0)