Rollup merge of #79267 - ssomers:btree_namespaces, r=Mark-Simulacrum

BTreeMap: address namespace conflicts

Fix an annoyance popping up whenever synchronizing the test cases with a version capable of miri-track-raw-pointers.

r? `@Mark-Simulacrum`
This commit is contained in:
Mara Bos 2020-11-22 23:01:02 +01:00 committed by GitHub
commit 5793fa9cda
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 33 additions and 35 deletions

View File

@ -6,13 +6,14 @@
use crate::rc::Rc;
use crate::string::{String, ToString};
use crate::vec::Vec;
use std::cmp::Ordering;
use std::convert::TryFrom;
use std::iter::{self, FromIterator};
use std::mem;
use std::ops::Bound::{self, Excluded, Included, Unbounded};
use std::ops::RangeBounds;
use std::panic::{catch_unwind, AssertUnwindSafe};
use std::sync::atomic::{AtomicUsize, Ordering};
use std::sync::atomic::{AtomicUsize, Ordering::SeqCst};
mod ord_chaos;
use ord_chaos::{Cyclic3, Governed, Governor};
@ -1094,7 +1095,7 @@ fn drop_panic_leak() {
struct D;
impl Drop for D {
fn drop(&mut self) {
if DROPS.fetch_add(1, Ordering::SeqCst) == 1 {
if DROPS.fetch_add(1, SeqCst) == 1 {
panic!("panic in `drop`");
}
}
@ -1105,14 +1106,14 @@ fn drop(&mut self) {
catch_unwind(move || {
drop(map.drain_filter(|i, _| {
PREDS.fetch_add(1usize << i, Ordering::SeqCst);
PREDS.fetch_add(1usize << i, SeqCst);
true
}))
})
.unwrap_err();
assert_eq!(PREDS.load(Ordering::SeqCst), 0x011);
assert_eq!(DROPS.load(Ordering::SeqCst), 3);
assert_eq!(PREDS.load(SeqCst), 0x011);
assert_eq!(DROPS.load(SeqCst), 3);
}
#[test]
@ -1123,7 +1124,7 @@ fn pred_panic_leak() {
struct D;
impl Drop for D {
fn drop(&mut self) {
DROPS.fetch_add(1, Ordering::SeqCst);
DROPS.fetch_add(1, SeqCst);
}
}
@ -1132,7 +1133,7 @@ fn drop(&mut self) {
catch_unwind(AssertUnwindSafe(|| {
drop(map.drain_filter(|i, _| {
PREDS.fetch_add(1usize << i, Ordering::SeqCst);
PREDS.fetch_add(1usize << i, SeqCst);
match i {
0 => true,
_ => panic!(),
@ -1141,8 +1142,8 @@ fn drop(&mut self) {
}))
.unwrap_err();
assert_eq!(PREDS.load(Ordering::SeqCst), 0x011);
assert_eq!(DROPS.load(Ordering::SeqCst), 1);
assert_eq!(PREDS.load(SeqCst), 0x011);
assert_eq!(DROPS.load(SeqCst), 1);
assert_eq!(map.len(), 2);
assert_eq!(map.first_entry().unwrap().key(), &4);
assert_eq!(map.last_entry().unwrap().key(), &8);
@ -1158,7 +1159,7 @@ fn pred_panic_reuse() {
struct D;
impl Drop for D {
fn drop(&mut self) {
DROPS.fetch_add(1, Ordering::SeqCst);
DROPS.fetch_add(1, SeqCst);
}
}
@ -1167,7 +1168,7 @@ fn drop(&mut self) {
{
let mut it = map.drain_filter(|i, _| {
PREDS.fetch_add(1usize << i, Ordering::SeqCst);
PREDS.fetch_add(1usize << i, SeqCst);
match i {
0 => true,
_ => panic!(),
@ -1180,8 +1181,8 @@ fn drop(&mut self) {
assert!(matches!(result, Ok(None)));
}
assert_eq!(PREDS.load(Ordering::SeqCst), 0x011);
assert_eq!(DROPS.load(Ordering::SeqCst), 1);
assert_eq!(PREDS.load(SeqCst), 0x011);
assert_eq!(DROPS.load(SeqCst), 1);
assert_eq!(map.len(), 2);
assert_eq!(map.first_entry().unwrap().key(), &4);
assert_eq!(map.last_entry().unwrap().key(), &8);
@ -1315,8 +1316,6 @@ fn test_zst() {
// undefined.
#[test]
fn test_bad_zst() {
use std::cmp::Ordering;
#[derive(Clone, Copy, Debug)]
struct Bad;
@ -1763,7 +1762,7 @@ fn test_append_drop_leak() {
impl Drop for D {
fn drop(&mut self) {
if DROPS.fetch_add(1, Ordering::SeqCst) == 0 {
if DROPS.fetch_add(1, SeqCst) == 0 {
panic!("panic in `drop`");
}
}
@ -1779,7 +1778,7 @@ fn drop(&mut self) {
catch_unwind(move || left.append(&mut right)).unwrap_err();
assert_eq!(DROPS.load(Ordering::SeqCst), 4); // Rust issue #47949 ate one little piggy
assert_eq!(DROPS.load(SeqCst), 4); // Rust issue #47949 ate one little piggy
}
#[test]
@ -1894,7 +1893,7 @@ fn test_into_iter_drop_leak_height_0() {
impl Drop for D {
fn drop(&mut self) {
if DROPS.fetch_add(1, Ordering::SeqCst) == 3 {
if DROPS.fetch_add(1, SeqCst) == 3 {
panic!("panic in `drop`");
}
}
@ -1909,7 +1908,7 @@ fn drop(&mut self) {
catch_unwind(move || drop(map.into_iter())).unwrap_err();
assert_eq!(DROPS.load(Ordering::SeqCst), 5);
assert_eq!(DROPS.load(SeqCst), 5);
}
#[test]
@ -1921,18 +1920,18 @@ fn test_into_iter_drop_leak_height_1() {
struct D;
impl Drop for D {
fn drop(&mut self) {
if DROPS.fetch_add(1, Ordering::SeqCst) == PANIC_POINT.load(Ordering::SeqCst) {
if DROPS.fetch_add(1, SeqCst) == PANIC_POINT.load(SeqCst) {
panic!("panic in `drop`");
}
}
}
for panic_point in vec![0, 1, size - 2, size - 1] {
DROPS.store(0, Ordering::SeqCst);
PANIC_POINT.store(panic_point, Ordering::SeqCst);
DROPS.store(0, SeqCst);
PANIC_POINT.store(panic_point, SeqCst);
let map: BTreeMap<_, _> = (0..size).map(|i| (i, D)).collect();
catch_unwind(move || drop(map.into_iter())).unwrap_err();
assert_eq!(DROPS.load(Ordering::SeqCst), size);
assert_eq!(DROPS.load(SeqCst), size);
}
}

View File

@ -50,7 +50,7 @@ pub fn search_node<BorrowType, K, V, Type, Q: ?Sized>(
{
match search_linear(&node, key) {
(idx, true) => Found(unsafe { Handle::new_kv(node, idx) }),
(idx, false) => SearchResult::GoDown(unsafe { Handle::new_edge(node, idx) }),
(idx, false) => GoDown(unsafe { Handle::new_edge(node, idx) }),
}
}

View File

@ -1,9 +1,10 @@
use super::super::DeterministicRng;
use super::*;
use crate::vec::Vec;
use std::cmp::Ordering;
use std::iter::FromIterator;
use std::panic::{catch_unwind, AssertUnwindSafe};
use std::sync::atomic::{AtomicU32, Ordering};
use std::sync::atomic::{AtomicU32, Ordering::SeqCst};
#[test]
fn test_clone_eq() {
@ -355,7 +356,7 @@ fn test_drain_filter_drop_panic_leak() {
struct D(i32);
impl Drop for D {
fn drop(&mut self) {
if DROPS.fetch_add(1, Ordering::SeqCst) == 1 {
if DROPS.fetch_add(1, SeqCst) == 1 {
panic!("panic in `drop`");
}
}
@ -368,14 +369,14 @@ fn drop(&mut self) {
catch_unwind(move || {
drop(set.drain_filter(|d| {
PREDS.fetch_add(1u32 << d.0, Ordering::SeqCst);
PREDS.fetch_add(1u32 << d.0, SeqCst);
true
}))
})
.ok();
assert_eq!(PREDS.load(Ordering::SeqCst), 0x011);
assert_eq!(DROPS.load(Ordering::SeqCst), 3);
assert_eq!(PREDS.load(SeqCst), 0x011);
assert_eq!(DROPS.load(SeqCst), 3);
}
#[test]
@ -387,7 +388,7 @@ fn test_drain_filter_pred_panic_leak() {
struct D(i32);
impl Drop for D {
fn drop(&mut self) {
DROPS.fetch_add(1, Ordering::SeqCst);
DROPS.fetch_add(1, SeqCst);
}
}
@ -398,7 +399,7 @@ fn drop(&mut self) {
catch_unwind(AssertUnwindSafe(|| {
drop(set.drain_filter(|d| {
PREDS.fetch_add(1u32 << d.0, Ordering::SeqCst);
PREDS.fetch_add(1u32 << d.0, SeqCst);
match d.0 {
0 => true,
_ => panic!(),
@ -407,8 +408,8 @@ fn drop(&mut self) {
}))
.ok();
assert_eq!(PREDS.load(Ordering::SeqCst), 0x011);
assert_eq!(DROPS.load(Ordering::SeqCst), 1);
assert_eq!(PREDS.load(SeqCst), 0x011);
assert_eq!(DROPS.load(SeqCst), 1);
assert_eq!(set.len(), 2);
assert_eq!(set.first().unwrap().0, 4);
assert_eq!(set.last().unwrap().0, 8);
@ -498,8 +499,6 @@ fn test_extend_ref() {
#[test]
fn test_recovery() {
use std::cmp::Ordering;
#[derive(Debug)]
struct Foo(&'static str, i32);