Skip to content

Commit 0f005c2

Browse files
committed
BTreeMap: address namespace conflicts
1 parent 29a74e6 commit 0f005c2

File tree

3 files changed

+33
-35
lines changed

3 files changed

+33
-35
lines changed

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

+22-23
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};
@@ -1094,7 +1095,7 @@ mod test_drain_filter {
10941095
struct D;
10951096
impl Drop for D {
10961097
fn drop(&mut self) {
1097-
if DROPS.fetch_add(1, Ordering::SeqCst) == 1 {
1098+
if DROPS.fetch_add(1, SeqCst) == 1 {
10981099
panic!("panic in `drop`");
10991100
}
11001101
}
@@ -1105,14 +1106,14 @@ mod test_drain_filter {
11051106

11061107
catch_unwind(move || {
11071108
drop(map.drain_filter(|i, _| {
1108-
PREDS.fetch_add(1usize << i, Ordering::SeqCst);
1109+
PREDS.fetch_add(1usize << i, SeqCst);
11091110
true
11101111
}))
11111112
})
11121113
.unwrap_err();
11131114

1114-
assert_eq!(PREDS.load(Ordering::SeqCst), 0x011);
1115-
assert_eq!(DROPS.load(Ordering::SeqCst), 3);
1115+
assert_eq!(PREDS.load(SeqCst), 0x011);
1116+
assert_eq!(DROPS.load(SeqCst), 3);
11161117
}
11171118

11181119
#[test]
@@ -1123,7 +1124,7 @@ mod test_drain_filter {
11231124
struct D;
11241125
impl Drop for D {
11251126
fn drop(&mut self) {
1126-
DROPS.fetch_add(1, Ordering::SeqCst);
1127+
DROPS.fetch_add(1, SeqCst);
11271128
}
11281129
}
11291130

@@ -1132,7 +1133,7 @@ mod test_drain_filter {
11321133

11331134
catch_unwind(AssertUnwindSafe(|| {
11341135
drop(map.drain_filter(|i, _| {
1135-
PREDS.fetch_add(1usize << i, Ordering::SeqCst);
1136+
PREDS.fetch_add(1usize << i, SeqCst);
11361137
match i {
11371138
0 => true,
11381139
_ => panic!(),
@@ -1141,8 +1142,8 @@ mod test_drain_filter {
11411142
}))
11421143
.unwrap_err();
11431144

1144-
assert_eq!(PREDS.load(Ordering::SeqCst), 0x011);
1145-
assert_eq!(DROPS.load(Ordering::SeqCst), 1);
1145+
assert_eq!(PREDS.load(SeqCst), 0x011);
1146+
assert_eq!(DROPS.load(SeqCst), 1);
11461147
assert_eq!(map.len(), 2);
11471148
assert_eq!(map.first_entry().unwrap().key(), &4);
11481149
assert_eq!(map.last_entry().unwrap().key(), &8);
@@ -1158,7 +1159,7 @@ mod test_drain_filter {
11581159
struct D;
11591160
impl Drop for D {
11601161
fn drop(&mut self) {
1161-
DROPS.fetch_add(1, Ordering::SeqCst);
1162+
DROPS.fetch_add(1, SeqCst);
11621163
}
11631164
}
11641165

@@ -1167,7 +1168,7 @@ mod test_drain_filter {
11671168

11681169
{
11691170
let mut it = map.drain_filter(|i, _| {
1170-
PREDS.fetch_add(1usize << i, Ordering::SeqCst);
1171+
PREDS.fetch_add(1usize << i, SeqCst);
11711172
match i {
11721173
0 => true,
11731174
_ => panic!(),
@@ -1180,8 +1181,8 @@ mod test_drain_filter {
11801181
assert!(matches!(result, Ok(None)));
11811182
}
11821183

1183-
assert_eq!(PREDS.load(Ordering::SeqCst), 0x011);
1184-
assert_eq!(DROPS.load(Ordering::SeqCst), 1);
1184+
assert_eq!(PREDS.load(SeqCst), 0x011);
1185+
assert_eq!(DROPS.load(SeqCst), 1);
11851186
assert_eq!(map.len(), 2);
11861187
assert_eq!(map.first_entry().unwrap().key(), &4);
11871188
assert_eq!(map.last_entry().unwrap().key(), &8);
@@ -1315,8 +1316,6 @@ fn test_zst() {
13151316
// undefined.
13161317
#[test]
13171318
fn test_bad_zst() {
1318-
use std::cmp::Ordering;
1319-
13201319
#[derive(Clone, Copy, Debug)]
13211320
struct Bad;
13221321

@@ -1763,7 +1762,7 @@ fn test_append_drop_leak() {
17631762

17641763
impl Drop for D {
17651764
fn drop(&mut self) {
1766-
if DROPS.fetch_add(1, Ordering::SeqCst) == 0 {
1765+
if DROPS.fetch_add(1, SeqCst) == 0 {
17671766
panic!("panic in `drop`");
17681767
}
17691768
}
@@ -1779,7 +1778,7 @@ fn test_append_drop_leak() {
17791778

17801779
catch_unwind(move || left.append(&mut right)).unwrap_err();
17811780

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

17851784
#[test]
@@ -1894,7 +1893,7 @@ fn test_into_iter_drop_leak_height_0() {
18941893

18951894
impl Drop for D {
18961895
fn drop(&mut self) {
1897-
if DROPS.fetch_add(1, Ordering::SeqCst) == 3 {
1896+
if DROPS.fetch_add(1, SeqCst) == 3 {
18981897
panic!("panic in `drop`");
18991898
}
19001899
}
@@ -1909,7 +1908,7 @@ fn test_into_iter_drop_leak_height_0() {
19091908

19101909
catch_unwind(move || drop(map.into_iter())).unwrap_err();
19111910

1912-
assert_eq!(DROPS.load(Ordering::SeqCst), 5);
1911+
assert_eq!(DROPS.load(SeqCst), 5);
19131912
}
19141913

19151914
#[test]
@@ -1921,18 +1920,18 @@ fn test_into_iter_drop_leak_height_1() {
19211920
struct D;
19221921
impl Drop for D {
19231922
fn drop(&mut self) {
1924-
if DROPS.fetch_add(1, Ordering::SeqCst) == PANIC_POINT.load(Ordering::SeqCst) {
1923+
if DROPS.fetch_add(1, SeqCst) == PANIC_POINT.load(SeqCst) {
19251924
panic!("panic in `drop`");
19261925
}
19271926
}
19281927
}
19291928

19301929
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);
1930+
DROPS.store(0, SeqCst);
1931+
PANIC_POINT.store(panic_point, SeqCst);
19331932
let map: BTreeMap<_, _> = (0..size).map(|i| (i, D)).collect();
19341933
catch_unwind(move || drop(map.into_iter())).unwrap_err();
1935-
assert_eq!(DROPS.load(Ordering::SeqCst), size);
1934+
assert_eq!(DROPS.load(SeqCst), size);
19361935
}
19371936
}
19381937

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ where
5050
{
5151
match search_linear(&node, key) {
5252
(idx, true) => Found(unsafe { Handle::new_kv(node, idx) }),
53-
(idx, false) => SearchResult::GoDown(unsafe { Handle::new_edge(node, idx) }),
53+
(idx, false) => GoDown(unsafe { Handle::new_edge(node, idx) }),
5454
}
5555
}
5656

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

+10-11
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
use super::super::DeterministicRng;
22
use super::*;
33
use crate::vec::Vec;
4+
use std::cmp::Ordering;
45
use std::iter::FromIterator;
56
use std::panic::{catch_unwind, AssertUnwindSafe};
6-
use std::sync::atomic::{AtomicU32, Ordering};
7+
use std::sync::atomic::{AtomicU32, Ordering::SeqCst};
78

89
#[test]
910
fn test_clone_eq() {
@@ -355,7 +356,7 @@ fn test_drain_filter_drop_panic_leak() {
355356
struct D(i32);
356357
impl Drop for D {
357358
fn drop(&mut self) {
358-
if DROPS.fetch_add(1, Ordering::SeqCst) == 1 {
359+
if DROPS.fetch_add(1, SeqCst) == 1 {
359360
panic!("panic in `drop`");
360361
}
361362
}
@@ -368,14 +369,14 @@ fn test_drain_filter_drop_panic_leak() {
368369

369370
catch_unwind(move || {
370371
drop(set.drain_filter(|d| {
371-
PREDS.fetch_add(1u32 << d.0, Ordering::SeqCst);
372+
PREDS.fetch_add(1u32 << d.0, SeqCst);
372373
true
373374
}))
374375
})
375376
.ok();
376377

377-
assert_eq!(PREDS.load(Ordering::SeqCst), 0x011);
378-
assert_eq!(DROPS.load(Ordering::SeqCst), 3);
378+
assert_eq!(PREDS.load(SeqCst), 0x011);
379+
assert_eq!(DROPS.load(SeqCst), 3);
379380
}
380381

381382
#[test]
@@ -387,7 +388,7 @@ fn test_drain_filter_pred_panic_leak() {
387388
struct D(i32);
388389
impl Drop for D {
389390
fn drop(&mut self) {
390-
DROPS.fetch_add(1, Ordering::SeqCst);
391+
DROPS.fetch_add(1, SeqCst);
391392
}
392393
}
393394

@@ -398,7 +399,7 @@ fn test_drain_filter_pred_panic_leak() {
398399

399400
catch_unwind(AssertUnwindSafe(|| {
400401
drop(set.drain_filter(|d| {
401-
PREDS.fetch_add(1u32 << d.0, Ordering::SeqCst);
402+
PREDS.fetch_add(1u32 << d.0, SeqCst);
402403
match d.0 {
403404
0 => true,
404405
_ => panic!(),
@@ -407,8 +408,8 @@ fn test_drain_filter_pred_panic_leak() {
407408
}))
408409
.ok();
409410

410-
assert_eq!(PREDS.load(Ordering::SeqCst), 0x011);
411-
assert_eq!(DROPS.load(Ordering::SeqCst), 1);
411+
assert_eq!(PREDS.load(SeqCst), 0x011);
412+
assert_eq!(DROPS.load(SeqCst), 1);
412413
assert_eq!(set.len(), 2);
413414
assert_eq!(set.first().unwrap().0, 4);
414415
assert_eq!(set.last().unwrap().0, 8);
@@ -498,8 +499,6 @@ fn test_extend_ref() {
498499

499500
#[test]
500501
fn test_recovery() {
501-
use std::cmp::Ordering;
502-
503502
#[derive(Debug)]
504503
struct Foo(&'static str, i32);
505504

0 commit comments

Comments
 (0)