Skip to content

Commit 50ba11b

Browse files
committed
merge rustc history
2 parents 62bccc1 + 6b40315 commit 50ba11b

File tree

223 files changed

+5179
-3633
lines changed

Some content is hidden

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

223 files changed

+5179
-3633
lines changed

alloc/benches/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
#![cfg(not(target_os = "android"))]
44
#![feature(btree_drain_filter)]
55
#![feature(iter_next_chunk)]
6-
#![feature(map_first_last)]
76
#![feature(repr_simd)]
87
#![feature(slice_partition_dedup)]
98
#![feature(test)]

alloc/src/alloc.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,20 @@ extern "Rust" {
2828
// The rustc fork of LLVM 14 and earlier also special-cases these function names to be able to optimize them
2929
// like `malloc`, `realloc`, and `free`, respectively.
3030
#[rustc_allocator]
31-
#[rustc_allocator_nounwind]
31+
#[cfg_attr(not(bootstrap), rustc_nounwind)]
32+
#[cfg_attr(bootstrap, rustc_allocator_nounwind)]
3233
fn __rust_alloc(size: usize, align: usize) -> *mut u8;
3334
#[rustc_deallocator]
34-
#[rustc_allocator_nounwind]
35+
#[cfg_attr(not(bootstrap), rustc_nounwind)]
36+
#[cfg_attr(bootstrap, rustc_allocator_nounwind)]
3537
fn __rust_dealloc(ptr: *mut u8, size: usize, align: usize);
3638
#[rustc_reallocator]
37-
#[rustc_allocator_nounwind]
39+
#[cfg_attr(not(bootstrap), rustc_nounwind)]
40+
#[cfg_attr(bootstrap, rustc_allocator_nounwind)]
3841
fn __rust_realloc(ptr: *mut u8, old_size: usize, align: usize, new_size: usize) -> *mut u8;
3942
#[rustc_allocator_zeroed]
40-
#[rustc_allocator_nounwind]
43+
#[cfg_attr(not(bootstrap), rustc_nounwind)]
44+
#[cfg_attr(bootstrap, rustc_allocator_nounwind)]
4145
fn __rust_alloc_zeroed(size: usize, align: usize) -> *mut u8;
4246
}
4347

alloc/src/boxed.rs

Lines changed: 50 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,6 @@ use core::async_iter::AsyncIterator;
151151
use core::borrow;
152152
use core::cmp::Ordering;
153153
use core::convert::{From, TryFrom};
154-
#[cfg(not(bootstrap))]
155154
use core::error::Error;
156155
use core::fmt;
157156
use core::future::Future;
@@ -176,7 +175,6 @@ use crate::borrow::Cow;
176175
use crate::raw_vec::RawVec;
177176
#[cfg(not(no_global_oom_handling))]
178177
use crate::str::from_boxed_utf8_unchecked;
179-
#[cfg(not(bootstrap))]
180178
#[cfg(not(no_global_oom_handling))]
181179
use crate::string::String;
182180
#[cfg(not(no_global_oom_handling))]
@@ -1622,6 +1620,22 @@ impl<T, const N: usize> From<[T; N]> for Box<[T]> {
16221620
}
16231621
}
16241622

1623+
/// Casts a boxed slice to a boxed array.
1624+
///
1625+
/// # Safety
1626+
///
1627+
/// `boxed_slice.len()` must be exactly `N`.
1628+
unsafe fn boxed_slice_as_array_unchecked<T, A: Allocator, const N: usize>(
1629+
boxed_slice: Box<[T], A>,
1630+
) -> Box<[T; N], A> {
1631+
debug_assert_eq!(boxed_slice.len(), N);
1632+
1633+
let (ptr, alloc) = Box::into_raw_with_allocator(boxed_slice);
1634+
// SAFETY: Pointer and allocator came from an existing box,
1635+
// and our safety condition requires that the length is exactly `N`
1636+
unsafe { Box::from_raw_in(ptr as *mut [T; N], alloc) }
1637+
}
1638+
16251639
#[stable(feature = "boxed_slice_try_from", since = "1.43.0")]
16261640
impl<T, const N: usize> TryFrom<Box<[T]>> for Box<[T; N]> {
16271641
type Error = Box<[T]>;
@@ -1637,13 +1651,46 @@ impl<T, const N: usize> TryFrom<Box<[T]>> for Box<[T; N]> {
16371651
/// `boxed_slice.len()` does not equal `N`.
16381652
fn try_from(boxed_slice: Box<[T]>) -> Result<Self, Self::Error> {
16391653
if boxed_slice.len() == N {
1640-
Ok(unsafe { Box::from_raw(Box::into_raw(boxed_slice) as *mut [T; N]) })
1654+
Ok(unsafe { boxed_slice_as_array_unchecked(boxed_slice) })
16411655
} else {
16421656
Err(boxed_slice)
16431657
}
16441658
}
16451659
}
16461660

1661+
#[cfg(not(no_global_oom_handling))]
1662+
#[stable(feature = "boxed_array_try_from_vec", since = "CURRENT_RUSTC_VERSION")]
1663+
impl<T, const N: usize> TryFrom<Vec<T>> for Box<[T; N]> {
1664+
type Error = Vec<T>;
1665+
1666+
/// Attempts to convert a `Vec<T>` into a `Box<[T; N]>`.
1667+
///
1668+
/// Like [`Vec::into_boxed_slice`], this is in-place if `vec.capacity() == N`,
1669+
/// but will require a reallocation otherwise.
1670+
///
1671+
/// # Errors
1672+
///
1673+
/// Returns the original `Vec<T>` in the `Err` variant if
1674+
/// `boxed_slice.len()` does not equal `N`.
1675+
///
1676+
/// # Examples
1677+
///
1678+
/// This can be used with [`vec!`] to create an array on the heap:
1679+
///
1680+
/// ```
1681+
/// let state: Box<[f32; 100]> = vec![1.0; 100].try_into().unwrap();
1682+
/// assert_eq!(state.len(), 100);
1683+
/// ```
1684+
fn try_from(vec: Vec<T>) -> Result<Self, Self::Error> {
1685+
if vec.len() == N {
1686+
let boxed_slice = vec.into_boxed_slice();
1687+
Ok(unsafe { boxed_slice_as_array_unchecked(boxed_slice) })
1688+
} else {
1689+
Err(vec)
1690+
}
1691+
}
1692+
}
1693+
16471694
impl<A: Allocator> Box<dyn Any, A> {
16481695
/// Attempt to downcast the box to a concrete type.
16491696
///
@@ -2090,7 +2137,6 @@ impl<S: ?Sized + AsyncIterator + Unpin> AsyncIterator for Box<S> {
20902137
}
20912138
}
20922139

2093-
#[cfg(not(bootstrap))]
20942140
impl dyn Error {
20952141
#[inline]
20962142
#[stable(feature = "error_downcast", since = "1.3.0")]
@@ -2108,7 +2154,6 @@ impl dyn Error {
21082154
}
21092155
}
21102156

2111-
#[cfg(not(bootstrap))]
21122157
impl dyn Error + Send {
21132158
#[inline]
21142159
#[stable(feature = "error_downcast", since = "1.3.0")]
@@ -2123,7 +2168,6 @@ impl dyn Error + Send {
21232168
}
21242169
}
21252170

2126-
#[cfg(not(bootstrap))]
21272171
impl dyn Error + Send + Sync {
21282172
#[inline]
21292173
#[stable(feature = "error_downcast", since = "1.3.0")]
@@ -2138,7 +2182,6 @@ impl dyn Error + Send + Sync {
21382182
}
21392183
}
21402184

2141-
#[cfg(not(bootstrap))]
21422185
#[cfg(not(no_global_oom_handling))]
21432186
#[stable(feature = "rust1", since = "1.0.0")]
21442187
impl<'a, E: Error + 'a> From<E> for Box<dyn Error + 'a> {
@@ -2172,7 +2215,6 @@ impl<'a, E: Error + 'a> From<E> for Box<dyn Error + 'a> {
21722215
}
21732216
}
21742217

2175-
#[cfg(not(bootstrap))]
21762218
#[cfg(not(no_global_oom_handling))]
21772219
#[stable(feature = "rust1", since = "1.0.0")]
21782220
impl<'a, E: Error + Send + Sync + 'a> From<E> for Box<dyn Error + Send + Sync + 'a> {
@@ -2212,7 +2254,6 @@ impl<'a, E: Error + Send + Sync + 'a> From<E> for Box<dyn Error + Send + Sync +
22122254
}
22132255
}
22142256

2215-
#[cfg(not(bootstrap))]
22162257
#[cfg(not(no_global_oom_handling))]
22172258
#[stable(feature = "rust1", since = "1.0.0")]
22182259
impl From<String> for Box<dyn Error + Send + Sync> {
@@ -2257,7 +2298,6 @@ impl From<String> for Box<dyn Error + Send + Sync> {
22572298
}
22582299
}
22592300

2260-
#[cfg(not(bootstrap))]
22612301
#[cfg(not(no_global_oom_handling))]
22622302
#[stable(feature = "string_box_error", since = "1.6.0")]
22632303
impl From<String> for Box<dyn Error> {
@@ -2280,7 +2320,6 @@ impl From<String> for Box<dyn Error> {
22802320
}
22812321
}
22822322

2283-
#[cfg(not(bootstrap))]
22842323
#[cfg(not(no_global_oom_handling))]
22852324
#[stable(feature = "rust1", since = "1.0.0")]
22862325
impl<'a> From<&str> for Box<dyn Error + Send + Sync + 'a> {
@@ -2305,7 +2344,6 @@ impl<'a> From<&str> for Box<dyn Error + Send + Sync + 'a> {
23052344
}
23062345
}
23072346

2308-
#[cfg(not(bootstrap))]
23092347
#[cfg(not(no_global_oom_handling))]
23102348
#[stable(feature = "string_box_error", since = "1.6.0")]
23112349
impl From<&str> for Box<dyn Error> {
@@ -2328,7 +2366,6 @@ impl From<&str> for Box<dyn Error> {
23282366
}
23292367
}
23302368

2331-
#[cfg(not(bootstrap))]
23322369
#[cfg(not(no_global_oom_handling))]
23332370
#[stable(feature = "cow_box_error", since = "1.22.0")]
23342371
impl<'a, 'b> From<Cow<'b, str>> for Box<dyn Error + Send + Sync + 'a> {
@@ -2351,7 +2388,6 @@ impl<'a, 'b> From<Cow<'b, str>> for Box<dyn Error + Send + Sync + 'a> {
23512388
}
23522389
}
23532390

2354-
#[cfg(not(bootstrap))]
23552391
#[cfg(not(no_global_oom_handling))]
23562392
#[stable(feature = "cow_box_error", since = "1.22.0")]
23572393
impl<'a> From<Cow<'a, str>> for Box<dyn Error> {
@@ -2373,7 +2409,6 @@ impl<'a> From<Cow<'a, str>> for Box<dyn Error> {
23732409
}
23742410
}
23752411

2376-
#[cfg(not(bootstrap))]
23772412
#[stable(feature = "box_error", since = "1.8.0")]
23782413
impl<T: core::error::Error> core::error::Error for Box<T> {
23792414
#[allow(deprecated, deprecated_in_future)]

alloc/src/boxed/thin.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// https://github.com/matthieu-m/rfc2580/blob/b58d1d3cba0d4b5e859d3617ea2d0943aaa31329/examples/thin.rs
33
// by matthieu-m
44
use crate::alloc::{self, Layout, LayoutError};
5-
#[cfg(not(bootstrap))]
65
use core::error::Error;
76
use core::fmt::{self, Debug, Display, Formatter};
87
use core::marker::PhantomData;
@@ -274,7 +273,6 @@ impl<H> WithHeader<H> {
274273
}
275274
}
276275

277-
#[cfg(not(bootstrap))]
278276
#[unstable(feature = "thin_box", issue = "92791")]
279277
impl<T: ?Sized + Error> Error for ThinBox<T> {
280278
fn source(&self) -> Option<&(dyn Error + 'static)> {

0 commit comments

Comments
 (0)