Skip to content

Commit 723914d

Browse files
committed
Merge commit 'dd0d2657eb2c8466bbd9fa6ea4bf2b094565c680' into sync-2024-07-17
2 parents a70ad70 + dd0d265 commit 723914d

File tree

410 files changed

+14531
-8741
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

410 files changed

+14531
-8741
lines changed

library/alloc/Cargo.toml

+4-3
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ rand_xorshift = "0.3.0"
2020
name = "alloctests"
2121
path = "tests/lib.rs"
2222

23+
[[test]]
24+
name = "vec_deque_alloc_error"
25+
path = "tests/vec_deque_alloc_error.rs"
26+
2327
[[bench]]
2428
name = "allocbenches"
2529
path = "benches/lib.rs"
@@ -43,9 +47,6 @@ optimize_for_size = ["core/optimize_for_size"]
4347

4448
[lints.rust.unexpected_cfgs]
4549
level = "warn"
46-
# x.py uses beta cargo, so `check-cfg` entries do not yet take effect
47-
# for rust-lang/rust. But for users of `-Zbuild-std` it does.
48-
# The unused warning is waiting for rust-lang/cargo#13925 to reach beta.
4950
check-cfg = [
5051
'cfg(bootstrap)',
5152
'cfg(no_global_oom_handling)',

library/alloc/src/alloc.rs

-26
Original file line numberDiff line numberDiff line change
@@ -424,29 +424,3 @@ pub mod __alloc_error_handler {
424424
}
425425
}
426426
}
427-
428-
#[cfg(not(no_global_oom_handling))]
429-
/// Specialize clones into pre-allocated, uninitialized memory.
430-
/// Used by `Box::clone` and `Rc`/`Arc::make_mut`.
431-
pub(crate) trait WriteCloneIntoRaw: Sized {
432-
unsafe fn write_clone_into_raw(&self, target: *mut Self);
433-
}
434-
435-
#[cfg(not(no_global_oom_handling))]
436-
impl<T: Clone> WriteCloneIntoRaw for T {
437-
#[inline]
438-
default unsafe fn write_clone_into_raw(&self, target: *mut Self) {
439-
// Having allocated *first* may allow the optimizer to create
440-
// the cloned value in-place, skipping the local and move.
441-
unsafe { target.write(self.clone()) };
442-
}
443-
}
444-
445-
#[cfg(not(no_global_oom_handling))]
446-
impl<T: Copy> WriteCloneIntoRaw for T {
447-
#[inline]
448-
unsafe fn write_clone_into_raw(&self, target: *mut Self) {
449-
// We can always copy in-place, without ever involving a local value.
450-
unsafe { target.copy_from_nonoverlapping(self, 1) };
451-
}
452-
}

library/alloc/src/boxed.rs

+26-19
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,7 @@
145145
//! to `into_iter()` for boxed slices will defer to the slice implementation on editions before
146146
//! 2024:
147147
//!
148-
#![cfg_attr(bootstrap, doc = "```rust,edition2021,ignore")]
149-
#![cfg_attr(not(bootstrap), doc = "```rust,edition2021")]
148+
//! ```rust,edition2021
150149
//! // Rust 2015, 2018, and 2021:
151150
//!
152151
//! # #![allow(boxed_slice_into_iter)] // override our `deny(warnings)`
@@ -189,6 +188,8 @@
189188
use core::any::Any;
190189
use core::async_iter::AsyncIterator;
191190
use core::borrow;
191+
#[cfg(not(no_global_oom_handling))]
192+
use core::clone::CloneToUninit;
192193
use core::cmp::Ordering;
193194
use core::error::Error;
194195
use core::fmt;
@@ -208,7 +209,7 @@ use core::slice;
208209
use core::task::{Context, Poll};
209210

210211
#[cfg(not(no_global_oom_handling))]
211-
use crate::alloc::{handle_alloc_error, WriteCloneIntoRaw};
212+
use crate::alloc::handle_alloc_error;
212213
use crate::alloc::{AllocError, Allocator, Global, Layout};
213214
#[cfg(not(no_global_oom_handling))]
214215
use crate::borrow::Cow;
@@ -1212,6 +1213,9 @@ impl<T: ?Sized, A: Allocator> Box<T, A> {
12121213
/// let static_ref: &'static mut usize = Box::leak(x);
12131214
/// *static_ref += 1;
12141215
/// assert_eq!(*static_ref, 42);
1216+
/// # // FIXME(https://github.com/rust-lang/miri/issues/3670):
1217+
/// # // use -Zmiri-disable-leak-check instead of unleaking in tests meant to leak.
1218+
/// # drop(unsafe { Box::from_raw(static_ref) });
12151219
/// ```
12161220
///
12171221
/// Unsized data:
@@ -1221,6 +1225,9 @@ impl<T: ?Sized, A: Allocator> Box<T, A> {
12211225
/// let static_ref = Box::leak(x);
12221226
/// static_ref[0] = 4;
12231227
/// assert_eq!(*static_ref, [4, 2, 3]);
1228+
/// # // FIXME(https://github.com/rust-lang/miri/issues/3670):
1229+
/// # // use -Zmiri-disable-leak-check instead of unleaking in tests meant to leak.
1230+
/// # drop(unsafe { Box::from_raw(static_ref) });
12241231
/// ```
12251232
#[stable(feature = "box_leak", since = "1.26.0")]
12261233
#[inline]
@@ -1347,7 +1354,7 @@ impl<T: Clone, A: Allocator + Clone> Clone for Box<T, A> {
13471354
// Pre-allocate memory to allow writing the cloned value directly.
13481355
let mut boxed = Self::new_uninit_in(self.1.clone());
13491356
unsafe {
1350-
(**self).write_clone_into_raw(boxed.as_mut_ptr());
1357+
(**self).clone_to_uninit(boxed.as_mut_ptr());
13511358
boxed.assume_init()
13521359
}
13531360
}
@@ -2123,23 +2130,23 @@ impl<I> FromIterator<I> for Box<[I]> {
21232130

21242131
/// This implementation is required to make sure that the `Box<[I]>: IntoIterator`
21252132
/// implementation doesn't overlap with `IntoIterator for T where T: Iterator` blanket.
2126-
#[stable(feature = "boxed_slice_into_iter", since = "CURRENT_RUSTC_VERSION")]
2133+
#[stable(feature = "boxed_slice_into_iter", since = "1.80.0")]
21272134
impl<I, A: Allocator> !Iterator for Box<[I], A> {}
21282135

21292136
/// This implementation is required to make sure that the `&Box<[I]>: IntoIterator`
21302137
/// implementation doesn't overlap with `IntoIterator for T where T: Iterator` blanket.
2131-
#[stable(feature = "boxed_slice_into_iter", since = "CURRENT_RUSTC_VERSION")]
2138+
#[stable(feature = "boxed_slice_into_iter", since = "1.80.0")]
21322139
impl<'a, I, A: Allocator> !Iterator for &'a Box<[I], A> {}
21332140

21342141
/// This implementation is required to make sure that the `&mut Box<[I]>: IntoIterator`
21352142
/// implementation doesn't overlap with `IntoIterator for T where T: Iterator` blanket.
2136-
#[stable(feature = "boxed_slice_into_iter", since = "CURRENT_RUSTC_VERSION")]
2143+
#[stable(feature = "boxed_slice_into_iter", since = "1.80.0")]
21372144
impl<'a, I, A: Allocator> !Iterator for &'a mut Box<[I], A> {}
21382145

21392146
// Note: the `#[rustc_skip_during_method_dispatch(boxed_slice)]` on `trait IntoIterator`
21402147
// hides this implementation from explicit `.into_iter()` calls on editions < 2024,
21412148
// so those calls will still resolve to the slice implementation, by reference.
2142-
#[stable(feature = "boxed_slice_into_iter", since = "CURRENT_RUSTC_VERSION")]
2149+
#[stable(feature = "boxed_slice_into_iter", since = "1.80.0")]
21432150
impl<I, A: Allocator> IntoIterator for Box<[I], A> {
21442151
type IntoIter = vec::IntoIter<I, A>;
21452152
type Item = I;
@@ -2148,7 +2155,7 @@ impl<I, A: Allocator> IntoIterator for Box<[I], A> {
21482155
}
21492156
}
21502157

2151-
#[stable(feature = "boxed_slice_into_iter", since = "CURRENT_RUSTC_VERSION")]
2158+
#[stable(feature = "boxed_slice_into_iter", since = "1.80.0")]
21522159
impl<'a, I, A: Allocator> IntoIterator for &'a Box<[I], A> {
21532160
type IntoIter = slice::Iter<'a, I>;
21542161
type Item = &'a I;
@@ -2157,7 +2164,7 @@ impl<'a, I, A: Allocator> IntoIterator for &'a Box<[I], A> {
21572164
}
21582165
}
21592166

2160-
#[stable(feature = "boxed_slice_into_iter", since = "CURRENT_RUSTC_VERSION")]
2167+
#[stable(feature = "boxed_slice_into_iter", since = "1.80.0")]
21612168
impl<'a, I, A: Allocator> IntoIterator for &'a mut Box<[I], A> {
21622169
type IntoIter = slice::IterMut<'a, I>;
21632170
type Item = &'a mut I;
@@ -2167,47 +2174,47 @@ impl<'a, I, A: Allocator> IntoIterator for &'a mut Box<[I], A> {
21672174
}
21682175

21692176
#[cfg(not(no_global_oom_handling))]
2170-
#[stable(feature = "boxed_str_from_iter", since = "CURRENT_RUSTC_VERSION")]
2177+
#[stable(feature = "boxed_str_from_iter", since = "1.80.0")]
21712178
impl FromIterator<char> for Box<str> {
21722179
fn from_iter<T: IntoIterator<Item = char>>(iter: T) -> Self {
21732180
String::from_iter(iter).into_boxed_str()
21742181
}
21752182
}
21762183

21772184
#[cfg(not(no_global_oom_handling))]
2178-
#[stable(feature = "boxed_str_from_iter", since = "CURRENT_RUSTC_VERSION")]
2185+
#[stable(feature = "boxed_str_from_iter", since = "1.80.0")]
21792186
impl<'a> FromIterator<&'a char> for Box<str> {
21802187
fn from_iter<T: IntoIterator<Item = &'a char>>(iter: T) -> Self {
21812188
String::from_iter(iter).into_boxed_str()
21822189
}
21832190
}
21842191

21852192
#[cfg(not(no_global_oom_handling))]
2186-
#[stable(feature = "boxed_str_from_iter", since = "CURRENT_RUSTC_VERSION")]
2193+
#[stable(feature = "boxed_str_from_iter", since = "1.80.0")]
21872194
impl<'a> FromIterator<&'a str> for Box<str> {
21882195
fn from_iter<T: IntoIterator<Item = &'a str>>(iter: T) -> Self {
21892196
String::from_iter(iter).into_boxed_str()
21902197
}
21912198
}
21922199

21932200
#[cfg(not(no_global_oom_handling))]
2194-
#[stable(feature = "boxed_str_from_iter", since = "CURRENT_RUSTC_VERSION")]
2201+
#[stable(feature = "boxed_str_from_iter", since = "1.80.0")]
21952202
impl FromIterator<String> for Box<str> {
21962203
fn from_iter<T: IntoIterator<Item = String>>(iter: T) -> Self {
21972204
String::from_iter(iter).into_boxed_str()
21982205
}
21992206
}
22002207

22012208
#[cfg(not(no_global_oom_handling))]
2202-
#[stable(feature = "boxed_str_from_iter", since = "CURRENT_RUSTC_VERSION")]
2209+
#[stable(feature = "boxed_str_from_iter", since = "1.80.0")]
22032210
impl<A: Allocator> FromIterator<Box<str, A>> for Box<str> {
22042211
fn from_iter<T: IntoIterator<Item = Box<str, A>>>(iter: T) -> Self {
22052212
String::from_iter(iter).into_boxed_str()
22062213
}
22072214
}
22082215

22092216
#[cfg(not(no_global_oom_handling))]
2210-
#[stable(feature = "boxed_str_from_iter", since = "CURRENT_RUSTC_VERSION")]
2217+
#[stable(feature = "boxed_str_from_iter", since = "1.80.0")]
22112218
impl<'a> FromIterator<Cow<'a, str>> for Box<str> {
22122219
fn from_iter<T: IntoIterator<Item = Cow<'a, str>>>(iter: T) -> Self {
22132220
String::from_iter(iter).into_boxed_str()
@@ -2373,7 +2380,7 @@ impl dyn Error + Send {
23732380
let err: Box<dyn Error> = self;
23742381
<dyn Error>::downcast(err).map_err(|s| unsafe {
23752382
// Reapply the `Send` marker.
2376-
Box::from_raw(Box::into_raw(s) as *mut (dyn Error + Send))
2383+
mem::transmute::<Box<dyn Error>, Box<dyn Error + Send>>(s)
23772384
})
23782385
}
23792386
}
@@ -2386,8 +2393,8 @@ impl dyn Error + Send + Sync {
23862393
pub fn downcast<T: Error + 'static>(self: Box<Self>) -> Result<Box<T>, Box<Self>> {
23872394
let err: Box<dyn Error> = self;
23882395
<dyn Error>::downcast(err).map_err(|s| unsafe {
2389-
// Reapply the `Send + Sync` marker.
2390-
Box::from_raw(Box::into_raw(s) as *mut (dyn Error + Send + Sync))
2396+
// Reapply the `Send + Sync` markers.
2397+
mem::transmute::<Box<dyn Error>, Box<dyn Error + Send + Sync>>(s)
23912398
})
23922399
}
23932400
}

library/alloc/src/boxed/thin.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
// Based on
2-
// https://github.com/matthieu-m/rfc2580/blob/b58d1d3cba0d4b5e859d3617ea2d0943aaa31329/examples/thin.rs
3-
// by matthieu-m
1+
//! Based on
2+
//! <https://github.com/matthieu-m/rfc2580/blob/b58d1d3cba0d4b5e859d3617ea2d0943aaa31329/examples/thin.rs>
3+
//! by matthieu-m
4+
45
use crate::alloc::{self, Layout, LayoutError};
56
use core::error::Error;
67
use core::fmt::{self, Debug, Display, Formatter};

library/alloc/src/collections/binary_heap/mod.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ impl<T: Ord> BinaryHeap<T> {
440440
/// heap.push(4);
441441
/// ```
442442
#[stable(feature = "rust1", since = "1.0.0")]
443-
#[rustc_const_unstable(feature = "const_binary_heap_constructor", issue = "112353")]
443+
#[rustc_const_stable(feature = "const_binary_heap_constructor", since = "1.80.0")]
444444
#[must_use]
445445
pub const fn new() -> BinaryHeap<T> {
446446
BinaryHeap { data: vec![] }
@@ -484,7 +484,7 @@ impl<T: Ord, A: Allocator> BinaryHeap<T, A> {
484484
/// heap.push(4);
485485
/// ```
486486
#[unstable(feature = "allocator_api", issue = "32838")]
487-
#[rustc_const_unstable(feature = "const_binary_heap_constructor", issue = "112353")]
487+
#[rustc_const_unstable(feature = "const_binary_heap_new_in", issue = "112353")]
488488
#[must_use]
489489
pub const fn new_in(alloc: A) -> BinaryHeap<T, A> {
490490
BinaryHeap { data: Vec::new_in(alloc) }
@@ -1213,7 +1213,6 @@ impl<T, A: Allocator> BinaryHeap<T, A> {
12131213
/// Basic usage:
12141214
///
12151215
/// ```
1216-
/// #![feature(binary_heap_as_slice)]
12171216
/// use std::collections::BinaryHeap;
12181217
/// use std::io::{self, Write};
12191218
///
@@ -1222,7 +1221,7 @@ impl<T, A: Allocator> BinaryHeap<T, A> {
12221221
/// io::sink().write(heap.as_slice()).unwrap();
12231222
/// ```
12241223
#[must_use]
1225-
#[unstable(feature = "binary_heap_as_slice", issue = "83659")]
1224+
#[stable(feature = "binary_heap_as_slice", since = "1.80.0")]
12261225
pub fn as_slice(&self) -> &[T] {
12271226
self.data.as_slice()
12281227
}

library/alloc/src/collections/btree/map/tests.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -1796,18 +1796,18 @@ fn test_ord_absence() {
17961796
}
17971797

17981798
fn map_debug<K: Debug>(mut map: BTreeMap<K, ()>) {
1799-
format!("{map:?}");
1800-
format!("{:?}", map.iter());
1801-
format!("{:?}", map.iter_mut());
1802-
format!("{:?}", map.keys());
1803-
format!("{:?}", map.values());
1804-
format!("{:?}", map.values_mut());
1799+
let _ = format!("{map:?}");
1800+
let _ = format!("{:?}", map.iter());
1801+
let _ = format!("{:?}", map.iter_mut());
1802+
let _ = format!("{:?}", map.keys());
1803+
let _ = format!("{:?}", map.values());
1804+
let _ = format!("{:?}", map.values_mut());
18051805
if true {
1806-
format!("{:?}", map.into_iter());
1806+
let _ = format!("{:?}", map.into_iter());
18071807
} else if true {
1808-
format!("{:?}", map.into_keys());
1808+
let _ = format!("{:?}", map.into_keys());
18091809
} else {
1810-
format!("{:?}", map.into_values());
1810+
let _ = format!("{:?}", map.into_values());
18111811
}
18121812
}
18131813

library/alloc/src/collections/btree/set/tests.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -705,9 +705,9 @@ fn test_ord_absence() {
705705
}
706706

707707
fn set_debug<K: Debug>(set: BTreeSet<K>) {
708-
format!("{set:?}");
709-
format!("{:?}", set.iter());
710-
format!("{:?}", set.into_iter());
708+
let _ = format!("{set:?}");
709+
let _ = format!("{:?}", set.iter());
710+
let _ = format!("{:?}", set.into_iter());
711711
}
712712

713713
fn set_clone<K: Clone>(mut set: BTreeSet<K>) {

library/alloc/src/collections/linked_list.rs

+22-2
Original file line numberDiff line numberDiff line change
@@ -1495,6 +1495,14 @@ impl<'a, T, A: Allocator> Cursor<'a, T, A> {
14951495
pub fn back(&self) -> Option<&'a T> {
14961496
self.list.back()
14971497
}
1498+
1499+
/// Provides a reference to the cursor's parent list.
1500+
#[must_use]
1501+
#[inline(always)]
1502+
#[unstable(feature = "linked_list_cursors", issue = "58533")]
1503+
pub fn as_list(&self) -> &'a LinkedList<T, A> {
1504+
self.list
1505+
}
14981506
}
14991507

15001508
impl<'a, T, A: Allocator> CursorMut<'a, T, A> {
@@ -1605,6 +1613,18 @@ impl<'a, T, A: Allocator> CursorMut<'a, T, A> {
16051613
pub fn as_cursor(&self) -> Cursor<'_, T, A> {
16061614
Cursor { list: self.list, current: self.current, index: self.index }
16071615
}
1616+
1617+
/// Provides a read-only reference to the cursor's parent list.
1618+
///
1619+
/// The lifetime of the returned reference is bound to that of the
1620+
/// `CursorMut`, which means it cannot outlive the `CursorMut` and that the
1621+
/// `CursorMut` is frozen for the lifetime of the reference.
1622+
#[must_use]
1623+
#[inline(always)]
1624+
#[unstable(feature = "linked_list_cursors", issue = "58533")]
1625+
pub fn as_list(&self) -> &LinkedList<T, A> {
1626+
self.list
1627+
}
16081628
}
16091629

16101630
// Now the list editing operations
@@ -1705,7 +1725,7 @@ impl<'a, T, A: Allocator> CursorMut<'a, T, A> {
17051725
unsafe {
17061726
self.current = unlinked_node.as_ref().next;
17071727
self.list.unlink_node(unlinked_node);
1708-
let unlinked_node = Box::from_raw(unlinked_node.as_ptr());
1728+
let unlinked_node = Box::from_raw_in(unlinked_node.as_ptr(), &self.list.alloc);
17091729
Some(unlinked_node.element)
17101730
}
17111731
}
@@ -1946,7 +1966,7 @@ where
19461966
if (self.pred)(&mut node.as_mut().element) {
19471967
// `unlink_node` is okay with aliasing `element` references.
19481968
self.list.unlink_node(node);
1949-
return Some(Box::from_raw(node.as_ptr()).element);
1969+
return Some(Box::from_raw_in(node.as_ptr(), &self.list.alloc).element);
19501970
}
19511971
}
19521972
}

0 commit comments

Comments
 (0)