Skip to content

Commit 5b17039

Browse files
committed
Auto merge of #120375 - matthiaskrgr:rollup-ueakvms, r=matthiaskrgr
Rollup of 9 pull requests Successful merges: - #117420 (Make `#![allow_internal_unstable(..)]` work with `stmt_expr_attributes`) - #117678 (Stabilize `slice_group_by`) - #119917 (Remove special-case handling of `vec.split_off(0)`) - #120117 (Update `std::io::Error::downcast` return type) - #120329 (RFC 3349 precursors) - #120339 (privacy: Refactor top-level visiting in `NamePrivacyVisitor`) - #120345 (Clippy subtree update) - #120360 (Don't fire `OPAQUE_HIDDEN_INFERRED_BOUND` on sized return of AFIT) - #120372 (Fix outdated comment on Box) r? `@ghost` `@rustbot` modify labels: rollup
2 parents a1fa12d + 6418d6b commit 5b17039

File tree

3 files changed

+17
-18
lines changed

3 files changed

+17
-18
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: 9 additions & 10 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, CStrUnit, 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
@@ -336,12 +336,11 @@ impl ast::CString {
336336
let mut buf = Vec::new();
337337
let mut prev_end = 0;
338338
let mut has_error = false;
339-
let mut char_buf = [0u8; 4];
340-
let mut extend_unit = |buf: &mut Vec<u8>, unit: CStrUnit| match unit {
341-
CStrUnit::Byte(b) => buf.push(b),
342-
CStrUnit::Char(c) => buf.extend(c.encode_utf8(&mut char_buf).as_bytes()),
339+
let extend_unit = |buf: &mut Vec<u8>, unit: MixedUnit| match unit {
340+
MixedUnit::Char(c) => buf.extend(c.encode_utf8(&mut [0; 4]).as_bytes()),
341+
MixedUnit::HighByte(b) => buf.push(b),
343342
};
344-
unescape_c_string(text, Self::MODE, &mut |char_range, unescaped| match (
343+
unescape_mixed(text, Self::MODE, &mut |char_range, unescaped| match (
345344
unescaped,
346345
buf.capacity() == 0,
347346
) {

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_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_literal(without_quotes, Mode::ByteStr, &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)