Skip to content

Rollup of 5 pull requests #138583

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Mar 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions compiler/rustc_driver_impl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -649,10 +649,10 @@ fn print_crate_info(
HostTuple => println_info!("{}", rustc_session::config::host_tuple()),
Sysroot => println_info!("{}", sess.sysroot.display()),
TargetLibdir => println_info!("{}", sess.target_tlib_path.dir.display()),
TargetSpec => {
TargetSpecJson => {
println_info!("{}", serde_json::to_string_pretty(&sess.target.to_json()).unwrap());
}
AllTargetSpecs => {
AllTargetSpecsJson => {
let mut targets = BTreeMap::new();
for name in rustc_target::spec::TARGETS {
let triple = TargetTuple::from_tuple(name);
Expand Down
114 changes: 54 additions & 60 deletions compiler/rustc_session/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub mod sigpipe;

pub const PRINT_KINDS: &[(&str, PrintKind)] = &[
// tidy-alphabetical-start
("all-target-specs-json", PrintKind::AllTargetSpecs),
("all-target-specs-json", PrintKind::AllTargetSpecsJson),
("calling-conventions", PrintKind::CallingConventions),
("cfg", PrintKind::Cfg),
("check-cfg", PrintKind::CheckCfg),
Expand All @@ -63,7 +63,7 @@ pub const PRINT_KINDS: &[(&str, PrintKind)] = &[
("target-features", PrintKind::TargetFeatures),
("target-libdir", PrintKind::TargetLibdir),
("target-list", PrintKind::TargetList),
("target-spec-json", PrintKind::TargetSpec),
("target-spec-json", PrintKind::TargetSpecJson),
("tls-models", PrintKind::TlsModels),
// tidy-alphabetical-end
];
Expand Down Expand Up @@ -873,27 +873,29 @@ pub struct PrintRequest {

#[derive(Copy, Clone, PartialEq, Eq, Debug)]
pub enum PrintKind {
// tidy-alphabetical-start
AllTargetSpecsJson,
CallingConventions,
Cfg,
CheckCfg,
CodeModels,
CrateName,
DeploymentTarget,
FileNames,
HostTuple,
LinkArgs,
NativeStaticLibs,
RelocationModels,
SplitDebuginfo,
StackProtectorStrategies,
Sysroot,
TargetLibdir,
CrateName,
Cfg,
CheckCfg,
CallingConventions,
TargetList,
TargetCPUs,
TargetFeatures,
RelocationModels,
CodeModels,
TargetLibdir,
TargetList,
TargetSpecJson,
TlsModels,
TargetSpec,
AllTargetSpecs,
NativeStaticLibs,
StackProtectorStrategies,
LinkArgs,
SplitDebuginfo,
DeploymentTarget,
// tidy-alphabetical-end
}

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

let kind = match PRINT_KINDS.iter().find(|&&(name, _)| name == req) {
Some((_, PrintKind::TargetSpec)) => {
if unstable_opts.unstable_options {
PrintKind::TargetSpec
} else {
early_dcx.early_fatal(
"the `-Z unstable-options` flag must also be passed to \
enable the target-spec-json print option",
);
}
}
Some((_, PrintKind::AllTargetSpecs)) => {
if unstable_opts.unstable_options {
PrintKind::AllTargetSpecs
} else {
early_dcx.early_fatal(
"the `-Z unstable-options` flag must also be passed to \
enable the all-target-specs-json print option",
);
}
}
Some((_, PrintKind::CheckCfg)) => {
if unstable_opts.unstable_options {
PrintKind::CheckCfg
} else {
early_dcx.early_fatal(
"the `-Z unstable-options` flag must also be passed to \
enable the check-cfg print option",
);
}
}
Some(&(_, print_kind)) => print_kind,
None => {
let prints =
PRINT_KINDS.iter().map(|(name, _)| format!("`{name}`")).collect::<Vec<_>>();
let prints = prints.join(", ");

let mut diag =
early_dcx.early_struct_fatal(format!("unknown print request: `{req}`"));
#[allow(rustc::diagnostic_outside_of_impl)]
diag.help(format!("valid print requests are: {prints}"));
diag.emit()
}
let kind = if let Some((print_name, print_kind)) =
PRINT_KINDS.iter().find(|&&(name, _)| name == req)
{
check_print_request_stability(early_dcx, unstable_opts, (print_name, *print_kind));
*print_kind
} else {
emit_unknown_print_request_help(early_dcx, req)
};

let out = out.unwrap_or(OutFileName::Stdout);
Expand All @@ -2091,6 +2057,34 @@ fn collect_print_requests(
prints
}

fn check_print_request_stability(
early_dcx: &EarlyDiagCtxt,
unstable_opts: &UnstableOptions,
(print_name, print_kind): (&str, PrintKind),
) {
match print_kind {
PrintKind::AllTargetSpecsJson | PrintKind::CheckCfg | PrintKind::TargetSpecJson
if !unstable_opts.unstable_options =>
{
early_dcx.early_fatal(format!(
"the `-Z unstable-options` flag must also be passed to enable the `{print_name}` \
print option"
));
}
_ => {}
}
}

fn emit_unknown_print_request_help(early_dcx: &EarlyDiagCtxt, req: &str) -> ! {
let prints = PRINT_KINDS.iter().map(|(name, _)| format!("`{name}`")).collect::<Vec<_>>();
let prints = prints.join(", ");

let mut diag = early_dcx.early_struct_fatal(format!("unknown print request: `{req}`"));
#[allow(rustc::diagnostic_outside_of_impl)]
diag.help(format!("valid print requests are: {prints}"));
diag.emit()
}

pub fn parse_target_triple(early_dcx: &EarlyDiagCtxt, matches: &getopts::Matches) -> TargetTuple {
match matches.opt_str("target") {
Some(target) if target.ends_with(".json") => {
Expand Down
13 changes: 13 additions & 0 deletions library/alloc/src/vec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1252,6 +1252,19 @@ impl<T, A: Allocator> Vec<T, A> {
/// vec.push(42);
/// assert!(vec.capacity() >= 10);
/// ```
///
/// A vector with zero-sized elements will always have a capacity of usize::MAX:
///
/// ```
/// #[derive(Clone)]
/// struct ZeroSized;
///
/// fn main() {
/// assert_eq!(std::mem::size_of::<ZeroSized>(), 0);
/// let v = vec![ZeroSized; 0];
/// assert_eq!(v.capacity(), usize::MAX);
/// }
/// ```
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_stable(feature = "const_vec_string_slice", since = "CURRENT_RUSTC_VERSION")]
Expand Down
9 changes: 6 additions & 3 deletions library/core/src/intrinsics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3641,7 +3641,8 @@ pub const fn ptr_metadata<P: ptr::Pointee<Metadata = M> + ?Sized, M>(ptr: *const
/// For regions of memory which might overlap, use [`copy`] instead.
///
/// `copy_nonoverlapping` is semantically equivalent to C's [`memcpy`], but
/// with the argument order swapped.
/// with the source and destination arguments swapped,
/// and `count` counting the number of `T`s instead of bytes.
///
/// The copy is "untyped" in the sense that data may be uninitialized or otherwise violate the
/// requirements of `T`. The initialization state is preserved exactly.
Expand Down Expand Up @@ -3761,8 +3762,10 @@ pub const unsafe fn copy_nonoverlapping<T>(src: *const T, dst: *mut T, count: us
/// If the source and destination will *never* overlap,
/// [`copy_nonoverlapping`] can be used instead.
///
/// `copy` is semantically equivalent to C's [`memmove`], but with the argument
/// order swapped. Copying takes place as if the bytes were copied from `src`
/// `copy` is semantically equivalent to C's [`memmove`], but
/// with the source and destination arguments swapped,
/// and `count` counting the number of `T`s instead of bytes.
/// Copying takes place as if the bytes were copied from `src`
/// to a temporary array and then copied from the array to `dst`.
///
/// The copy is "untyped" in the sense that data may be uninitialized or otherwise violate the
Expand Down
4 changes: 2 additions & 2 deletions library/std/src/sys/personality/gcc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ cfg_if::cfg_if! {
Ok(action) => action,
Err(_) => return uw::_URC_FATAL_PHASE1_ERROR,
};
if actions as i32 & uw::_UA_SEARCH_PHASE as i32 != 0 {
if actions & uw::_UA_SEARCH_PHASE != 0 {
match eh_action {
EHAction::None | EHAction::Cleanup(_) => uw::_URC_CONTINUE_UNWIND,
EHAction::Catch(_) | EHAction::Filter(_) => uw::_URC_HANDLER_FOUND,
Expand All @@ -230,7 +230,7 @@ cfg_if::cfg_if! {
match eh_action {
EHAction::None => uw::_URC_CONTINUE_UNWIND,
// Forced unwinding hits a terminate action.
EHAction::Filter(_) if actions as i32 & uw::_UA_FORCE_UNWIND as i32 != 0 => uw::_URC_CONTINUE_UNWIND,
EHAction::Filter(_) if actions & uw::_UA_FORCE_UNWIND != 0 => uw::_URC_CONTINUE_UNWIND,
EHAction::Cleanup(lpad) | EHAction::Catch(lpad) | EHAction::Filter(lpad) => {
uw::_Unwind_SetGR(
context,
Expand Down
17 changes: 7 additions & 10 deletions library/unwind/src/libunwind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,16 +128,13 @@ if #[cfg(any(target_vendor = "apple", target_os = "netbsd", not(target_arch = "a
//
// 32-bit ARM on iOS/tvOS/watchOS use either DWARF/Compact unwinding or
// "setjmp-longjmp" / SjLj unwinding.
#[repr(C)]
#[derive(Copy, Clone, PartialEq)]
pub enum _Unwind_Action {
_UA_SEARCH_PHASE = 1,
_UA_CLEANUP_PHASE = 2,
_UA_HANDLER_FRAME = 4,
_UA_FORCE_UNWIND = 8,
_UA_END_OF_STACK = 16,
}
pub use _Unwind_Action::*;
pub type _Unwind_Action = c_int;

pub const _UA_SEARCH_PHASE: c_int = 1;
pub const _UA_CLEANUP_PHASE: c_int = 2;
pub const _UA_HANDLER_FRAME: c_int = 4;
pub const _UA_FORCE_UNWIND: c_int = 8;
pub const _UA_END_OF_STACK: c_int = 16;

#[cfg_attr(
all(feature = "llvm-libunwind", any(target_os = "fuchsia", target_os = "linux", target_os = "xous")),
Expand Down
17 changes: 7 additions & 10 deletions library/unwind/src/unwinding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,13 @@

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

#[repr(C)]
#[derive(Copy, Clone, PartialEq)]
pub enum _Unwind_Action {
_UA_SEARCH_PHASE = 1,
_UA_CLEANUP_PHASE = 2,
_UA_HANDLER_FRAME = 4,
_UA_FORCE_UNWIND = 8,
_UA_END_OF_STACK = 16,
}
pub use _Unwind_Action::*;
pub type _Unwind_Action = c_int;

pub const _UA_SEARCH_PHASE: c_int = 1;
pub const _UA_CLEANUP_PHASE: c_int = 2;
pub const _UA_HANDLER_FRAME: c_int = 4;
pub const _UA_FORCE_UNWIND: c_int = 8;
pub const _UA_END_OF_STACK: c_int = 16;

#[repr(C)]
#[derive(Debug, Copy, Clone, PartialEq)]
Expand Down
32 changes: 11 additions & 21 deletions src/librustdoc/html/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1465,8 +1465,6 @@ pub(crate) fn notable_traits_button(
ty: &clean::Type,
cx: &Context<'_>,
) -> Option<impl fmt::Display> {
let mut has_notable_trait = false;

if ty.is_unit() {
// Very common fast path.
return None;
Expand All @@ -1484,27 +1482,19 @@ pub(crate) fn notable_traits_button(
return None;
}

if let Some(impls) = cx.cache().impls.get(&did) {
for i in impls {
let impl_ = i.inner_impl();
if impl_.polarity != ty::ImplPolarity::Positive {
continue;
}

if !ty.is_doc_subtype_of(&impl_.for_, cx.cache()) {
let impls = cx.cache().impls.get(&did)?;
let has_notable_trait = impls
.iter()
.map(Impl::inner_impl)
.filter(|impl_| {
impl_.polarity == ty::ImplPolarity::Positive
// Two different types might have the same did,
// without actually being the same.
continue;
}
if let Some(trait_) = &impl_.trait_ {
let trait_did = trait_.def_id();

if cx.cache().traits.get(&trait_did).is_some_and(|t| t.is_notable_trait(cx.tcx())) {
has_notable_trait = true;
}
}
}
}
&& ty.is_doc_subtype_of(&impl_.for_, cx.cache())
})
.filter_map(|impl_| impl_.trait_.as_ref())
.filter_map(|trait_| cx.cache().traits.get(&trait_.def_id()))
.any(|t| t.is_notable_trait(cx.tcx()));

has_notable_trait.then(|| {
cx.types_with_notable_traits.borrow_mut().insert(ty.clone());
Expand Down
3 changes: 0 additions & 3 deletions tests/ui/feature-gates/feature-gate-print-check-cfg.rs

This file was deleted.

2 changes: 0 additions & 2 deletions tests/ui/feature-gates/feature-gate-print-check-cfg.stderr

This file was deleted.

Loading
Loading