std test: better type name, clarifying comment
This commit is contained in:
parent
c54c8cbac8
commit
997101824b
@ -181,7 +181,7 @@ fn test_mutex_arc_poison() {
|
|||||||
let arc2 = arc.clone();
|
let arc2 = arc.clone();
|
||||||
let _ = thread::spawn(move || {
|
let _ = thread::spawn(move || {
|
||||||
let lock = arc2.lock().unwrap();
|
let lock = arc2.lock().unwrap();
|
||||||
assert_eq!(*lock, 2);
|
assert_eq!(*lock, 2); // deliberate assertion failure to poison the mutex
|
||||||
})
|
})
|
||||||
.join();
|
.join();
|
||||||
assert!(arc.lock().is_err());
|
assert!(arc.lock().is_err());
|
||||||
|
@ -23,11 +23,11 @@ fn wait(&self) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Foo(Signal);
|
struct NotifyOnDrop(Signal);
|
||||||
|
|
||||||
impl Drop for Foo {
|
impl Drop for NotifyOnDrop {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
let Foo(ref f) = *self;
|
let NotifyOnDrop(ref f) = *self;
|
||||||
f.notify();
|
f.notify();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -82,18 +82,18 @@ fn run(foo: &'static LocalKey<Foo>) {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn smoke_dtor() {
|
fn smoke_dtor() {
|
||||||
thread_local!(static FOO: UnsafeCell<Option<Foo>> = UnsafeCell::new(None));
|
thread_local!(static FOO: UnsafeCell<Option<NotifyOnDrop>> = UnsafeCell::new(None));
|
||||||
run(&FOO);
|
run(&FOO);
|
||||||
thread_local!(static FOO2: UnsafeCell<Option<Foo>> = const { UnsafeCell::new(None) });
|
thread_local!(static FOO2: UnsafeCell<Option<NotifyOnDrop>> = const { UnsafeCell::new(None) });
|
||||||
run(&FOO2);
|
run(&FOO2);
|
||||||
|
|
||||||
fn run(key: &'static LocalKey<UnsafeCell<Option<Foo>>>) {
|
fn run(key: &'static LocalKey<UnsafeCell<Option<NotifyOnDrop>>>) {
|
||||||
let signal = Signal::default();
|
let signal = Signal::default();
|
||||||
let signal2 = signal.clone();
|
let signal2 = signal.clone();
|
||||||
let t = thread::spawn(move || unsafe {
|
let t = thread::spawn(move || unsafe {
|
||||||
let mut signal = Some(signal2);
|
let mut signal = Some(signal2);
|
||||||
key.with(|f| {
|
key.with(|f| {
|
||||||
*f.get() = Some(Foo(signal.take().unwrap()));
|
*f.get() = Some(NotifyOnDrop(signal.take().unwrap()));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
signal.wait();
|
signal.wait();
|
||||||
@ -187,13 +187,13 @@ fn drop(&mut self) {
|
|||||||
fn dtors_in_dtors_in_dtors() {
|
fn dtors_in_dtors_in_dtors() {
|
||||||
struct S1(Signal);
|
struct S1(Signal);
|
||||||
thread_local!(static K1: UnsafeCell<Option<S1>> = UnsafeCell::new(None));
|
thread_local!(static K1: UnsafeCell<Option<S1>> = UnsafeCell::new(None));
|
||||||
thread_local!(static K2: UnsafeCell<Option<Foo>> = UnsafeCell::new(None));
|
thread_local!(static K2: UnsafeCell<Option<NotifyOnDrop>> = UnsafeCell::new(None));
|
||||||
|
|
||||||
impl Drop for S1 {
|
impl Drop for S1 {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
let S1(ref signal) = *self;
|
let S1(ref signal) = *self;
|
||||||
unsafe {
|
unsafe {
|
||||||
let _ = K2.try_with(|s| *s.get() = Some(Foo(signal.clone())));
|
let _ = K2.try_with(|s| *s.get() = Some(NotifyOnDrop(signal.clone())));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -211,13 +211,13 @@ fn drop(&mut self) {
|
|||||||
fn dtors_in_dtors_in_dtors_const_init() {
|
fn dtors_in_dtors_in_dtors_const_init() {
|
||||||
struct S1(Signal);
|
struct S1(Signal);
|
||||||
thread_local!(static K1: UnsafeCell<Option<S1>> = const { UnsafeCell::new(None) });
|
thread_local!(static K1: UnsafeCell<Option<S1>> = const { UnsafeCell::new(None) });
|
||||||
thread_local!(static K2: UnsafeCell<Option<Foo>> = const { UnsafeCell::new(None) });
|
thread_local!(static K2: UnsafeCell<Option<NotifyOnDrop>> = const { UnsafeCell::new(None) });
|
||||||
|
|
||||||
impl Drop for S1 {
|
impl Drop for S1 {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
let S1(ref signal) = *self;
|
let S1(ref signal) = *self;
|
||||||
unsafe {
|
unsafe {
|
||||||
let _ = K2.try_with(|s| *s.get() = Some(Foo(signal.clone())));
|
let _ = K2.try_with(|s| *s.get() = Some(NotifyOnDrop(signal.clone())));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user