Skip to content

Commit b4c0f99

Browse files
m-ou-seMark-Simulacrum
authored andcommitted
Update ReentrantMutex tests to use Pin.
1 parent 76567e9 commit b4c0f99

File tree

2 files changed

+21
-15
lines changed

2 files changed

+21
-15
lines changed

library/std/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,7 @@
267267
#![feature(format_args_nl)]
268268
#![feature(gen_future)]
269269
#![feature(generator_trait)]
270+
#![feature(get_mut_unchecked)]
270271
#![feature(global_asm)]
271272
#![feature(hashmap_internals)]
272273
#![feature(int_error_internals)]

library/std/src/sys_common/remutex/tests.rs

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
1+
use crate::boxed::Box;
12
use crate::cell::RefCell;
3+
use crate::pin::Pin;
24
use crate::sync::Arc;
35
use crate::sys_common::remutex::{ReentrantMutex, ReentrantMutexGuard};
46
use crate::thread;
57

68
#[test]
79
fn smoke() {
810
let m = unsafe {
9-
let m = ReentrantMutex::new(());
10-
m.init();
11+
let mut m = Box::pin(ReentrantMutex::new(()));
12+
m.as_mut().init();
1113
m
1214
};
15+
let m = m.as_ref();
1316
{
1417
let a = m.lock();
1518
{
@@ -27,18 +30,19 @@ fn smoke() {
2730
#[test]
2831
fn is_mutex() {
2932
let m = unsafe {
30-
let m = Arc::new(ReentrantMutex::new(RefCell::new(0)));
31-
m.init();
32-
m
33+
// FIXME: Simplify this if Arc gets a Arc::get_pin_mut.
34+
let mut m = Arc::new(ReentrantMutex::new(RefCell::new(0)));
35+
Pin::new_unchecked(Arc::get_mut_unchecked(&mut m)).init();
36+
Pin::new_unchecked(m)
3337
};
3438
let m2 = m.clone();
35-
let lock = m.lock();
39+
let lock = m.as_ref().lock();
3640
let child = thread::spawn(move || {
37-
let lock = m2.lock();
41+
let lock = m2.as_ref().lock();
3842
assert_eq!(*lock.borrow(), 4950);
3943
});
4044
for i in 0..100 {
41-
let lock = m.lock();
45+
let lock = m.as_ref().lock();
4246
*lock.borrow_mut() += i;
4347
}
4448
drop(lock);
@@ -48,20 +52,21 @@ fn is_mutex() {
4852
#[test]
4953
fn trylock_works() {
5054
let m = unsafe {
51-
let m = Arc::new(ReentrantMutex::new(()));
52-
m.init();
53-
m
55+
// FIXME: Simplify this if Arc gets a Arc::get_pin_mut.
56+
let mut m = Arc::new(ReentrantMutex::new(()));
57+
Pin::new_unchecked(Arc::get_mut_unchecked(&mut m)).init();
58+
Pin::new_unchecked(m)
5459
};
5560
let m2 = m.clone();
56-
let _lock = m.try_lock();
57-
let _lock2 = m.try_lock();
61+
let _lock = m.as_ref().try_lock();
62+
let _lock2 = m.as_ref().try_lock();
5863
thread::spawn(move || {
59-
let lock = m2.try_lock();
64+
let lock = m2.as_ref().try_lock();
6065
assert!(lock.is_none());
6166
})
6267
.join()
6368
.unwrap();
64-
let _lock3 = m.try_lock();
69+
let _lock3 = m.as_ref().try_lock();
6570
}
6671

6772
pub struct Answer<'a>(pub ReentrantMutexGuard<'a, RefCell<u32>>);

0 commit comments

Comments
 (0)