Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 8b713e2

Browse files
authoredMar 19, 2025
Rollup merge of rust-lang#138661 - RalfJung:revert-rustc-dev-breakage, r=petrochenkov
Revert: Add *_value methods to proc_macro lib This reverts rust-lang#136355. That PR caused unexpected breakage: - the rustc-dev component can no longer be loaded by cargo, which impacts Miri and clippy and likely others - rustc_lexer can no longer be published to crates.io, which impacts RA See rust-lang#138647 for context. Cc `@GuillaumeGomez` `@Amanieu`
2 parents 00dddc6 + 20d04d8 commit 8b713e2

File tree

27 files changed

+15
-253
lines changed

27 files changed

+15
-253
lines changed
 

‎Cargo.lock

-17
Original file line numberDiff line numberDiff line change
@@ -2082,13 +2082,6 @@ version = "0.7.4"
20822082
source = "registry+https://github.com/rust-lang/crates.io-index"
20832083
checksum = "4ee93343901ab17bd981295f2cf0026d4ad018c7c31ba84549a4ddbb47a45104"
20842084

2085-
[[package]]
2086-
name = "literal-escaper"
2087-
version = "0.0.0"
2088-
dependencies = [
2089-
"rustc-std-workspace-std 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
2090-
]
2091-
20922085
[[package]]
20932086
name = "lld-wrapper"
20942087
version = "0.1.0"
@@ -3155,12 +3148,6 @@ version = "1.0.1"
31553148
name = "rustc-std-workspace-std"
31563149
version = "1.0.1"
31573150

3158-
[[package]]
3159-
name = "rustc-std-workspace-std"
3160-
version = "1.0.1"
3161-
source = "registry+https://github.com/rust-lang/crates.io-index"
3162-
checksum = "aba676a20abe46e5b0f1b0deae474aaaf31407e6c71147159890574599da04ef"
3163-
31643151
[[package]]
31653152
name = "rustc_abi"
31663153
version = "0.0.0"
@@ -3199,7 +3186,6 @@ name = "rustc_ast"
31993186
version = "0.0.0"
32003187
dependencies = [
32013188
"bitflags",
3202-
"literal-escaper",
32033189
"memchr",
32043190
"rustc_ast_ir",
32053191
"rustc_data_structures",
@@ -3909,7 +3895,6 @@ name = "rustc_lexer"
39093895
version = "0.0.0"
39103896
dependencies = [
39113897
"expect-test",
3912-
"literal-escaper",
39133898
"memchr",
39143899
"unicode-properties",
39153900
"unicode-xid",
@@ -4172,7 +4157,6 @@ name = "rustc_parse"
41724157
version = "0.0.0"
41734158
dependencies = [
41744159
"bitflags",
4175-
"literal-escaper",
41764160
"rustc_ast",
41774161
"rustc_ast_pretty",
41784162
"rustc_data_structures",
@@ -4195,7 +4179,6 @@ dependencies = [
41954179
name = "rustc_parse_format"
41964180
version = "0.0.0"
41974181
dependencies = [
4198-
"literal-escaper",
41994182
"rustc_index",
42004183
"rustc_lexer",
42014184
]

‎compiler/rustc_ast/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ edition = "2024"
66
[dependencies]
77
# tidy-alphabetical-start
88
bitflags = "2.4.1"
9-
literal-escaper = { path = "../../library/literal-escaper" }
109
memchr = "2.7.4"
1110
rustc_ast_ir = { path = "../rustc_ast_ir" }
1211
rustc_data_structures = { path = "../rustc_data_structures" }

‎compiler/rustc_ast/src/util/literal.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
use std::{ascii, fmt, str};
44

5-
use literal_escaper::{
5+
use rustc_lexer::unescape::{
66
MixedUnit, Mode, byte_from_char, unescape_byte, unescape_char, unescape_mixed, unescape_unicode,
77
};
88
use rustc_span::{Span, Symbol, kw, sym};

‎compiler/rustc_lexer/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ Rust lexer used by rustc. No stability guarantees are provided.
1616
[dependencies]
1717
memchr = "2.7.4"
1818
unicode-xid = "0.2.0"
19-
literal-escaper = { path = "../../library/literal-escaper" }
2019

2120
[dependencies.unicode-properties]
2221
version = "0.1.0"

‎compiler/rustc_lexer/src/lib.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,11 @@
2626
// tidy-alphabetical-end
2727

2828
mod cursor;
29+
pub mod unescape;
2930

3031
#[cfg(test)]
3132
mod tests;
3233

33-
// FIXME: This is needed for rust-analyzer. Remove this dependency once rust-analyzer uses
34-
// `literal-escaper`.
35-
pub use literal_escaper as unescape;
3634
use unicode_properties::UnicodeEmoji;
3735
pub use unicode_xid::UNICODE_VERSION as UNICODE_XID_VERSION;
3836

File renamed without changes.

‎compiler/rustc_parse/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ edition = "2024"
66
[dependencies]
77
# tidy-alphabetical-start
88
bitflags = "2.4.1"
9-
literal-escaper = { path = "../../library/literal-escaper" }
109
rustc_ast = { path = "../rustc_ast" }
1110
rustc_ast_pretty = { path = "../rustc_ast_pretty" }
1211
rustc_data_structures = { path = "../rustc_data_structures" }

‎compiler/rustc_parse/src/lexer/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
use std::ops::Range;
22

3-
use literal_escaper::{self, EscapeError, Mode};
43
use rustc_ast::ast::{self, AttrStyle};
54
use rustc_ast::token::{self, CommentKind, Delimiter, IdentIsRaw, Token, TokenKind};
65
use rustc_ast::tokenstream::TokenStream;
76
use rustc_ast::util::unicode::contains_text_flow_control_chars;
87
use rustc_errors::codes::*;
98
use rustc_errors::{Applicability, Diag, DiagCtxtHandle, StashKey};
9+
use rustc_lexer::unescape::{self, EscapeError, Mode};
1010
use rustc_lexer::{Base, Cursor, DocStyle, LiteralKind, RawStrError};
1111
use rustc_session::lint::BuiltinLintDiag;
1212
use rustc_session::lint::builtin::{
@@ -970,7 +970,7 @@ impl<'psess, 'src> Lexer<'psess, 'src> {
970970
postfix_len: u32,
971971
) -> (token::LitKind, Symbol) {
972972
self.cook_common(kind, mode, start, end, prefix_len, postfix_len, |src, mode, callback| {
973-
literal_escaper::unescape_unicode(src, mode, &mut |span, result| {
973+
unescape::unescape_unicode(src, mode, &mut |span, result| {
974974
callback(span, result.map(drop))
975975
})
976976
})
@@ -986,7 +986,7 @@ impl<'psess, 'src> Lexer<'psess, 'src> {
986986
postfix_len: u32,
987987
) -> (token::LitKind, Symbol) {
988988
self.cook_common(kind, mode, start, end, prefix_len, postfix_len, |src, mode, callback| {
989-
literal_escaper::unescape_mixed(src, mode, &mut |span, result| {
989+
unescape::unescape_mixed(src, mode, &mut |span, result| {
990990
callback(span, result.map(drop))
991991
})
992992
})

‎compiler/rustc_parse/src/lexer/unescape_error_reporting.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
use std::iter::once;
44
use std::ops::Range;
55

6-
use literal_escaper::{EscapeError, Mode};
76
use rustc_errors::{Applicability, DiagCtxtHandle, ErrorGuaranteed};
7+
use rustc_lexer::unescape::{EscapeError, Mode};
88
use rustc_span::{BytePos, Span};
99
use tracing::debug;
1010

‎compiler/rustc_parse/src/parser/expr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use core::ops::{Bound, ControlFlow};
66
use ast::mut_visit::{self, MutVisitor};
77
use ast::token::{IdentIsRaw, MetaVarKind};
88
use ast::{CoroutineKind, ForLoopKind, GenBlockKind, MatchKind, Pat, Path, PathSegment, Recovered};
9-
use literal_escaper::unescape_char;
109
use rustc_ast::ptr::P;
1110
use rustc_ast::token::{self, Delimiter, Token, TokenKind};
1211
use rustc_ast::tokenstream::TokenTree;
@@ -22,6 +21,7 @@ use rustc_ast::{
2221
use rustc_ast_pretty::pprust;
2322
use rustc_data_structures::stack::ensure_sufficient_stack;
2423
use rustc_errors::{Applicability, Diag, PResult, StashKey, Subdiagnostic};
24+
use rustc_lexer::unescape::unescape_char;
2525
use rustc_macros::Subdiagnostic;
2626
use rustc_session::errors::{ExprParenthesesNeeded, report_lit_error};
2727
use rustc_session::lint::BuiltinLintDiag;

‎compiler/rustc_parse_format/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ edition = "2024"
55

66
[dependencies]
77
# tidy-alphabetical-start
8-
literal-escaper = { path = "../../library/literal-escaper" }
98
rustc_index = { path = "../rustc_index", default-features = false }
109
rustc_lexer = { path = "../rustc_lexer" }
1110
# tidy-alphabetical-end

‎compiler/rustc_parse_format/src/lib.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
pub use Alignment::*;
1919
pub use Count::*;
2020
pub use Position::*;
21+
use rustc_lexer::unescape;
2122

2223
// Note: copied from rustc_span
2324
/// Range inside of a `Span` used for diagnostics when we only have access to relative positions.
@@ -1093,14 +1094,12 @@ fn find_width_map_from_snippet(
10931094
fn unescape_string(string: &str) -> Option<String> {
10941095
let mut buf = String::new();
10951096
let mut ok = true;
1096-
literal_escaper::unescape_unicode(
1097-
string,
1098-
literal_escaper::Mode::Str,
1099-
&mut |_, unescaped_char| match unescaped_char {
1097+
unescape::unescape_unicode(string, unescape::Mode::Str, &mut |_, unescaped_char| {
1098+
match unescaped_char {
11001099
Ok(c) => buf.push(c),
11011100
Err(_) => ok = false,
1102-
},
1103-
);
1101+
}
1102+
});
11041103

11051104
ok.then_some(buf)
11061105
}

‎library/Cargo.lock

-8
Original file line numberDiff line numberDiff line change
@@ -164,13 +164,6 @@ dependencies = [
164164
"rustc-std-workspace-core",
165165
]
166166

167-
[[package]]
168-
name = "literal-escaper"
169-
version = "0.0.0"
170-
dependencies = [
171-
"rustc-std-workspace-std",
172-
]
173-
174167
[[package]]
175168
name = "memchr"
176169
version = "2.7.4"
@@ -242,7 +235,6 @@ name = "proc_macro"
242235
version = "0.0.0"
243236
dependencies = [
244237
"core",
245-
"literal-escaper",
246238
"std",
247239
]
248240

‎library/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ members = [
88
]
99

1010
exclude = [
11-
"literal-escaper",
1211
# stdarch has its own Cargo workspace
1312
"stdarch",
1413
"windows_targets"

‎library/literal-escaper/Cargo.toml

-10
This file was deleted.

‎library/literal-escaper/README.md

-4
This file was deleted.

‎library/proc_macro/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ version = "0.0.0"
44
edition = "2024"
55

66
[dependencies]
7-
literal-escaper = { path = "../literal-escaper", features = ["rustc-dep-of-std"] }
87
std = { path = "../std" }
98
# Workaround: when documenting this crate rustdoc will try to load crate named
109
# `core` when resolving doc links. Without this line a different `core` will be

‎library/proc_macro/src/lib.rs

-115
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
#![feature(restricted_std)]
2929
#![feature(rustc_attrs)]
3030
#![feature(extend_one)]
31-
#![feature(stmt_expr_attributes)]
3231
#![recursion_limit = "256"]
3332
#![allow(internal_features)]
3433
#![deny(ffi_unwind_calls)]
@@ -52,24 +51,11 @@ use std::{error, fmt};
5251

5352
#[unstable(feature = "proc_macro_diagnostic", issue = "54140")]
5453
pub use diagnostic::{Diagnostic, Level, MultiSpan};
55-
#[unstable(feature = "proc_macro_value", issue = "136652")]
56-
pub use literal_escaper::EscapeError;
57-
use literal_escaper::{MixedUnit, Mode, byte_from_char, unescape_mixed, unescape_unicode};
5854
#[unstable(feature = "proc_macro_totokens", issue = "130977")]
5955
pub use to_tokens::ToTokens;
6056

6157
use crate::escape::{EscapeOptions, escape_bytes};
6258

63-
/// Errors returned when trying to retrieve a literal unescaped value.
64-
#[unstable(feature = "proc_macro_value", issue = "136652")]
65-
#[derive(Debug, PartialEq, Eq)]
66-
pub enum ConversionErrorKind {
67-
/// The literal failed to be escaped, take a look at [`EscapeError`] for more information.
68-
FailedToUnescape(EscapeError),
69-
/// Trying to convert a literal with the wrong type.
70-
InvalidLiteralKind,
71-
}
72-
7359
/// Determines whether proc_macro has been made accessible to the currently
7460
/// running program.
7561
///
@@ -1465,107 +1451,6 @@ impl Literal {
14651451
}
14661452
})
14671453
}
1468-
1469-
/// Returns the unescaped string value if the current literal is a string or a string literal.
1470-
#[unstable(feature = "proc_macro_value", issue = "136652")]
1471-
pub fn str_value(&self) -> Result<String, ConversionErrorKind> {
1472-
self.0.symbol.with(|symbol| match self.0.kind {
1473-
bridge::LitKind::Str => {
1474-
if symbol.contains('\\') {
1475-
let mut buf = String::with_capacity(symbol.len());
1476-
let mut error = None;
1477-
// Force-inlining here is aggressive but the closure is
1478-
// called on every char in the string, so it can be hot in
1479-
// programs with many long strings containing escapes.
1480-
unescape_unicode(
1481-
symbol,
1482-
Mode::Str,
1483-
&mut #[inline(always)]
1484-
|_, c| match c {
1485-
Ok(c) => buf.push(c),
1486-
Err(err) => {
1487-
if err.is_fatal() {
1488-
error = Some(ConversionErrorKind::FailedToUnescape(err));
1489-
}
1490-
}
1491-
},
1492-
);
1493-
if let Some(error) = error { Err(error) } else { Ok(buf) }
1494-
} else {
1495-
Ok(symbol.to_string())
1496-
}
1497-
}
1498-
bridge::LitKind::StrRaw(_) => Ok(symbol.to_string()),
1499-
_ => Err(ConversionErrorKind::InvalidLiteralKind),
1500-
})
1501-
}
1502-
1503-
/// Returns the unescaped string value if the current literal is a c-string or a c-string
1504-
/// literal.
1505-
#[unstable(feature = "proc_macro_value", issue = "136652")]
1506-
pub fn cstr_value(&self) -> Result<Vec<u8>, ConversionErrorKind> {
1507-
self.0.symbol.with(|symbol| match self.0.kind {
1508-
bridge::LitKind::CStr => {
1509-
let mut error = None;
1510-
let mut buf = Vec::with_capacity(symbol.len());
1511-
1512-
unescape_mixed(symbol, Mode::CStr, &mut |_span, c| match c {
1513-
Ok(MixedUnit::Char(c)) => {
1514-
buf.extend_from_slice(c.encode_utf8(&mut [0; 4]).as_bytes())
1515-
}
1516-
Ok(MixedUnit::HighByte(b)) => buf.push(b),
1517-
Err(err) => {
1518-
if err.is_fatal() {
1519-
error = Some(ConversionErrorKind::FailedToUnescape(err));
1520-
}
1521-
}
1522-
});
1523-
if let Some(error) = error {
1524-
Err(error)
1525-
} else {
1526-
buf.push(0);
1527-
Ok(buf)
1528-
}
1529-
}
1530-
bridge::LitKind::CStrRaw(_) => {
1531-
// Raw strings have no escapes so we can convert the symbol
1532-
// directly to a `Lrc<u8>` after appending the terminating NUL
1533-
// char.
1534-
let mut buf = symbol.to_owned().into_bytes();
1535-
buf.push(0);
1536-
Ok(buf)
1537-
}
1538-
_ => Err(ConversionErrorKind::InvalidLiteralKind),
1539-
})
1540-
}
1541-
1542-
/// Returns the unescaped string value if the current literal is a byte string or a byte string
1543-
/// literal.
1544-
#[unstable(feature = "proc_macro_value", issue = "136652")]
1545-
pub fn byte_str_value(&self) -> Result<Vec<u8>, ConversionErrorKind> {
1546-
self.0.symbol.with(|symbol| match self.0.kind {
1547-
bridge::LitKind::ByteStr => {
1548-
let mut buf = Vec::with_capacity(symbol.len());
1549-
let mut error = None;
1550-
1551-
unescape_unicode(symbol, Mode::ByteStr, &mut |_, c| match c {
1552-
Ok(c) => buf.push(byte_from_char(c)),
1553-
Err(err) => {
1554-
if err.is_fatal() {
1555-
error = Some(ConversionErrorKind::FailedToUnescape(err));
1556-
}
1557-
}
1558-
});
1559-
if let Some(error) = error { Err(error) } else { Ok(buf) }
1560-
}
1561-
bridge::LitKind::ByteStrRaw(_) => {
1562-
// Raw strings have no escapes so we can convert the symbol
1563-
// directly to a `Lrc<u8>`.
1564-
Ok(symbol.to_owned().into_bytes())
1565-
}
1566-
_ => Err(ConversionErrorKind::InvalidLiteralKind),
1567-
})
1568-
}
15691454
}
15701455

15711456
/// Parse a single literal from its stringified representation.
There was a problem loading the remainder of the diff.

0 commit comments

Comments
 (0)
Failed to load comments.