Skip to content

Commit b8ae372

Browse files
committed
Move std::sync unit tests to integration tests
This removes two minor OnceLock tests which test private methods. The rest of the tests should be more than enough to catch mistakes in those private methods. Also makes ReentrantLock::try_lock public. And finally it makes the mpmc tests actually run.
1 parent 332fb7e commit b8ae372

22 files changed

+101
-99
lines changed

library/std/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,10 @@ name = "pipe-subprocess"
130130
path = "tests/pipe_subprocess.rs"
131131
harness = false
132132

133+
[[test]]
134+
name = "sync"
135+
path = "tests/sync/lib.rs"
136+
133137
[[test]]
134138
name = "floats"
135139
path = "tests/floats/lib.rs"

library/std/src/sync/barrier.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
#[cfg(test)]
2-
mod tests;
3-
41
use crate::fmt;
52
// FIXME(nonpoison_mutex,nonpoison_condvar): switch to nonpoison versions once they are available
63
use crate::sync::{Condvar, Mutex};

library/std/src/sync/lazy_lock.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,3 @@ unsafe impl<T: Sync + Send, F: Send> Sync for LazyLock<T, F> {}
350350
impl<T: RefUnwindSafe + UnwindSafe, F: UnwindSafe> RefUnwindSafe for LazyLock<T, F> {}
351351
#[stable(feature = "lazy_cell", since = "1.80.0")]
352352
impl<T: UnwindSafe, F: UnwindSafe> UnwindSafe for LazyLock<T, F> {}
353-
354-
#[cfg(test)]
355-
mod tests;

library/std/src/sync/mpsc/mod.rs renamed to library/std/src/sync/mpsc.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -137,12 +137,6 @@
137137
138138
#![stable(feature = "rust1", since = "1.0.0")]
139139

140-
#[cfg(all(test, not(any(target_os = "emscripten", target_os = "wasi"))))]
141-
mod tests;
142-
143-
#[cfg(all(test, not(any(target_os = "emscripten", target_os = "wasi"))))]
144-
mod sync_tests;
145-
146140
// MPSC channels are built as a wrapper around MPMC channels, which
147141
// were ported from the `crossbeam-channel` crate. MPMC channels are
148142
// not exposed publicly, but if you are curious about the implementation,
@@ -737,9 +731,10 @@ impl<T> SyncSender<T> {
737731
// Attempts to send for a value on this receiver, returning an error if the
738732
// corresponding channel has hung up, or if it waits more than `timeout`.
739733
//
740-
// This method is currently private and only used for tests.
741-
#[allow(unused)]
742-
fn send_timeout(&self, t: T, timeout: Duration) -> Result<(), mpmc::SendTimeoutError<T>> {
734+
// This method is currently only used for tests.
735+
#[unstable(issue = "none", feature = "std_internals")]
736+
#[doc(hidden)]
737+
pub fn send_timeout(&self, t: T, timeout: Duration) -> Result<(), mpmc::SendTimeoutError<T>> {
743738
self.inner.send_timeout(t, timeout)
744739
}
745740
}

library/std/src/sync/once_lock.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -676,6 +676,3 @@ unsafe impl<#[may_dangle] T> Drop for OnceLock<T> {
676676
}
677677
}
678678
}
679-
680-
#[cfg(test)]
681-
mod tests;

library/std/src/sync/poison/condvar.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
#[cfg(test)]
2-
mod tests;
3-
41
use crate::fmt;
52
use crate::sync::poison::{self, LockResult, MutexGuard, PoisonError, mutex};
63
use crate::sys::sync as sys;

library/std/src/sync/poison/mutex.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
#[cfg(all(test, not(any(target_os = "emscripten", target_os = "wasi"))))]
2-
mod tests;
3-
41
use crate::cell::UnsafeCell;
52
use crate::fmt;
63
use crate::marker::PhantomData;

library/std/src/sync/poison/once.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33
//! This primitive is meant to be used to run one-time initialization. An
44
//! example use case would be for initializing an FFI library.
55
6-
#[cfg(all(test, not(any(target_os = "emscripten", target_os = "wasi"))))]
7-
mod tests;
8-
96
use crate::fmt;
107
use crate::panic::{RefUnwindSafe, UnwindSafe};
118
use crate::sys::sync as sys;

library/std/src/sync/poison/rwlock.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
#[cfg(all(test, not(any(target_os = "emscripten", target_os = "wasi"))))]
2-
mod tests;
3-
41
use crate::cell::UnsafeCell;
52
use crate::fmt;
63
use crate::marker::PhantomData;

library/std/src/sync/reentrant_lock.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
#[cfg(all(test, not(any(target_os = "emscripten", target_os = "wasi"))))]
2-
mod tests;
3-
41
use cfg_if::cfg_if;
52

63
use crate::cell::UnsafeCell;
@@ -324,7 +321,10 @@ impl<T: ?Sized> ReentrantLock<T> {
324321
/// Otherwise, an RAII guard is returned.
325322
///
326323
/// This function does not block.
327-
pub(crate) fn try_lock(&self) -> Option<ReentrantLockGuard<'_, T>> {
324+
// FIXME maybe make it a public part of the API?
325+
#[unstable(issue = "none", feature = "std_internals")]
326+
#[doc(hidden)]
327+
pub fn try_lock(&self) -> Option<ReentrantLockGuard<'_, T>> {
328328
let this_thread = current_id();
329329
// Safety: We only touch lock_count when we own the inner mutex.
330330
// Additionally, we only call `self.owner.set()` while holding

0 commit comments

Comments
 (0)