Skip to content

Commit 335d42e

Browse files
authored
Merge pull request #498 from AltF02/rust-1.55
rust: port `liballoc` to release `1.55.0`
2 parents 7dff751 + d508f60 commit 335d42e

File tree

12 files changed

+63
-38
lines changed

12 files changed

+63
-38
lines changed

rust/alloc/borrow.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ where
179179
/// }
180180
/// ```
181181
#[stable(feature = "rust1", since = "1.0.0")]
182+
#[cfg_attr(not(test), rustc_diagnostic_item = "Cow")]
182183
pub enum Cow<'a, B: ?Sized + 'a>
183184
where
184185
B: ToOwned,

rust/alloc/boxed.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,6 @@ impl<T> Box<T> {
189189
/// ```
190190
#[cfg(not(no_global_oom_handling))]
191191
#[inline(always)]
192-
#[doc(alias = "alloc")]
193-
#[doc(alias = "malloc")]
194192
#[stable(feature = "rust1", since = "1.0.0")]
195193
pub fn new(x: T) -> Self {
196194
box x
@@ -241,7 +239,6 @@ impl<T> Box<T> {
241239
/// [zeroed]: mem::MaybeUninit::zeroed
242240
#[cfg(not(no_global_oom_handling))]
243241
#[inline]
244-
#[doc(alias = "calloc")]
245242
#[unstable(feature = "new_uninit", issue = "63291")]
246243
pub fn new_zeroed() -> Box<mem::MaybeUninit<T>> {
247244
Self::new_zeroed_in(Global)

rust/alloc/collections/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ pub enum TryReserveError {
8585

8686
#[unstable(feature = "try_reserve", reason = "new API", issue = "48043")]
8787
impl From<LayoutError> for TryReserveError {
88+
/// Always evaluates to [`TryReserveError::CapacityOverflow`].
8889
#[inline]
8990
fn from(_: LayoutError) -> Self {
9091
TryReserveError::CapacityOverflow

rust/alloc/lib.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@
5858
//! [`Rc`]: rc
5959
//! [`RefCell`]: core::cell
6060
61+
// To run liballoc tests without x.py without ending up with two copies of liballoc, Miri needs to be
62+
// able to "empty" this crate. See <https://github.com/rust-lang/miri-test-libstd/issues/4>.
63+
// rustc itself never sets the feature, so this line has no affect there.
64+
#![cfg(any(not(feature = "miri-test-libstd"), test, doctest))]
6165
#![allow(unused_attributes)]
6266
#![stable(feature = "alloc", since = "1.36.0")]
6367
#![doc(
@@ -111,7 +115,6 @@
111115
#![feature(iter_zip)]
112116
#![feature(lang_items)]
113117
#![feature(layout_for_ptr)]
114-
#![feature(maybe_uninit_ref)]
115118
#![feature(negative_impls)]
116119
#![feature(never_type)]
117120
#![feature(nll)]
@@ -139,8 +142,7 @@
139142
#![feature(maybe_uninit_extra, maybe_uninit_slice, maybe_uninit_uninit_array)]
140143
#![feature(alloc_layout_extra)]
141144
#![feature(trusted_random_access)]
142-
#![cfg_attr(bootstrap, feature(try_trait))]
143-
#![cfg_attr(not(bootstrap), feature(try_trait_v2))]
145+
#![feature(try_trait_v2)]
144146
#![feature(min_type_alias_impl_trait)]
145147
#![feature(associated_type_bounds)]
146148
#![feature(slice_group_by)]

rust/alloc/macros.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@
3737
///
3838
/// [`Vec`]: crate::vec::Vec
3939
#[cfg(not(test))]
40-
#[doc(alias = "alloc")]
41-
#[doc(alias = "malloc")]
4240
#[macro_export]
4341
#[stable(feature = "rust1", since = "1.0.0")]
4442
#[allow_internal_unstable(box_syntax, liballoc_internals)]

rust/alloc/slice.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1133,7 +1133,7 @@ where
11331133
}
11341134

11351135
/// This merge sort borrows some (but not all) ideas from TimSort, which is described in detail
1136-
/// [here](http://svn.python.org/projects/python/trunk/Objects/listsort.txt).
1136+
/// [here](https://github.com/python/cpython/blob/main/Objects/listsort.txt).
11371137
///
11381138
/// The algorithm identifies strictly descending and non-descending subsequences, which are called
11391139
/// natural runs. There is a stack of pending runs yet to be merged. Each newly found run is pushed

rust/alloc/str.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ impl str {
399399
return s;
400400

401401
fn map_uppercase_sigma(from: &str, i: usize, to: &mut String) {
402-
// See http://www.unicode.org/versions/Unicode7.0.0/ch03.pdf#G33992
402+
// See https://www.unicode.org/versions/Unicode7.0.0/ch03.pdf#G33992
403403
// for the definition of `Final_Sigma`.
404404
debug_assert!('Σ'.len_utf8() == 2);
405405
let is_word_final = case_ignoreable_then_cased(from[..i].chars().rev())

rust/alloc/string.rs

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -421,8 +421,6 @@ impl String {
421421
/// ```
422422
#[cfg(not(no_global_oom_handling))]
423423
#[inline]
424-
#[doc(alias = "alloc")]
425-
#[doc(alias = "malloc")]
426424
#[stable(feature = "rust1", since = "1.0.0")]
427425
pub fn with_capacity(capacity: usize) -> String {
428426
String { vec: Vec::with_capacity(capacity) }
@@ -1453,7 +1451,7 @@ impl String {
14531451

14541452
unsafe {
14551453
ptr::copy(self.vec.as_ptr().add(idx), self.vec.as_mut_ptr().add(idx + amt), len - idx);
1456-
ptr::copy(bytes.as_ptr(), self.vec.as_mut_ptr().add(idx), amt);
1454+
ptr::copy_nonoverlapping(bytes.as_ptr(), self.vec.as_mut_ptr().add(idx), amt);
14571455
self.vec.set_len(len + amt);
14581456
}
14591457
}
@@ -1536,7 +1534,6 @@ impl String {
15361534
/// assert_eq!(fancy_f.len(), 4);
15371535
/// assert_eq!(fancy_f.chars().count(), 3);
15381536
/// ```
1539-
#[doc(alias = "length")]
15401537
#[inline]
15411538
#[stable(feature = "rust1", since = "1.0.0")]
15421539
pub fn len(&self) -> usize {
@@ -2771,33 +2768,31 @@ impl<'a> Drain<'a> {
27712768
/// # Examples
27722769
///
27732770
/// ```
2774-
/// #![feature(string_drain_as_str)]
27752771
/// let mut s = String::from("abc");
27762772
/// let mut drain = s.drain(..);
27772773
/// assert_eq!(drain.as_str(), "abc");
27782774
/// let _ = drain.next().unwrap();
27792775
/// assert_eq!(drain.as_str(), "bc");
27802776
/// ```
2781-
#[unstable(feature = "string_drain_as_str", issue = "76905")] // Note: uncomment AsRef impls below when stabilizing.
2777+
#[stable(feature = "string_drain_as_str", since = "1.55.0")]
27822778
pub fn as_str(&self) -> &str {
27832779
self.iter.as_str()
27842780
}
27852781
}
27862782

2787-
// Uncomment when stabilizing `string_drain_as_str`.
2788-
// #[unstable(feature = "string_drain_as_str", issue = "76905")]
2789-
// impl<'a> AsRef<str> for Drain<'a> {
2790-
// fn as_ref(&self) -> &str {
2791-
// self.as_str()
2792-
// }
2793-
// }
2794-
//
2795-
// #[unstable(feature = "string_drain_as_str", issue = "76905")]
2796-
// impl<'a> AsRef<[u8]> for Drain<'a> {
2797-
// fn as_ref(&self) -> &[u8] {
2798-
// self.as_str().as_bytes()
2799-
// }
2800-
// }
2783+
#[stable(feature = "string_drain_as_str", since = "1.55.0")]
2784+
impl<'a> AsRef<str> for Drain<'a> {
2785+
fn as_ref(&self) -> &str {
2786+
self.as_str()
2787+
}
2788+
}
2789+
2790+
#[stable(feature = "string_drain_as_str", since = "1.55.0")]
2791+
impl<'a> AsRef<[u8]> for Drain<'a> {
2792+
fn as_ref(&self) -> &[u8] {
2793+
self.as_str().as_bytes()
2794+
}
2795+
}
28012796

28022797
#[stable(feature = "drain", since = "1.6.0")]
28032798
impl Iterator for Drain<'_> {

rust/alloc/sync.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,14 @@ impl<T> Arc<T> {
496496
unsafe { Pin::new_unchecked(Arc::new(data)) }
497497
}
498498

499+
/// Constructs a new `Pin<Arc<T>>`, return an error if allocation fails.
500+
#[cfg(not(no_global_oom_handling))]
501+
#[unstable(feature = "allocator_api", issue = "32838")]
502+
#[inline]
503+
pub fn try_pin(data: T) -> Result<Pin<Arc<T>>, AllocError> {
504+
unsafe { Ok(Pin::new_unchecked(Arc::try_new(data)?)) }
505+
}
506+
499507
/// Constructs a new `Arc<T>`, returning an error if allocation fails.
500508
///
501509
/// # Examples
@@ -2333,6 +2341,20 @@ impl<T: ?Sized + Hash> Hash for Arc<T> {
23332341
#[cfg(not(no_global_oom_handling))]
23342342
#[stable(feature = "from_for_ptrs", since = "1.6.0")]
23352343
impl<T> From<T> for Arc<T> {
2344+
/// Converts a `T` into an `Arc<T>`
2345+
///
2346+
/// The conversion moves the value into a
2347+
/// newly allocated `Arc`. It is equivalent to
2348+
/// calling `Arc::new(t)`.
2349+
///
2350+
/// # Example
2351+
/// ```rust
2352+
/// # use std::sync::Arc;
2353+
/// let x = 5;
2354+
/// let arc = Arc::new(5);
2355+
///
2356+
/// assert_eq!(Arc::from(x), arc);
2357+
/// ```
23362358
fn from(t: T) -> Self {
23372359
Arc::new(t)
23382360
}

rust/alloc/vec/into_iter.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ impl<T, A: Allocator> Iterator for IntoIter<T, A> {
165165
self.len()
166166
}
167167

168+
#[doc(hidden)]
168169
unsafe fn __iterator_get_unchecked(&mut self, i: usize) -> Self::Item
169170
where
170171
Self: TrustedRandomAccess,

rust/alloc/vec/mod.rs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,6 @@ impl<T> Vec<T> {
460460
/// ```
461461
#[cfg(not(no_global_oom_handling))]
462462
#[inline]
463-
#[doc(alias = "malloc")]
464463
#[stable(feature = "rust1", since = "1.0.0")]
465464
pub fn with_capacity(capacity: usize) -> Self {
466465
Self::with_capacity_in(capacity, Global)
@@ -890,7 +889,6 @@ impl<T, A: Allocator> Vec<T, A> {
890889
/// assert!(vec.capacity() >= 11);
891890
/// ```
892891
#[cfg(not(no_global_oom_handling))]
893-
#[doc(alias = "realloc")]
894892
#[stable(feature = "rust1", since = "1.0.0")]
895893
pub fn reserve(&mut self, additional: usize) {
896894
self.buf.reserve(self.len, additional);
@@ -917,7 +915,6 @@ impl<T, A: Allocator> Vec<T, A> {
917915
/// assert!(vec.capacity() >= 11);
918916
/// ```
919917
#[cfg(not(no_global_oom_handling))]
920-
#[doc(alias = "realloc")]
921918
#[stable(feature = "rust1", since = "1.0.0")]
922919
pub fn reserve_exact(&mut self, additional: usize) {
923920
self.buf.reserve_exact(self.len, additional);
@@ -955,7 +952,6 @@ impl<T, A: Allocator> Vec<T, A> {
955952
/// }
956953
/// # process_data(&[1, 2, 3]).expect("why is the test harness OOMing on 12 bytes?");
957954
/// ```
958-
#[doc(alias = "realloc")]
959955
#[unstable(feature = "try_reserve", reason = "new API", issue = "48043")]
960956
pub fn try_reserve(&mut self, additional: usize) -> Result<(), TryReserveError> {
961957
self.buf.try_reserve(self.len, additional)
@@ -997,7 +993,6 @@ impl<T, A: Allocator> Vec<T, A> {
997993
/// }
998994
/// # process_data(&[1, 2, 3]).expect("why is the test harness OOMing on 12 bytes?");
999995
/// ```
1000-
#[doc(alias = "realloc")]
1001996
#[unstable(feature = "try_reserve", reason = "new API", issue = "48043")]
1002997
pub fn try_reserve_exact(&mut self, additional: usize) -> Result<(), TryReserveError> {
1003998
self.buf.try_reserve_exact(self.len, additional)
@@ -1018,7 +1013,6 @@ impl<T, A: Allocator> Vec<T, A> {
10181013
/// assert!(vec.capacity() >= 3);
10191014
/// ```
10201015
#[cfg(not(no_global_oom_handling))]
1021-
#[doc(alias = "realloc")]
10221016
#[stable(feature = "rust1", since = "1.0.0")]
10231017
pub fn shrink_to_fit(&mut self) {
10241018
// The capacity is never less than the length, and there's nothing to do when
@@ -1076,7 +1070,6 @@ impl<T, A: Allocator> Vec<T, A> {
10761070
/// assert!(vec.capacity() >= 3);
10771071
/// ```
10781072
#[cfg(not(no_global_oom_handling))]
1079-
#[doc(alias = "realloc")]
10801073
#[unstable(feature = "shrink_to", reason = "new API", issue = "56431")]
10811074
pub fn shrink_to(&mut self, min_capacity: usize) {
10821075
if self.capacity() > min_capacity {
@@ -2007,7 +2000,6 @@ impl<T, A: Allocator> Vec<T, A> {
20072000
/// let a = vec![1, 2, 3];
20082001
/// assert_eq!(a.len(), 3);
20092002
/// ```
2010-
#[doc(alias = "length")]
20112003
#[inline]
20122004
#[stable(feature = "rust1", since = "1.0.0")]
20132005
pub fn len(&self) -> usize {
@@ -2686,6 +2678,18 @@ impl<T: Clone, A: Allocator + Clone> Clone for Vec<T, A> {
26862678
}
26872679
}
26882680

2681+
/// The hash of a vector is the same as that of the corresponding slice,
2682+
/// as required by the `core::borrow::Borrow` implementation.
2683+
///
2684+
/// ```
2685+
/// #![feature(build_hasher_simple_hash_one)]
2686+
/// use std::hash::BuildHasher;
2687+
///
2688+
/// let b = std::collections::hash_map::RandomState::new();
2689+
/// let v: Vec<u8> = vec![0xa8, 0x3c, 0x09];
2690+
/// let s: &[u8] = &[0xa8, 0x3c, 0x09];
2691+
/// assert_eq!(b.hash_one(v), b.hash_one(s));
2692+
/// ```
26892693
#[stable(feature = "rust1", since = "1.0.0")]
26902694
impl<T: Hash, A: Allocator> Hash for Vec<T, A> {
26912695
#[inline]
@@ -2830,6 +2834,8 @@ impl<T, A: Allocator> Vec<T, A> {
28302834
}
28312835
unsafe {
28322836
ptr::write(self.as_mut_ptr().add(len), element);
2837+
// Since next() executes user code which can panic we have to bump the length
2838+
// after each step.
28332839
// NB can't overflow since we would have had to alloc the address space
28342840
self.set_len(len + 1);
28352841
}

rust/alloc/vec/spec_extend.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ where
6060
iterator.for_each(move |element| {
6161
ptr::write(ptr, element);
6262
ptr = ptr.offset(1);
63+
// Since the loop executes user code which can panic we have to bump the pointer
64+
// after each step.
6365
// NB can't overflow since we would have had to alloc the address space
6466
local_len.increment_len(1);
6567
});

0 commit comments

Comments
 (0)