Skip to content

Commit 0e04ae4

Browse files
author
The Miri Cronjob Bot
committed
Merge ref '6244effd0372' from rust-lang/rust
Pull recent changes from https://github.com/rust-lang/rust via Josh. Upstream ref: 6244eff Filtered ref: 2b788f903ef58db43f16530dbf73f4a0502e4452 Upstream diff: rust-lang/rust@96fe3c3...6244eff This merge was created using https://github.com/rust-lang/josh-sync.
2 parents 421e6b0 + f140393 commit 0e04ae4

File tree

28 files changed

+744
-341
lines changed

28 files changed

+744
-341
lines changed

alloc/src/collections/vec_deque/tests.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ fn test_rotate_right_panic() {
367367

368368
#[test]
369369
fn test_binary_search() {
370-
// If the givin VecDeque is not sorted, the returned result is unspecified and meaningless,
370+
// If the given VecDeque is not sorted, the returned result is unspecified and meaningless,
371371
// as this method performs a binary search.
372372

373373
let tester: VecDeque<_> = [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55].into();
@@ -391,7 +391,7 @@ fn test_binary_search() {
391391

392392
#[test]
393393
fn test_binary_search_by() {
394-
// If the givin VecDeque is not sorted, the returned result is unspecified and meaningless,
394+
// If the given VecDeque is not sorted, the returned result is unspecified and meaningless,
395395
// as this method performs a binary search.
396396

397397
let tester: VecDeque<_> = [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55].into();
@@ -406,7 +406,7 @@ fn test_binary_search_by() {
406406

407407
#[test]
408408
fn test_binary_search_key() {
409-
// If the givin VecDeque is not sorted, the returned result is unspecified and meaningless,
409+
// If the given VecDeque is not sorted, the returned result is unspecified and meaningless,
410410
// as this method performs a binary search.
411411

412412
let tester: VecDeque<_> = [

alloc/src/string.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2378,6 +2378,28 @@ impl<'a> FromIterator<Cow<'a, str>> for String {
23782378
}
23792379
}
23802380

2381+
#[cfg(not(no_global_oom_handling))]
2382+
#[unstable(feature = "ascii_char", issue = "110998")]
2383+
impl FromIterator<core::ascii::Char> for String {
2384+
fn from_iter<T: IntoIterator<Item = core::ascii::Char>>(iter: T) -> Self {
2385+
let buf = iter.into_iter().map(core::ascii::Char::to_u8).collect();
2386+
// SAFETY: `buf` is guaranteed to be valid UTF-8 because the `core::ascii::Char` type
2387+
// only contains ASCII values (0x00-0x7F), which are valid UTF-8.
2388+
unsafe { String::from_utf8_unchecked(buf) }
2389+
}
2390+
}
2391+
2392+
#[cfg(not(no_global_oom_handling))]
2393+
#[unstable(feature = "ascii_char", issue = "110998")]
2394+
impl<'a> FromIterator<&'a core::ascii::Char> for String {
2395+
fn from_iter<T: IntoIterator<Item = &'a core::ascii::Char>>(iter: T) -> Self {
2396+
let buf = iter.into_iter().copied().map(core::ascii::Char::to_u8).collect();
2397+
// SAFETY: `buf` is guaranteed to be valid UTF-8 because the `core::ascii::Char` type
2398+
// only contains ASCII values (0x00-0x7F), which are valid UTF-8.
2399+
unsafe { String::from_utf8_unchecked(buf) }
2400+
}
2401+
}
2402+
23812403
#[cfg(not(no_global_oom_handling))]
23822404
#[stable(feature = "rust1", since = "1.0.0")]
23832405
impl Extend<char> for String {
@@ -3184,6 +3206,14 @@ impl<'a> FromIterator<String> for Cow<'a, str> {
31843206
}
31853207
}
31863208

3209+
#[cfg(not(no_global_oom_handling))]
3210+
#[unstable(feature = "ascii_char", issue = "110998")]
3211+
impl<'a> FromIterator<core::ascii::Char> for Cow<'a, str> {
3212+
fn from_iter<T: IntoIterator<Item = core::ascii::Char>>(it: T) -> Self {
3213+
Cow::Owned(FromIterator::from_iter(it))
3214+
}
3215+
}
3216+
31873217
#[stable(feature = "from_string_for_vec_u8", since = "1.14.0")]
31883218
impl From<String> for Vec<u8> {
31893219
/// Converts the given [`String`] to a vector [`Vec`] that holds values of type [`u8`].

core/src/asserting.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,14 @@ where
7373

7474
// ***** Others *****
7575

76+
//spellchecker:off
7677
/// All possible captured `assert!` elements
7778
///
7879
/// # Types
7980
///
8081
/// * `E`: **E**lement that is going to be displayed.
8182
/// * `M`: **M**arker used to differentiate [Capture]s in regards to [Debug].
83+
//spellchecker:on
8284
#[unstable(feature = "generic_assert_internals", issue = "44838")]
8385
pub struct Capture<E, M> {
8486
// If None, then `E` does not implements [Printable] or `E` wasn't evaluated (`assert!( ... )`

core/src/cell.rs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@
252252

253253
use crate::cmp::Ordering;
254254
use crate::fmt::{self, Debug, Display};
255-
use crate::marker::{PhantomData, Unsize};
255+
use crate::marker::{Destruct, PhantomData, Unsize};
256256
use crate::mem::{self, ManuallyDrop};
257257
use crate::ops::{self, CoerceUnsized, Deref, DerefMut, DerefPure, DispatchFromDyn};
258258
use crate::panic::const_panic;
@@ -429,7 +429,11 @@ impl<T> Cell<T> {
429429
/// ```
430430
#[inline]
431431
#[stable(feature = "rust1", since = "1.0.0")]
432-
pub fn set(&self, val: T) {
432+
#[rustc_const_unstable(feature = "const_cell_traits", issue = "147787")]
433+
pub const fn set(&self, val: T)
434+
where
435+
T: [const] Destruct,
436+
{
433437
self.replace(val);
434438
}
435439

@@ -561,7 +565,12 @@ impl<T: Copy> Cell<T> {
561565
/// ```
562566
#[inline]
563567
#[stable(feature = "cell_update", since = "1.88.0")]
564-
pub fn update(&self, f: impl FnOnce(T) -> T) {
568+
#[rustc_const_unstable(feature = "const_cell_traits", issue = "147787")]
569+
pub const fn update(&self, f: impl [const] FnOnce(T) -> T)
570+
where
571+
// FIXME(const-hack): `Copy` should imply `const Destruct`
572+
T: [const] Destruct,
573+
{
565574
let old = self.get();
566575
self.set(f(old));
567576
}
@@ -654,7 +663,11 @@ impl<T: Default> Cell<T> {
654663
/// assert_eq!(c.into_inner(), 0);
655664
/// ```
656665
#[stable(feature = "move_cell", since = "1.17.0")]
657-
pub fn take(&self) -> T {
666+
#[rustc_const_unstable(feature = "const_cell_traits", issue = "147787")]
667+
pub const fn take(&self) -> T
668+
where
669+
T: [const] Default,
670+
{
658671
self.replace(Default::default())
659672
}
660673
}

core/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@
116116
#![feature(link_cfg)]
117117
#![feature(offset_of_enum)]
118118
#![feature(panic_internals)]
119+
#![feature(pattern_type_macro)]
119120
#![feature(ptr_alignment_type)]
120121
#![feature(ptr_metadata)]
121122
#![feature(set_ptr_value)]
@@ -171,6 +172,7 @@
171172
#![feature(never_type)]
172173
#![feature(no_core)]
173174
#![feature(optimize_attribute)]
175+
#![feature(pattern_types)]
174176
#![feature(prelude_import)]
175177
#![feature(reborrow)]
176178
#![feature(repr_simd)]

core/src/panic/unwind_safe.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,9 @@ pub auto trait UnwindSafe {}
101101
#[rustc_diagnostic_item = "ref_unwind_safe_trait"]
102102
#[diagnostic::on_unimplemented(
103103
message = "the type `{Self}` may contain interior mutability and a reference may not be safely \
104-
transferrable across a catch_unwind boundary",
104+
transferable across a catch_unwind boundary",
105105
label = "`{Self}` may contain interior mutability and a reference may not be safely \
106-
transferrable across a catch_unwind boundary"
106+
transferable across a catch_unwind boundary"
107107
)]
108108
pub auto trait RefUnwindSafe {}
109109

core/src/pat.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
//! Helper module for exporting the `pattern_type` macro
22
3+
use crate::marker::{Freeze, PointeeSized, Unsize};
4+
use crate::ops::{CoerceUnsized, DispatchFromDyn};
5+
36
/// Creates a pattern type.
47
/// ```ignore (cannot test this from within core yet)
58
/// type Positive = std::pat::pattern_type!(i32 is 1..);
@@ -73,3 +76,16 @@ impl const RangePattern for char {
7376
}
7477
}
7578
}
79+
80+
impl<T: PointeeSized, U: PointeeSized> CoerceUnsized<pattern_type!(*const U is !null)> for pattern_type!(*const T is !null) where
81+
T: Unsize<U>
82+
{
83+
}
84+
85+
impl<T: DispatchFromDyn<U>, U> DispatchFromDyn<pattern_type!(U is !null)> for pattern_type!(T is !null) {}
86+
87+
impl<T: PointeeSized> Unpin for pattern_type!(*const T is !null) {}
88+
89+
unsafe impl<T: PointeeSized> Freeze for pattern_type!(*const T is !null) {}
90+
91+
unsafe impl<T: PointeeSized> Freeze for pattern_type!(*mut T is !null) {}

coretests/tests/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#![feature(char_internals)]
1717
#![feature(char_max_len)]
1818
#![feature(clone_to_uninit)]
19+
#![feature(const_cell_traits)]
1920
#![feature(const_cmp)]
2021
#![feature(const_convert)]
2122
#![feature(const_destruct)]

coretests/tests/manually_drop.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,41 @@ fn smoke() {
2727
drop(x);
2828
drop(y);
2929
}
30+
31+
#[test]
32+
fn const_drop_in_place() {
33+
const COUNTER: usize = {
34+
use core::cell::Cell;
35+
36+
let counter = Cell::new(0);
37+
38+
// only exists to make `Drop` indirect impl
39+
#[allow(dead_code)]
40+
struct Test<'a>(Dropped<'a>);
41+
42+
struct Dropped<'a>(&'a Cell<usize>);
43+
impl const Drop for Dropped<'_> {
44+
fn drop(&mut self) {
45+
self.0.set(self.0.get() + 1);
46+
}
47+
}
48+
49+
let mut one = ManuallyDrop::new(Test(Dropped(&counter)));
50+
let mut two = ManuallyDrop::new(Test(Dropped(&counter)));
51+
let mut three = ManuallyDrop::new(Test(Dropped(&counter)));
52+
assert!(counter.get() == 0);
53+
unsafe {
54+
ManuallyDrop::drop(&mut one);
55+
}
56+
assert!(counter.get() == 1);
57+
unsafe {
58+
ManuallyDrop::drop(&mut two);
59+
}
60+
assert!(counter.get() == 2);
61+
unsafe {
62+
ManuallyDrop::drop(&mut three);
63+
}
64+
counter.get()
65+
};
66+
assert_eq!(COUNTER, 3);
67+
}

coretests/tests/ptr.rs

Lines changed: 1 addition & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use core::cell::RefCell;
22
use core::marker::Freeze;
3-
use core::mem::{ManuallyDrop, MaybeUninit};
3+
use core::mem::MaybeUninit;
44
use core::num::NonZero;
55
use core::ptr;
66
use core::ptr::*;
@@ -1045,42 +1045,3 @@ fn test_ptr_default() {
10451045
let default = PtrMutDefaultTest::default();
10461046
assert!(default.ptr.is_null());
10471047
}
1048-
1049-
#[test]
1050-
fn test_const_drop_in_place() {
1051-
const COUNTER: usize = {
1052-
let mut counter = 0;
1053-
let counter_ptr = &raw mut counter;
1054-
1055-
// only exists to make `Drop` indirect impl
1056-
#[allow(dead_code)]
1057-
struct Test(Dropped);
1058-
1059-
struct Dropped(*mut usize);
1060-
impl const Drop for Dropped {
1061-
fn drop(&mut self) {
1062-
unsafe {
1063-
*self.0 += 1;
1064-
}
1065-
}
1066-
}
1067-
1068-
let mut one = ManuallyDrop::new(Test(Dropped(counter_ptr)));
1069-
let mut two = ManuallyDrop::new(Test(Dropped(counter_ptr)));
1070-
let mut three = ManuallyDrop::new(Test(Dropped(counter_ptr)));
1071-
assert!(counter == 0);
1072-
unsafe {
1073-
ManuallyDrop::drop(&mut one);
1074-
}
1075-
assert!(counter == 1);
1076-
unsafe {
1077-
ManuallyDrop::drop(&mut two);
1078-
}
1079-
assert!(counter == 2);
1080-
unsafe {
1081-
ManuallyDrop::drop(&mut three);
1082-
}
1083-
counter
1084-
};
1085-
assert_eq!(COUNTER, 3);
1086-
}

0 commit comments

Comments
 (0)