Skip to content

Commit d6c2912

Browse files
committed
Merge from rustc
2 parents fbc18e4 + ffabd00 commit d6c2912

File tree

30 files changed

+785
-442
lines changed

30 files changed

+785
-442
lines changed

alloc/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@
106106
#![feature(const_size_of_val)]
107107
#![feature(const_align_of_val)]
108108
#![feature(const_ptr_read)]
109+
#![feature(const_maybe_uninit_zeroed)]
109110
#![feature(const_maybe_uninit_write)]
110111
#![feature(const_maybe_uninit_as_mut_ptr)]
111112
#![feature(const_refs_to_cell)]

alloc/src/slice.rs

Lines changed: 39 additions & 309 deletions
Large diffs are not rendered by default.

alloc/src/str.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -559,10 +559,9 @@ impl str {
559559
#[stable(feature = "ascii_methods_on_intrinsics", since = "1.23.0")]
560560
#[inline]
561561
pub fn to_ascii_uppercase(&self) -> String {
562-
let mut bytes = self.as_bytes().to_vec();
563-
bytes.make_ascii_uppercase();
564-
// make_ascii_uppercase() preserves the UTF-8 invariant.
565-
unsafe { String::from_utf8_unchecked(bytes) }
562+
let mut s = self.to_owned();
563+
s.make_ascii_uppercase();
564+
s
566565
}
567566

568567
/// Returns a copy of this string where each character is mapped to its
@@ -592,10 +591,9 @@ impl str {
592591
#[stable(feature = "ascii_methods_on_intrinsics", since = "1.23.0")]
593592
#[inline]
594593
pub fn to_ascii_lowercase(&self) -> String {
595-
let mut bytes = self.as_bytes().to_vec();
596-
bytes.make_ascii_lowercase();
597-
// make_ascii_lowercase() preserves the UTF-8 invariant.
598-
unsafe { String::from_utf8_unchecked(bytes) }
594+
let mut s = self.to_owned();
595+
s.make_ascii_lowercase();
596+
s
599597
}
600598
}
601599

alloc/src/vec/drain.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,9 +223,9 @@ impl<T, A: Allocator> Drop for Drain<'_, T, A> {
223223
}
224224

225225
// as_slice() must only be called when iter.len() is > 0 because
226-
// vec::Splice modifies vec::Drain fields and may grow the vec which would invalidate
227-
// the iterator's internal pointers. Creating a reference to deallocated memory
228-
// is invalid even when it is zero-length
226+
// it also gets touched by vec::Splice which may turn it into a dangling pointer
227+
// which would make it and the vec pointer point to different allocations which would
228+
// lead to invalid pointer arithmetic below.
229229
let drop_ptr = iter.as_slice().as_ptr();
230230

231231
unsafe {

alloc/src/vec/is_zero.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ use crate::boxed::Box;
44

55
#[rustc_specialization_trait]
66
pub(super) unsafe trait IsZero {
7-
/// Whether this value's representation is all zeros
7+
/// Whether this value's representation is all zeros,
8+
/// or can be represented with all zeroes.
89
fn is_zero(&self) -> bool;
910
}
1011

@@ -147,6 +148,23 @@ impl_is_zero_option_of_nonzero!(
147148
NonZeroIsize,
148149
);
149150

151+
macro_rules! impl_is_zero_option_of_num {
152+
($($t:ty,)+) => {$(
153+
unsafe impl IsZero for Option<$t> {
154+
#[inline]
155+
fn is_zero(&self) -> bool {
156+
const {
157+
let none: Self = unsafe { core::mem::MaybeUninit::zeroed().assume_init() };
158+
assert!(none.is_none());
159+
}
160+
self.is_none()
161+
}
162+
}
163+
)+};
164+
}
165+
166+
impl_is_zero_option_of_num!(u8, u16, u32, u64, u128, i8, i16, i32, i64, i128, usize, isize,);
167+
150168
unsafe impl<T: IsZero> IsZero for Wrapping<T> {
151169
#[inline]
152170
fn is_zero(&self) -> bool {

alloc/src/vec/splice.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ impl<I: Iterator, A: Allocator> ExactSizeIterator for Splice<'_, I, A> {}
5454
impl<I: Iterator, A: Allocator> Drop for Splice<'_, I, A> {
5555
fn drop(&mut self) {
5656
self.drain.by_ref().for_each(drop);
57+
// At this point draining is done and the only remaining tasks are splicing
58+
// and moving things into the final place.
59+
// Which means we can replace the slice::Iter with pointers that won't point to deallocated
60+
// memory, so that Drain::drop is still allowed to call iter.len(), otherwise it would break
61+
// the ptr.sub_ptr contract.
62+
self.drain.iter = (&[]).iter();
5763

5864
unsafe {
5965
if self.drain.tail_len == 0 {

alloc/tests/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#![feature(allocator_api)]
22
#![feature(alloc_layout_extra)]
33
#![feature(assert_matches)]
4-
#![feature(box_syntax)]
54
#![feature(btree_drain_filter)]
65
#![feature(cow_is_borrowed)]
76
#![feature(const_box)]

core/src/any.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,8 @@ impl dyn Any + Send + Sync {
662662
/// While `TypeId` implements `Hash`, `PartialOrd`, and `Ord`, it is worth
663663
/// noting that the hashes and ordering will vary between Rust releases. Beware
664664
/// of relying on them inside of your code!
665-
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)]
665+
#[derive(Clone, Copy, Debug, Hash, Eq)]
666+
#[derive_const(PartialEq, PartialOrd, Ord)]
666667
#[stable(feature = "rust1", since = "1.0.0")]
667668
pub struct TypeId {
668669
t: u64,

core/src/fmt/mod.rs

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1355,11 +1355,11 @@ impl<'a> Formatter<'a> {
13551355
/// }
13561356
/// }
13571357
///
1358-
/// assert_eq!(&format!("{}", Foo::new(2)), "2");
1359-
/// assert_eq!(&format!("{}", Foo::new(-1)), "-1");
1360-
/// assert_eq!(&format!("{}", Foo::new(0)), "0");
1361-
/// assert_eq!(&format!("{:#}", Foo::new(-1)), "-Foo 1");
1362-
/// assert_eq!(&format!("{:0>#8}", Foo::new(-1)), "00-Foo 1");
1358+
/// assert_eq!(format!("{}", Foo::new(2)), "2");
1359+
/// assert_eq!(format!("{}", Foo::new(-1)), "-1");
1360+
/// assert_eq!(format!("{}", Foo::new(0)), "0");
1361+
/// assert_eq!(format!("{:#}", Foo::new(-1)), "-Foo 1");
1362+
/// assert_eq!(format!("{:0>#8}", Foo::new(-1)), "00-Foo 1");
13631363
/// ```
13641364
#[stable(feature = "rust1", since = "1.0.0")]
13651365
pub fn pad_integral(&mut self, is_nonnegative: bool, prefix: &str, buf: &str) -> Result {
@@ -1452,8 +1452,8 @@ impl<'a> Formatter<'a> {
14521452
/// }
14531453
/// }
14541454
///
1455-
/// assert_eq!(&format!("{Foo:<4}"), "Foo ");
1456-
/// assert_eq!(&format!("{Foo:0>4}"), "0Foo");
1455+
/// assert_eq!(format!("{Foo:<4}"), "Foo ");
1456+
/// assert_eq!(format!("{Foo:0>4}"), "0Foo");
14571457
/// ```
14581458
#[stable(feature = "rust1", since = "1.0.0")]
14591459
pub fn pad(&mut self, s: &str) -> Result {
@@ -1636,8 +1636,8 @@ impl<'a> Formatter<'a> {
16361636
/// }
16371637
/// }
16381638
///
1639-
/// assert_eq!(&format!("{Foo}"), "Foo");
1640-
/// assert_eq!(&format!("{Foo:0>8}"), "Foo");
1639+
/// assert_eq!(format!("{Foo}"), "Foo");
1640+
/// assert_eq!(format!("{Foo:0>8}"), "Foo");
16411641
/// ```
16421642
#[stable(feature = "rust1", since = "1.0.0")]
16431643
pub fn write_str(&mut self, data: &str) -> Result {
@@ -1659,8 +1659,8 @@ impl<'a> Formatter<'a> {
16591659
/// }
16601660
/// }
16611661
///
1662-
/// assert_eq!(&format!("{}", Foo(-1)), "Foo -1");
1663-
/// assert_eq!(&format!("{:0>8}", Foo(2)), "Foo 2");
1662+
/// assert_eq!(format!("{}", Foo(-1)), "Foo -1");
1663+
/// assert_eq!(format!("{:0>8}", Foo(2)), "Foo 2");
16641664
/// ```
16651665
#[stable(feature = "rust1", since = "1.0.0")]
16661666
pub fn write_fmt(&mut self, fmt: Arguments<'_>) -> Result {
@@ -1703,8 +1703,8 @@ impl<'a> Formatter<'a> {
17031703
/// }
17041704
///
17051705
/// // We set alignment to the right with ">".
1706-
/// assert_eq!(&format!("{Foo:G>3}"), "GGG");
1707-
/// assert_eq!(&format!("{Foo:t>6}"), "tttttt");
1706+
/// assert_eq!(format!("{Foo:G>3}"), "GGG");
1707+
/// assert_eq!(format!("{Foo:t>6}"), "tttttt");
17081708
/// ```
17091709
#[must_use]
17101710
#[stable(feature = "fmt_flags", since = "1.5.0")]
@@ -1738,10 +1738,10 @@ impl<'a> Formatter<'a> {
17381738
/// }
17391739
/// }
17401740
///
1741-
/// assert_eq!(&format!("{Foo:<}"), "left");
1742-
/// assert_eq!(&format!("{Foo:>}"), "right");
1743-
/// assert_eq!(&format!("{Foo:^}"), "center");
1744-
/// assert_eq!(&format!("{Foo}"), "into the void");
1741+
/// assert_eq!(format!("{Foo:<}"), "left");
1742+
/// assert_eq!(format!("{Foo:>}"), "right");
1743+
/// assert_eq!(format!("{Foo:^}"), "center");
1744+
/// assert_eq!(format!("{Foo}"), "into the void");
17451745
/// ```
17461746
#[must_use]
17471747
#[stable(feature = "fmt_flags_align", since = "1.28.0")]
@@ -1767,16 +1767,16 @@ impl<'a> Formatter<'a> {
17671767
/// fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
17681768
/// if let Some(width) = formatter.width() {
17691769
/// // If we received a width, we use it
1770-
/// write!(formatter, "{:width$}", &format!("Foo({})", self.0), width = width)
1770+
/// write!(formatter, "{:width$}", format!("Foo({})", self.0), width = width)
17711771
/// } else {
17721772
/// // Otherwise we do nothing special
17731773
/// write!(formatter, "Foo({})", self.0)
17741774
/// }
17751775
/// }
17761776
/// }
17771777
///
1778-
/// assert_eq!(&format!("{:10}", Foo(23)), "Foo(23) ");
1779-
/// assert_eq!(&format!("{}", Foo(23)), "Foo(23)");
1778+
/// assert_eq!(format!("{:10}", Foo(23)), "Foo(23) ");
1779+
/// assert_eq!(format!("{}", Foo(23)), "Foo(23)");
17801780
/// ```
17811781
#[must_use]
17821782
#[stable(feature = "fmt_flags", since = "1.5.0")]
@@ -1806,8 +1806,8 @@ impl<'a> Formatter<'a> {
18061806
/// }
18071807
/// }
18081808
///
1809-
/// assert_eq!(&format!("{:.4}", Foo(23.2)), "Foo(23.2000)");
1810-
/// assert_eq!(&format!("{}", Foo(23.2)), "Foo(23.20)");
1809+
/// assert_eq!(format!("{:.4}", Foo(23.2)), "Foo(23.2000)");
1810+
/// assert_eq!(format!("{}", Foo(23.2)), "Foo(23.20)");
18111811
/// ```
18121812
#[must_use]
18131813
#[stable(feature = "fmt_flags", since = "1.5.0")]
@@ -1837,9 +1837,9 @@ impl<'a> Formatter<'a> {
18371837
/// }
18381838
/// }
18391839
///
1840-
/// assert_eq!(&format!("{:+}", Foo(23)), "Foo(+23)");
1841-
/// assert_eq!(&format!("{:+}", Foo(-23)), "Foo(-23)");
1842-
/// assert_eq!(&format!("{}", Foo(23)), "Foo(23)");
1840+
/// assert_eq!(format!("{:+}", Foo(23)), "Foo(+23)");
1841+
/// assert_eq!(format!("{:+}", Foo(-23)), "Foo(-23)");
1842+
/// assert_eq!(format!("{}", Foo(23)), "Foo(23)");
18431843
/// ```
18441844
#[must_use]
18451845
#[stable(feature = "fmt_flags", since = "1.5.0")]
@@ -1867,8 +1867,8 @@ impl<'a> Formatter<'a> {
18671867
/// }
18681868
/// }
18691869
///
1870-
/// assert_eq!(&format!("{:-}", Foo(23)), "-Foo(23)");
1871-
/// assert_eq!(&format!("{}", Foo(23)), "Foo(23)");
1870+
/// assert_eq!(format!("{:-}", Foo(23)), "-Foo(23)");
1871+
/// assert_eq!(format!("{}", Foo(23)), "Foo(23)");
18721872
/// ```
18731873
#[must_use]
18741874
#[stable(feature = "fmt_flags", since = "1.5.0")]
@@ -1895,8 +1895,8 @@ impl<'a> Formatter<'a> {
18951895
/// }
18961896
/// }
18971897
///
1898-
/// assert_eq!(&format!("{:#}", Foo(23)), "Foo(23)");
1899-
/// assert_eq!(&format!("{}", Foo(23)), "23");
1898+
/// assert_eq!(format!("{:#}", Foo(23)), "Foo(23)");
1899+
/// assert_eq!(format!("{}", Foo(23)), "23");
19001900
/// ```
19011901
#[must_use]
19021902
#[stable(feature = "fmt_flags", since = "1.5.0")]
@@ -1922,7 +1922,7 @@ impl<'a> Formatter<'a> {
19221922
/// }
19231923
/// }
19241924
///
1925-
/// assert_eq!(&format!("{:04}", Foo(23)), "23");
1925+
/// assert_eq!(format!("{:04}", Foo(23)), "23");
19261926
/// ```
19271927
#[must_use]
19281928
#[stable(feature = "fmt_flags", since = "1.5.0")]

core/src/future/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,10 @@ pub unsafe fn get_context<'a, 'b>(cx: ResumeTy) -> &'a mut Context<'b> {
112112
unsafe { &mut *cx.0.as_ptr().cast() }
113113
}
114114

115+
// FIXME(swatinem): This fn is currently needed to work around shortcomings
116+
// in type and lifetime inference.
117+
// See the comment at the bottom of `LoweringContext::make_async_expr` and
118+
// <https://github.com/rust-lang/rust/issues/104826>.
115119
#[doc(hidden)]
116120
#[unstable(feature = "gen_future", issue = "50547")]
117121
#[inline]

0 commit comments

Comments
 (0)