Skip to content

Commit c6e53ce

Browse files
author
The Miri Cronjob Bot
committed
Merge from rustc
2 parents 28dc012 + fa66a61 commit c6e53ce

File tree

37 files changed

+234
-123
lines changed

37 files changed

+234
-123
lines changed

alloc/src/collections/linked_list.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1705,7 +1705,7 @@ impl<'a, T, A: Allocator> CursorMut<'a, T, A> {
17051705
unsafe {
17061706
self.current = unlinked_node.as_ref().next;
17071707
self.list.unlink_node(unlinked_node);
1708-
let unlinked_node = Box::from_raw(unlinked_node.as_ptr());
1708+
let unlinked_node = Box::from_raw_in(unlinked_node.as_ptr(), &self.list.alloc);
17091709
Some(unlinked_node.element)
17101710
}
17111711
}
@@ -1946,7 +1946,7 @@ where
19461946
if (self.pred)(&mut node.as_mut().element) {
19471947
// `unlink_node` is okay with aliasing `element` references.
19481948
self.list.unlink_node(node);
1949-
return Some(Box::from_raw(node.as_ptr()).element);
1949+
return Some(Box::from_raw_in(node.as_ptr(), &self.list.alloc).element);
19501950
}
19511951
}
19521952
}

alloc/src/collections/linked_list/tests.rs

+39
Original file line numberDiff line numberDiff line change
@@ -1164,3 +1164,42 @@ fn test_drop_panic() {
11641164

11651165
assert_eq!(unsafe { DROPS }, 8);
11661166
}
1167+
1168+
#[test]
1169+
fn test_allocator() {
1170+
use core::alloc::AllocError;
1171+
use core::alloc::Allocator;
1172+
use core::alloc::Layout;
1173+
use core::cell::Cell;
1174+
1175+
struct A {
1176+
has_allocated: Cell<bool>,
1177+
has_deallocated: Cell<bool>,
1178+
}
1179+
1180+
unsafe impl Allocator for A {
1181+
fn allocate(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError> {
1182+
assert!(!self.has_allocated.get());
1183+
self.has_allocated.set(true);
1184+
1185+
Global.allocate(layout)
1186+
}
1187+
1188+
unsafe fn deallocate(&self, ptr: NonNull<u8>, layout: Layout) {
1189+
assert!(!self.has_deallocated.get());
1190+
self.has_deallocated.set(true);
1191+
1192+
unsafe { Global.deallocate(ptr, layout) }
1193+
}
1194+
}
1195+
1196+
let alloc = &A { has_allocated: Cell::new(false), has_deallocated: Cell::new(false) };
1197+
{
1198+
let mut list = LinkedList::new_in(alloc);
1199+
list.push_back(5u32);
1200+
list.remove(0);
1201+
}
1202+
1203+
assert!(alloc.has_allocated.get());
1204+
assert!(alloc.has_deallocated.get());
1205+
}

alloc/src/rc.rs

-2
Original file line numberDiff line numberDiff line change
@@ -257,8 +257,6 @@ use core::intrinsics::abort;
257257
#[cfg(not(no_global_oom_handling))]
258258
use core::iter;
259259
use core::marker::{PhantomData, Unsize};
260-
#[cfg(not(no_global_oom_handling))]
261-
use core::mem::size_of_val;
262260
use core::mem::{self, align_of_val_raw, forget, ManuallyDrop};
263261
use core::ops::{CoerceUnsized, Deref, DerefMut, DerefPure, DispatchFromDyn, Receiver};
264262
use core::panic::{RefUnwindSafe, UnwindSafe};

alloc/src/sync.rs

-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ use core::intrinsics::abort;
1818
#[cfg(not(no_global_oom_handling))]
1919
use core::iter;
2020
use core::marker::{PhantomData, Unsize};
21-
#[cfg(not(no_global_oom_handling))]
22-
use core::mem::size_of_val;
2321
use core::mem::{self, align_of_val_raw};
2422
use core::ops::{CoerceUnsized, Deref, DerefPure, DispatchFromDyn, Receiver};
2523
use core::panic::{RefUnwindSafe, UnwindSafe};

alloc/tests/vec_deque_alloc_error.rs

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use std::{
88
};
99

1010
#[test]
11+
#[cfg_attr(not(panic = "unwind"), ignore = "test requires unwinding support")]
1112
fn test_shrink_to_unwind() {
1213
// This tests that `shrink_to` leaves the deque in a consistent state when
1314
// the call to `RawVec::shrink_to_fit` unwinds. The code is adapted from #123369

core/src/cell.rs

+16-1
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,20 @@
8282
//!
8383
//! The corresponding [`Sync`] version of `OnceCell<T>` is [`OnceLock<T>`].
8484
//!
85+
//! ## `LazyCell<T, F>`
86+
//!
87+
//! A common pattern with OnceCell is, for a given OnceCell, to use the same function on every
88+
//! call to [`OnceCell::get_or_init`] with that cell. This is what is offered by [`LazyCell`],
89+
//! which pairs cells of `T` with functions of `F`, and always calls `F` before it yields `&T`.
90+
//! This happens implicitly by simply attempting to dereference the LazyCell to get its contents,
91+
//! so its use is much more transparent with a place which has been initialized by a constant.
92+
//!
93+
//! More complicated patterns that don't fit this description can be built on `OnceCell<T>` instead.
94+
//!
95+
//! `LazyCell` works by providing an implementation of `impl Deref` that calls the function,
96+
//! so you can just use it by dereference (e.g. `*lazy_cell` or `lazy_cell.deref()`).
97+
//!
98+
//! The corresponding [`Sync`] version of `LazyCell<T, F>` is [`LazyLock<T, F>`].
8599
//!
86100
//! # When to choose interior mutability
87101
//!
@@ -230,6 +244,7 @@
230244
//! [`RwLock<T>`]: ../../std/sync/struct.RwLock.html
231245
//! [`Mutex<T>`]: ../../std/sync/struct.Mutex.html
232246
//! [`OnceLock<T>`]: ../../std/sync/struct.OnceLock.html
247+
//! [`LazyLock<T, F>`]: ../../std/sync/struct.LazyLock.html
233248
//! [`Sync`]: ../../std/marker/trait.Sync.html
234249
//! [`atomic`]: crate::sync::atomic
235250
@@ -238,7 +253,7 @@
238253
use crate::cmp::Ordering;
239254
use crate::fmt::{self, Debug, Display};
240255
use crate::marker::{PhantomData, Unsize};
241-
use crate::mem::{self, size_of};
256+
use crate::mem;
242257
use crate::ops::{CoerceUnsized, Deref, DerefMut, DerefPure, DispatchFromDyn};
243258
use crate::ptr::{self, NonNull};
244259

core/src/intrinsics.rs

-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@
6565

6666
use crate::marker::DiscriminantKind;
6767
use crate::marker::Tuple;
68-
use crate::mem::align_of;
6968
use crate::ptr;
7069
use crate::ub_checks;
7170

core/src/iter/adapters/chain.rs

+35-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ use crate::ops::Try;
44

55
/// An iterator that links two iterators together, in a chain.
66
///
7-
/// This `struct` is created by [`Iterator::chain`]. See its documentation
8-
/// for more.
7+
/// This `struct` is created by [`chain`] or [`Iterator::chain`]. See their
8+
/// documentation for more.
99
///
1010
/// # Examples
1111
///
@@ -38,6 +38,39 @@ impl<A, B> Chain<A, B> {
3838
}
3939
}
4040

41+
/// Converts the arguments to iterators and links them together, in a chain.
42+
///
43+
/// See the documentation of [`Iterator::chain`] for more.
44+
///
45+
/// # Examples
46+
///
47+
/// ```
48+
/// #![feature(iter_chain)]
49+
///
50+
/// use std::iter::chain;
51+
///
52+
/// let a = [1, 2, 3];
53+
/// let b = [4, 5, 6];
54+
///
55+
/// let mut iter = chain(a, b);
56+
///
57+
/// assert_eq!(iter.next(), Some(1));
58+
/// assert_eq!(iter.next(), Some(2));
59+
/// assert_eq!(iter.next(), Some(3));
60+
/// assert_eq!(iter.next(), Some(4));
61+
/// assert_eq!(iter.next(), Some(5));
62+
/// assert_eq!(iter.next(), Some(6));
63+
/// assert_eq!(iter.next(), None);
64+
/// ```
65+
#[unstable(feature = "iter_chain", reason = "recently added", issue = "125964")]
66+
pub fn chain<A, B>(a: A, b: B) -> Chain<A::IntoIter, B::IntoIter>
67+
where
68+
A: IntoIterator,
69+
B: IntoIterator<Item = A::Item>,
70+
{
71+
Chain::new(a.into_iter(), b.into_iter())
72+
}
73+
4174
#[stable(feature = "rust1", since = "1.0.0")]
4275
impl<A, B> Iterator for Chain<A, B>
4376
where

core/src/iter/adapters/mod.rs

+3
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ pub use self::array_chunks::ArrayChunks;
4141
#[unstable(feature = "std_internals", issue = "none")]
4242
pub use self::by_ref_sized::ByRefSized;
4343

44+
#[unstable(feature = "iter_chain", reason = "recently added", issue = "125964")]
45+
pub use self::chain::chain;
46+
4447
#[stable(feature = "iter_cloned", since = "1.1.0")]
4548
pub use self::cloned::Cloned;
4649

core/src/iter/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,8 @@ pub use self::traits::{
428428
DoubleEndedIterator, ExactSizeIterator, Extend, FromIterator, IntoIterator, Product, Sum,
429429
};
430430

431+
#[unstable(feature = "iter_chain", reason = "recently added", issue = "125964")]
432+
pub use self::adapters::chain;
431433
#[stable(feature = "iter_zip", since = "1.59.0")]
432434
pub use self::adapters::zip;
433435
#[unstable(feature = "iter_array_chunks", reason = "recently added", issue = "100450")]

core/src/macros/mod.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -1569,7 +1569,12 @@ pub(crate) mod builtin {
15691569
#[rustc_builtin_macro]
15701570
#[macro_export]
15711571
#[rustc_diagnostic_item = "assert_macro"]
1572-
#[allow_internal_unstable(panic_internals, edition_panic, generic_assert_internals)]
1572+
#[allow_internal_unstable(
1573+
core_intrinsics,
1574+
panic_internals,
1575+
edition_panic,
1576+
generic_assert_internals
1577+
)]
15731578
macro_rules! assert {
15741579
($cond:expr $(,)?) => {{ /* compiler built-in */ }};
15751580
($cond:expr, $($arg:tt)+) => {{ /* compiler built-in */ }};

core/src/mem/maybe_uninit.rs

+5-12
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,8 @@ use crate::slice;
120120
/// use std::mem::{self, MaybeUninit};
121121
///
122122
/// let data = {
123-
/// // Create an uninitialized array of `MaybeUninit`. The `assume_init` is
124-
/// // safe because the type we are claiming to have initialized here is a
125-
/// // bunch of `MaybeUninit`s, which do not require initialization.
126-
/// let mut data: [MaybeUninit<Vec<u32>>; 1000] = unsafe {
127-
/// MaybeUninit::uninit().assume_init()
128-
/// };
123+
/// // Create an uninitialized array of `MaybeUninit`.
124+
/// let mut data: [MaybeUninit<Vec<u32>>; 1000] = [const { MaybeUninit::uninit() }; 1000];
129125
///
130126
/// // Dropping a `MaybeUninit` does nothing, so if there is a panic during this loop,
131127
/// // we have a memory leak, but there is no memory safety issue.
@@ -147,10 +143,8 @@ use crate::slice;
147143
/// ```
148144
/// use std::mem::MaybeUninit;
149145
///
150-
/// // Create an uninitialized array of `MaybeUninit`. The `assume_init` is
151-
/// // safe because the type we are claiming to have initialized here is a
152-
/// // bunch of `MaybeUninit`s, which do not require initialization.
153-
/// let mut data: [MaybeUninit<String>; 1000] = unsafe { MaybeUninit::uninit().assume_init() };
146+
/// // Create an uninitialized array of `MaybeUninit`.
147+
/// let mut data: [MaybeUninit<String>; 1000] = [const { MaybeUninit::uninit() }; 1000];
154148
/// // Count the number of elements we have assigned.
155149
/// let mut data_len: usize = 0;
156150
///
@@ -348,8 +342,7 @@ impl<T> MaybeUninit<T> {
348342
#[must_use]
349343
#[inline(always)]
350344
pub const fn uninit_array<const N: usize>() -> [Self; N] {
351-
// SAFETY: An uninitialized `[MaybeUninit<_>; LEN]` is valid.
352-
unsafe { MaybeUninit::<[MaybeUninit<T>; N]>::uninit().assume_init() }
345+
[const { MaybeUninit::uninit() }; N]
353346
}
354347

355348
/// Creates a new `MaybeUninit<T>` in an uninitialized state, with the memory being

core/src/prelude/common.rs

+3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ pub use crate::ops::{Drop, Fn, FnMut, FnOnce};
1414
#[stable(feature = "core_prelude", since = "1.4.0")]
1515
#[doc(no_inline)]
1616
pub use crate::mem::drop;
17+
#[stable(feature = "size_of_prelude", since = "CURRENT_RUSTC_VERSION")]
18+
#[doc(no_inline)]
19+
pub use crate::mem::{align_of, align_of_val, size_of, size_of_val};
1720

1821
// Re-exported types and traits
1922
#[stable(feature = "core_prelude", since = "1.4.0")]

core/src/ptr/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ use crate::intrinsics;
415415
use crate::marker::FnPtr;
416416
use crate::ub_checks;
417417

418-
use crate::mem::{self, align_of, size_of, MaybeUninit};
418+
use crate::mem::{self, MaybeUninit};
419419

420420
mod alignment;
421421
#[unstable(feature = "ptr_alignment_type", issue = "102070")]

core/src/slice/raw.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
//! Free functions to create `&[T]` and `&mut [T]`.
22
33
use crate::array;
4-
use crate::mem::{align_of, size_of};
54
use crate::ops::Range;
65
use crate::ptr;
76
use crate::ub_checks;

core/src/sync/atomic.rs

-3
Original file line numberDiff line numberDiff line change
@@ -1296,7 +1296,6 @@ impl<T> AtomicPtr<T> {
12961296
#[cfg(target_has_atomic_equal_alignment = "ptr")]
12971297
#[unstable(feature = "atomic_from_mut", issue = "76314")]
12981298
pub fn from_mut(v: &mut *mut T) -> &mut Self {
1299-
use crate::mem::align_of;
13001299
let [] = [(); align_of::<AtomicPtr<()>>() - align_of::<*mut ()>()];
13011300
// SAFETY:
13021301
// - the mutable reference guarantees unique ownership.
@@ -2286,7 +2285,6 @@ macro_rules! atomic_int {
22862285
#[$cfg_align]
22872286
#[unstable(feature = "atomic_from_mut", issue = "76314")]
22882287
pub fn from_mut(v: &mut $int_type) -> &mut Self {
2289-
use crate::mem::align_of;
22902288
let [] = [(); align_of::<Self>() - align_of::<$int_type>()];
22912289
// SAFETY:
22922290
// - the mutable reference guarantees unique ownership.
@@ -2354,7 +2352,6 @@ macro_rules! atomic_int {
23542352
#[$cfg_align]
23552353
#[unstable(feature = "atomic_from_mut", issue = "76314")]
23562354
pub fn from_mut_slice(v: &mut [$int_type]) -> &mut [Self] {
2357-
use crate::mem::align_of;
23582355
let [] = [(); align_of::<Self>() - align_of::<$int_type>()];
23592356
// SAFETY:
23602357
// - the mutable reference guarantees unique ownership.

core/tests/iter/adapters/chain.rs

+8
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@ use super::*;
22
use core::iter::*;
33
use core::num::NonZero;
44

5+
#[test]
6+
fn test_chain() {
7+
let xs = [0, 1, 2, 3, 4, 5];
8+
let ys = [30, 40, 50, 60];
9+
let expected = [0, 1, 2, 3, 4, 5, 30, 40, 50, 60];
10+
assert_eq!(Vec::from_iter(chain(xs, ys)), expected);
11+
}
12+
513
#[test]
614
fn test_iterator_chain() {
715
let xs = [0, 1, 2, 3, 4, 5];

core/tests/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
#![feature(ip)]
7676
#![feature(iter_advance_by)]
7777
#![feature(iter_array_chunks)]
78+
#![feature(iter_chain)]
7879
#![feature(iter_collect_into)]
7980
#![feature(iter_partition_in_place)]
8081
#![feature(iter_intersperse)]

portable-simd/crates/core_simd/src/simd/ptr/const_ptr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ where
9696
fn cast<U>(self) -> Self::CastPtr<U> {
9797
// SimdElement currently requires zero-sized metadata, so this should never fail.
9898
// If this ever changes, `simd_cast_ptr` should produce a post-mono error.
99-
use core::{mem::size_of, ptr::Pointee};
99+
use core::ptr::Pointee;
100100
assert_eq!(size_of::<<T as Pointee>::Metadata>(), 0);
101101
assert_eq!(size_of::<<U as Pointee>::Metadata>(), 0);
102102

portable-simd/crates/core_simd/src/simd/ptr/mut_ptr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ where
9393
fn cast<U>(self) -> Self::CastPtr<U> {
9494
// SimdElement currently requires zero-sized metadata, so this should never fail.
9595
// If this ever changes, `simd_cast_ptr` should produce a post-mono error.
96-
use core::{mem::size_of, ptr::Pointee};
96+
use core::ptr::Pointee;
9797
assert_eq!(size_of::<<T as Pointee>::Metadata>(), 0);
9898
assert_eq!(size_of::<<U as Pointee>::Metadata>(), 0);
9999

proc_macro/src/bridge/fxhash.rs

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
use std::collections::HashMap;
88
use std::hash::BuildHasherDefault;
99
use std::hash::Hasher;
10-
use std::mem::size_of;
1110
use std::ops::BitXor;
1211

1312
/// Type alias for a hashmap using the `fx` hash algorithm.

std/src/collections/hash/map.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1218,7 +1218,7 @@ where
12181218
/// will cause the map to produce seemingly random results. Higher-level and
12191219
/// more foolproof APIs like `entry` should be preferred when possible.
12201220
///
1221-
/// In particular, the hash used to initialized the raw entry must still be
1221+
/// In particular, the hash used to initialize the raw entry must still be
12221222
/// consistent with the hash of the key that is ultimately stored in the entry.
12231223
/// This is because implementations of HashMap may need to recompute hashes
12241224
/// when resizing, at which point only the keys are available.

std/src/io/error/repr_bitpacked.rs

-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@
104104
105105
use super::{Custom, ErrorData, ErrorKind, RawOsError, SimpleMessage};
106106
use core::marker::PhantomData;
107-
use core::mem::{align_of, size_of};
108107
use core::ptr::{self, NonNull};
109108

110109
// The 2 least-significant bits are used as tag.

std/src/io/stdio.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1190,9 +1190,8 @@ pub trait IsTerminal: crate::sealed::Sealed {
11901190
///
11911191
/// - If you run this example by piping some text to it, e.g. `echo "foo" | path/to/executable`
11921192
/// it will print: `Hello foo`.
1193-
/// - If you instead run the example interactively by running the executable directly, it will
1194-
/// panic with the message "Expected input to be piped to the process".
1195-
///
1193+
/// - If you instead run the example interactively by running `path/to/executable` directly, it will
1194+
/// prompt for input.
11961195
///
11971196
/// [changes]: io#platform-specific-behavior
11981197
/// [`Stdin`]: crate::io::Stdin

std/src/os/unix/net/ancillary.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use super::{sockaddr_un, SocketAddr};
44
use crate::io::{self, IoSlice, IoSliceMut};
55
use crate::marker::PhantomData;
6-
use crate::mem::{size_of, zeroed};
6+
use crate::mem::zeroed;
77
use crate::os::unix::io::RawFd;
88
use crate::path::Path;
99
use crate::ptr::{eq, read_unaligned};

0 commit comments

Comments
 (0)