Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 17 pull requests #75538

Merged
merged 46 commits into from
Aug 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
6293dca
Change Debug impl of SocketAddr and IpAddr to match their Display output
LukasKalbertodt Jul 16, 2020
3a02e06
BTreeMap: purge innocent use of into_kv_mut
ssomers Aug 5, 2020
e005b71
Switch to intra-doc links in `std::process`
camelid Aug 12, 2020
d8f9614
Use `Child::std{in,out,err}` instead of `Child.`
camelid Aug 12, 2020
bbad31d
Clean up E0752 explanation
GuillaumeGomez Aug 13, 2020
406719b
Improve wording
GuillaumeGomez Aug 13, 2020
0ce97fc
Fix code examples
GuillaumeGomez Aug 13, 2020
2adc8c0
Move to intra doc links in std::ffi
poliorcetics Aug 13, 2020
643258f
Tweak suggestion for `this` -> `self`
estebank Aug 14, 2020
360388b
Suggest adding `&self` when accessing `self` in static assoc `fn`
estebank Aug 14, 2020
b77c40e
Do not emit E0228 when it is implied by E0106
estebank Aug 14, 2020
dba647e
Remove liballoc unneeded explicit link
pickfire Jul 9, 2020
e0d215f
Update src/liballoc/vec.rs
pickfire Jul 23, 2020
d2ecfcf
Update liballoc vec doc link
pickfire Jul 24, 2020
28bca67
Bump std's libc version to 0.2.74
workingjubilee Aug 14, 2020
6e11329
mention 'lifetime extension' in promotion doc comments
RalfJung Aug 14, 2020
7805c20
answer an old question re: intern kinds
RalfJung Aug 14, 2020
d0d9048
add a FIXME concerning interning of promoteds
RalfJung Aug 14, 2020
90e4c90
Improve documentation on process::Child.std* fields
xkr47 Jul 9, 2020
421e0ff
BTreeMap: refactor splitpoint and move testing over to unit test
ssomers Aug 14, 2020
8d1c3c1
BTreeMap: refactor splitpoint and move testing over to unit test
ssomers Aug 14, 2020
232e3d0
Switch to intra-doc links in os/raw/*.md
nixphix Aug 14, 2020
ff45df2
Move btree unit test to their native, privileged location
ssomers Aug 14, 2020
84539eb
remove primitive type links
nixphix Aug 14, 2020
ee4f893
Apply suggestions from code review
poliorcetics Aug 14, 2020
4ecdec1
review comment: suggestion message wording
estebank Aug 14, 2020
e97fa1e
libstd/ffi/c_str.rs: #![deny(unsafe_op_in_unsafe_fn)], enclose unsafe…
poliorcetics Aug 14, 2020
61866bc
Use intra-doc links in `mem::manually_drop` & `mem::maybe_uninit`
Aug 6, 2020
0e610bb
Document the unsafe keyword
poliorcetics Aug 14, 2020
f163ec5
Rollup merge of #73943 - poliorcetics:unsafe-keyword, r=steveklabnik
tmandry Aug 14, 2020
fba3989
Rollup merge of #74062 - poliorcetics:unsafe-in-unsafe-c_str, r=Mark-…
tmandry Aug 14, 2020
3111a8c
Rollup merge of #74185 - pickfire:liballoc-iter-doc, r=jyn514
tmandry Aug 14, 2020
dae020d
Rollup merge of #74192 - xkr47:patch-1, r=Mark-Simulacrum
tmandry Aug 14, 2020
5b61230
Rollup merge of #74409 - LukasKalbertodt:improve-debug-impl-of-socket…
tmandry Aug 14, 2020
83e75ac
Rollup merge of #75195 - ssomers:btree_split_up_into_kv_mut, r=Mark-S…
tmandry Aug 14, 2020
ad8c5e1
Rollup merge of #75214 - chansuke:fix-intra-doc-links, r=jyn514
tmandry Aug 14, 2020
b026181
Rollup merge of #75432 - camelid:intra-doc-links-for-std-process, r=j…
tmandry Aug 14, 2020
1cf79ec
Rollup merge of #75482 - GuillaumeGomez:cleanup-e0752, r=pickfire
tmandry Aug 14, 2020
ad1bfd2
Rollup merge of #75501 - poliorcetics:intra-links-std-ffi, r=jyn514
tmandry Aug 14, 2020
2fb2af4
Rollup merge of #75509 - estebank:coming-merrily-from-java-land, r=lcnr
tmandry Aug 14, 2020
0c8c3b9
Rollup merge of #75511 - estebank:elide-trait-object-lt-error, r=lcnr
tmandry Aug 14, 2020
83c0439
Rollup merge of #75515 - workingjubilee:patch-4, r=Mark-Simulacrum
tmandry Aug 14, 2020
00e2dcb
Rollup merge of #75517 - RalfJung:promo-intern-comments, r=oli-obk
tmandry Aug 14, 2020
2564135
Rollup merge of #75519 - ssomers:btree_splitpoint_cleanup, r=Mark-Sim…
tmandry Aug 14, 2020
6d09e29
Rollup merge of #75530 - nixphix:docs/os-raw, r=jyn514
tmandry Aug 14, 2020
939befd
Rollup merge of #75531 - ssomers:btree_tests_migration, r=Mark-Simula…
tmandry Aug 14, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions library/alloc/src/collections/btree/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ where
fn replace(&mut self, key: K) -> Option<K> {
let root = Self::ensure_is_owned(&mut self.root);
match search::search_tree::<marker::Mut<'_>, K, (), K>(root.node_as_mut(), &key) {
Found(handle) => Some(mem::replace(handle.into_kv_mut().0, key)),
Found(handle) => Some(mem::replace(handle.into_key_mut(), key)),
GoDown(handle) => {
VacantEntry { key, handle, length: &mut self.length, _marker: PhantomData }
.insert(());
Expand Down Expand Up @@ -811,7 +811,7 @@ impl<K: Ord, V> BTreeMap<K, V> {
{
let root_node = self.root.as_mut()?.node_as_mut();
match search::search_tree(root_node, key) {
Found(handle) => Some(handle.into_kv_mut().1),
Found(handle) => Some(handle.into_val_mut()),
GoDown(_) => None,
}
}
Expand Down Expand Up @@ -2748,7 +2748,7 @@ impl<'a, K: Ord, V> OccupiedEntry<'a, K, V> {
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn into_mut(self) -> &'a mut V {
self.handle.into_kv_mut().1
self.handle.into_val_mut()
}

/// Sets the value of the entry with the `OccupiedEntry`'s key,
Expand Down Expand Up @@ -3024,3 +3024,6 @@ impl<K: Ord, V, I: Iterator<Item = (K, V)>> Iterator for MergeIter<K, V, I> {
}
}
}

#[cfg(test)]
mod tests;
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
use std::collections::btree_map::Entry::{Occupied, Vacant};
use std::collections::BTreeMap;
use crate::boxed::Box;
use crate::collections::btree_map::Entry::{Occupied, Vacant};
use crate::collections::BTreeMap;
use crate::fmt::Debug;
use crate::rc::Rc;
use crate::string::String;
use crate::string::ToString;
use crate::vec::Vec;
use std::convert::TryFrom;
use std::fmt::Debug;
use std::iter::FromIterator;
use std::mem;
use std::ops::Bound::{self, Excluded, Included, Unbounded};
use std::ops::RangeBounds;
use std::panic::{catch_unwind, AssertUnwindSafe};
use std::rc::Rc;
use std::sync::atomic::{AtomicUsize, Ordering};

use super::DeterministicRng;
use super::super::DeterministicRng;

// Value of node::CAPACITY, thus capacity of a tree with a single level,
// i.e. a tree who's root is a leaf node at height 0.
Expand Down
27 changes: 27 additions & 0 deletions library/alloc/src/collections/btree/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,30 @@ pub unsafe fn unwrap_unchecked<T>(val: Option<T>) -> T {
}
})
}

#[cfg(test)]
/// XorShiftRng
struct DeterministicRng {
x: u32,
y: u32,
z: u32,
w: u32,
}

#[cfg(test)]
impl DeterministicRng {
fn new() -> Self {
DeterministicRng { x: 0x193a6754, y: 0xa8a7d469, z: 0x97830e05, w: 0x113ba7bb }
}

fn next(&mut self) -> u32 {
let x = self.x;
let t = x ^ (x << 11);
self.x = self.y;
self.y = self.z;
self.z = self.w;
let w_ = self.w;
self.w = w_ ^ (w_ >> 19) ^ (t ^ (t >> 8));
self.w
}
}
64 changes: 27 additions & 37 deletions library/alloc/src/collections/btree/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ use crate::boxed::Box;
const B: usize = 6;
pub const MIN_LEN: usize = B - 1;
pub const CAPACITY: usize = 2 * B - 1;
const KV_IDX_CENTER: usize = B - 1;
const EDGE_IDX_LEFT_OF_CENTER: usize = B - 1;
const EDGE_IDX_RIGHT_OF_CENTER: usize = B;

/// The underlying representation of leaf nodes.
#[repr(C)]
Expand Down Expand Up @@ -834,38 +837,12 @@ enum InsertionPlace {
fn splitpoint(edge_idx: usize) -> (usize, InsertionPlace) {
debug_assert!(edge_idx <= CAPACITY);
// Rust issue #74834 tries to explain these symmetric rules.
let middle_kv_idx;
let insertion;
if edge_idx <= B - 2 {
middle_kv_idx = B - 2;
insertion = InsertionPlace::Left(edge_idx);
} else if edge_idx == B - 1 {
middle_kv_idx = B - 1;
insertion = InsertionPlace::Left(edge_idx);
} else if edge_idx == B {
middle_kv_idx = B - 1;
insertion = InsertionPlace::Right(0);
} else {
middle_kv_idx = B;
let new_edge_idx = edge_idx - (B + 1);
insertion = InsertionPlace::Right(new_edge_idx);
}
let mut left_len = middle_kv_idx;
let mut right_len = CAPACITY - middle_kv_idx - 1;
match insertion {
InsertionPlace::Left(edge_idx) => {
debug_assert!(edge_idx <= left_len);
left_len += 1;
}
InsertionPlace::Right(edge_idx) => {
debug_assert!(edge_idx <= right_len);
right_len += 1;
}
match edge_idx {
0..EDGE_IDX_LEFT_OF_CENTER => (KV_IDX_CENTER - 1, InsertionPlace::Left(edge_idx)),
EDGE_IDX_LEFT_OF_CENTER => (KV_IDX_CENTER, InsertionPlace::Left(edge_idx)),
EDGE_IDX_RIGHT_OF_CENTER => (KV_IDX_CENTER, InsertionPlace::Right(0)),
_ => (KV_IDX_CENTER + 1, InsertionPlace::Right(edge_idx - (KV_IDX_CENTER + 1 + 1))),
}
debug_assert!(left_len >= MIN_LEN);
debug_assert!(right_len >= MIN_LEN);
debug_assert!(left_len + right_len == CAPACITY);
(middle_kv_idx, insertion)
}

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

impl<'a, K: 'a, V: 'a, NodeType> Handle<NodeRef<marker::Mut<'a>, K, V, NodeType>, marker::KV> {
pub fn into_key_mut(self) -> &'a mut K {
let keys = self.node.into_key_slice_mut();
unsafe { keys.get_unchecked_mut(self.idx) }
}

pub fn into_val_mut(self) -> &'a mut V {
let vals = self.node.into_val_slice_mut();
unsafe { vals.get_unchecked_mut(self.idx) }
}

pub fn into_kv_mut(self) -> (&'a mut K, &'a mut V) {
unsafe {
let (keys, vals) = self.node.into_slices_mut();
Expand Down Expand Up @@ -1261,8 +1248,8 @@ impl<'a, K, V> Handle<NodeRef<marker::Mut<'a>, K, V, marker::Internal>, marker::
unsafe {
let (k, v, edge) = self.reborrow_mut().left_edge().descend().pop();

let k = mem::replace(self.reborrow_mut().into_kv_mut().0, k);
let v = mem::replace(self.reborrow_mut().into_kv_mut().1, v);
let k = mem::replace(self.kv_mut().0, k);
let v = mem::replace(self.kv_mut().1, v);

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

let k = mem::replace(self.reborrow_mut().into_kv_mut().0, k);
let v = mem::replace(self.reborrow_mut().into_kv_mut().1, v);
let k = mem::replace(self.kv_mut().0, k);
let v = mem::replace(self.kv_mut().1, v);

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

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

Expand Down Expand Up @@ -1590,3 +1577,6 @@ unsafe fn slice_remove<T>(slice: &mut [T], idx: usize) -> T {
ret
}
}

#[cfg(test)]
mod tests;
25 changes: 25 additions & 0 deletions library/alloc/src/collections/btree/node/tests.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
use super::*;

#[test]
fn test_splitpoint() {
for idx in 0..=CAPACITY {
let (middle_kv_idx, insertion) = splitpoint(idx);

// Simulate performing the split:
let mut left_len = middle_kv_idx;
let mut right_len = CAPACITY - middle_kv_idx - 1;
match insertion {
InsertionPlace::Left(edge_idx) => {
assert!(edge_idx <= left_len);
left_len += 1;
}
InsertionPlace::Right(edge_idx) => {
assert!(edge_idx <= right_len);
right_len += 1;
}
}
assert!(left_len >= MIN_LEN);
assert!(right_len >= MIN_LEN);
assert!(left_len + right_len == CAPACITY);
}
}
3 changes: 3 additions & 0 deletions library/alloc/src/collections/btree/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1572,3 +1572,6 @@ impl<'a, T: Ord> Iterator for Union<'a, T> {

#[stable(feature = "fused", since = "1.26.0")]
impl<T: Ord> FusedIterator for Union<'_, T> {}

#[cfg(test)]
mod tests;
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use std::collections::BTreeSet;
use crate::collections::BTreeSet;
use crate::vec::Vec;
use std::iter::FromIterator;
use std::panic::{catch_unwind, AssertUnwindSafe};
use std::sync::atomic::{AtomicU32, Ordering};

use super::DeterministicRng;
use super::super::DeterministicRng;

#[test]
fn test_clone_eq() {
Expand All @@ -15,24 +16,6 @@ fn test_clone_eq() {
assert_eq!(m.clone(), m);
}

#[test]
fn test_hash() {
use crate::hash;

let mut x = BTreeSet::new();
let mut y = BTreeSet::new();

x.insert(1);
x.insert(2);
x.insert(3);

y.insert(3);
y.insert(2);
y.insert(1);

assert_eq!(hash(&x), hash(&y));
}

#[test]
fn test_iter_min_max() {
let mut a = BTreeSet::new();
Expand Down
4 changes: 4 additions & 0 deletions library/alloc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
#![feature(arbitrary_self_types)]
#![feature(box_patterns)]
#![feature(box_syntax)]
#![feature(btree_drain_filter)]
#![feature(cfg_sanitize)]
#![feature(cfg_target_has_atomic)]
#![feature(coerce_unsized)]
Expand All @@ -93,6 +94,7 @@
#![feature(container_error_extra)]
#![feature(dropck_eyepatch)]
#![feature(exact_size_is_empty)]
#![feature(exclusive_range_pattern)]
#![feature(extend_one)]
#![feature(fmt_internals)]
#![feature(fn_traits)]
Expand All @@ -101,6 +103,8 @@
#![feature(lang_items)]
#![feature(layout_for_ptr)]
#![feature(libc)]
#![feature(map_first_last)]
#![feature(map_into_keys_values)]
#![feature(negative_impls)]
#![feature(new_uninit)]
#![feature(nll)]
Expand Down
15 changes: 3 additions & 12 deletions library/alloc/src/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2620,9 +2620,6 @@ where
///
/// This `struct` is created by the `into_iter` method on [`Vec`] (provided
/// by the [`IntoIterator`] trait).
///
/// [`Vec`]: struct.Vec.html
/// [`IntoIterator`]: ../../std/iter/trait.IntoIterator.html
#[stable(feature = "rust1", since = "1.0.0")]
pub struct IntoIter<T> {
buf: NonNull<T>,
Expand Down Expand Up @@ -2802,10 +2799,7 @@ unsafe impl<#[may_dangle] T> Drop for IntoIter<T> {

/// A draining iterator for `Vec<T>`.
///
/// This `struct` is created by the [`drain`] method on [`Vec`].
///
/// [`drain`]: struct.Vec.html#method.drain
/// [`Vec`]: struct.Vec.html
/// This `struct` is created by [`Vec::drain`].
#[stable(feature = "drain", since = "1.6.0")]
pub struct Drain<'a, T: 'a> {
/// Index of tail to preserve
Expand Down Expand Up @@ -2933,11 +2927,8 @@ impl<T> FusedIterator for Drain<'_, T> {}

/// A splicing iterator for `Vec`.
///
/// This struct is created by the [`splice()`] method on [`Vec`]. See its
/// documentation for more.
///
/// [`splice()`]: struct.Vec.html#method.splice
/// [`Vec`]: struct.Vec.html
/// This struct is created by [`Vec::splice()`].
/// See its documentation for more.
#[derive(Debug)]
#[stable(feature = "vec_splice", since = "1.21.0")]
pub struct Splice<'a, I: Iterator + 'a> {
Expand Down
27 changes: 0 additions & 27 deletions library/alloc/tests/btree/mod.rs

This file was deleted.

19 changes: 19 additions & 0 deletions library/alloc/tests/btree_set_hash.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
use std::collections::BTreeSet;

#[test]
fn test_hash() {
use crate::hash;

let mut x = BTreeSet::new();
let mut y = BTreeSet::new();

x.insert(1);
x.insert(2);
x.insert(3);

y.insert(3);
y.insert(2);
y.insert(1);

assert_eq!(hash(&x), hash(&y));
}
Loading