Auto merge of #155166 - JonathanBrouwer:rollup-YH2oUIz, r=JonathanBrouwer

Rollup of 6 pull requests

Successful merges:

 - rust-lang/rust#155057 (Update libc to v0.2.184)
 - rust-lang/rust#154967 (Test(lib/sync): Fix `test_rwlock_max_readers` for x86 Win7)
 - rust-lang/rust#154994 (don't leak internal temporaries from `dbg!`)
 - rust-lang/rust#155130 (Stabilize feature `isolate_most_least_significant_one`)
 - rust-lang/rust#154925 (Make Box/Rc/Arc::into_array allocator-aware (and add doctest))
 - rust-lang/rust#155063 (`ty::Alias`: replace `def_id: did` with `def_id`)
This commit is contained in:
bors
2026-04-12 04:25:51 +00:00
13 changed files with 150 additions and 92 deletions
@@ -1134,22 +1134,22 @@ fn probe_trait_that_defines_assoc_item(
fn lower_path_segment(
&self,
span: Span,
did: DefId,
def_id: DefId,
item_segment: &hir::PathSegment<'tcx>,
) -> Ty<'tcx> {
let tcx = self.tcx();
let args = self.lower_generic_args_of_path_segment(span, did, item_segment);
let args = self.lower_generic_args_of_path_segment(span, def_id, item_segment);
if let DefKind::TyAlias = tcx.def_kind(did)
&& tcx.type_alias_is_lazy(did)
if let DefKind::TyAlias = tcx.def_kind(def_id)
&& tcx.type_alias_is_lazy(def_id)
{
// Type aliases defined in crates that have the
// feature `lazy_type_alias` enabled get encoded as a type alias that normalization will
// then actually instantiate the where bounds of.
let alias_ty = ty::AliasTy::new_from_args(tcx, ty::Free { def_id: did }, args);
let alias_ty = ty::AliasTy::new_from_args(tcx, ty::Free { def_id }, args);
Ty::new_alias(tcx, alias_ty)
} else {
tcx.at(span).type_of(did).instantiate(tcx, args)
tcx.at(span).type_of(def_id).instantiate(tcx, args)
}
}
+2 -2
View File
@@ -146,9 +146,9 @@ dependencies = [
[[package]]
name = "libc"
version = "0.2.183"
version = "0.2.184"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b5b646652bf6661599e1da8901b3b9522896f01e736bad5f723fe7a3a27f899d"
checksum = "48f5d2a454e16a5ea0f4ced81bd44e4cfc7bd3a507b61887c99fd3538b28e4af"
dependencies = [
"rustc-std-workspace-core",
]
+30 -20
View File
@@ -1006,26 +1006,6 @@ pub fn try_new_zeroed_slice(len: usize) -> Result<Box<[mem::MaybeUninit<T>]>, Al
};
unsafe { Ok(RawVec::from_raw_parts_in(ptr.as_ptr(), len, Global).into_box(len)) }
}
/// Converts the boxed slice into a boxed array.
///
/// This operation does not reallocate; the underlying array of the slice is simply reinterpreted as an array type.
///
/// If `N` is not exactly equal to the length of `self`, then this method returns `None`.
#[unstable(feature = "alloc_slice_into_array", issue = "148082")]
#[inline]
#[must_use]
pub fn into_array<const N: usize>(self) -> Option<Box<[T; N]>> {
if self.len() == N {
let ptr = Self::into_raw(self) as *mut [T; N];
// SAFETY: The underlying array of a slice has the exact same layout as an actual array `[T; N]` if `N` is equal to the slice's length.
let me = unsafe { Box::from_raw(ptr) };
Some(me)
} else {
None
}
}
}
impl<T, A: Allocator> Box<[T], A> {
@@ -1157,6 +1137,36 @@ pub fn try_new_zeroed_slice_in(
};
unsafe { Ok(RawVec::from_raw_parts_in(ptr.as_ptr(), len, alloc).into_box(len)) }
}
/// Converts the boxed slice into a boxed array.
///
/// This operation does not reallocate; the underlying array of the slice is simply reinterpreted as an array type.
///
/// If `N` is not exactly equal to the length of `self`, then this method returns `None`.
///
/// # Examples
///
/// ```
/// #![feature(alloc_slice_into_array)]
/// let box_slice: Box<[i32]> = Box::new([1, 2, 3]);
///
/// let box_array: Box<[i32; 3]> = box_slice.into_array().unwrap();
/// ```
#[unstable(feature = "alloc_slice_into_array", issue = "148082")]
#[inline]
#[must_use]
pub fn into_array<const N: usize>(self) -> Option<Box<[T; N], A>> {
if self.len() == N {
let (ptr, alloc) = Self::into_raw_with_allocator(self);
let ptr = ptr as *mut [T; N];
// SAFETY: The underlying array of a slice has the exact same layout as an actual array `[T; N]` if `N` is equal to the slice's length.
let me = unsafe { Box::from_raw_in(ptr, alloc) };
Some(me)
} else {
None
}
}
}
impl<T, A: Allocator> Box<mem::MaybeUninit<T>, A> {
+32 -20
View File
@@ -1167,26 +1167,6 @@ pub fn new_zeroed_slice(len: usize) -> Rc<[mem::MaybeUninit<T>]> {
))
}
}
/// Converts the reference-counted slice into a reference-counted array.
///
/// This operation does not reallocate; the underlying array of the slice is simply reinterpreted as an array type.
///
/// If `N` is not exactly equal to the length of `self`, then this method returns `None`.
#[unstable(feature = "alloc_slice_into_array", issue = "148082")]
#[inline]
#[must_use]
pub fn into_array<const N: usize>(self) -> Option<Rc<[T; N]>> {
if self.len() == N {
let ptr = Self::into_raw(self) as *const [T; N];
// SAFETY: The underlying array of a slice has the exact same layout as an actual array `[T; N]` if `N` is equal to the slice's length.
let me = unsafe { Rc::from_raw(ptr) };
Some(me)
} else {
None
}
}
}
impl<T, A: Allocator> Rc<[T], A> {
@@ -1260,6 +1240,38 @@ pub fn new_zeroed_slice_in(len: usize, alloc: A) -> Rc<[mem::MaybeUninit<T>], A>
)
}
}
/// Converts the reference-counted slice into a reference-counted array.
///
/// This operation does not reallocate; the underlying array of the slice is simply reinterpreted as an array type.
///
/// If `N` is not exactly equal to the length of `self`, then this method returns `None`.
///
/// # Examples
///
/// ```
/// #![feature(alloc_slice_into_array)]
/// use std::rc::Rc;
///
/// let rc_slice: Rc<[i32]> = Rc::new([1, 2, 3]);
///
/// let rc_array: Rc<[i32; 3]> = rc_slice.into_array().unwrap();
/// ```
#[unstable(feature = "alloc_slice_into_array", issue = "148082")]
#[inline]
#[must_use]
pub fn into_array<const N: usize>(self) -> Option<Rc<[T; N], A>> {
if self.len() == N {
let (ptr, alloc) = Self::into_raw_with_allocator(self);
let ptr = ptr as *const [T; N];
// SAFETY: The underlying array of a slice has the exact same layout as an actual array `[T; N]` if `N` is equal to the slice's length.
let me = unsafe { Rc::from_raw_in(ptr, alloc) };
Some(me)
} else {
None
}
}
}
impl<T, A: Allocator> Rc<mem::MaybeUninit<T>, A> {
+32 -20
View File
@@ -1313,26 +1313,6 @@ pub fn new_zeroed_slice(len: usize) -> Arc<[mem::MaybeUninit<T>]> {
))
}
}
/// Converts the reference-counted slice into a reference-counted array.
///
/// This operation does not reallocate; the underlying array of the slice is simply reinterpreted as an array type.
///
/// If `N` is not exactly equal to the length of `self`, then this method returns `None`.
#[unstable(feature = "alloc_slice_into_array", issue = "148082")]
#[inline]
#[must_use]
pub fn into_array<const N: usize>(self) -> Option<Arc<[T; N]>> {
if self.len() == N {
let ptr = Self::into_raw(self) as *const [T; N];
// SAFETY: The underlying array of a slice has the exact same layout as an actual array `[T; N]` if `N` is equal to the slice's length.
let me = unsafe { Arc::from_raw(ptr) };
Some(me)
} else {
None
}
}
}
impl<T, A: Allocator> Arc<[T], A> {
@@ -1407,6 +1387,38 @@ pub fn new_zeroed_slice_in(len: usize, alloc: A) -> Arc<[mem::MaybeUninit<T>], A
)
}
}
/// Converts the reference-counted slice into a reference-counted array.
///
/// This operation does not reallocate; the underlying array of the slice is simply reinterpreted as an array type.
///
/// If `N` is not exactly equal to the length of `self`, then this method returns `None`.
///
/// # Examples
///
/// ```
/// #![feature(alloc_slice_into_array)]
/// use std::sync::Arc;
///
/// let arc_slice: Arc<[i32]> = Arc::new([1, 2, 3]);
///
/// let arc_array: Arc<[i32; 3]> = arc_slice.into_array().unwrap();
/// ```
#[unstable(feature = "alloc_slice_into_array", issue = "148082")]
#[inline]
#[must_use]
pub fn into_array<const N: usize>(self) -> Option<Arc<[T; N], A>> {
if self.len() == N {
let (ptr, alloc) = Self::into_raw_with_allocator(self);
let ptr = ptr as *const [T; N];
// SAFETY: The underlying array of a slice has the exact same layout as an actual array `[T; N]` if `N` is equal to the slice's length.
let me = unsafe { Arc::from_raw_in(ptr, alloc) };
Some(me)
} else {
None
}
}
}
impl<T, A: Allocator> Arc<mem::MaybeUninit<T>, A> {
+4 -6
View File
@@ -173,14 +173,13 @@ pub const fn trailing_ones(self) -> u32 {
/// # Examples
///
/// ```
/// #![feature(isolate_most_least_significant_one)]
///
#[doc = concat!("let n: ", stringify!($SelfT), " = 0b_01100100;")]
///
/// assert_eq!(n.isolate_highest_one(), 0b_01000000);
#[doc = concat!("assert_eq!(0_", stringify!($SelfT), ".isolate_highest_one(), 0);")]
/// ```
#[unstable(feature = "isolate_most_least_significant_one", issue = "136909")]
#[stable(feature = "isolate_most_least_significant_one", since = "CURRENT_RUSTC_VERSION")]
#[rustc_const_stable(feature = "isolate_most_least_significant_one", since = "CURRENT_RUSTC_VERSION")]
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[inline(always)]
@@ -194,14 +193,13 @@ pub const fn isolate_highest_one(self) -> Self {
/// # Examples
///
/// ```
/// #![feature(isolate_most_least_significant_one)]
///
#[doc = concat!("let n: ", stringify!($SelfT), " = 0b_01100100;")]
///
/// assert_eq!(n.isolate_lowest_one(), 0b_00000100);
#[doc = concat!("assert_eq!(0_", stringify!($SelfT), ".isolate_lowest_one(), 0);")]
/// ```
#[unstable(feature = "isolate_most_least_significant_one", issue = "136909")]
#[stable(feature = "isolate_most_least_significant_one", since = "CURRENT_RUSTC_VERSION")]
#[rustc_const_stable(feature = "isolate_most_least_significant_one", since = "CURRENT_RUSTC_VERSION")]
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[inline(always)]
+4 -6
View File
@@ -650,8 +650,6 @@ pub const fn trailing_zeros(self) -> u32 {
/// # Example
///
/// ```
/// #![feature(isolate_most_least_significant_one)]
///
/// # use core::num::NonZero;
/// # fn main() { test().unwrap(); }
/// # fn test() -> Option<()> {
@@ -662,7 +660,8 @@ pub const fn trailing_zeros(self) -> u32 {
/// # Some(())
/// # }
/// ```
#[unstable(feature = "isolate_most_least_significant_one", issue = "136909")]
#[stable(feature = "isolate_most_least_significant_one", since = "CURRENT_RUSTC_VERSION")]
#[rustc_const_stable(feature = "isolate_most_least_significant_one", since = "CURRENT_RUSTC_VERSION")]
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[inline(always)]
@@ -683,8 +682,6 @@ pub const fn isolate_highest_one(self) -> Self {
/// # Example
///
/// ```
/// #![feature(isolate_most_least_significant_one)]
///
/// # use core::num::NonZero;
/// # fn main() { test().unwrap(); }
/// # fn test() -> Option<()> {
@@ -695,7 +692,8 @@ pub const fn isolate_highest_one(self) -> Self {
/// # Some(())
/// # }
/// ```
#[unstable(feature = "isolate_most_least_significant_one", issue = "136909")]
#[stable(feature = "isolate_most_least_significant_one", since = "CURRENT_RUSTC_VERSION")]
#[rustc_const_stable(feature = "isolate_most_least_significant_one", since = "CURRENT_RUSTC_VERSION")]
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[inline(always)]
+4 -6
View File
@@ -253,14 +253,13 @@ pub const fn bit_width(self) -> u32 {
/// # Examples
///
/// ```
/// #![feature(isolate_most_least_significant_one)]
///
#[doc = concat!("let n: ", stringify!($SelfT), " = 0b_01100100;")]
///
/// assert_eq!(n.isolate_highest_one(), 0b_01000000);
#[doc = concat!("assert_eq!(0_", stringify!($SelfT), ".isolate_highest_one(), 0);")]
/// ```
#[unstable(feature = "isolate_most_least_significant_one", issue = "136909")]
#[stable(feature = "isolate_most_least_significant_one", since = "CURRENT_RUSTC_VERSION")]
#[rustc_const_stable(feature = "isolate_most_least_significant_one", since = "CURRENT_RUSTC_VERSION")]
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[inline(always)]
@@ -274,14 +273,13 @@ pub const fn isolate_highest_one(self) -> Self {
/// # Examples
///
/// ```
/// #![feature(isolate_most_least_significant_one)]
///
#[doc = concat!("let n: ", stringify!($SelfT), " = 0b_01100100;")]
///
/// assert_eq!(n.isolate_lowest_one(), 0b_00000100);
#[doc = concat!("assert_eq!(0_", stringify!($SelfT), ".isolate_lowest_one(), 0);")]
/// ```
#[unstable(feature = "isolate_most_least_significant_one", issue = "136909")]
#[stable(feature = "isolate_most_least_significant_one", since = "CURRENT_RUSTC_VERSION")]
#[rustc_const_stable(feature = "isolate_most_least_significant_one", since = "CURRENT_RUSTC_VERSION")]
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[inline(always)]
-1
View File
@@ -70,7 +70,6 @@
#![feature(int_roundings)]
#![feature(ip)]
#![feature(is_ascii_octdigit)]
#![feature(isolate_most_least_significant_one)]
#![feature(iter_advance_by)]
#![feature(iter_array_chunks)]
#![feature(iter_collect_into)]
+1 -1
View File
@@ -33,7 +33,7 @@ miniz_oxide = { version = "0.8.0", optional = true, default-features = false }
addr2line = { version = "0.25.0", optional = true, default-features = false }
[target.'cfg(not(all(windows, target_env = "msvc")))'.dependencies]
libc = { version = "0.2.183", default-features = false, features = [
libc = { version = "0.2.184", default-features = false, features = [
'rustc-dep-of-std',
], public = true }
+5 -2
View File
@@ -369,7 +369,8 @@ macro_rules! dbg {
/// E.g. `dbg_internal!(() () (1, 2))` expands into
/// ```rust, ignore
/// match (1, 2) {
/// (tmp_1, tmp_2) => {
/// args => {
/// let (tmp_1, tmp_2) = args;
/// eprint!("...", &tmp_1, &tmp_2, /* some other arguments */);
/// (tmp_1, tmp_2)
/// }
@@ -385,7 +386,9 @@ macro_rules! dbg {
// of temporaries - https://stackoverflow.com/a/48732525/1063961
// Always put the arguments in a tuple to avoid an unused parens lint on the pattern.
match ($($processed,)+) {
($($bound,)+) => {
// Move the entire tuple so it doesn't stick around as a temporary (#154988).
args => {
let ($($bound,)+) = args;
$crate::eprint!(
$crate::concat!($($piece),+),
$(
+24
View File
@@ -1,5 +1,7 @@
// ignore-tidy-dbg
use core::fmt::Debug;
/// Test for <https://github.com/rust-lang/rust/issues/153850>:
/// `dbg!` shouldn't drop arguments' temporaries.
#[test]
@@ -11,3 +13,25 @@ fn temp() {}
*dbg!(0, &temp()).1;
*dbg!(0, &temp(), 2).1;
}
/// Test for <https://github.com/rust-lang/rust/issues/154988>:
/// `dbg!` shouldn't create a temporary that lives past its invocation.
#[test]
fn no_leaking_internal_temps_from_dbg() {
#[derive(Debug)]
struct Foo;
#[derive(Debug)]
struct Bar<'a>(#[allow(unused)] &'a Foo);
impl Drop for Bar<'_> {
fn drop(&mut self) {}
}
let foo = Foo;
let bar = Bar(&foo);
// If `dbg!` creates a `(Bar<'_>,)` temporary that lasts past its expansion, this will fail
// to compile, because it will be dropped after `foo`, which it borrows from. The tuple
// mimics the drop order of block tail expressions before Rust 2024: first the result of `dbg!`
// is dropped, then `foo`, then any temporaries left over from `dbg!` are dropped, if present.
(drop(dbg!(bar)), drop(foo));
}
+6 -2
View File
@@ -917,19 +917,23 @@ fn test_rwlock_max_readers() {
target_os = "fuchsia",
all(target_family = "wasm", target_feature = "atomics"),
target_os = "hermit",
target_os = "motor",
target_os = "motor",
) => {
(1 << 30) - 2
},
any(
target_family = "unix",
all(target_os = "windows", target_vendor = "win7"),
all(target_os = "windows", target_vendor = "win7", target_pointer_width = "64"),
all(target_vendor = "fortanix", target_env = "sgx"),
target_os = "xous",
target_os = "teeos",
) => {
u32::MAX
},
// Otherwise a form of deadlock is observed.
all(target_os = "windows", target_vendor = "win7", target_pointer_width = "32") => {
(1 << 28) - 1
},
target_os = "solid_asp3" => {
(1 << 30)
},