Skip to content

Commit 1f60e2f

Browse files
committed
Improve test, using test in rust-lang#71570
1 parent 655aa92 commit 1f60e2f

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

library/alloc/src/sync/tests.rs

+22
Original file line numberDiff line numberDiff line change
@@ -633,3 +633,25 @@ where
633633
{
634634
f()
635635
}
636+
637+
#[test]
638+
fn test_arc_fn2() {
639+
fn apply_fn_once<T>(v: T, f: impl FnOnce(T)) {
640+
f(v)
641+
}
642+
fn apply_fn_mut<T>(v: T, mut f: impl FnMut(T)) {
643+
f(v)
644+
}
645+
fn apply_fn<T>(v: T, f: impl Fn(T)) {
646+
f(v)
647+
}
648+
649+
let x = Mutex::new(0);
650+
let f = Arc::new(|v: i32| *x.lock().unwrap() += v);
651+
652+
apply_fn_once(1, f.clone());
653+
apply_fn_mut(2, f.clone());
654+
apply_fn(4, f.clone());
655+
656+
assert_eq!(*x.lock().unwrap(), 7);
657+
}

0 commit comments

Comments
 (0)