Skip to content

Commit e87d391

Browse files
committed
BTreeMap: complete the compile-time test_variance test case
1 parent fc42fb8 commit e87d391

File tree

1 file changed

+34
-17
lines changed
  • library/alloc/src/collections/btree/map

1 file changed

+34
-17
lines changed

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

Lines changed: 34 additions & 17 deletions
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, ()> {
14191430
v
14201431
}
1421-
fn vals<'a, 'new>(v: Values<'a, (), &'static str>) -> Values<'a, (), &'new str> {
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, ()> {
1437+
v
1438+
}
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 + '_ {

0 commit comments

Comments
 (0)