Skip to content

Commit bdad0f1

Browse files
author
The rustc-josh-sync Cronjob Bot
committed
Merge ref 'd36f96412516' from rust-lang/rust
Pull recent changes from https://github.com/rust-lang/rust via Josh. Upstream ref: d36f964 Filtered ref: 92461731ae79cfe5044e4826160665b77c0363a2 This merge was created using https://github.com/rust-lang/josh-sync.
2 parents 9facee6 + 42e3b80 commit bdad0f1

File tree

230 files changed

+6620
-4847
lines changed

Some content is hidden

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

230 files changed

+6620
-4847
lines changed

Cargo.lock

Lines changed: 8 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,3 @@ rustflags = ["-Cpanic=abort"]
5959
rustc-std-workspace-core = { path = 'rustc-std-workspace-core' }
6060
rustc-std-workspace-alloc = { path = 'rustc-std-workspace-alloc' }
6161
rustc-std-workspace-std = { path = 'rustc-std-workspace-std' }
62-
compiler_builtins = { path = "compiler-builtins/compiler-builtins" }

alloc/src/alloc.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ unsafe extern "Rust" {
1717
#[rustc_allocator]
1818
#[rustc_nounwind]
1919
#[rustc_std_internal_symbol]
20+
#[rustc_allocator_zeroed_variant = "__rust_alloc_zeroed"]
2021
fn __rust_alloc(size: usize, align: usize) -> *mut u8;
2122
#[rustc_deallocator]
2223
#[rustc_nounwind]

alloc/src/boxed.rs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1672,7 +1672,7 @@ unsafe impl<#[may_dangle] T: ?Sized, A: Allocator> Drop for Box<T, A> {
16721672
#[cfg(not(no_global_oom_handling))]
16731673
#[stable(feature = "rust1", since = "1.0.0")]
16741674
impl<T: Default> Default for Box<T> {
1675-
/// Creates a `Box<T>`, with the `Default` value for T.
1675+
/// Creates a `Box<T>`, with the `Default` value for `T`.
16761676
#[inline]
16771677
fn default() -> Self {
16781678
let mut x: Box<mem::MaybeUninit<T>> = Box::new_uninit();
@@ -1695,6 +1695,7 @@ impl<T: Default> Default for Box<T> {
16951695
#[cfg(not(no_global_oom_handling))]
16961696
#[stable(feature = "rust1", since = "1.0.0")]
16971697
impl<T> Default for Box<[T]> {
1698+
/// Creates an empty `[T]` inside a `Box`.
16981699
#[inline]
16991700
fn default() -> Self {
17001701
let ptr: Unique<[T]> = Unique::<[T; 0]>::dangling();
@@ -1716,6 +1717,19 @@ impl Default for Box<str> {
17161717
}
17171718
}
17181719

1720+
#[cfg(not(no_global_oom_handling))]
1721+
#[stable(feature = "pin_default_impls", since = "CURRENT_RUSTC_VERSION")]
1722+
impl<T> Default for Pin<Box<T>>
1723+
where
1724+
T: ?Sized,
1725+
Box<T>: Default,
1726+
{
1727+
#[inline]
1728+
fn default() -> Self {
1729+
Box::into_pin(Box::<T>::default())
1730+
}
1731+
}
1732+
17191733
#[cfg(not(no_global_oom_handling))]
17201734
#[stable(feature = "rust1", since = "1.0.0")]
17211735
impl<T: Clone, A: Allocator + Clone> Clone for Box<T, A> {
@@ -2114,11 +2128,6 @@ impl<F: ?Sized + Future + Unpin, A: Allocator> Future for Box<F, A> {
21142128

21152129
#[stable(feature = "box_error", since = "1.8.0")]
21162130
impl<E: Error> Error for Box<E> {
2117-
#[allow(deprecated, deprecated_in_future)]
2118-
fn description(&self) -> &str {
2119-
Error::description(&**self)
2120-
}
2121-
21222131
#[allow(deprecated)]
21232132
fn cause(&self) -> Option<&dyn Error> {
21242133
Error::cause(&**self)

alloc/src/boxed/convert.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -608,12 +608,7 @@ impl<'a> From<String> for Box<dyn Error + Send + Sync + 'a> {
608608
fn from(err: String) -> Box<dyn Error + Send + Sync + 'a> {
609609
struct StringError(String);
610610

611-
impl Error for StringError {
612-
#[allow(deprecated)]
613-
fn description(&self) -> &str {
614-
&self.0
615-
}
616-
}
611+
impl Error for StringError {}
617612

618613
impl fmt::Display for StringError {
619614
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {

alloc/src/collections/btree/map.rs

Lines changed: 47 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -40,30 +40,15 @@ pub(super) const MIN_LEN: usize = node::MIN_LEN_AFTER_SPLIT;
4040

4141
/// An ordered map based on a [B-Tree].
4242
///
43-
/// B-Trees represent a fundamental compromise between cache-efficiency and actually minimizing
44-
/// the amount of work performed in a search. In theory, a binary search tree (BST) is the optimal
45-
/// choice for a sorted map, as a perfectly balanced BST performs the theoretical minimum amount of
46-
/// comparisons necessary to find an element (log<sub>2</sub>n). However, in practice the way this
47-
/// is done is *very* inefficient for modern computer architectures. In particular, every element
48-
/// is stored in its own individually heap-allocated node. This means that every single insertion
49-
/// triggers a heap-allocation, and every single comparison should be a cache-miss. Since these
50-
/// are both notably expensive things to do in practice, we are forced to, at the very least,
51-
/// reconsider the BST strategy.
52-
///
53-
/// A B-Tree instead makes each node contain B-1 to 2B-1 elements in a contiguous array. By doing
54-
/// this, we reduce the number of allocations by a factor of B, and improve cache efficiency in
55-
/// searches. However, this does mean that searches will have to do *more* comparisons on average.
56-
/// The precise number of comparisons depends on the node search strategy used. For optimal cache
57-
/// efficiency, one could search the nodes linearly. For optimal comparisons, one could search
58-
/// the node using binary search. As a compromise, one could also perform a linear search
59-
/// that initially only checks every i<sup>th</sup> element for some choice of i.
43+
/// Given a key type with a [total order], an ordered map stores its entries in key order.
44+
/// That means that keys must be of a type that implements the [`Ord`] trait,
45+
/// such that two keys can always be compared to determine their [`Ordering`].
46+
/// Examples of keys with a total order are strings with lexicographical order,
47+
/// and numbers with their natural order.
6048
///
61-
/// Currently, our implementation simply performs naive linear search. This provides excellent
62-
/// performance on *small* nodes of elements which are cheap to compare. However in the future we
63-
/// would like to further explore choosing the optimal search strategy based on the choice of B,
64-
/// and possibly other factors. Using linear search, searching for a random element is expected
65-
/// to take B * log(n) comparisons, which is generally worse than a BST. In practice,
66-
/// however, performance is excellent.
49+
/// Iterators obtained from functions such as [`BTreeMap::iter`], [`BTreeMap::into_iter`], [`BTreeMap::values`], or
50+
/// [`BTreeMap::keys`] produce their items in key order, and take worst-case logarithmic and
51+
/// amortized constant time per item returned.
6752
///
6853
/// It is a logic error for a key to be modified in such a way that the key's ordering relative to
6954
/// any other key, as determined by the [`Ord`] trait, changes while it is in the map. This is
@@ -72,14 +57,6 @@ pub(super) const MIN_LEN: usize = node::MIN_LEN_AFTER_SPLIT;
7257
/// `BTreeMap` that observed the logic error and not result in undefined behavior. This could
7358
/// include panics, incorrect results, aborts, memory leaks, and non-termination.
7459
///
75-
/// Iterators obtained from functions such as [`BTreeMap::iter`], [`BTreeMap::into_iter`], [`BTreeMap::values`], or
76-
/// [`BTreeMap::keys`] produce their items in order by key, and take worst-case logarithmic and
77-
/// amortized constant time per item returned.
78-
///
79-
/// [B-Tree]: https://en.wikipedia.org/wiki/B-tree
80-
/// [`Cell`]: core::cell::Cell
81-
/// [`RefCell`]: core::cell::RefCell
82-
///
8360
/// # Examples
8461
///
8562
/// ```
@@ -135,6 +112,8 @@ pub(super) const MIN_LEN: usize = node::MIN_LEN_AFTER_SPLIT;
135112
/// ]);
136113
/// ```
137114
///
115+
/// ## `Entry` API
116+
///
138117
/// `BTreeMap` implements an [`Entry API`], which allows for complex
139118
/// methods of getting, setting, updating and removing keys and their values:
140119
///
@@ -167,6 +146,43 @@ pub(super) const MIN_LEN: usize = node::MIN_LEN_AFTER_SPLIT;
167146
/// // modify an entry before an insert with in-place mutation
168147
/// player_stats.entry("mana").and_modify(|mana| *mana += 200).or_insert(100);
169148
/// ```
149+
///
150+
/// # Background
151+
///
152+
/// A B-tree is (like) a [binary search tree], but adapted to the natural granularity that modern
153+
/// machines like to consume data at. This means that each node contains an entire array of elements,
154+
/// instead of just a single element.
155+
///
156+
/// B-Trees represent a fundamental compromise between cache-efficiency and actually minimizing
157+
/// the amount of work performed in a search. In theory, a binary search tree (BST) is the optimal
158+
/// choice for a sorted map, as a perfectly balanced BST performs the theoretical minimum number of
159+
/// comparisons necessary to find an element (log<sub>2</sub>n). However, in practice the way this
160+
/// is done is *very* inefficient for modern computer architectures. In particular, every element
161+
/// is stored in its own individually heap-allocated node. This means that every single insertion
162+
/// triggers a heap-allocation, and every comparison is a potential cache-miss due to the indirection.
163+
/// Since both heap-allocations and cache-misses are notably expensive in practice, we are forced to,
164+
/// at the very least, reconsider the BST strategy.
165+
///
166+
/// A B-Tree instead makes each node contain B-1 to 2B-1 elements in a contiguous array. By doing
167+
/// this, we reduce the number of allocations by a factor of B, and improve cache efficiency in
168+
/// searches. However, this does mean that searches will have to do *more* comparisons on average.
169+
/// The precise number of comparisons depends on the node search strategy used. For optimal cache
170+
/// efficiency, one could search the nodes linearly. For optimal comparisons, one could search
171+
/// the node using binary search. As a compromise, one could also perform a linear search
172+
/// that initially only checks every i<sup>th</sup> element for some choice of i.
173+
///
174+
/// Currently, our implementation simply performs naive linear search. This provides excellent
175+
/// performance on *small* nodes of elements which are cheap to compare. However in the future we
176+
/// would like to further explore choosing the optimal search strategy based on the choice of B,
177+
/// and possibly other factors. Using linear search, searching for a random element is expected
178+
/// to take B * log(n) comparisons, which is generally worse than a BST. In practice,
179+
/// however, performance is excellent.
180+
///
181+
/// [B-Tree]: https://en.wikipedia.org/wiki/B-tree
182+
/// [binary search tree]: https://en.wikipedia.org/wiki/Binary_search_tree
183+
/// [total order]: https://en.wikipedia.org/wiki/Total_order
184+
/// [`Cell`]: core::cell::Cell
185+
/// [`RefCell`]: core::cell::RefCell
170186
#[stable(feature = "rust1", since = "1.0.0")]
171187
#[cfg_attr(not(test), rustc_diagnostic_item = "BTreeMap")]
172188
#[rustc_insignificant_dtor]

alloc/src/collections/btree/map/entry.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,6 @@ impl<'a, K: Debug + Ord, V: Debug, A: Allocator + Clone> fmt::Display
136136
impl<'a, K: core::fmt::Debug + Ord, V: core::fmt::Debug> core::error::Error
137137
for crate::collections::btree_map::OccupiedError<'a, K, V>
138138
{
139-
#[allow(deprecated)]
140-
fn description(&self) -> &str {
141-
"key already exists"
142-
}
143139
}
144140

145141
impl<'a, K: Ord, V, A: Allocator + Clone> Entry<'a, K, V, A> {

alloc/src/ffi/c_str.rs

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1061,17 +1061,10 @@ impl IntoStringError {
10611061
}
10621062
}
10631063

1064-
impl IntoStringError {
1065-
fn description(&self) -> &str {
1066-
"C string contained non-utf8 bytes"
1067-
}
1068-
}
1069-
10701064
#[stable(feature = "cstring_into", since = "1.7.0")]
10711065
impl fmt::Display for IntoStringError {
1072-
#[allow(deprecated, deprecated_in_future)]
10731066
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1074-
self.description().fmt(f)
1067+
"C string contained non-utf8 bytes".fmt(f)
10751068
}
10761069
}
10771070

@@ -1291,23 +1284,13 @@ impl PartialEq<CString> for Cow<'_, CStr> {
12911284
}
12921285

12931286
#[stable(feature = "rust1", since = "1.0.0")]
1294-
impl core::error::Error for NulError {
1295-
#[allow(deprecated)]
1296-
fn description(&self) -> &str {
1297-
"nul byte found in data"
1298-
}
1299-
}
1287+
impl core::error::Error for NulError {}
13001288

13011289
#[stable(feature = "cstring_from_vec_with_nul", since = "1.58.0")]
13021290
impl core::error::Error for FromVecWithNulError {}
13031291

13041292
#[stable(feature = "cstring_into", since = "1.7.0")]
13051293
impl core::error::Error for IntoStringError {
1306-
#[allow(deprecated)]
1307-
fn description(&self) -> &str {
1308-
"C string contained non-utf8 bytes"
1309-
}
1310-
13111294
fn source(&self) -> Option<&(dyn core::error::Error + 'static)> {
13121295
Some(&self.error)
13131296
}

alloc/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@
102102
#![feature(async_iterator)]
103103
#![feature(bstr)]
104104
#![feature(bstr_internals)]
105+
#![feature(cast_maybe_uninit)]
105106
#![feature(char_internals)]
106107
#![feature(char_max_len)]
107108
#![feature(clone_to_uninit)]
@@ -158,6 +159,7 @@
158159
#![feature(unicode_internals)]
159160
#![feature(unsize)]
160161
#![feature(unwrap_infallible)]
162+
#![feature(wtf8_internals)]
161163
// tidy-alphabetical-end
162164
//
163165
// Language features:
@@ -231,6 +233,8 @@ pub mod sync;
231233
#[cfg(all(not(no_global_oom_handling), not(no_rc), not(no_sync)))]
232234
pub mod task;
233235
pub mod vec;
236+
#[cfg(all(not(no_rc), not(no_sync), not(no_global_oom_handling)))]
237+
pub mod wtf8;
234238

235239
#[doc(hidden)]
236240
#[unstable(feature = "liballoc_internals", issue = "none", reason = "implementation detail")]

alloc/src/raw_vec/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ impl RawVecInner<Global> {
155155
}
156156

157157
// Tiny Vecs are dumb. Skip to:
158-
// - 8 if the element size is 1, because any heap allocators is likely
158+
// - 8 if the element size is 1, because any heap allocator is likely
159159
// to round up a request of less than 8 bytes to at least 8 bytes.
160160
// - 4 if elements are moderate-sized (<= 1 KiB).
161161
// - 1 otherwise, to avoid wasting too much space for very short Vecs.

0 commit comments

Comments
 (0)