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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 39 additions & 0 deletions
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

Lines changed: 0 additions & 2 deletions
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

Lines changed: 0 additions & 2 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 16 additions & 1 deletion
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

Lines changed: 0 additions & 1 deletion
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

Lines changed: 35 additions & 2 deletions
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

Lines changed: 3 additions & 0 deletions
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

Lines changed: 2 additions & 0 deletions
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")]

0 commit comments

Comments
 (0)