Skip to content

Commit c4ee91f

Browse files
author
The Miri Cronjob Bot
committed
Merge from rustc
2 parents 16450f7 + 09bda4f commit c4ee91f

Some content is hidden

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

49 files changed

+659
-508
lines changed

alloc/src/collections/binary_heap/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ impl<T: Ord, A: Allocator> BinaryHeap<T, A> {
484484
/// heap.push(4);
485485
/// ```
486486
#[unstable(feature = "allocator_api", issue = "32838")]
487-
#[rustc_const_unstable(feature = "const_binary_heap_new_in", issue = "112353")]
487+
#[rustc_const_unstable(feature = "const_binary_heap_new_in", issue = "125961")]
488488
#[must_use]
489489
pub const fn new_in(alloc: A) -> BinaryHeap<T, A> {
490490
BinaryHeap { data: Vec::new_in(alloc) }

alloc/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@
101101
#![feature(array_windows)]
102102
#![feature(ascii_char)]
103103
#![feature(assert_matches)]
104+
#![feature(async_closure)]
104105
#![feature(async_fn_traits)]
105106
#![feature(async_iterator)]
106107
#![feature(clone_to_uninit)]

alloc/src/rc.rs

+22-25
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ use core::intrinsics::abort;
259259
#[cfg(not(no_global_oom_handling))]
260260
use core::iter;
261261
use core::marker::{PhantomData, Unsize};
262-
use core::mem::{self, align_of_val_raw, forget, ManuallyDrop};
262+
use core::mem::{self, align_of_val_raw, ManuallyDrop};
263263
use core::ops::{CoerceUnsized, Deref, DerefMut, DerefPure, DispatchFromDyn, Receiver};
264264
use core::panic::{RefUnwindSafe, UnwindSafe};
265265
#[cfg(not(no_global_oom_handling))]
@@ -908,19 +908,18 @@ impl<T, A: Allocator> Rc<T, A> {
908908
#[stable(feature = "rc_unique", since = "1.4.0")]
909909
pub fn try_unwrap(this: Self) -> Result<T, Self> {
910910
if Rc::strong_count(&this) == 1 {
911-
unsafe {
912-
let val = ptr::read(&*this); // copy the contained object
913-
let alloc = ptr::read(&this.alloc); // copy the allocator
914-
915-
// Indicate to Weaks that they can't be promoted by decrementing
916-
// the strong count, and then remove the implicit "strong weak"
917-
// pointer while also handling drop logic by just crafting a
918-
// fake Weak.
919-
this.inner().dec_strong();
920-
let _weak = Weak { ptr: this.ptr, alloc };
921-
forget(this);
922-
Ok(val)
923-
}
911+
let this = ManuallyDrop::new(this);
912+
913+
let val: T = unsafe { ptr::read(&**this) }; // copy the contained object
914+
let alloc: A = unsafe { ptr::read(&this.alloc) }; // copy the allocator
915+
916+
// Indicate to Weaks that they can't be promoted by decrementing
917+
// the strong count, and then remove the implicit "strong weak"
918+
// pointer while also handling drop logic by just crafting a
919+
// fake Weak.
920+
this.inner().dec_strong();
921+
let _weak = Weak { ptr: this.ptr, alloc };
922+
Ok(val)
924923
} else {
925924
Err(this)
926925
}
@@ -1354,9 +1353,8 @@ impl<T: ?Sized, A: Allocator> Rc<T, A> {
13541353
#[stable(feature = "rc_raw", since = "1.17.0")]
13551354
#[rustc_never_returns_null_ptr]
13561355
pub fn into_raw(this: Self) -> *const T {
1357-
let ptr = Self::as_ptr(&this);
1358-
mem::forget(this);
1359-
ptr
1356+
let this = ManuallyDrop::new(this);
1357+
Self::as_ptr(&*this)
13601358
}
13611359

13621360
/// Consumes the `Rc`, returning the wrapped pointer and allocator.
@@ -2127,7 +2125,7 @@ impl<T> Rc<[T]> {
21272125
}
21282126

21292127
// All clear. Forget the guard so it doesn't free the new RcBox.
2130-
forget(guard);
2128+
mem::forget(guard);
21312129

21322130
Self::from_ptr(ptr)
21332131
}
@@ -3080,9 +3078,7 @@ impl<T: ?Sized, A: Allocator> Weak<T, A> {
30803078
#[must_use = "losing the pointer will leak memory"]
30813079
#[stable(feature = "weak_into_raw", since = "1.45.0")]
30823080
pub fn into_raw(self) -> *const T {
3083-
let result = self.as_ptr();
3084-
mem::forget(self);
3085-
result
3081+
mem::ManuallyDrop::new(self).as_ptr()
30863082
}
30873083

30883084
/// Consumes the `Weak<T>`, returning the wrapped pointer and allocator.
@@ -3762,10 +3758,11 @@ impl<T: ?Sized, A: Allocator> UniqueRcUninit<T, A> {
37623758
/// # Safety
37633759
///
37643760
/// The data must have been initialized (by writing to [`Self::data_ptr()`]).
3765-
unsafe fn into_rc(mut self) -> Rc<T, A> {
3766-
let ptr = self.ptr;
3767-
let alloc = self.alloc.take().unwrap();
3768-
mem::forget(self);
3761+
unsafe fn into_rc(self) -> Rc<T, A> {
3762+
let mut this = ManuallyDrop::new(self);
3763+
let ptr = this.ptr;
3764+
let alloc = this.alloc.take().unwrap();
3765+
37693766
// SAFETY: The pointer is valid as per `UniqueRcUninit::new`, and the caller is responsible
37703767
// for having initialized the data.
37713768
unsafe { Rc::from_ptr_in(ptr.as_ptr(), alloc) }

alloc/src/str.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ impl str {
269269
without modifying the original"]
270270
#[stable(feature = "rust1", since = "1.0.0")]
271271
#[inline]
272-
pub fn replace<'a, P: Pattern<'a>>(&'a self, from: P, to: &str) -> String {
272+
pub fn replace<P: Pattern>(&self, from: P, to: &str) -> String {
273273
let mut result = String::new();
274274
let mut last_end = 0;
275275
for (start, part) in self.match_indices(from) {
@@ -309,7 +309,7 @@ impl str {
309309
#[must_use = "this returns the replaced string as a new allocation, \
310310
without modifying the original"]
311311
#[stable(feature = "str_replacen", since = "1.16.0")]
312-
pub fn replacen<'a, P: Pattern<'a>>(&'a self, pat: P, to: &str, count: usize) -> String {
312+
pub fn replacen<P: Pattern>(&self, pat: P, to: &str, count: usize) -> String {
313313
// Hope to reduce the times of re-allocation
314314
let mut result = String::with_capacity(32);
315315
let mut last_end = 0;

alloc/src/string.rs

+15-12
Original file line numberDiff line numberDiff line change
@@ -1497,10 +1497,7 @@ impl String {
14971497
/// ```
14981498
#[cfg(not(no_global_oom_handling))]
14991499
#[unstable(feature = "string_remove_matches", reason = "new API", issue = "72826")]
1500-
pub fn remove_matches<'a, P>(&'a mut self, pat: P)
1501-
where
1502-
P: for<'x> Pattern<'x>,
1503-
{
1500+
pub fn remove_matches<P: Pattern>(&mut self, pat: P) {
15041501
use core::str::pattern::Searcher;
15051502

15061503
let rejections = {
@@ -2288,35 +2285,41 @@ impl<'a> Extend<Cow<'a, str>> for String {
22882285
reason = "API not fully fleshed out and ready to be stabilized",
22892286
issue = "27721"
22902287
)]
2291-
impl<'a, 'b> Pattern<'a> for &'b String {
2292-
type Searcher = <&'b str as Pattern<'a>>::Searcher;
2288+
impl<'b> Pattern for &'b String {
2289+
type Searcher<'a> = <&'b str as Pattern>::Searcher<'a>;
22932290

2294-
fn into_searcher(self, haystack: &'a str) -> <&'b str as Pattern<'a>>::Searcher {
2291+
fn into_searcher(self, haystack: &str) -> <&'b str as Pattern>::Searcher<'_> {
22952292
self[..].into_searcher(haystack)
22962293
}
22972294

22982295
#[inline]
2299-
fn is_contained_in(self, haystack: &'a str) -> bool {
2296+
fn is_contained_in(self, haystack: &str) -> bool {
23002297
self[..].is_contained_in(haystack)
23012298
}
23022299

23032300
#[inline]
2304-
fn is_prefix_of(self, haystack: &'a str) -> bool {
2301+
fn is_prefix_of(self, haystack: &str) -> bool {
23052302
self[..].is_prefix_of(haystack)
23062303
}
23072304

23082305
#[inline]
2309-
fn strip_prefix_of(self, haystack: &'a str) -> Option<&'a str> {
2306+
fn strip_prefix_of(self, haystack: &str) -> Option<&str> {
23102307
self[..].strip_prefix_of(haystack)
23112308
}
23122309

23132310
#[inline]
2314-
fn is_suffix_of(self, haystack: &'a str) -> bool {
2311+
fn is_suffix_of<'a>(self, haystack: &'a str) -> bool
2312+
where
2313+
Self::Searcher<'a>: core::str::pattern::ReverseSearcher<'a>,
2314+
{
23152315
self[..].is_suffix_of(haystack)
23162316
}
23172317

23182318
#[inline]
2319-
fn strip_suffix_of(self, haystack: &'a str) -> Option<&'a str> {
2319+
fn strip_suffix_of<'a>(self, haystack: &'a str) -> Option<&str>
2320+
where
2321+
Self::Searcher<'a>: core::str::pattern::ReverseSearcher<'a>,
2322+
{
23202323
self[..].strip_suffix_of(haystack)
23212324
}
23222325
}

alloc/src/sync.rs

+16-20
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use core::intrinsics::abort;
2020
#[cfg(not(no_global_oom_handling))]
2121
use core::iter;
2222
use core::marker::{PhantomData, Unsize};
23-
use core::mem::{self, align_of_val_raw};
23+
use core::mem::{self, align_of_val_raw, ManuallyDrop};
2424
use core::ops::{CoerceUnsized, Deref, DerefPure, DispatchFromDyn, Receiver};
2525
use core::panic::{RefUnwindSafe, UnwindSafe};
2626
use core::pin::Pin;
@@ -960,16 +960,14 @@ impl<T, A: Allocator> Arc<T, A> {
960960

961961
acquire!(this.inner().strong);
962962

963-
unsafe {
964-
let elem = ptr::read(&this.ptr.as_ref().data);
965-
let alloc = ptr::read(&this.alloc); // copy the allocator
963+
let this = ManuallyDrop::new(this);
964+
let elem: T = unsafe { ptr::read(&this.ptr.as_ref().data) };
965+
let alloc: A = unsafe { ptr::read(&this.alloc) }; // copy the allocator
966966

967-
// Make a weak pointer to clean up the implicit strong-weak reference
968-
let _weak = Weak { ptr: this.ptr, alloc };
969-
mem::forget(this);
967+
// Make a weak pointer to clean up the implicit strong-weak reference
968+
let _weak = Weak { ptr: this.ptr, alloc };
970969

971-
Ok(elem)
972-
}
970+
Ok(elem)
973971
}
974972

975973
/// Returns the inner value, if the `Arc` has exactly one strong reference.
@@ -1493,9 +1491,8 @@ impl<T: ?Sized, A: Allocator> Arc<T, A> {
14931491
#[stable(feature = "rc_raw", since = "1.17.0")]
14941492
#[rustc_never_returns_null_ptr]
14951493
pub fn into_raw(this: Self) -> *const T {
1496-
let ptr = Self::as_ptr(&this);
1497-
mem::forget(this);
1498-
ptr
1494+
let this = ManuallyDrop::new(this);
1495+
Self::as_ptr(&*this)
14991496
}
15001497

15011498
/// Consumes the `Arc`, returning the wrapped pointer and allocator.
@@ -2801,9 +2798,7 @@ impl<T: ?Sized, A: Allocator> Weak<T, A> {
28012798
#[must_use = "losing the pointer will leak memory"]
28022799
#[stable(feature = "weak_into_raw", since = "1.45.0")]
28032800
pub fn into_raw(self) -> *const T {
2804-
let result = self.as_ptr();
2805-
mem::forget(self);
2806-
result
2801+
ManuallyDrop::new(self).as_ptr()
28072802
}
28082803

28092804
/// Consumes the `Weak<T>`, returning the wrapped pointer and allocator.
@@ -3875,13 +3870,14 @@ impl<T: ?Sized, A: Allocator> UniqueArcUninit<T, A> {
38753870
/// # Safety
38763871
///
38773872
/// The data must have been initialized (by writing to [`Self::data_ptr()`]).
3878-
unsafe fn into_arc(mut self) -> Arc<T, A> {
3879-
let ptr = self.ptr;
3880-
let alloc = self.alloc.take().unwrap();
3881-
mem::forget(self);
3873+
unsafe fn into_arc(self) -> Arc<T, A> {
3874+
let mut this = ManuallyDrop::new(self);
3875+
let ptr = this.ptr.as_ptr();
3876+
let alloc = this.alloc.take().unwrap();
3877+
38823878
// SAFETY: The pointer is valid as per `UniqueArcUninit::new`, and the caller is responsible
38833879
// for having initialized the data.
3884-
unsafe { Arc::from_ptr_in(ptr.as_ptr(), alloc) }
3880+
unsafe { Arc::from_ptr_in(ptr, alloc) }
38853881
}
38863882
}
38873883

alloc/tests/str.rs

+6-8
Original file line numberDiff line numberDiff line change
@@ -1927,12 +1927,10 @@ mod pattern {
19271927
}
19281928
}
19291929

1930-
fn cmp_search_to_vec<'a>(
1931-
rev: bool,
1932-
pat: impl Pattern<'a, Searcher: ReverseSearcher<'a>>,
1933-
haystack: &'a str,
1934-
right: Vec<SearchStep>,
1935-
) {
1930+
fn cmp_search_to_vec<P>(rev: bool, pat: P, haystack: &str, right: Vec<SearchStep>)
1931+
where
1932+
P: for<'a> Pattern<Searcher<'a>: ReverseSearcher<'a>>,
1933+
{
19361934
let mut searcher = pat.into_searcher(haystack);
19371935
let mut v = vec![];
19381936
loop {
@@ -2191,9 +2189,9 @@ generate_iterator_test! {
21912189
fn different_str_pattern_forwarding_lifetimes() {
21922190
use std::str::pattern::Pattern;
21932191

2194-
fn foo<'a, P>(p: P)
2192+
fn foo<P>(p: P)
21952193
where
2196-
for<'b> &'b P: Pattern<'a>,
2194+
for<'b> &'b P: Pattern,
21972195
{
21982196
for _ in 0..3 {
21992197
"asdf".find(&p);

core/src/alloc/layout.rs

+2
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,8 @@ impl Layout {
183183
/// - a [slice], then the length of the slice tail must be an initialized
184184
/// integer, and the size of the *entire value*
185185
/// (dynamic tail length + statically sized prefix) must fit in `isize`.
186+
/// For the special case where the dynamic tail length is 0, this function
187+
/// is safe to call.
186188
/// - a [trait object], then the vtable part of the pointer must point
187189
/// to a valid vtable for the type `T` acquired by an unsizing coercion,
188190
/// and the size of the *entire value*

core/src/error.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ where
506506
/// ```
507507
///
508508
#[unstable(feature = "error_generic_member_access", issue = "99301")]
509-
#[cfg_attr(not(doc), repr(transparent))] // work around https://github.com/rust-lang/rust/issues/90435
509+
#[repr(transparent)]
510510
pub struct Request<'a>(Tagged<dyn Erased<'a> + 'a>);
511511

512512
impl<'a> Request<'a> {

core/src/ffi/c_str.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ use crate::str;
103103
// However, `CStr` layout is considered an implementation detail and must not be relied upon. We
104104
// want `repr(transparent)` but we don't want it to show up in rustdoc, so we hide it under
105105
// `cfg(doc)`. This is an ad-hoc implementation of attribute privacy.
106-
#[cfg_attr(not(doc), repr(transparent))]
106+
#[repr(transparent)]
107107
#[allow(clippy::derived_hash_with_manual_eq)]
108108
pub struct CStr {
109109
// FIXME: this should not be represented with a DST slice but rather with

core/src/ffi/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ mod c_long_definition {
191191
// be UB.
192192
#[doc = include_str!("c_void.md")]
193193
#[lang = "c_void"]
194-
#[cfg_attr(not(doc), repr(u8))] // work around https://github.com/rust-lang/rust/issues/90435
194+
#[cfg_attr(not(doc), repr(u8))] // An implementation detail we don't want to show up in rustdoc
195195
#[stable(feature = "core_c_void", since = "1.30.0")]
196196
pub enum c_void {
197197
#[unstable(

core/src/ffi/va_list.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use crate::ops::{Deref, DerefMut};
2323
target_os = "uefi",
2424
windows,
2525
))]
26-
#[cfg_attr(not(doc), repr(transparent))] // work around https://github.com/rust-lang/rust/issues/90435
26+
#[repr(transparent)]
2727
#[lang = "va_list"]
2828
pub struct VaListImpl<'f> {
2929
ptr: *mut c_void,
@@ -115,7 +115,7 @@ pub struct VaListImpl<'f> {
115115
}
116116

117117
/// A wrapper for a `va_list`
118-
#[cfg_attr(not(doc), repr(transparent))] // work around https://github.com/rust-lang/rust/issues/90435
118+
#[repr(transparent)]
119119
#[derive(Debug)]
120120
pub struct VaList<'a, 'f: 'a> {
121121
#[cfg(any(

core/src/mem/mod.rs

+8
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,12 @@ pub const fn size_of_val<T: ?Sized>(val: &T) -> usize {
359359
/// - a [slice], then the length of the slice tail must be an initialized
360360
/// integer, and the size of the *entire value*
361361
/// (dynamic tail length + statically sized prefix) must fit in `isize`.
362+
/// For the special case where the dynamic tail length is 0, this function
363+
/// is safe to call.
364+
// NOTE: the reason this is safe is that if an overflow were to occur already with size 0,
365+
// then we would stop compilation as even the "statically known" part of the type would
366+
// already be too big (or the call may be in dead code and optimized away, but then it
367+
// doesn't matter).
362368
/// - a [trait object], then the vtable part of the pointer must point
363369
/// to a valid vtable acquired by an unsizing coercion, and the size
364370
/// of the *entire value* (dynamic tail length + statically sized prefix)
@@ -506,6 +512,8 @@ pub const fn align_of_val<T: ?Sized>(val: &T) -> usize {
506512
/// - a [slice], then the length of the slice tail must be an initialized
507513
/// integer, and the size of the *entire value*
508514
/// (dynamic tail length + statically sized prefix) must fit in `isize`.
515+
/// For the special case where the dynamic tail length is 0, this function
516+
/// is safe to call.
509517
/// - a [trait object], then the vtable part of the pointer must point
510518
/// to a valid vtable acquired by an unsizing coercion, and the size
511519
/// of the *entire value* (dynamic tail length + statically sized prefix)

0 commit comments

Comments
 (0)