From 2733c29bb1a385779c1d74dbce96180799e15e56 Mon Sep 17 00:00:00 2001 From: Maybe Waffle Date: Thu, 6 Apr 2023 18:05:59 +0000 Subject: [PATCH] Support multithreaded mode in `OwnedSlice` tests --- .../src/owned_slice/tests.rs | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/compiler/rustc_data_structures/src/owned_slice/tests.rs b/compiler/rustc_data_structures/src/owned_slice/tests.rs index fe4173f422a..e715fb55362 100644 --- a/compiler/rustc_data_structures/src/owned_slice/tests.rs +++ b/compiler/rustc_data_structures/src/owned_slice/tests.rs @@ -1,4 +1,10 @@ -use std::{cell::Cell, ops::Deref, rc::Rc}; +use std::{ + ops::Deref, + sync::{ + atomic::{self, AtomicBool}, + Arc, + }, +}; use crate::{ owned_slice::{slice_owned, try_slice_owned, OwnedSlice}, @@ -47,18 +53,18 @@ fn boxed() { } #[test] -fn drop() { - let flag = Rc::new(Cell::new(false)); - let flag_prime = Rc::clone(&flag); - let d = OnDrop(move || flag_prime.set(true)); +fn drop_drops() { + let flag = Arc::new(AtomicBool::new(false)); + let flag_prime = Arc::clone(&flag); + let d = OnDrop(move || flag_prime.store(true, atomic::Ordering::Relaxed)); let slice = slice_owned(d, |_| &[]); - assert_eq!(flag.get(), false); + assert_eq!(flag.load(atomic::Ordering::Relaxed), false); - std::mem::drop(slice); + drop(slice); - assert_eq!(flag.get(), true); + assert_eq!(flag.load(atomic::Ordering::Relaxed), true); } #[test]