| author | bors <bors@rust-lang.org> 2025-06-25 01:03:30 UTC |
| committer | bors <bors@rust-lang.org> 2025-06-25 01:03:30 UTC |
| log | 2c2bb995af398383e3b93b859302bdc447ca7a7c |
| tree | b038512b5d792f44f554b823a9db293ba93c7697 |
| parent | 3de5b08ef6b260277dd4c77f7472fe6904bd6002 |
| parent | 707a6f54631c322e8c8ccff363fe024d67d93aa2 |
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 https://github.com/rust-lang/rust/pull/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`16 files changed, 67 insertions(+), 94 deletions(-)
Cargo.lock+2-2| ... | ... | @@ -3175,9 +3175,9 @@ checksum = "357703d41365b4b27c590e3ed91eabb1b663f07c4c084095e60cbed4362dff0d" |
| 3175 | 3175 | |
| 3176 | 3176 | [[package]] |
| 3177 | 3177 | name = "rustc-literal-escaper" |
| 3178 | version = "0.0.2" | |
| 3178 | version = "0.0.4" | |
| 3179 | 3179 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 3180 | checksum = "0041b6238913c41fe704213a4a9329e2f685a156d1781998128b4149c230ad04" | |
| 3180 | checksum = "ab03008eb631b703dd16978282ae36c73282e7922fe101a4bd072a40ecea7b8b" | |
| 3181 | 3181 | |
| 3182 | 3182 | [[package]] |
| 3183 | 3183 | name = "rustc-main" |
Cargo.toml+5| ... | ... | @@ -89,3 +89,8 @@ codegen-units = 1 |
| 89 | 89 | # FIXME: LTO cannot be enabled for binaries in a workspace |
| 90 | 90 | # <https://github.com/rust-lang/cargo/issues/9330> |
| 91 | 91 | # lto = true |
| 92 | ||
| 93 | # If you want to use a crate with local modifications, you can set a path or git dependency here. | |
| 94 | # For git dependencies, also add your source to ALLOWED_SOURCES in src/tools/tidy/src/extdeps.rs. | |
| 95 | #[patch.crates-io] | |
| 96 |
compiler/rustc_ast/Cargo.toml+1-1| ... | ... | @@ -7,7 +7,7 @@ edition = "2024" |
| 7 | 7 | # tidy-alphabetical-start |
| 8 | 8 | bitflags = "2.4.1" |
| 9 | 9 | memchr = "2.7.4" |
| 10 | rustc-literal-escaper = "0.0.2" | |
| 10 | rustc-literal-escaper = "0.0.4" | |
| 11 | 11 | rustc_ast_ir = { path = "../rustc_ast_ir" } |
| 12 | 12 | rustc_data_structures = { path = "../rustc_data_structures" } |
| 13 | 13 | rustc_index = { path = "../rustc_index" } |
compiler/rustc_ast/src/util/literal.rs+7-8| ... | ... | @@ -3,7 +3,7 @@ |
| 3 | 3 | use std::{ascii, fmt, str}; |
| 4 | 4 | |
| 5 | 5 | use rustc_literal_escaper::{ |
| 6 | MixedUnit, Mode, byte_from_char, unescape_byte, unescape_char, unescape_mixed, unescape_unicode, | |
| 6 | MixedUnit, unescape_byte, unescape_byte_str, unescape_c_str, unescape_char, unescape_str, | |
| 7 | 7 | }; |
| 8 | 8 | use rustc_span::{Span, Symbol, kw, sym}; |
| 9 | 9 | use tracing::debug; |
| ... | ... | @@ -87,11 +87,10 @@ impl LitKind { |
| 87 | 87 | // Force-inlining here is aggressive but the closure is |
| 88 | 88 | // called on every char in the string, so it can be hot in |
| 89 | 89 | // programs with many long strings containing escapes. |
| 90 | unescape_unicode( | |
| 90 | unescape_str( | |
| 91 | 91 | s, |
| 92 | Mode::Str, | |
| 93 | &mut #[inline(always)] | |
| 94 | |_, c| match c { | |
| 92 | #[inline(always)] | |
| 93 | |_, res| match res { | |
| 95 | 94 | Ok(c) => buf.push(c), |
| 96 | 95 | Err(err) => { |
| 97 | 96 | assert!(!err.is_fatal(), "failed to unescape string literal") |
| ... | ... | @@ -111,8 +110,8 @@ impl LitKind { |
| 111 | 110 | token::ByteStr => { |
| 112 | 111 | let s = symbol.as_str(); |
| 113 | 112 | let mut buf = Vec::with_capacity(s.len()); |
| 114 | unescape_unicode(s, Mode::ByteStr, &mut |_, c| match c { | |
| 115 | Ok(c) => buf.push(byte_from_char(c)), | |
| 113 | unescape_byte_str(s, |_, res| match res { | |
| 114 | Ok(b) => buf.push(b), | |
| 116 | 115 | Err(err) => { |
| 117 | 116 | assert!(!err.is_fatal(), "failed to unescape string literal") |
| 118 | 117 | } |
| ... | ... | @@ -128,7 +127,7 @@ impl LitKind { |
| 128 | 127 | token::CStr => { |
| 129 | 128 | let s = symbol.as_str(); |
| 130 | 129 | let mut buf = Vec::with_capacity(s.len()); |
| 131 | unescape_mixed(s, Mode::CStr, &mut |_span, c| match c { | |
| 130 | unescape_c_str(s, |_span, c| match c { | |
| 132 | 131 | Ok(MixedUnit::Char(c)) => { |
| 133 | 132 | buf.extend_from_slice(c.encode_utf8(&mut [0; 4]).as_bytes()) |
| 134 | 133 | } |
compiler/rustc_parse/Cargo.toml+1-1| ... | ... | @@ -6,7 +6,7 @@ edition = "2024" |
| 6 | 6 | [dependencies] |
| 7 | 7 | # tidy-alphabetical-start |
| 8 | 8 | bitflags = "2.4.1" |
| 9 | rustc-literal-escaper = "0.0.2" | |
| 9 | rustc-literal-escaper = "0.0.4" | |
| 10 | 10 | rustc_ast = { path = "../rustc_ast" } |
| 11 | 11 | rustc_ast_pretty = { path = "../rustc_ast_pretty" } |
| 12 | 12 | rustc_data_structures = { path = "../rustc_data_structures" } |
compiler/rustc_parse/src/lexer/mod.rs+32-62| ... | ... | @@ -1,5 +1,3 @@ |
| 1 | use std::ops::Range; | |
| 2 | ||
| 3 | 1 | use diagnostics::make_unclosed_delims_error; |
| 4 | 2 | use rustc_ast::ast::{self, AttrStyle}; |
| 5 | 3 | use rustc_ast::token::{self, CommentKind, Delimiter, IdentIsRaw, Token, TokenKind}; |
| ... | ... | @@ -10,7 +8,7 @@ use rustc_errors::{Applicability, Diag, DiagCtxtHandle, StashKey}; |
| 10 | 8 | use rustc_lexer::{ |
| 11 | 9 | Base, Cursor, DocStyle, FrontmatterAllowed, LiteralKind, RawStrError, is_whitespace, |
| 12 | 10 | }; |
| 13 | use rustc_literal_escaper::{EscapeError, Mode, unescape_mixed, unescape_unicode}; | |
| 11 | use rustc_literal_escaper::{EscapeError, Mode, check_for_errors}; | |
| 14 | 12 | use rustc_session::lint::BuiltinLintDiag; |
| 15 | 13 | use rustc_session::lint::builtin::{ |
| 16 | 14 | RUST_2021_PREFIXES_INCOMPATIBLE_SYNTAX, RUST_2024_GUARDED_STRING_INCOMPATIBLE_SYNTAX, |
| ... | ... | @@ -702,7 +700,7 @@ impl<'psess, 'src> Lexer<'psess, 'src> { |
| 702 | 700 | } |
| 703 | 701 | err.emit() |
| 704 | 702 | } |
| 705 | self.cook_unicode(token::Char, Mode::Char, start, end, 1, 1) // ' ' | |
| 703 | self.cook_quoted(token::Char, Mode::Char, start, end, 1, 1) // ' ' | |
| 706 | 704 | } |
| 707 | 705 | rustc_lexer::LiteralKind::Byte { terminated } => { |
| 708 | 706 | if !terminated { |
| ... | ... | @@ -714,7 +712,7 @@ impl<'psess, 'src> Lexer<'psess, 'src> { |
| 714 | 712 | .with_code(E0763) |
| 715 | 713 | .emit() |
| 716 | 714 | } |
| 717 | self.cook_unicode(token::Byte, Mode::Byte, start, end, 2, 1) // b' ' | |
| 715 | self.cook_quoted(token::Byte, Mode::Byte, start, end, 2, 1) // b' ' | |
| 718 | 716 | } |
| 719 | 717 | rustc_lexer::LiteralKind::Str { terminated } => { |
| 720 | 718 | if !terminated { |
| ... | ... | @@ -726,7 +724,7 @@ impl<'psess, 'src> Lexer<'psess, 'src> { |
| 726 | 724 | .with_code(E0765) |
| 727 | 725 | .emit() |
| 728 | 726 | } |
| 729 | self.cook_unicode(token::Str, Mode::Str, start, end, 1, 1) // " " | |
| 727 | self.cook_quoted(token::Str, Mode::Str, start, end, 1, 1) // " " | |
| 730 | 728 | } |
| 731 | 729 | rustc_lexer::LiteralKind::ByteStr { terminated } => { |
| 732 | 730 | if !terminated { |
| ... | ... | @@ -738,7 +736,8 @@ impl<'psess, 'src> Lexer<'psess, 'src> { |
| 738 | 736 | .with_code(E0766) |
| 739 | 737 | .emit() |
| 740 | 738 | } |
| 741 | self.cook_unicode(token::ByteStr, Mode::ByteStr, start, end, 2, 1) // b" " | |
| 739 | self.cook_quoted(token::ByteStr, Mode::ByteStr, start, end, 2, 1) | |
| 740 | // b" " | |
| 742 | 741 | } |
| 743 | 742 | rustc_lexer::LiteralKind::CStr { terminated } => { |
| 744 | 743 | if !terminated { |
| ... | ... | @@ -750,13 +749,14 @@ impl<'psess, 'src> Lexer<'psess, 'src> { |
| 750 | 749 | .with_code(E0767) |
| 751 | 750 | .emit() |
| 752 | 751 | } |
| 753 | self.cook_mixed(token::CStr, Mode::CStr, start, end, 2, 1) // c" " | |
| 752 | self.cook_quoted(token::CStr, Mode::CStr, start, end, 2, 1) // c" " | |
| 754 | 753 | } |
| 755 | 754 | rustc_lexer::LiteralKind::RawStr { n_hashes } => { |
| 756 | 755 | if let Some(n_hashes) = n_hashes { |
| 757 | 756 | let n = u32::from(n_hashes); |
| 758 | 757 | let kind = token::StrRaw(n_hashes); |
| 759 | self.cook_unicode(kind, Mode::RawStr, start, end, 2 + n, 1 + n) // r##" "## | |
| 758 | self.cook_quoted(kind, Mode::RawStr, start, end, 2 + n, 1 + n) | |
| 759 | // r##" "## | |
| 760 | 760 | } else { |
| 761 | 761 | self.report_raw_str_error(start, 1); |
| 762 | 762 | } |
| ... | ... | @@ -765,7 +765,8 @@ impl<'psess, 'src> Lexer<'psess, 'src> { |
| 765 | 765 | if let Some(n_hashes) = n_hashes { |
| 766 | 766 | let n = u32::from(n_hashes); |
| 767 | 767 | let kind = token::ByteStrRaw(n_hashes); |
| 768 | self.cook_unicode(kind, Mode::RawByteStr, start, end, 3 + n, 1 + n) // br##" "## | |
| 768 | self.cook_quoted(kind, Mode::RawByteStr, start, end, 3 + n, 1 + n) | |
| 769 | // br##" "## | |
| 769 | 770 | } else { |
| 770 | 771 | self.report_raw_str_error(start, 2); |
| 771 | 772 | } |
| ... | ... | @@ -774,7 +775,8 @@ impl<'psess, 'src> Lexer<'psess, 'src> { |
| 774 | 775 | if let Some(n_hashes) = n_hashes { |
| 775 | 776 | let n = u32::from(n_hashes); |
| 776 | 777 | let kind = token::CStrRaw(n_hashes); |
| 777 | self.cook_unicode(kind, Mode::RawCStr, start, end, 3 + n, 1 + n) // cr##" "## | |
| 778 | self.cook_quoted(kind, Mode::RawCStr, start, end, 3 + n, 1 + n) | |
| 779 | // cr##" "## | |
| 778 | 780 | } else { |
| 779 | 781 | self.report_raw_str_error(start, 2); |
| 780 | 782 | } |
| ... | ... | @@ -1091,7 +1093,7 @@ impl<'psess, 'src> Lexer<'psess, 'src> { |
| 1091 | 1093 | self.dcx().emit_fatal(errors::TooManyHashes { span: self.mk_sp(start, self.pos), num }); |
| 1092 | 1094 | } |
| 1093 | 1095 | |
| 1094 | fn cook_common( | |
| 1096 | fn cook_quoted( | |
| 1095 | 1097 | &self, |
| 1096 | 1098 | mut kind: token::LitKind, |
| 1097 | 1099 | mode: Mode, |
| ... | ... | @@ -1099,32 +1101,28 @@ impl<'psess, 'src> Lexer<'psess, 'src> { |
| 1099 | 1101 | end: BytePos, |
| 1100 | 1102 | prefix_len: u32, |
| 1101 | 1103 | postfix_len: u32, |
| 1102 | unescape: fn(&str, Mode, &mut dyn FnMut(Range<usize>, Result<(), EscapeError>)), | |
| 1103 | 1104 | ) -> (token::LitKind, Symbol) { |
| 1104 | 1105 | let content_start = start + BytePos(prefix_len); |
| 1105 | 1106 | let content_end = end - BytePos(postfix_len); |
| 1106 | 1107 | let lit_content = self.str_from_to(content_start, content_end); |
| 1107 | unescape(lit_content, mode, &mut |range, result| { | |
| 1108 | // Here we only check for errors. The actual unescaping is done later. | |
| 1109 | if let Err(err) = result { | |
| 1110 | let span_with_quotes = self.mk_sp(start, end); | |
| 1111 | let (start, end) = (range.start as u32, range.end as u32); | |
| 1112 | let lo = content_start + BytePos(start); | |
| 1113 | let hi = lo + BytePos(end - start); | |
| 1114 | let span = self.mk_sp(lo, hi); | |
| 1115 | let is_fatal = err.is_fatal(); | |
| 1116 | if let Some(guar) = emit_unescape_error( | |
| 1117 | self.dcx(), | |
| 1118 | lit_content, | |
| 1119 | span_with_quotes, | |
| 1120 | span, | |
| 1121 | mode, | |
| 1122 | range, | |
| 1123 | err, | |
| 1124 | ) { | |
| 1125 | assert!(is_fatal); | |
| 1126 | kind = token::Err(guar); | |
| 1127 | } | |
| 1108 | check_for_errors(lit_content, mode, |range, err| { | |
| 1109 | let span_with_quotes = self.mk_sp(start, end); | |
| 1110 | let (start, end) = (range.start as u32, range.end as u32); | |
| 1111 | let lo = content_start + BytePos(start); | |
| 1112 | let hi = lo + BytePos(end - start); | |
| 1113 | let span = self.mk_sp(lo, hi); | |
| 1114 | let is_fatal = err.is_fatal(); | |
| 1115 | if let Some(guar) = emit_unescape_error( | |
| 1116 | self.dcx(), | |
| 1117 | lit_content, | |
| 1118 | span_with_quotes, | |
| 1119 | span, | |
| 1120 | mode, | |
| 1121 | range, | |
| 1122 | err, | |
| 1123 | ) { | |
| 1124 | assert!(is_fatal); | |
| 1125 | kind = token::Err(guar); | |
| 1128 | 1126 | } |
| 1129 | 1127 | }); |
| 1130 | 1128 | |
| ... | ... | @@ -1137,34 +1135,6 @@ impl<'psess, 'src> Lexer<'psess, 'src> { |
| 1137 | 1135 | }; |
| 1138 | 1136 | (kind, sym) |
| 1139 | 1137 | } |
| 1140 | ||
| 1141 | fn cook_unicode( | |
| 1142 | &self, | |
| 1143 | kind: token::LitKind, | |
| 1144 | mode: Mode, | |
| 1145 | start: BytePos, | |
| 1146 | end: BytePos, | |
| 1147 | prefix_len: u32, | |
| 1148 | postfix_len: u32, | |
| 1149 | ) -> (token::LitKind, Symbol) { | |
| 1150 | self.cook_common(kind, mode, start, end, prefix_len, postfix_len, |src, mode, callback| { | |
| 1151 | unescape_unicode(src, mode, &mut |span, result| callback(span, result.map(drop))) | |
| 1152 | }) | |
| 1153 | } | |
| 1154 | ||
| 1155 | fn cook_mixed( | |
| 1156 | &self, | |
| 1157 | kind: token::LitKind, | |
| 1158 | mode: Mode, | |
| 1159 | start: BytePos, | |
| 1160 | end: BytePos, | |
| 1161 | prefix_len: u32, | |
| 1162 | postfix_len: u32, | |
| 1163 | ) -> (token::LitKind, Symbol) { | |
| 1164 | self.cook_common(kind, mode, start, end, prefix_len, postfix_len, |src, mode, callback| { | |
| 1165 | unescape_mixed(src, mode, &mut |span, result| callback(span, result.map(drop))) | |
| 1166 | }) | |
| 1167 | } | |
| 1168 | 1138 | } |
| 1169 | 1139 | |
| 1170 | 1140 | pub fn nfc_normalize(string: &str) -> Symbol { |
compiler/rustc_parse_format/Cargo.toml+1-1| ... | ... | @@ -5,7 +5,7 @@ edition = "2024" |
| 5 | 5 | |
| 6 | 6 | [dependencies] |
| 7 | 7 | # tidy-alphabetical-start |
| 8 | rustc-literal-escaper = "0.0.2" | |
| 8 | rustc-literal-escaper = "0.0.4" | |
| 9 | 9 | rustc_lexer = { path = "../rustc_lexer" } |
| 10 | 10 | # tidy-alphabetical-end |
| 11 | 11 |
compiler/rustc_parse_format/src/lib.rs+1-2| ... | ... | @@ -20,7 +20,6 @@ use std::ops::Range; |
| 20 | 20 | pub use Alignment::*; |
| 21 | 21 | pub use Count::*; |
| 22 | 22 | pub use Position::*; |
| 23 | use rustc_literal_escaper::{Mode, unescape_unicode}; | |
| 24 | 23 | |
| 25 | 24 | /// The type of format string that we are parsing. |
| 26 | 25 | #[derive(Copy, Clone, Debug, Eq, PartialEq)] |
| ... | ... | @@ -320,7 +319,7 @@ impl<'input> Parser<'input> { |
| 320 | 319 | let without_quotes = &snippet[1..snippet.len() - 1]; |
| 321 | 320 | let (mut ok, mut vec) = (true, vec![]); |
| 322 | 321 | let mut chars = input.chars(); |
| 323 | unescape_unicode(without_quotes, Mode::Str, &mut |range, res| match res { | |
| 322 | rustc_literal_escaper::unescape_str(without_quotes, |range, res| match res { | |
| 324 | 323 | Ok(ch) if ok && chars.next().is_some_and(|c| ch == c) => { |
| 325 | 324 | vec.push((range, ch)); |
| 326 | 325 | } |
compiler/rustc_proc_macro/Cargo.toml+1-1| ... | ... | @@ -15,7 +15,7 @@ test = false |
| 15 | 15 | doctest = false |
| 16 | 16 | |
| 17 | 17 | [dependencies] |
| 18 | rustc-literal-escaper = "0.0.2" | |
| 18 | rustc-literal-escaper = "0.0.4" | |
| 19 | 19 | |
| 20 | 20 | [features] |
| 21 | 21 | rustc-dep-of-std = [] |
library/Cargo.lock+3-2| ... | ... | @@ -271,10 +271,11 @@ dependencies = [ |
| 271 | 271 | |
| 272 | 272 | [[package]] |
| 273 | 273 | name = "rustc-literal-escaper" |
| 274 | version = "0.0.2" | |
| 274 | version = "0.0.4" | |
| 275 | 275 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 276 | checksum = "0041b6238913c41fe704213a4a9329e2f685a156d1781998128b4149c230ad04" | |
| 276 | checksum = "ab03008eb631b703dd16978282ae36c73282e7922fe101a4bd072a40ecea7b8b" | |
| 277 | 277 | dependencies = [ |
| 278 | "rustc-std-workspace-core", | |
| 278 | 279 | "rustc-std-workspace-std", |
| 279 | 280 | ] |
| 280 | 281 |
library/Cargo.toml+1-2| ... | ... | @@ -55,8 +55,7 @@ rustflags = ["-Cpanic=abort"] |
| 55 | 55 | rustflags = ["-Cpanic=abort"] |
| 56 | 56 | |
| 57 | 57 | [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 | |
| 60 | 59 | rustc-std-workspace-core = { path = 'rustc-std-workspace-core' } |
| 61 | 60 | rustc-std-workspace-alloc = { path = 'rustc-std-workspace-alloc' } |
| 62 | 61 | rustc-std-workspace-std = { path = 'rustc-std-workspace-std' } |
library/proc_macro/Cargo.toml+1-1| ... | ... | @@ -9,7 +9,7 @@ std = { path = "../std" } |
| 9 | 9 | # `core` when resolving doc links. Without this line a different `core` will be |
| 10 | 10 | # loaded from sysroot causing duplicate lang items and other similar errors. |
| 11 | 11 | 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"] } | |
| 13 | 13 | |
| 14 | 14 | [features] |
| 15 | 15 | default = ["rustc-dep-of-std"] |
library/proc_macro/src/lib.rs+6-7| ... | ... | @@ -56,7 +56,7 @@ use std::{error, fmt}; |
| 56 | 56 | pub use diagnostic::{Diagnostic, Level, MultiSpan}; |
| 57 | 57 | #[unstable(feature = "proc_macro_value", issue = "136652")] |
| 58 | 58 | 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}; | |
| 60 | 60 | #[unstable(feature = "proc_macro_totokens", issue = "130977")] |
| 61 | 61 | pub use to_tokens::ToTokens; |
| 62 | 62 | |
| ... | ... | @@ -1440,10 +1440,9 @@ impl Literal { |
| 1440 | 1440 | // Force-inlining here is aggressive but the closure is |
| 1441 | 1441 | // called on every char in the string, so it can be hot in |
| 1442 | 1442 | // programs with many long strings containing escapes. |
| 1443 | unescape_unicode( | |
| 1443 | unescape_str( | |
| 1444 | 1444 | symbol, |
| 1445 | Mode::Str, | |
| 1446 | &mut #[inline(always)] | |
| 1445 | #[inline(always)] | |
| 1447 | 1446 | |_, c| match c { |
| 1448 | 1447 | Ok(c) => buf.push(c), |
| 1449 | 1448 | Err(err) => { |
| ... | ... | @@ -1472,7 +1471,7 @@ impl Literal { |
| 1472 | 1471 | let mut error = None; |
| 1473 | 1472 | let mut buf = Vec::with_capacity(symbol.len()); |
| 1474 | 1473 | |
| 1475 | unescape_mixed(symbol, Mode::CStr, &mut |_span, c| match c { | |
| 1474 | unescape_c_str(symbol, |_span, c| match c { | |
| 1476 | 1475 | Ok(MixedUnit::Char(c)) => { |
| 1477 | 1476 | buf.extend_from_slice(c.encode_utf8(&mut [0; 4]).as_bytes()) |
| 1478 | 1477 | } |
| ... | ... | @@ -1511,8 +1510,8 @@ impl Literal { |
| 1511 | 1510 | let mut buf = Vec::with_capacity(symbol.len()); |
| 1512 | 1511 | let mut error = None; |
| 1513 | 1512 | |
| 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), | |
| 1516 | 1515 | Err(err) => { |
| 1517 | 1516 | if err.is_fatal() { |
| 1518 | 1517 | error = Some(ConversionErrorKind::FailedToUnescape(err)); |
src/tools/clippy/clippy_dev/src/update_lints.rs+2-1| ... | ... | @@ -2,6 +2,7 @@ use crate::utils::{ |
| 2 | 2 | ErrAction, File, FileUpdater, RustSearcher, Token, UpdateMode, UpdateStatus, expect_action, update_text_region_fn, |
| 3 | 3 | }; |
| 4 | 4 | use itertools::Itertools; |
| 5 | use rustc_lexer::{LiteralKind, TokenKind, tokenize}; | |
| 5 | 6 | use std::collections::HashSet; |
| 6 | 7 | use std::fmt::Write; |
| 7 | 8 | use std::ops::Range; |
| ... | ... | @@ -342,7 +343,7 @@ fn parse_str_lit(s: &str) -> String { |
| 342 | 343 | .and_then(|s| s.strip_suffix('"')) |
| 343 | 344 | .unwrap_or_else(|| panic!("expected quoted string, found `{s}`")); |
| 344 | 345 | let mut res = String::with_capacity(s.len()); |
| 345 | rustc_literal_escaper::unescape_unicode(s, mode, &mut |_, ch| { | |
| 346 | rustc_literal_escaper::unescape_str(s, |range, ch| { | |
| 346 | 347 | if let Ok(ch) = ch { |
| 347 | 348 | res.push(ch); |
| 348 | 349 | } |
src/tools/lint-docs/Cargo.toml+1-1| ... | ... | @@ -7,7 +7,7 @@ description = "A script to extract the lint documentation for the rustc book." |
| 7 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html |
| 8 | 8 | |
| 9 | 9 | [dependencies] |
| 10 | rustc-literal-escaper = "0.0.2" | |
| 10 | rustc-literal-escaper = "0.0.4" | |
| 11 | 11 | serde_json = "1.0.57" |
| 12 | 12 | tempfile = "3.1.0" |
| 13 | 13 | walkdir = "2.3.1" |
src/tools/lint-docs/src/lib.rs+2-2| ... | ... | @@ -4,7 +4,7 @@ use std::fs; |
| 4 | 4 | use std::path::{Path, PathBuf}; |
| 5 | 5 | use std::process::Command; |
| 6 | 6 | |
| 7 | use rustc_literal_escaper::{Mode, unescape_unicode}; | |
| 7 | use rustc_literal_escaper::unescape_str; | |
| 8 | 8 | use walkdir::WalkDir; |
| 9 | 9 | |
| 10 | 10 | mod groups; |
| ... | ... | @@ -218,7 +218,7 @@ impl<'a> LintExtractor<'a> { |
| 218 | 218 | } else if let Some(text) = line.strip_prefix("#[doc = \"") { |
| 219 | 219 | let escaped = text.strip_suffix("\"]").unwrap(); |
| 220 | 220 | let mut buf = String::new(); |
| 221 | unescape_unicode(escaped, Mode::Str, &mut |_, c| match c { | |
| 221 | unescape_str(escaped, |_, res| match res { | |
| 222 | 222 | Ok(c) => buf.push(c), |
| 223 | 223 | Err(err) => { |
| 224 | 224 | assert!(!err.is_fatal(), "failed to unescape string literal") |