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 10bcdad

Browse files
committedMar 17, 2025
Auto merge of #138583 - jhpratt:rollup-h699hty, r=jhpratt
Rollup of 5 pull requests Successful merges: - #136293 (document capacity for ZST as example) - #136359 (doc all differences of ptr:copy(_nonoverlapping) with memcpy and memmove) - #136816 (refactor `notable_traits_button` to use iterator combinators instead of for loop) - #138552 (Misc print request handling cleanups + a centralized test for print request stability gating) - #138573 (Make `_Unwind_Action` a type alias, not enum) r? `@ghost` `@rustbot` modify labels: rollup
2 parents c3dd4ee + 5144055 commit 10bcdad

File tree

11 files changed

+205
-113
lines changed

11 files changed

+205
-113
lines changed
 

‎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_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/alloc/src/vec/mod.rs

+13
Original file line numberDiff line numberDiff line change
@@ -1252,6 +1252,19 @@ impl<T, A: Allocator> Vec<T, A> {
12521252
/// vec.push(42);
12531253
/// assert!(vec.capacity() >= 10);
12541254
/// ```
1255+
///
1256+
/// A vector with zero-sized elements will always have a capacity of usize::MAX:
1257+
///
1258+
/// ```
1259+
/// #[derive(Clone)]
1260+
/// struct ZeroSized;
1261+
///
1262+
/// fn main() {
1263+
/// assert_eq!(std::mem::size_of::<ZeroSized>(), 0);
1264+
/// let v = vec![ZeroSized; 0];
1265+
/// assert_eq!(v.capacity(), usize::MAX);
1266+
/// }
1267+
/// ```
12551268
#[inline]
12561269
#[stable(feature = "rust1", since = "1.0.0")]
12571270
#[rustc_const_stable(feature = "const_vec_string_slice", since = "CURRENT_RUSTC_VERSION")]

‎library/core/src/intrinsics/mod.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -3641,7 +3641,8 @@ pub const fn ptr_metadata<P: ptr::Pointee<Metadata = M> + ?Sized, M>(ptr: *const
36413641
/// For regions of memory which might overlap, use [`copy`] instead.
36423642
///
36433643
/// `copy_nonoverlapping` is semantically equivalent to C's [`memcpy`], but
3644-
/// with the argument order swapped.
3644+
/// with the source and destination arguments swapped,
3645+
/// and `count` counting the number of `T`s instead of bytes.
36453646
///
36463647
/// The copy is "untyped" in the sense that data may be uninitialized or otherwise violate the
36473648
/// requirements of `T`. The initialization state is preserved exactly.
@@ -3761,8 +3762,10 @@ pub const unsafe fn copy_nonoverlapping<T>(src: *const T, dst: *mut T, count: us
37613762
/// If the source and destination will *never* overlap,
37623763
/// [`copy_nonoverlapping`] can be used instead.
37633764
///
3764-
/// `copy` is semantically equivalent to C's [`memmove`], but with the argument
3765-
/// order swapped. Copying takes place as if the bytes were copied from `src`
3765+
/// `copy` is semantically equivalent to C's [`memmove`], but
3766+
/// with the source and destination arguments swapped,
3767+
/// and `count` counting the number of `T`s instead of bytes.
3768+
/// Copying takes place as if the bytes were copied from `src`
37663769
/// to a temporary array and then copied from the array to `dst`.
37673770
///
37683771
/// The copy is "untyped" in the sense that data may be uninitialized or otherwise violate the

‎library/std/src/sys/personality/gcc.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ cfg_if::cfg_if! {
220220
Ok(action) => action,
221221
Err(_) => return uw::_URC_FATAL_PHASE1_ERROR,
222222
};
223-
if actions as i32 & uw::_UA_SEARCH_PHASE as i32 != 0 {
223+
if actions & uw::_UA_SEARCH_PHASE != 0 {
224224
match eh_action {
225225
EHAction::None | EHAction::Cleanup(_) => uw::_URC_CONTINUE_UNWIND,
226226
EHAction::Catch(_) | EHAction::Filter(_) => uw::_URC_HANDLER_FOUND,
@@ -230,7 +230,7 @@ cfg_if::cfg_if! {
230230
match eh_action {
231231
EHAction::None => uw::_URC_CONTINUE_UNWIND,
232232
// Forced unwinding hits a terminate action.
233-
EHAction::Filter(_) if actions as i32 & uw::_UA_FORCE_UNWIND as i32 != 0 => uw::_URC_CONTINUE_UNWIND,
233+
EHAction::Filter(_) if actions & uw::_UA_FORCE_UNWIND != 0 => uw::_URC_CONTINUE_UNWIND,
234234
EHAction::Cleanup(lpad) | EHAction::Catch(lpad) | EHAction::Filter(lpad) => {
235235
uw::_Unwind_SetGR(
236236
context,

‎library/unwind/src/libunwind.rs

+7-10
Original file line numberDiff line numberDiff line change
@@ -128,16 +128,13 @@ if #[cfg(any(target_vendor = "apple", target_os = "netbsd", not(target_arch = "a
128128
//
129129
// 32-bit ARM on iOS/tvOS/watchOS use either DWARF/Compact unwinding or
130130
// "setjmp-longjmp" / SjLj unwinding.
131-
#[repr(C)]
132-
#[derive(Copy, Clone, PartialEq)]
133-
pub enum _Unwind_Action {
134-
_UA_SEARCH_PHASE = 1,
135-
_UA_CLEANUP_PHASE = 2,
136-
_UA_HANDLER_FRAME = 4,
137-
_UA_FORCE_UNWIND = 8,
138-
_UA_END_OF_STACK = 16,
139-
}
140-
pub use _Unwind_Action::*;
131+
pub type _Unwind_Action = c_int;
132+
133+
pub const _UA_SEARCH_PHASE: c_int = 1;
134+
pub const _UA_CLEANUP_PHASE: c_int = 2;
135+
pub const _UA_HANDLER_FRAME: c_int = 4;
136+
pub const _UA_FORCE_UNWIND: c_int = 8;
137+
pub const _UA_END_OF_STACK: c_int = 16;
141138

142139
#[cfg_attr(
143140
all(feature = "llvm-libunwind", any(target_os = "fuchsia", target_os = "linux", target_os = "xous")),

‎library/unwind/src/unwinding.rs

+7-10
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,13 @@
22

33
use core::ffi::{c_int, c_void};
44

5-
#[repr(C)]
6-
#[derive(Copy, Clone, PartialEq)]
7-
pub enum _Unwind_Action {
8-
_UA_SEARCH_PHASE = 1,
9-
_UA_CLEANUP_PHASE = 2,
10-
_UA_HANDLER_FRAME = 4,
11-
_UA_FORCE_UNWIND = 8,
12-
_UA_END_OF_STACK = 16,
13-
}
14-
pub use _Unwind_Action::*;
5+
pub type _Unwind_Action = c_int;
6+
7+
pub const _UA_SEARCH_PHASE: c_int = 1;
8+
pub const _UA_CLEANUP_PHASE: c_int = 2;
9+
pub const _UA_HANDLER_FRAME: c_int = 4;
10+
pub const _UA_FORCE_UNWIND: c_int = 8;
11+
pub const _UA_END_OF_STACK: c_int = 16;
1512

1613
#[repr(C)]
1714
#[derive(Debug, Copy, Clone, PartialEq)]

‎src/librustdoc/html/render/mod.rs

+11-21
Original file line numberDiff line numberDiff line change
@@ -1465,8 +1465,6 @@ pub(crate) fn notable_traits_button(
14651465
ty: &clean::Type,
14661466
cx: &Context<'_>,
14671467
) -> Option<impl fmt::Display> {
1468-
let mut has_notable_trait = false;
1469-
14701468
if ty.is_unit() {
14711469
// Very common fast path.
14721470
return None;
@@ -1484,27 +1482,19 @@ pub(crate) fn notable_traits_button(
14841482
return None;
14851483
}
14861484

1487-
if let Some(impls) = cx.cache().impls.get(&did) {
1488-
for i in impls {
1489-
let impl_ = i.inner_impl();
1490-
if impl_.polarity != ty::ImplPolarity::Positive {
1491-
continue;
1492-
}
1493-
1494-
if !ty.is_doc_subtype_of(&impl_.for_, cx.cache()) {
1485+
let impls = cx.cache().impls.get(&did)?;
1486+
let has_notable_trait = impls
1487+
.iter()
1488+
.map(Impl::inner_impl)
1489+
.filter(|impl_| {
1490+
impl_.polarity == ty::ImplPolarity::Positive
14951491
// Two different types might have the same did,
14961492
// without actually being the same.
1497-
continue;
1498-
}
1499-
if let Some(trait_) = &impl_.trait_ {
1500-
let trait_did = trait_.def_id();
1501-
1502-
if cx.cache().traits.get(&trait_did).is_some_and(|t| t.is_notable_trait(cx.tcx())) {
1503-
has_notable_trait = true;
1504-
}
1505-
}
1506-
}
1507-
}
1493+
&& ty.is_doc_subtype_of(&impl_.for_, cx.cache())
1494+
})
1495+
.filter_map(|impl_| impl_.trait_.as_ref())
1496+
.filter_map(|trait_| cx.cache().traits.get(&trait_.def_id()))
1497+
.any(|t| t.is_notable_trait(cx.tcx()));
15081498

15091499
has_notable_trait.then(|| {
15101500
cx.types_with_notable_traits.borrow_mut().insert(ty.clone());

‎tests/ui/feature-gates/feature-gate-print-check-cfg.rs

-3
This file was deleted.

‎tests/ui/feature-gates/feature-gate-print-check-cfg.stderr

-2
This file was deleted.
There was a problem loading the remainder of the diff.

0 commit comments

Comments
 (0)
Failed to load comments.