Skip to content

Commit 32da90b

Browse files
committed
Auto merge of rust-lang#79319 - m-ou-se:rollup-d9n5viq, r=m-ou-se
Rollup of 10 pull requests Successful merges: - rust-lang#76941 (Add f{32,64}::is_subnormal) - rust-lang#77697 (Split each iterator adapter and source into individual modules) - rust-lang#78305 (Stabilize alloc::Layout const functions) - rust-lang#78608 (Stabilize refcell_take) - rust-lang#78793 (Clean up `StructuralEq` docs) - rust-lang#79267 (BTreeMap: address namespace conflicts) - rust-lang#79293 (Add test for eval order for a+=b) - rust-lang#79295 (BTreeMap: fix minor testing mistakes in rust-lang#78903) - rust-lang#79297 (BTreeMap: swap the names of NodeRef::new and Root::new_leaf) - rust-lang#79299 (Stabilise `then`) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents a0d664b + 41c033b commit 32da90b

Some content is hidden

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

53 files changed

+3777
-3550
lines changed

compiler/rustc_index/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#![feature(allow_internal_unstable)]
2-
#![feature(bool_to_option)]
32
#![feature(const_fn)]
43
#![feature(const_panic)]
54
#![feature(extend_one)]

compiler/rustc_metadata/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
2-
#![feature(bool_to_option)]
32
#![feature(core_intrinsics)]
43
#![feature(crate_visibility_modifier)]
54
#![feature(drain_filter)]

compiler/rustc_parse/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
//! The main parser interface.
22
3-
#![feature(bool_to_option)]
43
#![feature(crate_visibility_modifier)]
54
#![feature(bindings_after_at)]
65
#![feature(iter_order_by)]

library/alloc/src/collections/btree/append.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ impl<K, V> Root<K, V> {
6767

6868
// Push key-value pair and new right subtree.
6969
let tree_height = open_node.height() - 1;
70-
let mut right_tree = Root::new_leaf();
70+
let mut right_tree = Root::new();
7171
for _ in 0..tree_height {
7272
right_tree.push_internal_level();
7373
}

library/alloc/src/collections/btree/map.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use core::ops::{Index, RangeBounds};
99
use core::ptr;
1010

1111
use super::borrow::DormantMutRef;
12-
use super::node::{self, marker, ForceResult::*, Handle, NodeRef};
12+
use super::node::{self, marker, ForceResult::*, Handle, NodeRef, Root};
1313
use super::search::{self, SearchResult::*};
1414
use super::unwrap_unchecked;
1515

@@ -128,7 +128,7 @@ pub(super) const MIN_LEN: usize = node::MIN_LEN_AFTER_SPLIT;
128128
/// ```
129129
#[stable(feature = "rust1", since = "1.0.0")]
130130
pub struct BTreeMap<K, V> {
131-
root: Option<node::Root<K, V>>,
131+
root: Option<Root<K, V>>,
132132
length: usize,
133133
}
134134

@@ -145,15 +145,15 @@ unsafe impl<#[may_dangle] K, #[may_dangle] V> Drop for BTreeMap<K, V> {
145145
impl<K: Clone, V: Clone> Clone for BTreeMap<K, V> {
146146
fn clone(&self) -> BTreeMap<K, V> {
147147
fn clone_subtree<'a, K: Clone, V: Clone>(
148-
node: node::NodeRef<marker::Immut<'a>, K, V, marker::LeafOrInternal>,
148+
node: NodeRef<marker::Immut<'a>, K, V, marker::LeafOrInternal>,
149149
) -> BTreeMap<K, V>
150150
where
151151
K: 'a,
152152
V: 'a,
153153
{
154154
match node.force() {
155155
Leaf(leaf) => {
156-
let mut out_tree = BTreeMap { root: Some(node::Root::new_leaf()), length: 0 };
156+
let mut out_tree = BTreeMap { root: Some(Root::new()), length: 0 };
157157

158158
{
159159
let root = out_tree.root.as_mut().unwrap(); // unwrap succeeds because we just wrapped
@@ -198,7 +198,7 @@ impl<K: Clone, V: Clone> Clone for BTreeMap<K, V> {
198198
(root, length)
199199
};
200200

201-
out_node.push(k, v, subroot.unwrap_or_else(node::Root::new_leaf));
201+
out_node.push(k, v, subroot.unwrap_or_else(Root::new));
202202
out_tree.length += 1 + sublength;
203203
}
204204
}
@@ -1558,7 +1558,7 @@ pub(super) struct DrainFilterInner<'a, K: 'a, V: 'a> {
15581558
length: &'a mut usize,
15591559
/// Burried reference to the root field in the borrowed map.
15601560
/// Wrapped in `Option` to allow drop handler to `take` it.
1561-
dormant_root: Option<DormantMutRef<'a, node::Root<K, V>>>,
1561+
dormant_root: Option<DormantMutRef<'a, Root<K, V>>>,
15621562
/// Contains a leaf edge preceding the next element to be returned, or the last leaf edge.
15631563
/// Empty if the map has no root, if iteration went beyond the last leaf edge,
15641564
/// or if a panic occurred in the predicate.
@@ -2160,8 +2160,8 @@ impl<K, V> BTreeMap<K, V> {
21602160

21612161
/// If the root node is the empty (non-allocated) root node, allocate our
21622162
/// own node. Is an associated function to avoid borrowing the entire BTreeMap.
2163-
fn ensure_is_owned(root: &mut Option<node::Root<K, V>>) -> &mut node::Root<K, V> {
2164-
root.get_or_insert_with(node::Root::new_leaf)
2163+
fn ensure_is_owned(root: &mut Option<Root<K, V>>) -> &mut Root<K, V> {
2164+
root.get_or_insert_with(Root::new)
21652165
}
21662166
}
21672167

library/alloc/src/collections/btree/map/tests.rs

+32-39
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@ use crate::fmt::Debug;
66
use crate::rc::Rc;
77
use crate::string::{String, ToString};
88
use crate::vec::Vec;
9+
use std::cmp::Ordering;
910
use std::convert::TryFrom;
1011
use std::iter::{self, FromIterator};
1112
use std::mem;
1213
use std::ops::Bound::{self, Excluded, Included, Unbounded};
1314
use std::ops::RangeBounds;
1415
use std::panic::{catch_unwind, AssertUnwindSafe};
15-
use std::sync::atomic::{AtomicUsize, Ordering};
16+
use std::sync::atomic::{AtomicUsize, Ordering::SeqCst};
1617

1718
mod ord_chaos;
1819
use ord_chaos::{Cyclic3, Governed, Governor};
@@ -56,24 +57,23 @@ impl<K, V> BTreeMap<K, V> {
5657
assert!(root_node.ascend().is_err());
5758
root_node.assert_back_pointers();
5859

59-
// Check consistenty of `length` and some of the navigation.
60+
// Check consistency of `length` with what navigation code encounters.
6061
assert_eq!(self.length, root_node.calc_length());
61-
assert_eq!(self.length, self.keys().count());
6262

6363
// Lastly, check the invariant causing the least harm.
6464
root_node.assert_min_len(if root_node.height() > 0 { 1 } else { 0 });
6565
} else {
66-
// Check consistenty of `length` and some of the navigation.
6766
assert_eq!(self.length, 0);
68-
assert_eq!(self.length, self.keys().count());
6967
}
68+
69+
// Check that `assert_strictly_ascending` will encounter all keys.
70+
assert_eq!(self.length, self.keys().count());
7071
}
7172

7273
// Panics if the map is corrupted or if the keys are not in strictly
7374
// ascending order, in the current opinion of the `Ord` implementation.
74-
// If the `Ord` implementation does not honor transitivity, this method
75-
// does not guarantee that all the keys are unique, just that adjacent
76-
// keys are unique.
75+
// If the `Ord` implementation violates transitivity, this method does not
76+
// guarantee that all keys are unique, just that adjacent keys are unique.
7777
fn check(&self)
7878
where
7979
K: Debug + Ord,
@@ -879,6 +879,7 @@ mod test_drain_filter {
879879
map.check();
880880
}
881881

882+
// Explicitly consumes the iterator, where most test cases drop it instantly.
882883
#[test]
883884
fn consumed_keeping_all() {
884885
let pairs = (0..3).map(|i| (i, i));
@@ -887,6 +888,7 @@ mod test_drain_filter {
887888
map.check();
888889
}
889890

891+
// Explicitly consumes the iterator, where most test cases drop it instantly.
890892
#[test]
891893
fn consumed_removing_all() {
892894
let pairs = (0..3).map(|i| (i, i));
@@ -896,15 +898,7 @@ mod test_drain_filter {
896898
map.check();
897899
}
898900

899-
#[test]
900-
fn dropped_removing_all() {
901-
let pairs = (0..3).map(|i| (i, i));
902-
let mut map: BTreeMap<_, _> = pairs.collect();
903-
map.drain_filter(|_, _| true);
904-
assert!(map.is_empty());
905-
map.check();
906-
}
907-
901+
// Explicitly consumes the iterator and modifies values through it.
908902
#[test]
909903
fn mutating_and_keeping() {
910904
let pairs = (0..3).map(|i| (i, i));
@@ -921,6 +915,7 @@ mod test_drain_filter {
921915
map.check();
922916
}
923917

918+
// Explicitly consumes the iterator and modifies values through it.
924919
#[test]
925920
fn mutating_and_removing() {
926921
let pairs = (0..3).map(|i| (i, i));
@@ -1094,7 +1089,7 @@ mod test_drain_filter {
10941089
struct D;
10951090
impl Drop for D {
10961091
fn drop(&mut self) {
1097-
if DROPS.fetch_add(1, Ordering::SeqCst) == 1 {
1092+
if DROPS.fetch_add(1, SeqCst) == 1 {
10981093
panic!("panic in `drop`");
10991094
}
11001095
}
@@ -1105,14 +1100,14 @@ mod test_drain_filter {
11051100

11061101
catch_unwind(move || {
11071102
drop(map.drain_filter(|i, _| {
1108-
PREDS.fetch_add(1usize << i, Ordering::SeqCst);
1103+
PREDS.fetch_add(1usize << i, SeqCst);
11091104
true
11101105
}))
11111106
})
11121107
.unwrap_err();
11131108

1114-
assert_eq!(PREDS.load(Ordering::SeqCst), 0x011);
1115-
assert_eq!(DROPS.load(Ordering::SeqCst), 3);
1109+
assert_eq!(PREDS.load(SeqCst), 0x011);
1110+
assert_eq!(DROPS.load(SeqCst), 3);
11161111
}
11171112

11181113
#[test]
@@ -1123,7 +1118,7 @@ mod test_drain_filter {
11231118
struct D;
11241119
impl Drop for D {
11251120
fn drop(&mut self) {
1126-
DROPS.fetch_add(1, Ordering::SeqCst);
1121+
DROPS.fetch_add(1, SeqCst);
11271122
}
11281123
}
11291124

@@ -1132,7 +1127,7 @@ mod test_drain_filter {
11321127

11331128
catch_unwind(AssertUnwindSafe(|| {
11341129
drop(map.drain_filter(|i, _| {
1135-
PREDS.fetch_add(1usize << i, Ordering::SeqCst);
1130+
PREDS.fetch_add(1usize << i, SeqCst);
11361131
match i {
11371132
0 => true,
11381133
_ => panic!(),
@@ -1141,8 +1136,8 @@ mod test_drain_filter {
11411136
}))
11421137
.unwrap_err();
11431138

1144-
assert_eq!(PREDS.load(Ordering::SeqCst), 0x011);
1145-
assert_eq!(DROPS.load(Ordering::SeqCst), 1);
1139+
assert_eq!(PREDS.load(SeqCst), 0x011);
1140+
assert_eq!(DROPS.load(SeqCst), 1);
11461141
assert_eq!(map.len(), 2);
11471142
assert_eq!(map.first_entry().unwrap().key(), &4);
11481143
assert_eq!(map.last_entry().unwrap().key(), &8);
@@ -1158,7 +1153,7 @@ mod test_drain_filter {
11581153
struct D;
11591154
impl Drop for D {
11601155
fn drop(&mut self) {
1161-
DROPS.fetch_add(1, Ordering::SeqCst);
1156+
DROPS.fetch_add(1, SeqCst);
11621157
}
11631158
}
11641159

@@ -1167,7 +1162,7 @@ mod test_drain_filter {
11671162

11681163
{
11691164
let mut it = map.drain_filter(|i, _| {
1170-
PREDS.fetch_add(1usize << i, Ordering::SeqCst);
1165+
PREDS.fetch_add(1usize << i, SeqCst);
11711166
match i {
11721167
0 => true,
11731168
_ => panic!(),
@@ -1180,8 +1175,8 @@ mod test_drain_filter {
11801175
assert!(matches!(result, Ok(None)));
11811176
}
11821177

1183-
assert_eq!(PREDS.load(Ordering::SeqCst), 0x011);
1184-
assert_eq!(DROPS.load(Ordering::SeqCst), 1);
1178+
assert_eq!(PREDS.load(SeqCst), 0x011);
1179+
assert_eq!(DROPS.load(SeqCst), 1);
11851180
assert_eq!(map.len(), 2);
11861181
assert_eq!(map.first_entry().unwrap().key(), &4);
11871182
assert_eq!(map.last_entry().unwrap().key(), &8);
@@ -1315,8 +1310,6 @@ fn test_zst() {
13151310
// undefined.
13161311
#[test]
13171312
fn test_bad_zst() {
1318-
use std::cmp::Ordering;
1319-
13201313
#[derive(Clone, Copy, Debug)]
13211314
struct Bad;
13221315

@@ -1763,7 +1756,7 @@ fn test_append_drop_leak() {
17631756

17641757
impl Drop for D {
17651758
fn drop(&mut self) {
1766-
if DROPS.fetch_add(1, Ordering::SeqCst) == 0 {
1759+
if DROPS.fetch_add(1, SeqCst) == 0 {
17671760
panic!("panic in `drop`");
17681761
}
17691762
}
@@ -1779,7 +1772,7 @@ fn test_append_drop_leak() {
17791772

17801773
catch_unwind(move || left.append(&mut right)).unwrap_err();
17811774

1782-
assert_eq!(DROPS.load(Ordering::SeqCst), 4); // Rust issue #47949 ate one little piggy
1775+
assert_eq!(DROPS.load(SeqCst), 4); // Rust issue #47949 ate one little piggy
17831776
}
17841777

17851778
#[test]
@@ -1894,7 +1887,7 @@ fn test_into_iter_drop_leak_height_0() {
18941887

18951888
impl Drop for D {
18961889
fn drop(&mut self) {
1897-
if DROPS.fetch_add(1, Ordering::SeqCst) == 3 {
1890+
if DROPS.fetch_add(1, SeqCst) == 3 {
18981891
panic!("panic in `drop`");
18991892
}
19001893
}
@@ -1909,7 +1902,7 @@ fn test_into_iter_drop_leak_height_0() {
19091902

19101903
catch_unwind(move || drop(map.into_iter())).unwrap_err();
19111904

1912-
assert_eq!(DROPS.load(Ordering::SeqCst), 5);
1905+
assert_eq!(DROPS.load(SeqCst), 5);
19131906
}
19141907

19151908
#[test]
@@ -1921,18 +1914,18 @@ fn test_into_iter_drop_leak_height_1() {
19211914
struct D;
19221915
impl Drop for D {
19231916
fn drop(&mut self) {
1924-
if DROPS.fetch_add(1, Ordering::SeqCst) == PANIC_POINT.load(Ordering::SeqCst) {
1917+
if DROPS.fetch_add(1, SeqCst) == PANIC_POINT.load(SeqCst) {
19251918
panic!("panic in `drop`");
19261919
}
19271920
}
19281921
}
19291922

19301923
for panic_point in vec![0, 1, size - 2, size - 1] {
1931-
DROPS.store(0, Ordering::SeqCst);
1932-
PANIC_POINT.store(panic_point, Ordering::SeqCst);
1924+
DROPS.store(0, SeqCst);
1925+
PANIC_POINT.store(panic_point, SeqCst);
19331926
let map: BTreeMap<_, _> = (0..size).map(|i| (i, D)).collect();
19341927
catch_unwind(move || drop(map.into_iter())).unwrap_err();
1935-
assert_eq!(DROPS.load(Ordering::SeqCst), size);
1928+
assert_eq!(DROPS.load(SeqCst), size);
19361929
}
19371930
}
19381931

library/alloc/src/collections/btree/map/tests/ord_chaos.rs

+5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use std::cell::Cell;
22
use std::cmp::Ordering::{self, *};
33
use std::ptr;
44

5+
// Minimal type with an `Ord` implementation violating transitivity.
56
#[derive(Debug)]
67
pub enum Cyclic3 {
78
A,
@@ -34,6 +35,7 @@ impl PartialEq for Cyclic3 {
3435

3536
impl Eq for Cyclic3 {}
3637

38+
// Controls the ordering of values wrapped by `Governed`.
3739
#[derive(Debug)]
3840
pub struct Governor {
3941
flipped: Cell<bool>,
@@ -49,6 +51,9 @@ impl Governor {
4951
}
5052
}
5153

54+
// Type with an `Ord` implementation that forms a total order at any moment
55+
// (assuming that `T` respects total order), but can suddenly be made to invert
56+
// that total order.
5257
#[derive(Debug)]
5358
pub struct Governed<'a, T>(pub T, pub &'a Governor);
5459

library/alloc/src/collections/btree/node.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -134,13 +134,13 @@ pub type Root<K, V> = NodeRef<marker::Owned, K, V, marker::LeafOrInternal>;
134134

135135
impl<K, V> Root<K, V> {
136136
/// Returns a new owned tree, with its own root node that is initially empty.
137-
pub fn new_leaf() -> Self {
138-
NodeRef::new().forget_type()
137+
pub fn new() -> Self {
138+
NodeRef::new_leaf().forget_type()
139139
}
140140
}
141141

142142
impl<K, V> NodeRef<marker::Owned, K, V, marker::Leaf> {
143-
fn new() -> Self {
143+
fn new_leaf() -> Self {
144144
Self::from_new_leaf(Box::new(unsafe { LeafNode::new() }))
145145
}
146146

library/alloc/src/collections/btree/node/tests.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,12 @@ fn test_splitpoint() {
7474

7575
#[test]
7676
fn test_partial_cmp_eq() {
77-
let mut root1 = NodeRef::new();
77+
let mut root1 = NodeRef::new_leaf();
7878
let mut leaf1 = root1.borrow_mut();
7979
leaf1.push(1, ());
8080
let mut root1 = root1.forget_type();
8181
root1.push_internal_level();
82-
let root2 = Root::new_leaf();
82+
let root2 = Root::new();
8383
root1.reborrow().assert_back_pointers();
8484
root2.reborrow().assert_back_pointers();
8585

0 commit comments

Comments
 (0)