Skip to content

Commit 95879ad

Browse files
committed
Auto merge of rust-lang#75538 - tmandry:rollup-i8miv8q, r=tmandry
Rollup of 17 pull requests Successful merges: - rust-lang#73943 (Document the unsafe keyword) - rust-lang#74062 (deny(unsafe_op_in_unsafe_fn) in libstd/ffi/c_str.rs) - rust-lang#74185 (Remove liballoc unneeded explicit link) - rust-lang#74192 (Improve documentation on process::Child.std* fields) - rust-lang#74409 (Change Debug impl of SocketAddr and IpAddr to match their Display output) - rust-lang#75195 (BTreeMap: purge innocent use of into_kv_mut) - rust-lang#75214 (Use intra-doc links in `mem::manually_drop` & `mem::maybe_uninit`) - rust-lang#75432 (Switch to intra-doc links in `std::process`) - rust-lang#75482 (Clean up E0752 explanation) - rust-lang#75501 (Move to intra doc links in std::ffi) - rust-lang#75509 (Tweak suggestion for `this` -> `self`) - rust-lang#75511 (Do not emit E0228 when it is implied by E0106) - rust-lang#75515 (Bump std's libc version to 0.2.74) - rust-lang#75517 (Promotion and const interning comments) - rust-lang#75519 (BTreeMap: refactor splitpoint and move testing over to unit test) - rust-lang#75530 (Switch to intra-doc links in os/raw/*.md) - rust-lang#75531 (Migrate unit tests of btree collections to their native breeding ground) Failed merges: r? @ghost
2 parents 8e21bd0 + 939befd commit 95879ad

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

+725
-567
lines changed

Diff for: library/alloc/src/collections/btree/map.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ where
245245
fn replace(&mut self, key: K) -> Option<K> {
246246
let root = Self::ensure_is_owned(&mut self.root);
247247
match search::search_tree::<marker::Mut<'_>, K, (), K>(root.node_as_mut(), &key) {
248-
Found(handle) => Some(mem::replace(handle.into_kv_mut().0, key)),
248+
Found(handle) => Some(mem::replace(handle.into_key_mut(), key)),
249249
GoDown(handle) => {
250250
VacantEntry { key, handle, length: &mut self.length, _marker: PhantomData }
251251
.insert(());
@@ -811,7 +811,7 @@ impl<K: Ord, V> BTreeMap<K, V> {
811811
{
812812
let root_node = self.root.as_mut()?.node_as_mut();
813813
match search::search_tree(root_node, key) {
814-
Found(handle) => Some(handle.into_kv_mut().1),
814+
Found(handle) => Some(handle.into_val_mut()),
815815
GoDown(_) => None,
816816
}
817817
}
@@ -2748,7 +2748,7 @@ impl<'a, K: Ord, V> OccupiedEntry<'a, K, V> {
27482748
/// ```
27492749
#[stable(feature = "rust1", since = "1.0.0")]
27502750
pub fn into_mut(self) -> &'a mut V {
2751-
self.handle.into_kv_mut().1
2751+
self.handle.into_val_mut()
27522752
}
27532753

27542754
/// Sets the value of the entry with the `OccupiedEntry`'s key,
@@ -3024,3 +3024,6 @@ impl<K: Ord, V, I: Iterator<Item = (K, V)>> Iterator for MergeIter<K, V, I> {
30243024
}
30253025
}
30263026
}
3027+
3028+
#[cfg(test)]
3029+
mod tests;

Diff for: library/alloc/tests/btree/map.rs renamed to library/alloc/src/collections/btree/map/tests.rs

+9-5
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
1-
use std::collections::btree_map::Entry::{Occupied, Vacant};
2-
use std::collections::BTreeMap;
1+
use crate::boxed::Box;
2+
use crate::collections::btree_map::Entry::{Occupied, Vacant};
3+
use crate::collections::BTreeMap;
4+
use crate::fmt::Debug;
5+
use crate::rc::Rc;
6+
use crate::string::String;
7+
use crate::string::ToString;
8+
use crate::vec::Vec;
39
use std::convert::TryFrom;
4-
use std::fmt::Debug;
510
use std::iter::FromIterator;
611
use std::mem;
712
use std::ops::Bound::{self, Excluded, Included, Unbounded};
813
use std::ops::RangeBounds;
914
use std::panic::{catch_unwind, AssertUnwindSafe};
10-
use std::rc::Rc;
1115
use std::sync::atomic::{AtomicUsize, Ordering};
1216

13-
use super::DeterministicRng;
17+
use super::super::DeterministicRng;
1418

1519
// Value of node::CAPACITY, thus capacity of a tree with a single level,
1620
// i.e. a tree who's root is a leaf node at height 0.

Diff for: library/alloc/src/collections/btree/mod.rs

+27
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,30 @@ pub unsafe fn unwrap_unchecked<T>(val: Option<T>) -> T {
2525
}
2626
})
2727
}
28+
29+
#[cfg(test)]
30+
/// XorShiftRng
31+
struct DeterministicRng {
32+
x: u32,
33+
y: u32,
34+
z: u32,
35+
w: u32,
36+
}
37+
38+
#[cfg(test)]
39+
impl DeterministicRng {
40+
fn new() -> Self {
41+
DeterministicRng { x: 0x193a6754, y: 0xa8a7d469, z: 0x97830e05, w: 0x113ba7bb }
42+
}
43+
44+
fn next(&mut self) -> u32 {
45+
let x = self.x;
46+
let t = x ^ (x << 11);
47+
self.x = self.y;
48+
self.y = self.z;
49+
self.z = self.w;
50+
let w_ = self.w;
51+
self.w = w_ ^ (w_ >> 19) ^ (t ^ (t >> 8));
52+
self.w
53+
}
54+
}

Diff for: library/alloc/src/collections/btree/node.rs

+27-37
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ use crate::boxed::Box;
4343
const B: usize = 6;
4444
pub const MIN_LEN: usize = B - 1;
4545
pub const CAPACITY: usize = 2 * B - 1;
46+
const KV_IDX_CENTER: usize = B - 1;
47+
const EDGE_IDX_LEFT_OF_CENTER: usize = B - 1;
48+
const EDGE_IDX_RIGHT_OF_CENTER: usize = B;
4649

4750
/// The underlying representation of leaf nodes.
4851
#[repr(C)]
@@ -834,38 +837,12 @@ enum InsertionPlace {
834837
fn splitpoint(edge_idx: usize) -> (usize, InsertionPlace) {
835838
debug_assert!(edge_idx <= CAPACITY);
836839
// Rust issue #74834 tries to explain these symmetric rules.
837-
let middle_kv_idx;
838-
let insertion;
839-
if edge_idx <= B - 2 {
840-
middle_kv_idx = B - 2;
841-
insertion = InsertionPlace::Left(edge_idx);
842-
} else if edge_idx == B - 1 {
843-
middle_kv_idx = B - 1;
844-
insertion = InsertionPlace::Left(edge_idx);
845-
} else if edge_idx == B {
846-
middle_kv_idx = B - 1;
847-
insertion = InsertionPlace::Right(0);
848-
} else {
849-
middle_kv_idx = B;
850-
let new_edge_idx = edge_idx - (B + 1);
851-
insertion = InsertionPlace::Right(new_edge_idx);
852-
}
853-
let mut left_len = middle_kv_idx;
854-
let mut right_len = CAPACITY - middle_kv_idx - 1;
855-
match insertion {
856-
InsertionPlace::Left(edge_idx) => {
857-
debug_assert!(edge_idx <= left_len);
858-
left_len += 1;
859-
}
860-
InsertionPlace::Right(edge_idx) => {
861-
debug_assert!(edge_idx <= right_len);
862-
right_len += 1;
863-
}
840+
match edge_idx {
841+
0..EDGE_IDX_LEFT_OF_CENTER => (KV_IDX_CENTER - 1, InsertionPlace::Left(edge_idx)),
842+
EDGE_IDX_LEFT_OF_CENTER => (KV_IDX_CENTER, InsertionPlace::Left(edge_idx)),
843+
EDGE_IDX_RIGHT_OF_CENTER => (KV_IDX_CENTER, InsertionPlace::Right(0)),
844+
_ => (KV_IDX_CENTER + 1, InsertionPlace::Right(edge_idx - (KV_IDX_CENTER + 1 + 1))),
864845
}
865-
debug_assert!(left_len >= MIN_LEN);
866-
debug_assert!(right_len >= MIN_LEN);
867-
debug_assert!(left_len + right_len == CAPACITY);
868-
(middle_kv_idx, insertion)
869846
}
870847

871848
impl<'a, K, V, NodeType> Handle<NodeRef<marker::Mut<'a>, K, V, NodeType>, marker::Edge> {
@@ -1067,6 +1044,16 @@ impl<'a, K: 'a, V: 'a, NodeType> Handle<NodeRef<marker::Immut<'a>, K, V, NodeTyp
10671044
}
10681045

10691046
impl<'a, K: 'a, V: 'a, NodeType> Handle<NodeRef<marker::Mut<'a>, K, V, NodeType>, marker::KV> {
1047+
pub fn into_key_mut(self) -> &'a mut K {
1048+
let keys = self.node.into_key_slice_mut();
1049+
unsafe { keys.get_unchecked_mut(self.idx) }
1050+
}
1051+
1052+
pub fn into_val_mut(self) -> &'a mut V {
1053+
let vals = self.node.into_val_slice_mut();
1054+
unsafe { vals.get_unchecked_mut(self.idx) }
1055+
}
1056+
10701057
pub fn into_kv_mut(self) -> (&'a mut K, &'a mut V) {
10711058
unsafe {
10721059
let (keys, vals) = self.node.into_slices_mut();
@@ -1261,8 +1248,8 @@ impl<'a, K, V> Handle<NodeRef<marker::Mut<'a>, K, V, marker::Internal>, marker::
12611248
unsafe {
12621249
let (k, v, edge) = self.reborrow_mut().left_edge().descend().pop();
12631250

1264-
let k = mem::replace(self.reborrow_mut().into_kv_mut().0, k);
1265-
let v = mem::replace(self.reborrow_mut().into_kv_mut().1, v);
1251+
let k = mem::replace(self.kv_mut().0, k);
1252+
let v = mem::replace(self.kv_mut().1, v);
12661253

12671254
match self.reborrow_mut().right_edge().descend().force() {
12681255
ForceResult::Leaf(mut leaf) => leaf.push_front(k, v),
@@ -1278,8 +1265,8 @@ impl<'a, K, V> Handle<NodeRef<marker::Mut<'a>, K, V, marker::Internal>, marker::
12781265
unsafe {
12791266
let (k, v, edge) = self.reborrow_mut().right_edge().descend().pop_front();
12801267

1281-
let k = mem::replace(self.reborrow_mut().into_kv_mut().0, k);
1282-
let v = mem::replace(self.reborrow_mut().into_kv_mut().1, v);
1268+
let k = mem::replace(self.kv_mut().0, k);
1269+
let v = mem::replace(self.kv_mut().1, v);
12831270

12841271
match self.reborrow_mut().left_edge().descend().force() {
12851272
ForceResult::Leaf(mut leaf) => leaf.push(k, v),
@@ -1307,7 +1294,7 @@ impl<'a, K, V> Handle<NodeRef<marker::Mut<'a>, K, V, marker::Internal>, marker::
13071294
let left_kv = left_node.reborrow_mut().into_kv_pointers_mut();
13081295
let right_kv = right_node.reborrow_mut().into_kv_pointers_mut();
13091296
let parent_kv = {
1310-
let kv = self.reborrow_mut().into_kv_mut();
1297+
let kv = self.kv_mut();
13111298
(kv.0 as *mut K, kv.1 as *mut V)
13121299
};
13131300

@@ -1364,7 +1351,7 @@ impl<'a, K, V> Handle<NodeRef<marker::Mut<'a>, K, V, marker::Internal>, marker::
13641351
let left_kv = left_node.reborrow_mut().into_kv_pointers_mut();
13651352
let right_kv = right_node.reborrow_mut().into_kv_pointers_mut();
13661353
let parent_kv = {
1367-
let kv = self.reborrow_mut().into_kv_mut();
1354+
let kv = self.kv_mut();
13681355
(kv.0 as *mut K, kv.1 as *mut V)
13691356
};
13701357

@@ -1590,3 +1577,6 @@ unsafe fn slice_remove<T>(slice: &mut [T], idx: usize) -> T {
15901577
ret
15911578
}
15921579
}
1580+
1581+
#[cfg(test)]
1582+
mod tests;

Diff for: library/alloc/src/collections/btree/node/tests.rs

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
use super::*;
2+
3+
#[test]
4+
fn test_splitpoint() {
5+
for idx in 0..=CAPACITY {
6+
let (middle_kv_idx, insertion) = splitpoint(idx);
7+
8+
// Simulate performing the split:
9+
let mut left_len = middle_kv_idx;
10+
let mut right_len = CAPACITY - middle_kv_idx - 1;
11+
match insertion {
12+
InsertionPlace::Left(edge_idx) => {
13+
assert!(edge_idx <= left_len);
14+
left_len += 1;
15+
}
16+
InsertionPlace::Right(edge_idx) => {
17+
assert!(edge_idx <= right_len);
18+
right_len += 1;
19+
}
20+
}
21+
assert!(left_len >= MIN_LEN);
22+
assert!(right_len >= MIN_LEN);
23+
assert!(left_len + right_len == CAPACITY);
24+
}
25+
}

Diff for: library/alloc/src/collections/btree/set.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1572,3 +1572,6 @@ impl<'a, T: Ord> Iterator for Union<'a, T> {
15721572

15731573
#[stable(feature = "fused", since = "1.26.0")]
15741574
impl<T: Ord> FusedIterator for Union<'_, T> {}
1575+
1576+
#[cfg(test)]
1577+
mod tests;

Diff for: library/alloc/tests/btree/set.rs renamed to library/alloc/src/collections/btree/set/tests.rs

+3-20
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
use std::collections::BTreeSet;
1+
use crate::collections::BTreeSet;
2+
use crate::vec::Vec;
23
use std::iter::FromIterator;
34
use std::panic::{catch_unwind, AssertUnwindSafe};
45
use std::sync::atomic::{AtomicU32, Ordering};
56

6-
use super::DeterministicRng;
7+
use super::super::DeterministicRng;
78

89
#[test]
910
fn test_clone_eq() {
@@ -15,24 +16,6 @@ fn test_clone_eq() {
1516
assert_eq!(m.clone(), m);
1617
}
1718

18-
#[test]
19-
fn test_hash() {
20-
use crate::hash;
21-
22-
let mut x = BTreeSet::new();
23-
let mut y = BTreeSet::new();
24-
25-
x.insert(1);
26-
x.insert(2);
27-
x.insert(3);
28-
29-
y.insert(3);
30-
y.insert(2);
31-
y.insert(1);
32-
33-
assert_eq!(hash(&x), hash(&y));
34-
}
35-
3619
#[test]
3720
fn test_iter_min_max() {
3821
let mut a = BTreeSet::new();

Diff for: library/alloc/src/lib.rs

+4
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@
8080
#![feature(arbitrary_self_types)]
8181
#![feature(box_patterns)]
8282
#![feature(box_syntax)]
83+
#![feature(btree_drain_filter)]
8384
#![feature(cfg_sanitize)]
8485
#![feature(cfg_target_has_atomic)]
8586
#![feature(coerce_unsized)]
@@ -93,6 +94,7 @@
9394
#![feature(container_error_extra)]
9495
#![feature(dropck_eyepatch)]
9596
#![feature(exact_size_is_empty)]
97+
#![feature(exclusive_range_pattern)]
9698
#![feature(extend_one)]
9799
#![feature(fmt_internals)]
98100
#![feature(fn_traits)]
@@ -101,6 +103,8 @@
101103
#![feature(lang_items)]
102104
#![feature(layout_for_ptr)]
103105
#![feature(libc)]
106+
#![feature(map_first_last)]
107+
#![feature(map_into_keys_values)]
104108
#![feature(negative_impls)]
105109
#![feature(new_uninit)]
106110
#![feature(nll)]

Diff for: library/alloc/src/vec.rs

+3-12
Original file line numberDiff line numberDiff line change
@@ -2620,9 +2620,6 @@ where
26202620
///
26212621
/// This `struct` is created by the `into_iter` method on [`Vec`] (provided
26222622
/// by the [`IntoIterator`] trait).
2623-
///
2624-
/// [`Vec`]: struct.Vec.html
2625-
/// [`IntoIterator`]: ../../std/iter/trait.IntoIterator.html
26262623
#[stable(feature = "rust1", since = "1.0.0")]
26272624
pub struct IntoIter<T> {
26282625
buf: NonNull<T>,
@@ -2802,10 +2799,7 @@ unsafe impl<#[may_dangle] T> Drop for IntoIter<T> {
28022799

28032800
/// A draining iterator for `Vec<T>`.
28042801
///
2805-
/// This `struct` is created by the [`drain`] method on [`Vec`].
2806-
///
2807-
/// [`drain`]: struct.Vec.html#method.drain
2808-
/// [`Vec`]: struct.Vec.html
2802+
/// This `struct` is created by [`Vec::drain`].
28092803
#[stable(feature = "drain", since = "1.6.0")]
28102804
pub struct Drain<'a, T: 'a> {
28112805
/// Index of tail to preserve
@@ -2933,11 +2927,8 @@ impl<T> FusedIterator for Drain<'_, T> {}
29332927

29342928
/// A splicing iterator for `Vec`.
29352929
///
2936-
/// This struct is created by the [`splice()`] method on [`Vec`]. See its
2937-
/// documentation for more.
2938-
///
2939-
/// [`splice()`]: struct.Vec.html#method.splice
2940-
/// [`Vec`]: struct.Vec.html
2930+
/// This struct is created by [`Vec::splice()`].
2931+
/// See its documentation for more.
29412932
#[derive(Debug)]
29422933
#[stable(feature = "vec_splice", since = "1.21.0")]
29432934
pub struct Splice<'a, I: Iterator + 'a> {

Diff for: library/alloc/tests/btree/mod.rs

-27
This file was deleted.

Diff for: library/alloc/tests/btree_set_hash.rs

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
use std::collections::BTreeSet;
2+
3+
#[test]
4+
fn test_hash() {
5+
use crate::hash;
6+
7+
let mut x = BTreeSet::new();
8+
let mut y = BTreeSet::new();
9+
10+
x.insert(1);
11+
x.insert(2);
12+
x.insert(3);
13+
14+
y.insert(3);
15+
y.insert(2);
16+
y.insert(1);
17+
18+
assert_eq!(hash(&x), hash(&y));
19+
}

0 commit comments

Comments
 (0)