Skip to content

Commit ddf41b9

Browse files
committed
Auto merge of rust-lang#138578 - jhpratt:rollup-4r4y9y3, r=jhpratt
Rollup of 7 pull requests Successful merges: - rust-lang#136293 (document capacity for ZST as example) - rust-lang#136355 (Add `*_value` methods to proc_macro lib) - rust-lang#136359 (doc all differences of ptr:copy(_nonoverlapping) with memcpy and memmove) - rust-lang#136816 (refactor `notable_traits_button` to use iterator combinators instead of for loop) - rust-lang#138363 (Add `From<{integer}>` for `f16`/`f128` impls) - rust-lang#138552 (Misc print request handling cleanups + a centralized test for print request stability gating) - rust-lang#138573 (Make `_Unwind_Action` a type alias, not enum) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 227690a + 28d2fbd commit ddf41b9

File tree

40 files changed

+548
-129
lines changed

40 files changed

+548
-129
lines changed

Cargo.lock

+17
Original file line numberDiff line numberDiff line change
@@ -2082,6 +2082,13 @@ 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+
20852092
[[package]]
20862093
name = "lld-wrapper"
20872094
version = "0.1.0"
@@ -3148,6 +3155,12 @@ version = "1.0.1"
31483155
name = "rustc-std-workspace-std"
31493156
version = "1.0.1"
31503157

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+
31513164
[[package]]
31523165
name = "rustc_abi"
31533166
version = "0.0.0"
@@ -3186,6 +3199,7 @@ name = "rustc_ast"
31863199
version = "0.0.0"
31873200
dependencies = [
31883201
"bitflags",
3202+
"literal-escaper",
31893203
"memchr",
31903204
"rustc_ast_ir",
31913205
"rustc_data_structures",
@@ -3895,6 +3909,7 @@ name = "rustc_lexer"
38953909
version = "0.0.0"
38963910
dependencies = [
38973911
"expect-test",
3912+
"literal-escaper",
38983913
"memchr",
38993914
"unicode-properties",
39003915
"unicode-xid",
@@ -4157,6 +4172,7 @@ name = "rustc_parse"
41574172
version = "0.0.0"
41584173
dependencies = [
41594174
"bitflags",
4175+
"literal-escaper",
41604176
"rustc_ast",
41614177
"rustc_ast_pretty",
41624178
"rustc_data_structures",
@@ -4179,6 +4195,7 @@ dependencies = [
41794195
name = "rustc_parse_format"
41804196
version = "0.0.0"
41814197
dependencies = [
4198+
"literal-escaper",
41824199
"rustc_index",
41834200
"rustc_lexer",
41844201
]

compiler/rustc_ast/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ edition = "2024"
66
[dependencies]
77
# tidy-alphabetical-start
88
bitflags = "2.4.1"
9+
literal-escaper = { path = "../../library/literal-escaper" }
910
memchr = "2.7.4"
1011
rustc_ast_ir = { path = "../rustc_ast_ir" }
1112
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 rustc_lexer::unescape::{
5+
use literal_escaper::{
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_driver_impl/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -649,10 +649,10 @@ fn print_crate_info(
649649
HostTuple => println_info!("{}", rustc_session::config::host_tuple()),
650650
Sysroot => println_info!("{}", sess.sysroot.display()),
651651
TargetLibdir => println_info!("{}", sess.target_tlib_path.dir.display()),
652-
TargetSpec => {
652+
TargetSpecJson => {
653653
println_info!("{}", serde_json::to_string_pretty(&sess.target.to_json()).unwrap());
654654
}
655-
AllTargetSpecs => {
655+
AllTargetSpecsJson => {
656656
let mut targets = BTreeMap::new();
657657
for name in rustc_target::spec::TARGETS {
658658
let triple = TargetTuple::from_tuple(name);

compiler/rustc_lexer/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ 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" }
1920

2021
[dependencies.unicode-properties]
2122
version = "0.1.0"

compiler/rustc_lexer/src/lib.rs

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

2828
mod cursor;
29-
pub mod unescape;
3029

3130
#[cfg(test)]
3231
mod tests;
3332

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;
3436
use unicode_properties::UnicodeEmoji;
3537
pub use unicode_xid::UNICODE_VERSION as UNICODE_XID_VERSION;
3638

compiler/rustc_parse/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ edition = "2024"
66
[dependencies]
77
# tidy-alphabetical-start
88
bitflags = "2.4.1"
9+
literal-escaper = { path = "../../library/literal-escaper" }
910
rustc_ast = { path = "../rustc_ast" }
1011
rustc_ast_pretty = { path = "../rustc_ast_pretty" }
1112
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};
34
use rustc_ast::ast::{self, AttrStyle};
45
use rustc_ast::token::{self, CommentKind, Delimiter, IdentIsRaw, Token, TokenKind};
56
use rustc_ast::tokenstream::TokenStream;
67
use rustc_ast::util::unicode::contains_text_flow_control_chars;
78
use rustc_errors::codes::*;
89
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-
unescape::unescape_unicode(src, mode, &mut |span, result| {
973+
literal_escaper::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-
unescape::unescape_mixed(src, mode, &mut |span, result| {
989+
literal_escaper::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};
67
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,6 +6,7 @@ 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;
910
use rustc_ast::ptr::P;
1011
use rustc_ast::token::{self, Delimiter, Token, TokenKind};
1112
use rustc_ast::tokenstream::TokenTree;
@@ -21,7 +22,6 @@ use rustc_ast::{
2122
use rustc_ast_pretty::pprust;
2223
use rustc_data_structures::stack::ensure_sufficient_stack;
2324
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,6 +5,7 @@ edition = "2024"
55

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

compiler/rustc_parse_format/src/lib.rs

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

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

11041105
ok.then_some(buf)
11051106
}

compiler/rustc_session/src/config.rs

+54-60
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ pub mod sigpipe;
4444

4545
pub const PRINT_KINDS: &[(&str, PrintKind)] = &[
4646
// tidy-alphabetical-start
47-
("all-target-specs-json", PrintKind::AllTargetSpecs),
47+
("all-target-specs-json", PrintKind::AllTargetSpecsJson),
4848
("calling-conventions", PrintKind::CallingConventions),
4949
("cfg", PrintKind::Cfg),
5050
("check-cfg", PrintKind::CheckCfg),
@@ -63,7 +63,7 @@ pub const PRINT_KINDS: &[(&str, PrintKind)] = &[
6363
("target-features", PrintKind::TargetFeatures),
6464
("target-libdir", PrintKind::TargetLibdir),
6565
("target-list", PrintKind::TargetList),
66-
("target-spec-json", PrintKind::TargetSpec),
66+
("target-spec-json", PrintKind::TargetSpecJson),
6767
("tls-models", PrintKind::TlsModels),
6868
// tidy-alphabetical-end
6969
];
@@ -873,27 +873,29 @@ pub struct PrintRequest {
873873

874874
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
875875
pub enum PrintKind {
876+
// tidy-alphabetical-start
877+
AllTargetSpecsJson,
878+
CallingConventions,
879+
Cfg,
880+
CheckCfg,
881+
CodeModels,
882+
CrateName,
883+
DeploymentTarget,
876884
FileNames,
877885
HostTuple,
886+
LinkArgs,
887+
NativeStaticLibs,
888+
RelocationModels,
889+
SplitDebuginfo,
890+
StackProtectorStrategies,
878891
Sysroot,
879-
TargetLibdir,
880-
CrateName,
881-
Cfg,
882-
CheckCfg,
883-
CallingConventions,
884-
TargetList,
885892
TargetCPUs,
886893
TargetFeatures,
887-
RelocationModels,
888-
CodeModels,
894+
TargetLibdir,
895+
TargetList,
896+
TargetSpecJson,
889897
TlsModels,
890-
TargetSpec,
891-
AllTargetSpecs,
892-
NativeStaticLibs,
893-
StackProtectorStrategies,
894-
LinkArgs,
895-
SplitDebuginfo,
896-
DeploymentTarget,
898+
// tidy-alphabetical-end
897899
}
898900

899901
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq, Default)]
@@ -2030,49 +2032,13 @@ fn collect_print_requests(
20302032
prints.extend(matches.opt_strs("print").into_iter().map(|req| {
20312033
let (req, out) = split_out_file_name(&req);
20322034

2033-
let kind = match PRINT_KINDS.iter().find(|&&(name, _)| name == req) {
2034-
Some((_, PrintKind::TargetSpec)) => {
2035-
if unstable_opts.unstable_options {
2036-
PrintKind::TargetSpec
2037-
} else {
2038-
early_dcx.early_fatal(
2039-
"the `-Z unstable-options` flag must also be passed to \
2040-
enable the target-spec-json print option",
2041-
);
2042-
}
2043-
}
2044-
Some((_, PrintKind::AllTargetSpecs)) => {
2045-
if unstable_opts.unstable_options {
2046-
PrintKind::AllTargetSpecs
2047-
} else {
2048-
early_dcx.early_fatal(
2049-
"the `-Z unstable-options` flag must also be passed to \
2050-
enable the all-target-specs-json print option",
2051-
);
2052-
}
2053-
}
2054-
Some((_, PrintKind::CheckCfg)) => {
2055-
if unstable_opts.unstable_options {
2056-
PrintKind::CheckCfg
2057-
} else {
2058-
early_dcx.early_fatal(
2059-
"the `-Z unstable-options` flag must also be passed to \
2060-
enable the check-cfg print option",
2061-
);
2062-
}
2063-
}
2064-
Some(&(_, print_kind)) => print_kind,
2065-
None => {
2066-
let prints =
2067-
PRINT_KINDS.iter().map(|(name, _)| format!("`{name}`")).collect::<Vec<_>>();
2068-
let prints = prints.join(", ");
2069-
2070-
let mut diag =
2071-
early_dcx.early_struct_fatal(format!("unknown print request: `{req}`"));
2072-
#[allow(rustc::diagnostic_outside_of_impl)]
2073-
diag.help(format!("valid print requests are: {prints}"));
2074-
diag.emit()
2075-
}
2035+
let kind = if let Some((print_name, print_kind)) =
2036+
PRINT_KINDS.iter().find(|&&(name, _)| name == req)
2037+
{
2038+
check_print_request_stability(early_dcx, unstable_opts, (print_name, *print_kind));
2039+
*print_kind
2040+
} else {
2041+
emit_unknown_print_request_help(early_dcx, req)
20762042
};
20772043

20782044
let out = out.unwrap_or(OutFileName::Stdout);
@@ -2091,6 +2057,34 @@ fn collect_print_requests(
20912057
prints
20922058
}
20932059

2060+
fn check_print_request_stability(
2061+
early_dcx: &EarlyDiagCtxt,
2062+
unstable_opts: &UnstableOptions,
2063+
(print_name, print_kind): (&str, PrintKind),
2064+
) {
2065+
match print_kind {
2066+
PrintKind::AllTargetSpecsJson | PrintKind::CheckCfg | PrintKind::TargetSpecJson
2067+
if !unstable_opts.unstable_options =>
2068+
{
2069+
early_dcx.early_fatal(format!(
2070+
"the `-Z unstable-options` flag must also be passed to enable the `{print_name}` \
2071+
print option"
2072+
));
2073+
}
2074+
_ => {}
2075+
}
2076+
}
2077+
2078+
fn emit_unknown_print_request_help(early_dcx: &EarlyDiagCtxt, req: &str) -> ! {
2079+
let prints = PRINT_KINDS.iter().map(|(name, _)| format!("`{name}`")).collect::<Vec<_>>();
2080+
let prints = prints.join(", ");
2081+
2082+
let mut diag = early_dcx.early_struct_fatal(format!("unknown print request: `{req}`"));
2083+
#[allow(rustc::diagnostic_outside_of_impl)]
2084+
diag.help(format!("valid print requests are: {prints}"));
2085+
diag.emit()
2086+
}
2087+
20942088
pub fn parse_target_triple(early_dcx: &EarlyDiagCtxt, matches: &getopts::Matches) -> TargetTuple {
20952089
match matches.opt_str("target") {
20962090
Some(target) if target.ends_with(".json") => {

library/Cargo.lock

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

168+
[[package]]
169+
name = "literal-escaper"
170+
version = "0.0.0"
171+
dependencies = [
172+
"rustc-std-workspace-std",
173+
]
174+
168175
[[package]]
169176
name = "memchr"
170177
version = "2.7.4"
@@ -236,6 +243,7 @@ name = "proc_macro"
236243
version = "0.0.0"
237244
dependencies = [
238245
"core",
246+
"literal-escaper",
239247
"std",
240248
]
241249

library/Cargo.toml

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

1010
exclude = [
11+
"literal-escaper",
1112
# stdarch has its own Cargo workspace
1213
"stdarch",
1314
"windows_targets"

0 commit comments

Comments
 (0)