Skip to content

Commit 25f5512

Browse files
committed
Auto merge of rust-lang#133026 - workingjubilee:rollup-q8ig6ah, r=workingjubilee
Rollup of 7 pull requests Successful merges: - rust-lang#131304 (float types: move copysign, abs, signum to libcore) - rust-lang#132907 (Change intrinsic declarations to new style) - rust-lang#132971 (Handle infer vars in anon consts on stable) - rust-lang#133003 (Make `CloneToUninit` dyn-compatible) - rust-lang#133004 (btree: simplify the backdoor between set and map) - rust-lang#133008 (update outdated comment about test-float-parse) - rust-lang#133012 (Add test cases for rust-lang#125918) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 7bc0436 + c06bb34 commit 25f5512

File tree

27 files changed

+1710
-1312
lines changed

27 files changed

+1710
-1312
lines changed

alloc/src/boxed.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1735,7 +1735,7 @@ impl<T: Clone, A: Allocator + Clone> Clone for Box<T, A> {
17351735
// Pre-allocate memory to allow writing the cloned value directly.
17361736
let mut boxed = Self::new_uninit_in(self.1.clone());
17371737
unsafe {
1738-
(**self).clone_to_uninit(boxed.as_mut_ptr());
1738+
(**self).clone_to_uninit(boxed.as_mut_ptr().cast());
17391739
boxed.assume_init()
17401740
}
17411741
}

alloc/src/collections/btree/map.rs

+6-34
Original file line numberDiff line numberDiff line change
@@ -289,40 +289,12 @@ impl<K: Clone, V: Clone, A: Allocator + Clone> Clone for BTreeMap<K, V, A> {
289289
}
290290
}
291291

292-
impl<K, Q: ?Sized, A: Allocator + Clone> super::Recover<Q> for BTreeMap<K, SetValZST, A>
293-
where
294-
K: Borrow<Q> + Ord,
295-
Q: Ord,
296-
{
297-
type Key = K;
298-
299-
fn get(&self, key: &Q) -> Option<&K> {
300-
let root_node = self.root.as_ref()?.reborrow();
301-
match root_node.search_tree(key) {
302-
Found(handle) => Some(handle.into_kv().0),
303-
GoDown(_) => None,
304-
}
305-
}
306-
307-
fn take(&mut self, key: &Q) -> Option<K> {
308-
let (map, dormant_map) = DormantMutRef::new(self);
309-
let root_node = map.root.as_mut()?.borrow_mut();
310-
match root_node.search_tree(key) {
311-
Found(handle) => Some(
312-
OccupiedEntry {
313-
handle,
314-
dormant_map,
315-
alloc: (*map.alloc).clone(),
316-
_marker: PhantomData,
317-
}
318-
.remove_kv()
319-
.0,
320-
),
321-
GoDown(_) => None,
322-
}
323-
}
324-
325-
fn replace(&mut self, key: K) -> Option<K> {
292+
/// Internal functionality for `BTreeSet`.
293+
impl<K, A: Allocator + Clone> BTreeMap<K, SetValZST, A> {
294+
pub(super) fn replace(&mut self, key: K) -> Option<K>
295+
where
296+
K: Ord,
297+
{
326298
let (map, dormant_map) = DormantMutRef::new(self);
327299
let root_node =
328300
map.root.get_or_insert_with(|| Root::new((*map.alloc).clone())).borrow_mut();

alloc/src/collections/btree/mod.rs

-8
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,3 @@ mod search;
1212
pub mod set;
1313
mod set_val;
1414
mod split;
15-
16-
trait Recover<Q: ?Sized> {
17-
type Key;
18-
19-
fn get(&self, key: &Q) -> Option<&Self::Key>;
20-
fn take(&mut self, key: &Q) -> Option<Self::Key>;
21-
fn replace(&mut self, key: Self::Key) -> Option<Self::Key>;
22-
}

alloc/src/collections/btree/set.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use core::iter::{FusedIterator, Peekable};
77
use core::mem::ManuallyDrop;
88
use core::ops::{BitAnd, BitOr, BitXor, Bound, RangeBounds, Sub};
99

10-
use super::Recover;
1110
use super::map::{BTreeMap, Keys};
1211
use super::merge_iter::MergeIterInner;
1312
use super::set_val::SetValZST;
@@ -635,7 +634,7 @@ impl<T, A: Allocator + Clone> BTreeSet<T, A> {
635634
T: Borrow<Q> + Ord,
636635
Q: Ord,
637636
{
638-
Recover::get(&self.map, value)
637+
self.map.get_key_value(value).map(|(k, _)| k)
639638
}
640639

641640
/// Returns `true` if `self` has no elements in common with `other`.
@@ -926,7 +925,7 @@ impl<T, A: Allocator + Clone> BTreeSet<T, A> {
926925
where
927926
T: Ord,
928927
{
929-
Recover::replace(&mut self.map, value)
928+
self.map.replace(value)
930929
}
931930

932931
/// If the set contains an element equal to the value, removes it from the
@@ -978,7 +977,7 @@ impl<T, A: Allocator + Clone> BTreeSet<T, A> {
978977
T: Borrow<Q> + Ord,
979978
Q: Ord,
980979
{
981-
Recover::take(&mut self.map, value)
980+
self.map.remove_entry(value).map(|(k, _)| k)
982981
}
983982

984983
/// Retains only the elements specified by the predicate.

alloc/src/collections/btree/set_val.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
/// * `BTreeMap<T, ()>` (possible user-defined map)
44
/// * `BTreeMap<T, SetValZST>` (internal set representation)
55
#[derive(Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Clone, Default)]
6-
pub struct SetValZST;
6+
pub(super) struct SetValZST;
77

88
/// A trait to differentiate between `BTreeMap` and `BTreeSet` values.
99
/// Returns `true` only for type `SetValZST`, `false` for all other types (blanket implementation).
1010
/// `TypeId` requires a `'static` lifetime, use of this trait avoids that restriction.
1111
///
1212
/// [`TypeId`]: std::any::TypeId
13-
pub trait IsSetVal {
13+
pub(super) trait IsSetVal {
1414
fn is_set_val() -> bool;
1515
}
1616

alloc/src/rc.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1876,7 +1876,7 @@ impl<T: ?Sized + CloneToUninit, A: Allocator + Clone> Rc<T, A> {
18761876
// Initialize with clone of this.
18771877
let initialized_clone = unsafe {
18781878
// Clone. If the clone panics, `in_progress` will be dropped and clean up.
1879-
this_data_ref.clone_to_uninit(in_progress.data_ptr());
1879+
this_data_ref.clone_to_uninit(in_progress.data_ptr().cast());
18801880
// Cast type of pointer, now that it is initialized.
18811881
in_progress.into_rc()
18821882
};

alloc/src/sync.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2272,7 +2272,7 @@ impl<T: ?Sized + CloneToUninit, A: Allocator + Clone> Arc<T, A> {
22722272

22732273
let initialized_clone = unsafe {
22742274
// Clone. If the clone panics, `in_progress` will be dropped and clean up.
2275-
this_data_ref.clone_to_uninit(in_progress.data_ptr());
2275+
this_data_ref.clone_to_uninit(in_progress.data_ptr().cast());
22762276
// Cast type of pointer, now that it is initialized.
22772277
in_progress.into_arc()
22782278
};

core/src/clone.rs

+15-14
Original file line numberDiff line numberDiff line change
@@ -232,20 +232,20 @@ pub struct AssertParamIsCopy<T: Copy + ?Sized> {
232232
pub unsafe trait CloneToUninit {
233233
/// Performs copy-assignment from `self` to `dst`.
234234
///
235-
/// This is analogous to `std::ptr::write(dst, self.clone())`,
235+
/// This is analogous to `std::ptr::write(dst.cast(), self.clone())`,
236236
/// except that `self` may be a dynamically-sized type ([`!Sized`](Sized)).
237237
///
238238
/// Before this function is called, `dst` may point to uninitialized memory.
239239
/// After this function is called, `dst` will point to initialized memory; it will be
240-
/// sound to create a `&Self` reference from the pointer.
240+
/// sound to create a `&Self` reference from the pointer with the [pointer metadata]
241+
/// from `self`.
241242
///
242243
/// # Safety
243244
///
244245
/// Behavior is undefined if any of the following conditions are violated:
245246
///
246-
/// * `dst` must be [valid] for writes.
247-
/// * `dst` must be properly aligned.
248-
/// * `dst` must have the same [pointer metadata] (slice length or `dyn` vtable) as `self`.
247+
/// * `dst` must be [valid] for writes for `std::mem::size_of_val(self)` bytes.
248+
/// * `dst` must be properly aligned to `std::mem::align_of_val(self)`.
249249
///
250250
/// [valid]: crate::ptr#safety
251251
/// [pointer metadata]: crate::ptr::metadata()
@@ -266,23 +266,24 @@ pub unsafe trait CloneToUninit {
266266
/// that might have already been created. (For example, if a `[Foo]` of length 3 is being
267267
/// cloned, and the second of the three calls to `Foo::clone()` unwinds, then the first `Foo`
268268
/// cloned should be dropped.)
269-
unsafe fn clone_to_uninit(&self, dst: *mut Self);
269+
unsafe fn clone_to_uninit(&self, dst: *mut u8);
270270
}
271271

272272
#[unstable(feature = "clone_to_uninit", issue = "126799")]
273273
unsafe impl<T: Clone> CloneToUninit for T {
274274
#[inline]
275-
unsafe fn clone_to_uninit(&self, dst: *mut Self) {
275+
unsafe fn clone_to_uninit(&self, dst: *mut u8) {
276276
// SAFETY: we're calling a specialization with the same contract
277-
unsafe { <T as self::uninit::CopySpec>::clone_one(self, dst) }
277+
unsafe { <T as self::uninit::CopySpec>::clone_one(self, dst.cast::<T>()) }
278278
}
279279
}
280280

281281
#[unstable(feature = "clone_to_uninit", issue = "126799")]
282282
unsafe impl<T: Clone> CloneToUninit for [T] {
283283
#[inline]
284284
#[cfg_attr(debug_assertions, track_caller)]
285-
unsafe fn clone_to_uninit(&self, dst: *mut Self) {
285+
unsafe fn clone_to_uninit(&self, dst: *mut u8) {
286+
let dst: *mut [T] = dst.with_metadata_of(self);
286287
// SAFETY: we're calling a specialization with the same contract
287288
unsafe { <T as self::uninit::CopySpec>::clone_slice(self, dst) }
288289
}
@@ -292,21 +293,21 @@ unsafe impl<T: Clone> CloneToUninit for [T] {
292293
unsafe impl CloneToUninit for str {
293294
#[inline]
294295
#[cfg_attr(debug_assertions, track_caller)]
295-
unsafe fn clone_to_uninit(&self, dst: *mut Self) {
296+
unsafe fn clone_to_uninit(&self, dst: *mut u8) {
296297
// SAFETY: str is just a [u8] with UTF-8 invariant
297-
unsafe { self.as_bytes().clone_to_uninit(dst as *mut [u8]) }
298+
unsafe { self.as_bytes().clone_to_uninit(dst) }
298299
}
299300
}
300301

301302
#[unstable(feature = "clone_to_uninit", issue = "126799")]
302303
unsafe impl CloneToUninit for crate::ffi::CStr {
303304
#[cfg_attr(debug_assertions, track_caller)]
304-
unsafe fn clone_to_uninit(&self, dst: *mut Self) {
305+
unsafe fn clone_to_uninit(&self, dst: *mut u8) {
305306
// SAFETY: For now, CStr is just a #[repr(trasnsparent)] [c_char] with some invariants.
306307
// And we can cast [c_char] to [u8] on all supported platforms (see: to_bytes_with_nul).
307-
// The pointer metadata properly preserves the length (NUL included).
308+
// The pointer metadata properly preserves the length (so NUL is also copied).
308309
// See: `cstr_metadata_is_length_with_nul` in tests.
309-
unsafe { self.to_bytes_with_nul().clone_to_uninit(dst as *mut [u8]) }
310+
unsafe { self.to_bytes_with_nul().clone_to_uninit(dst) }
310311
}
311312
}
312313

core/src/fmt/float.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ macro_rules! impl_general_format {
1313
($($t:ident)*) => {
1414
$(impl GeneralFormat for $t {
1515
fn already_rounded_value_should_use_exponential(&self) -> bool {
16-
let abs = $t::abs_private(*self);
16+
let abs = $t::abs(*self);
1717
(abs != 0.0 && abs < 1e-4) || abs >= 1e+16
1818
}
1919
})*

0 commit comments

Comments
 (0)