Skip to content

Commit fb6f0c2

Browse files
committed
Auto merge of rust-lang#133339 - jieyouxu:rollup-gav0nvr, r=jieyouxu
Rollup of 8 pull requests Successful merges: - rust-lang#133238 (re-export `is_loongarch_feature_detected`) - rust-lang#133288 (Support `each_ref` and `each_mut` in `[T; N]` in constant expressions.) - rust-lang#133311 (Miri subtree update) - rust-lang#133313 (Use arc4random of libc for RTEMS target) - rust-lang#133319 (Simplify `fulfill_implication`) - rust-lang#133323 (Bail in effects in old solver if self ty is ty var) - rust-lang#133330 (library: update comment around close()) - rust-lang#133337 (Fix typo in `std::thread::Scope::spawn` documentation.) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 23a1b31 + c792ef3 commit fb6f0c2

File tree

5 files changed

+44
-17
lines changed

5 files changed

+44
-17
lines changed

core/src/array/mod.rs

+30-4
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@ use crate::convert::Infallible;
1010
use crate::error::Error;
1111
use crate::fmt;
1212
use crate::hash::{self, Hash};
13+
use crate::intrinsics::transmute_unchecked;
1314
use crate::iter::{UncheckedIterator, repeat_n};
1415
use crate::mem::{self, MaybeUninit};
1516
use crate::ops::{
1617
ChangeOutputType, ControlFlow, FromResidual, Index, IndexMut, NeverShortCircuit, Residual, Try,
1718
};
19+
use crate::ptr::{null, null_mut};
1820
use crate::slice::{Iter, IterMut};
1921

2022
mod ascii;
@@ -606,8 +608,20 @@ impl<T, const N: usize> [T; N] {
606608
/// assert_eq!(strings.len(), 3);
607609
/// ```
608610
#[stable(feature = "array_methods", since = "1.77.0")]
609-
pub fn each_ref(&self) -> [&T; N] {
610-
from_trusted_iterator(self.iter())
611+
#[rustc_const_unstable(feature = "const_array_each_ref", issue = "133289")]
612+
pub const fn each_ref(&self) -> [&T; N] {
613+
let mut buf = [null::<T>(); N];
614+
615+
// FIXME(const-hack): We would like to simply use iterators for this (as in the original implementation), but this is not allowed in constant expressions.
616+
let mut i = 0;
617+
while i < N {
618+
buf[i] = &raw const self[i];
619+
620+
i += 1;
621+
}
622+
623+
// SAFETY: `*const T` has the same layout as `&T`, and we've also initialised each pointer as a valid reference.
624+
unsafe { transmute_unchecked(buf) }
611625
}
612626

613627
/// Borrows each element mutably and returns an array of mutable references
@@ -625,8 +639,20 @@ impl<T, const N: usize> [T; N] {
625639
/// assert_eq!(floats, [0.0, 2.7, -1.0]);
626640
/// ```
627641
#[stable(feature = "array_methods", since = "1.77.0")]
628-
pub fn each_mut(&mut self) -> [&mut T; N] {
629-
from_trusted_iterator(self.iter_mut())
642+
#[rustc_const_unstable(feature = "const_array_each_ref", issue = "133289")]
643+
pub const fn each_mut(&mut self) -> [&mut T; N] {
644+
let mut buf = [null_mut::<T>(); N];
645+
646+
// FIXME(const-hack): We would like to simply use iterators for this (as in the original implementation), but this is not allowed in constant expressions.
647+
let mut i = 0;
648+
while i < N {
649+
buf[i] = &raw mut self[i];
650+
651+
i += 1;
652+
}
653+
654+
// SAFETY: `*mut T` has the same layout as `&mut T`, and we've also initialised each pointer as a valid reference.
655+
unsafe { transmute_unchecked(buf) }
630656
}
631657

632658
/// Divides one array reference into two at an index.

std/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -658,6 +658,8 @@ pub mod arch {
658658
pub use std_detect::is_aarch64_feature_detected;
659659
#[unstable(feature = "stdarch_arm_feature_detection", issue = "111190")]
660660
pub use std_detect::is_arm_feature_detected;
661+
#[unstable(feature = "is_loongarch_feature_detected", issue = "117425")]
662+
pub use std_detect::is_loongarch_feature_detected;
661663
#[unstable(feature = "is_riscv_feature_detected", issue = "111192")]
662664
pub use std_detect::is_riscv_feature_detected;
663665
#[stable(feature = "simd_x86", since = "1.27.0")]

std/src/os/fd/owned.rs

+11-10
Original file line numberDiff line numberDiff line change
@@ -173,16 +173,17 @@ impl Drop for OwnedFd {
173173
#[inline]
174174
fn drop(&mut self) {
175175
unsafe {
176-
// Note that errors are ignored when closing a file descriptor. The
177-
// reason for this is that if an error occurs we don't actually know if
178-
// the file descriptor was closed or not, and if we retried (for
179-
// something like EINTR), we might close another valid file descriptor
180-
// opened after we closed ours.
181-
// However, this is usually justified, as some of the major Unices
182-
// do make sure to always close the FD, even when `close()` is interrupted,
183-
// and the scenario is rare to begin with.
184-
// Helpful link to an epic discussion by POSIX workgroup:
185-
// http://austingroupbugs.net/view.php?id=529
176+
// Note that errors are ignored when closing a file descriptor. According to POSIX 2024,
177+
// we can and indeed should retry `close` on `EINTR`
178+
// (https://pubs.opengroup.org/onlinepubs/9799919799.2024edition/functions/close.html),
179+
// but it is not clear yet how well widely-used implementations are conforming with this
180+
// mandate since older versions of POSIX left the state of the FD after an `EINTR`
181+
// unspecified. Ignoring errors is "fine" because some of the major Unices (in
182+
// particular, Linux) do make sure to always close the FD, even when `close()` is
183+
// interrupted, and the scenario is rare to begin with. If we retried on a
184+
// not-POSIX-compliant implementation, the consequences could be really bad since we may
185+
// close the wrong FD. Helpful link to an epic discussion by POSIX workgroup that led to
186+
// the latest POSIX wording: http://austingroupbugs.net/view.php?id=529
186187
#[cfg(not(target_os = "hermit"))]
187188
{
188189
#[cfg(unix)]

std/src/sys/random/arc4random.rs

-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
#[cfg(not(any(
1313
target_os = "haiku",
1414
target_os = "illumos",
15-
target_os = "rtems",
1615
target_os = "solaris",
1716
target_os = "vita",
1817
)))]
@@ -22,7 +21,6 @@ use libc::arc4random_buf;
2221
#[cfg(any(
2322
target_os = "haiku", // See https://git.haiku-os.org/haiku/tree/headers/compatibility/bsd/stdlib.h
2423
target_os = "illumos", // See https://www.illumos.org/man/3C/arc4random
25-
target_os = "rtems", // See https://docs.rtems.org/branches/master/bsp-howto/getentropy.html
2624
target_os = "solaris", // See https://docs.oracle.com/cd/E88353_01/html/E37843/arc4random-3c.html
2725
target_os = "vita", // See https://github.com/vitasdk/newlib/blob/b89e5bc183b516945f9ee07eef483ecb916e45ff/newlib/libc/include/stdlib.h#L74
2826
))]

std/src/thread/scoped.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ impl<'scope, 'env> Scope<'scope, 'env> {
176176
/// thread. If the spawned thread panics, [`join`] will return an [`Err`] containing
177177
/// the panic payload.
178178
///
179-
/// If the join handle is dropped, the spawned thread will implicitly joined at the
179+
/// If the join handle is dropped, the spawned thread will be implicitly joined at the
180180
/// end of the scope. In that case, if the spawned thread panics, [`scope`] will
181181
/// panic after all threads are joined.
182182
///

0 commit comments

Comments
 (0)