Skip to content

Commit 8095317

Browse files
Rollup merge of #77445 - ssomers:btree_cleanup_7, r=Mark-Simulacrum
BTreeMap: complete the compile-time test_variance test case Some of the items added to the new `test_sync` belonged in the old `test_variance` as well. And fixed inconsistent paths to nearby modules. r? @Mark-Simulacrum
2 parents 9ea462f + a58089e commit 8095317

File tree

2 files changed

+118
-27
lines changed

2 files changed

+118
-27
lines changed

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

+37-21
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1+
use super::super::{navigate::Position, node, DeterministicRng};
2+
use super::Entry::{Occupied, Vacant};
3+
use super::*;
14
use crate::boxed::Box;
2-
use crate::collections::btree::navigate::Position;
3-
use crate::collections::btree::node;
4-
use crate::collections::btree_map::Entry::{Occupied, Vacant};
5-
use crate::collections::BTreeMap;
65
use crate::fmt::Debug;
76
use crate::rc::Rc;
8-
use crate::string::String;
9-
use crate::string::ToString;
7+
use crate::string::{String, ToString};
108
use crate::vec::Vec;
119
use std::convert::TryFrom;
1210
use std::iter::FromIterator;
@@ -16,19 +14,17 @@ use std::ops::RangeBounds;
1614
use std::panic::{catch_unwind, AssertUnwindSafe};
1715
use std::sync::atomic::{AtomicUsize, Ordering};
1816

19-
use super::super::DeterministicRng;
20-
2117
// Capacity of a tree with a single level,
22-
// i.e. a tree who's root is a leaf node at height 0.
18+
// i.e., a tree who's root is a leaf node at height 0.
2319
const NODE_CAPACITY: usize = node::CAPACITY;
2420

2521
// Minimum number of elements to insert, to guarantee a tree with 2 levels,
26-
// i.e. a tree who's root is an internal node at height 1, with edges to leaf nodes.
22+
// i.e., a tree who's root is an internal node at height 1, with edges to leaf nodes.
2723
// It's not the minimum size: removing an element from such a tree does not always reduce height.
2824
const MIN_INSERTS_HEIGHT_1: usize = NODE_CAPACITY + 1;
2925

3026
// Minimum number of elements to insert in ascending order, to guarantee a tree with 3 levels,
31-
// i.e. a tree who's root is an internal node at height 2, with edges to more internal nodes.
27+
// i.e., a tree who's root is an internal node at height 2, with edges to more internal nodes.
3228
// It's not the minimum size: removing an element from such a tree does not always reduce height.
3329
const MIN_INSERTS_HEIGHT_2: usize = 89;
3430

@@ -1386,44 +1382,65 @@ fn test_clone_from() {
13861382
}
13871383
}
13881384

1389-
#[test]
13901385
#[allow(dead_code)]
13911386
fn test_variance() {
1392-
use std::collections::btree_map::{IntoIter, Iter, Keys, Range, Values};
1393-
13941387
fn map_key<'new>(v: BTreeMap<&'static str, ()>) -> BTreeMap<&'new str, ()> {
13951388
v
13961389
}
13971390
fn map_val<'new>(v: BTreeMap<(), &'static str>) -> BTreeMap<(), &'new str> {
13981391
v
13991392
}
1393+
14001394
fn iter_key<'a, 'new>(v: Iter<'a, &'static str, ()>) -> Iter<'a, &'new str, ()> {
14011395
v
14021396
}
14031397
fn iter_val<'a, 'new>(v: Iter<'a, (), &'static str>) -> Iter<'a, (), &'new str> {
14041398
v
14051399
}
1400+
14061401
fn into_iter_key<'new>(v: IntoIter<&'static str, ()>) -> IntoIter<&'new str, ()> {
14071402
v
14081403
}
14091404
fn into_iter_val<'new>(v: IntoIter<(), &'static str>) -> IntoIter<(), &'new str> {
14101405
v
14111406
}
1407+
1408+
fn into_keys_key<'new>(v: IntoKeys<&'static str, ()>) -> IntoKeys<&'new str, ()> {
1409+
v
1410+
}
1411+
fn into_keys_val<'new>(v: IntoKeys<(), &'static str>) -> IntoKeys<(), &'new str> {
1412+
v
1413+
}
1414+
1415+
fn into_values_key<'new>(v: IntoValues<&'static str, ()>) -> IntoValues<&'new str, ()> {
1416+
v
1417+
}
1418+
fn into_values_val<'new>(v: IntoValues<(), &'static str>) -> IntoValues<(), &'new str> {
1419+
v
1420+
}
1421+
14121422
fn range_key<'a, 'new>(v: Range<'a, &'static str, ()>) -> Range<'a, &'new str, ()> {
14131423
v
14141424
}
14151425
fn range_val<'a, 'new>(v: Range<'a, (), &'static str>) -> Range<'a, (), &'new str> {
14161426
v
14171427
}
1418-
fn keys<'a, 'new>(v: Keys<'a, &'static str, ()>) -> Keys<'a, &'new str, ()> {
1428+
1429+
fn keys_key<'a, 'new>(v: Keys<'a, &'static str, ()>) -> Keys<'a, &'new str, ()> {
1430+
v
1431+
}
1432+
fn keys_val<'a, 'new>(v: Keys<'a, (), &'static str>) -> Keys<'a, (), &'new str> {
1433+
v
1434+
}
1435+
1436+
fn values_key<'a, 'new>(v: Values<'a, &'static str, ()>) -> Values<'a, &'new str, ()> {
14191437
v
14201438
}
1421-
fn vals<'a, 'new>(v: Values<'a, (), &'static str>) -> Values<'a, (), &'new str> {
1439+
fn values_val<'a, 'new>(v: Values<'a, (), &'static str>) -> Values<'a, (), &'new str> {
14221440
v
14231441
}
14241442
}
14251443

1426-
#[test]
14271444
#[allow(dead_code)]
14281445
fn test_sync() {
14291446
fn map<T: Sync>(v: &BTreeMap<T, T>) -> impl Sync + '_ {
@@ -1493,7 +1510,6 @@ fn test_sync() {
14931510
}
14941511
}
14951512

1496-
#[test]
14971513
#[allow(dead_code)]
14981514
fn test_send() {
14991515
fn map<T: Send>(v: BTreeMap<T, T>) -> impl Send {
@@ -1520,7 +1536,7 @@ fn test_send() {
15201536
v.iter()
15211537
}
15221538

1523-
fn iter_mut<T: Send + Sync>(v: &mut BTreeMap<T, T>) -> impl Send + '_ {
1539+
fn iter_mut<T: Send>(v: &mut BTreeMap<T, T>) -> impl Send + '_ {
15241540
v.iter_mut()
15251541
}
15261542

@@ -1532,15 +1548,15 @@ fn test_send() {
15321548
v.values()
15331549
}
15341550

1535-
fn values_mut<T: Send + Sync>(v: &mut BTreeMap<T, T>) -> impl Send + '_ {
1551+
fn values_mut<T: Send>(v: &mut BTreeMap<T, T>) -> impl Send + '_ {
15361552
v.values_mut()
15371553
}
15381554

15391555
fn range<T: Send + Sync + Ord>(v: &BTreeMap<T, T>) -> impl Send + '_ {
15401556
v.range(..)
15411557
}
15421558

1543-
fn range_mut<T: Send + Sync + Ord>(v: &mut BTreeMap<T, T>) -> impl Send + '_ {
1559+
fn range_mut<T: Send + Ord>(v: &mut BTreeMap<T, T>) -> impl Send + '_ {
15441560
v.range_mut(..)
15451561
}
15461562

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

+81-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
use crate::collections::BTreeSet;
1+
use super::super::DeterministicRng;
2+
use super::*;
23
use crate::vec::Vec;
34
use std::iter::FromIterator;
45
use std::panic::{catch_unwind, AssertUnwindSafe};
56
use std::sync::atomic::{AtomicU32, Ordering};
67

7-
use super::super::DeterministicRng;
8-
98
#[test]
109
fn test_clone_eq() {
1110
let mut m = BTreeSet::new();
@@ -528,11 +527,8 @@ fn test_recovery() {
528527
assert_eq!(s.iter().next(), None);
529528
}
530529

531-
#[test]
532530
#[allow(dead_code)]
533531
fn test_variance() {
534-
use std::collections::btree_set::{IntoIter, Iter, Range};
535-
536532
fn set<'new>(v: BTreeSet<&'static str>) -> BTreeSet<&'new str> {
537533
v
538534
}
@@ -545,6 +541,85 @@ fn test_variance() {
545541
fn range<'a, 'new>(v: Range<'a, &'static str>) -> Range<'a, &'new str> {
546542
v
547543
}
544+
// not applied to Difference, Intersection, SymmetricDifference, Union
545+
}
546+
547+
#[allow(dead_code)]
548+
fn test_sync() {
549+
fn set<T: Sync>(v: &BTreeSet<T>) -> impl Sync + '_ {
550+
v
551+
}
552+
553+
fn iter<T: Sync>(v: &BTreeSet<T>) -> impl Sync + '_ {
554+
v.iter()
555+
}
556+
557+
fn into_iter<T: Sync>(v: BTreeSet<T>) -> impl Sync {
558+
v.into_iter()
559+
}
560+
561+
fn range<T: Sync + Ord>(v: &BTreeSet<T>) -> impl Sync + '_ {
562+
v.range(..)
563+
}
564+
565+
fn drain_filter<T: Sync + Ord>(v: &mut BTreeSet<T>) -> impl Sync + '_ {
566+
v.drain_filter(|_| false)
567+
}
568+
569+
fn difference<T: Sync + Ord>(v: &BTreeSet<T>) -> impl Sync + '_ {
570+
v.difference(&v)
571+
}
572+
573+
fn intersection<T: Sync + Ord>(v: &BTreeSet<T>) -> impl Sync + '_ {
574+
v.intersection(&v)
575+
}
576+
577+
fn symmetric_difference<T: Sync + Ord>(v: &BTreeSet<T>) -> impl Sync + '_ {
578+
v.symmetric_difference(&v)
579+
}
580+
581+
fn union<T: Sync + Ord>(v: &BTreeSet<T>) -> impl Sync + '_ {
582+
v.union(&v)
583+
}
584+
}
585+
586+
#[allow(dead_code)]
587+
fn test_send() {
588+
fn set<T: Send>(v: BTreeSet<T>) -> impl Send {
589+
v
590+
}
591+
592+
fn iter<T: Send + Sync>(v: &BTreeSet<T>) -> impl Send + '_ {
593+
v.iter()
594+
}
595+
596+
fn into_iter<T: Send>(v: BTreeSet<T>) -> impl Send {
597+
v.into_iter()
598+
}
599+
600+
fn range<T: Send + Sync + Ord>(v: &BTreeSet<T>) -> impl Send + '_ {
601+
v.range(..)
602+
}
603+
604+
fn drain_filter<T: Send + Ord>(v: &mut BTreeSet<T>) -> impl Send + '_ {
605+
v.drain_filter(|_| false)
606+
}
607+
608+
fn difference<T: Send + Sync + Ord>(v: &BTreeSet<T>) -> impl Send + '_ {
609+
v.difference(&v)
610+
}
611+
612+
fn intersection<T: Send + Sync + Ord>(v: &BTreeSet<T>) -> impl Send + '_ {
613+
v.intersection(&v)
614+
}
615+
616+
fn symmetric_difference<T: Send + Sync + Ord>(v: &BTreeSet<T>) -> impl Send + '_ {
617+
v.symmetric_difference(&v)
618+
}
619+
620+
fn union<T: Send + Sync + Ord>(v: &BTreeSet<T>) -> impl Send + '_ {
621+
v.union(&v)
622+
}
548623
}
549624

550625
#[test]

0 commit comments

Comments
 (0)