Unnamed repository; edit this file 'description' to name the repository.
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
bors 2024-01-26
parent a1fa12d · parent 6418d6b · commit 5b17039
-rw-r--r--crates/parser/src/lexed_str.rs4
-rw-r--r--crates/syntax/src/ast/token_ext.rs19
-rw-r--r--crates/syntax/src/validation.rs12
3 files changed, 17 insertions, 18 deletions
diff --git a/crates/parser/src/lexed_str.rs b/crates/parser/src/lexed_str.rs
index aa25f82ae1..bf1feb9a7e 100644
--- a/crates/parser/src/lexed_str.rs
+++ b/crates/parser/src/lexed_str.rs
@@ -379,14 +379,14 @@ fn unescape_string_error_message(text: &str, mode: Mode) -> &'static str {
let mut error_message = "";
match mode {
Mode::CStr => {
- rustc_lexer::unescape::unescape_c_string(text, mode, &mut |_, res| {
+ rustc_lexer::unescape::unescape_mixed(text, mode, &mut |_, res| {
if let Err(e) = res {
error_message = error_to_diagnostic_message(e, mode);
}
});
}
Mode::ByteStr | Mode::Str => {
- rustc_lexer::unescape::unescape_literal(text, mode, &mut |_, res| {
+ rustc_lexer::unescape::unescape_unicode(text, mode, &mut |_, res| {
if let Err(e) = res {
error_message = error_to_diagnostic_message(e, mode);
}
diff --git a/crates/syntax/src/ast/token_ext.rs b/crates/syntax/src/ast/token_ext.rs
index b39006e2ff..7cd1f1550b 100644
--- a/crates/syntax/src/ast/token_ext.rs
+++ b/crates/syntax/src/ast/token_ext.rs
@@ -6,7 +6,7 @@ use std::{
};
use rustc_lexer::unescape::{
- unescape_byte, unescape_c_string, unescape_char, unescape_literal, CStrUnit, Mode,
+ unescape_byte, unescape_char, unescape_mixed, unescape_unicode, MixedUnit, Mode,
};
use crate::{
@@ -193,7 +193,7 @@ pub trait IsString: AstToken {
let text = &self.text()[text_range_no_quotes - start];
let offset = text_range_no_quotes.start() - start;
- unescape_literal(text, Self::MODE, &mut |range, unescaped_char| {
+ unescape_unicode(text, Self::MODE, &mut |range, unescaped_char| {
let text_range =
TextRange::new(range.start.try_into().unwrap(), range.end.try_into().unwrap());
cb(text_range + offset, unescaped_char);
@@ -226,7 +226,7 @@ impl ast::String {
let mut buf = String::new();
let mut prev_end = 0;
let mut has_error = false;
- unescape_literal(text, Self::MODE, &mut |char_range, unescaped_char| match (
+ unescape_unicode(text, Self::MODE, &mut |char_range, unescaped_char| match (
unescaped_char,
buf.capacity() == 0,
) {
@@ -270,7 +270,7 @@ impl ast::ByteString {
let mut buf: Vec<u8> = Vec::new();
let mut prev_end = 0;
let mut has_error = false;
- unescape_literal(text, Self::MODE, &mut |char_range, unescaped_char| match (
+ unescape_unicode(text, Self::MODE, &mut |char_range, unescaped_char| match (
unescaped_char,
buf.capacity() == 0,
) {
@@ -311,7 +311,7 @@ impl IsString for ast::CString {
let text = &self.text()[text_range_no_quotes - start];
let offset = text_range_no_quotes.start() - start;
- unescape_c_string(text, Self::MODE, &mut |range, unescaped_char| {
+ unescape_mixed(text, Self::MODE, &mut |range, unescaped_char| {
let text_range =
TextRange::new(range.start.try_into().unwrap(), range.end.try_into().unwrap());
// XXX: This method should only be used for highlighting ranges. The unescaped
@@ -336,12 +336,11 @@ impl ast::CString {
let mut buf = Vec::new();
let mut prev_end = 0;
let mut has_error = false;
- let mut char_buf = [0u8; 4];
- let mut extend_unit = |buf: &mut Vec<u8>, unit: CStrUnit| match unit {
- CStrUnit::Byte(b) => buf.push(b),
- CStrUnit::Char(c) => buf.extend(c.encode_utf8(&mut char_buf).as_bytes()),
+ let extend_unit = |buf: &mut Vec<u8>, unit: MixedUnit| match unit {
+ MixedUnit::Char(c) => buf.extend(c.encode_utf8(&mut [0; 4]).as_bytes()),
+ MixedUnit::HighByte(b) => buf.push(b),
};
- unescape_c_string(text, Self::MODE, &mut |char_range, unescaped| match (
+ unescape_mixed(text, Self::MODE, &mut |char_range, unescaped| match (
unescaped,
buf.capacity() == 0,
) {
diff --git a/crates/syntax/src/validation.rs b/crates/syntax/src/validation.rs
index 69dffbf79f..5c5b26f525 100644
--- a/crates/syntax/src/validation.rs
+++ b/crates/syntax/src/validation.rs
@@ -5,7 +5,7 @@
mod block;
use rowan::Direction;
-use rustc_lexer::unescape::{self, unescape_literal, Mode};
+use rustc_lexer::unescape::{self, unescape_mixed, unescape_unicode, Mode};
use crate::{
algo,
@@ -140,7 +140,7 @@ fn validate_literal(literal: ast::Literal, acc: &mut Vec<SyntaxError>) {
ast::LiteralKind::String(s) => {
if !s.is_raw() {
if let Some(without_quotes) = unquote(text, 1, '"') {
- unescape_literal(without_quotes, Mode::Str, &mut |range, char| {
+ unescape_unicode(without_quotes, Mode::Str, &mut |range, char| {
if let Err(err) = char {
push_err(1, range.start, err);
}
@@ -151,7 +151,7 @@ fn validate_literal(literal: ast::Literal, acc: &mut Vec<SyntaxError>) {
ast::LiteralKind::ByteString(s) => {
if !s.is_raw() {
if let Some(without_quotes) = unquote(text, 2, '"') {
- unescape_literal(without_quotes, Mode::ByteStr, &mut |range, char| {
+ unescape_unicode(without_quotes, Mode::ByteStr, &mut |range, char| {
if let Err(err) = char {
push_err(1, range.start, err);
}
@@ -162,7 +162,7 @@ fn validate_literal(literal: ast::Literal, acc: &mut Vec<SyntaxError>) {
ast::LiteralKind::CString(s) => {
if !s.is_raw() {
if let Some(without_quotes) = unquote(text, 2, '"') {
- unescape_literal(without_quotes, Mode::ByteStr, &mut |range, char| {
+ unescape_mixed(without_quotes, Mode::CStr, &mut |range, char| {
if let Err(err) = char {
push_err(1, range.start, err);
}
@@ -172,7 +172,7 @@ fn validate_literal(literal: ast::Literal, acc: &mut Vec<SyntaxError>) {
}
ast::LiteralKind::Char(_) => {
if let Some(without_quotes) = unquote(text, 1, '\'') {
- unescape_literal(without_quotes, Mode::Char, &mut |range, char| {
+ unescape_unicode(without_quotes, Mode::Char, &mut |range, char| {
if let Err(err) = char {
push_err(1, range.start, err);
}
@@ -181,7 +181,7 @@ fn validate_literal(literal: ast::Literal, acc: &mut Vec<SyntaxError>) {
}
ast::LiteralKind::Byte(_) => {
if let Some(without_quotes) = unquote(text, 2, '\'') {
- unescape_literal(without_quotes, Mode::Byte, &mut |range, char| {
+ unescape_unicode(without_quotes, Mode::Byte, &mut |range, char| {
if let Err(err) = char {
push_err(2, range.start, err);
}