Skip to content

Commit 0666bc4

Browse files
committed
Merge from rustc
2 parents cb21157 + ca811b1 commit 0666bc4

Some content is hidden

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

83 files changed

+5275
-3999
lines changed

alloc/src/boxed.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -283,9 +283,7 @@ impl<T> Box<T> {
283283
#[must_use]
284284
#[inline(always)]
285285
pub fn pin(x: T) -> Pin<Box<T>> {
286-
(#[rustc_box]
287-
Box::new(x))
288-
.into()
286+
Box::new(x).into()
289287
}
290288

291289
/// Allocates memory on the heap then places `x` into it,
@@ -1242,8 +1240,8 @@ unsafe impl<#[may_dangle] T: ?Sized, A: Allocator> Drop for Box<T, A> {
12421240
#[stable(feature = "rust1", since = "1.0.0")]
12431241
impl<T: Default> Default for Box<T> {
12441242
/// Creates a `Box<T>`, with the `Default` value for T.
1243+
#[inline]
12451244
fn default() -> Self {
1246-
#[rustc_box]
12471245
Box::new(T::default())
12481246
}
12491247
}
@@ -1252,6 +1250,7 @@ impl<T: Default> Default for Box<T> {
12521250
#[stable(feature = "rust1", since = "1.0.0")]
12531251
#[rustc_const_unstable(feature = "const_default_impls", issue = "87864")]
12541252
impl<T> const Default for Box<[T]> {
1253+
#[inline]
12551254
fn default() -> Self {
12561255
let ptr: Unique<[T]> = Unique::<[T; 0]>::dangling();
12571256
Box(ptr, Global)
@@ -1262,6 +1261,7 @@ impl<T> const Default for Box<[T]> {
12621261
#[stable(feature = "default_box_extra", since = "1.17.0")]
12631262
#[rustc_const_unstable(feature = "const_default_impls", issue = "87864")]
12641263
impl const Default for Box<str> {
1264+
#[inline]
12651265
fn default() -> Self {
12661266
// SAFETY: This is the same as `Unique::cast<U>` but with an unsized `U = str`.
12671267
let ptr: Unique<str> = unsafe {
@@ -1616,7 +1616,6 @@ impl<T, const N: usize> From<[T; N]> for Box<[T]> {
16161616
/// println!("{boxed:?}");
16171617
/// ```
16181618
fn from(array: [T; N]) -> Box<[T]> {
1619-
#[rustc_box]
16201619
Box::new(array)
16211620
}
16221621
}

alloc/src/collections/vec_deque/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1924,7 +1924,7 @@ impl<T, A: Allocator> VecDeque<T, A> {
19241924
#[stable(feature = "append", since = "1.4.0")]
19251925
pub fn append(&mut self, other: &mut Self) {
19261926
if T::IS_ZST {
1927-
self.len += other.len;
1927+
self.len = self.len.checked_add(other.len).expect("capacity overflow");
19281928
other.len = 0;
19291929
other.head = 0;
19301930
return;

alloc/src/macros.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ macro_rules! vec {
4848
);
4949
($($x:expr),+ $(,)?) => (
5050
$crate::__rust_force_expr!(<[_]>::into_vec(
51+
// This rustc_box is not required, but it produces a dramatic improvement in compile
52+
// time when constructing arrays with many elements.
5153
#[rustc_box]
5254
$crate::boxed::Box::new([$($x),+])
5355
))

alloc/src/rc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2145,7 +2145,7 @@ impl<T, I: iter::TrustedLen<Item = T>> ToRcSlice<T> for I {
21452145
Rc::from_iter_exact(self, low)
21462146
}
21472147
} else {
2148-
// TrustedLen contract guarantees that `upper_bound == `None` implies an iterator
2148+
// TrustedLen contract guarantees that `upper_bound == None` implies an iterator
21492149
// length exceeding `usize::MAX`.
21502150
// The default implementation would collect into a vec which would panic.
21512151
// Thus we panic here immediately without invoking `Vec` code.

alloc/src/string.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2213,10 +2213,6 @@ impl PartialEq for String {
22132213
fn eq(&self, other: &String) -> bool {
22142214
PartialEq::eq(&self[..], &other[..])
22152215
}
2216-
#[inline]
2217-
fn ne(&self, other: &String) -> bool {
2218-
PartialEq::ne(&self[..], &other[..])
2219-
}
22202216
}
22212217

22222218
macro_rules! impl_eq {

alloc/src/sync.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2895,7 +2895,7 @@ impl<T, I: iter::TrustedLen<Item = T>> ToArcSlice<T> for I {
28952895
Arc::from_iter_exact(self, low)
28962896
}
28972897
} else {
2898-
// TrustedLen contract guarantees that `upper_bound == `None` implies an iterator
2898+
// TrustedLen contract guarantees that `upper_bound == None` implies an iterator
28992899
// length exceeding `usize::MAX`.
29002900
// The default implementation would collect into a vec which would panic.
29012901
// Thus we panic here immediately without invoking `Vec` code.

alloc/src/vec/mod.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3131,10 +3131,7 @@ impl<T, const N: usize> From<[T; N]> for Vec<T> {
31313131
/// ```
31323132
#[cfg(not(test))]
31333133
fn from(s: [T; N]) -> Vec<T> {
3134-
<[T]>::into_vec(
3135-
#[rustc_box]
3136-
Box::new(s),
3137-
)
3134+
<[T]>::into_vec(Box::new(s))
31383135
}
31393136

31403137
#[cfg(test)]

alloc/tests/vec_deque.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1045,6 +1045,20 @@ fn test_append_double_drop() {
10451045
assert_eq!(count_b, 1);
10461046
}
10471047

1048+
#[test]
1049+
#[should_panic]
1050+
fn test_append_zst_capacity_overflow() {
1051+
let mut v = Vec::with_capacity(usize::MAX);
1052+
// note: using resize instead of set_len here would
1053+
// be *extremely* slow in unoptimized builds.
1054+
// SAFETY: `v` has capacity `usize::MAX`, and no initialization
1055+
// is needed for empty tuples.
1056+
unsafe { v.set_len(usize::MAX) };
1057+
let mut v = VecDeque::from(v);
1058+
let mut w = vec![()].into();
1059+
v.append(&mut w);
1060+
}
1061+
10481062
#[test]
10491063
fn test_retain() {
10501064
let mut buf = VecDeque::new();

core/src/any.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
//! let value_any = value as &dyn Any;
5757
//!
5858
//! // Try to convert our value to a `String`. If successful, we want to
59-
//! // output the String`'s length as well as its value. If not, it's a
59+
//! // output the `String`'s length as well as its value. If not, it's a
6060
//! // different type: just print it out unadorned.
6161
//! match value_any.downcast_ref::<String>() {
6262
//! Some(as_string) => {

core/src/array/equality.rs

Lines changed: 6 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1+
use crate::cmp::BytewiseEq;
12
use crate::convert::TryInto;
2-
use crate::num::{NonZeroI128, NonZeroI16, NonZeroI32, NonZeroI64, NonZeroI8, NonZeroIsize};
3-
use crate::num::{NonZeroU128, NonZeroU16, NonZeroU32, NonZeroU64, NonZeroU8, NonZeroUsize};
43

54
#[stable(feature = "rust1", since = "1.0.0")]
65
impl<A, B, const N: usize> PartialEq<[B; N]> for [A; N]
@@ -144,74 +143,14 @@ impl<T: PartialEq<Other>, Other, const N: usize> SpecArrayEq<Other, N> for T {
144143
}
145144
}
146145

147-
impl<T: IsRawEqComparable<U>, U, const N: usize> SpecArrayEq<U, N> for T {
146+
impl<T: BytewiseEq<U>, U, const N: usize> SpecArrayEq<U, N> for T {
148147
fn spec_eq(a: &[T; N], b: &[U; N]) -> bool {
149-
// SAFETY: This is why `IsRawEqComparable` is an `unsafe trait`.
150-
unsafe {
151-
let b = &*b.as_ptr().cast::<[T; N]>();
152-
crate::intrinsics::raw_eq(a, b)
153-
}
148+
// SAFETY: Arrays are compared element-wise, and don't add any padding
149+
// between elements, so when the elements are `BytewiseEq`, we can
150+
// compare the entire array at once.
151+
unsafe { crate::intrinsics::raw_eq(a, crate::mem::transmute(b)) }
154152
}
155153
fn spec_ne(a: &[T; N], b: &[U; N]) -> bool {
156154
!Self::spec_eq(a, b)
157155
}
158156
}
159-
160-
/// `U` exists on here mostly because `min_specialization` didn't let me
161-
/// repeat the `T` type parameter in the above specialization, so instead
162-
/// the `T == U` constraint comes from the impls on this.
163-
/// # Safety
164-
/// - Neither `Self` nor `U` has any padding.
165-
/// - `Self` and `U` have the same layout.
166-
/// - `Self: PartialEq<U>` is byte-wise (this means no floats, among other things)
167-
#[rustc_specialization_trait]
168-
unsafe trait IsRawEqComparable<U>: PartialEq<U> {}
169-
170-
macro_rules! is_raw_eq_comparable {
171-
($($t:ty),+ $(,)?) => {$(
172-
unsafe impl IsRawEqComparable<$t> for $t {}
173-
)+};
174-
}
175-
176-
// SAFETY: All the ordinary integer types have no padding, and are not pointers.
177-
is_raw_eq_comparable!(u8, u16, u32, u64, u128, usize, i8, i16, i32, i64, i128, isize);
178-
179-
// SAFETY: bool and char have *niches*, but no *padding* (and these are not pointer types), so this
180-
// is sound
181-
is_raw_eq_comparable!(bool, char);
182-
183-
// SAFETY: Similarly, the non-zero types have a niche, but no undef and no pointers,
184-
// and they compare like their underlying numeric type.
185-
is_raw_eq_comparable!(
186-
NonZeroU8,
187-
NonZeroU16,
188-
NonZeroU32,
189-
NonZeroU64,
190-
NonZeroU128,
191-
NonZeroUsize,
192-
NonZeroI8,
193-
NonZeroI16,
194-
NonZeroI32,
195-
NonZeroI64,
196-
NonZeroI128,
197-
NonZeroIsize,
198-
);
199-
200-
// SAFETY: The NonZero types have the "null" optimization guaranteed, and thus
201-
// are also safe to equality-compare bitwise inside an `Option`.
202-
// The way `PartialOrd` is defined for `Option` means that this wouldn't work
203-
// for `<` or `>` on the signed types, but since we only do `==` it's fine.
204-
is_raw_eq_comparable!(
205-
Option<NonZeroU8>,
206-
Option<NonZeroU16>,
207-
Option<NonZeroU32>,
208-
Option<NonZeroU64>,
209-
Option<NonZeroU128>,
210-
Option<NonZeroUsize>,
211-
Option<NonZeroI8>,
212-
Option<NonZeroI16>,
213-
Option<NonZeroI32>,
214-
Option<NonZeroI64>,
215-
Option<NonZeroI128>,
216-
Option<NonZeroIsize>,
217-
);

0 commit comments

Comments
 (0)