Skip to content

Commit 884bfed

Browse files
committed
Auto merge of rust-lang#140999 - hkBst:update-escaper, r=nnethercote
update to literal-escaper 0.0.4 for better API without `unreachable` and faster string parsing This is the replacement for just the part of rust-lang#138163 dealing with the changed API of unescape functionality, since that got moved into its own crate. <del>This uses an unpublished version of literal-escaper (https://github.com/rust-lang/literal-escaper/pull/8).</del> r? `@nnethercote`
2 parents b24d9ad + 39f6ede commit 884bfed

File tree

4 files changed

+11
-12
lines changed

4 files changed

+11
-12
lines changed

Cargo.lock

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,7 @@ rustflags = ["-Cpanic=abort"]
5555
rustflags = ["-Cpanic=abort"]
5656

5757
[patch.crates-io]
58-
# See comments in `library/rustc-std-workspace-core/README.md` for what's going on
59-
# here
58+
# See comments in `library/rustc-std-workspace-core/README.md` for what's going on here
6059
rustc-std-workspace-core = { path = 'rustc-std-workspace-core' }
6160
rustc-std-workspace-alloc = { path = 'rustc-std-workspace-alloc' }
6261
rustc-std-workspace-std = { path = 'rustc-std-workspace-std' }

proc_macro/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ std = { path = "../std" }
99
# `core` when resolving doc links. Without this line a different `core` will be
1010
# loaded from sysroot causing duplicate lang items and other similar errors.
1111
core = { path = "../core" }
12-
rustc-literal-escaper = { version = "0.0.2", features = ["rustc-dep-of-std"] }
12+
rustc-literal-escaper = { version = "0.0.4", features = ["rustc-dep-of-std"] }
1313

1414
[features]
1515
default = ["rustc-dep-of-std"]

proc_macro/src/lib.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ use std::{error, fmt};
5656
pub use diagnostic::{Diagnostic, Level, MultiSpan};
5757
#[unstable(feature = "proc_macro_value", issue = "136652")]
5858
pub use rustc_literal_escaper::EscapeError;
59-
use rustc_literal_escaper::{MixedUnit, Mode, byte_from_char, unescape_mixed, unescape_unicode};
59+
use rustc_literal_escaper::{MixedUnit, unescape_byte_str, unescape_c_str, unescape_str};
6060
#[unstable(feature = "proc_macro_totokens", issue = "130977")]
6161
pub use to_tokens::ToTokens;
6262

@@ -1440,10 +1440,9 @@ impl Literal {
14401440
// Force-inlining here is aggressive but the closure is
14411441
// called on every char in the string, so it can be hot in
14421442
// programs with many long strings containing escapes.
1443-
unescape_unicode(
1443+
unescape_str(
14441444
symbol,
1445-
Mode::Str,
1446-
&mut #[inline(always)]
1445+
#[inline(always)]
14471446
|_, c| match c {
14481447
Ok(c) => buf.push(c),
14491448
Err(err) => {
@@ -1472,7 +1471,7 @@ impl Literal {
14721471
let mut error = None;
14731472
let mut buf = Vec::with_capacity(symbol.len());
14741473

1475-
unescape_mixed(symbol, Mode::CStr, &mut |_span, c| match c {
1474+
unescape_c_str(symbol, |_span, c| match c {
14761475
Ok(MixedUnit::Char(c)) => {
14771476
buf.extend_from_slice(c.encode_utf8(&mut [0; 4]).as_bytes())
14781477
}
@@ -1511,8 +1510,8 @@ impl Literal {
15111510
let mut buf = Vec::with_capacity(symbol.len());
15121511
let mut error = None;
15131512

1514-
unescape_unicode(symbol, Mode::ByteStr, &mut |_, c| match c {
1515-
Ok(c) => buf.push(byte_from_char(c)),
1513+
unescape_byte_str(symbol, |_, res| match res {
1514+
Ok(b) => buf.push(b),
15161515
Err(err) => {
15171516
if err.is_fatal() {
15181517
error = Some(ConversionErrorKind::FailedToUnescape(err));

0 commit comments

Comments
 (0)