Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove #[cfg(miri)] from OnceCell tests #75696

Merged
merged 1 commit into from Aug 19, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 4 additions & 24 deletions library/std/src/lazy.rs
Expand Up @@ -516,6 +516,7 @@ mod tests {
mpsc::channel,
Mutex,
},
thread,
};

#[test]
Expand Down Expand Up @@ -552,26 +553,8 @@ mod tests {
}
}

// miri doesn't support threads
#[cfg(not(miri))]
fn spawn_and_wait<R: Send + 'static>(f: impl FnOnce() -> R + Send + 'static) -> R {
crate::thread::spawn(f).join().unwrap()
}

#[cfg(not(miri))]
fn spawn(f: impl FnOnce() + Send + 'static) {
let _ = crate::thread::spawn(f);
}

// "stub threads" for Miri
#[cfg(miri)]
fn spawn_and_wait<R: Send + 'static>(f: impl FnOnce() -> R + Send + 'static) -> R {
f(())
}

#[cfg(miri)]
fn spawn(f: impl FnOnce() + Send + 'static) {
f(())
thread::spawn(f).join().unwrap()
}

#[test]
Expand Down Expand Up @@ -734,7 +717,6 @@ mod tests {
}

#[test]
#[cfg_attr(miri, ignore)] // leaks memory
RalfJung marked this conversation as resolved.
Show resolved Hide resolved
fn static_sync_lazy() {
static XS: SyncLazy<Vec<i32>> = SyncLazy::new(|| {
let mut xs = Vec::new();
Expand All @@ -752,7 +734,6 @@ mod tests {
}

#[test]
#[cfg_attr(miri, ignore)] // leaks memory
fn static_sync_lazy_via_fn() {
fn xs() -> &'static Vec<i32> {
static XS: SyncOnceCell<Vec<i32>> = SyncOnceCell::new();
Expand Down Expand Up @@ -811,7 +792,6 @@ mod tests {
}

#[test]
#[cfg_attr(miri, ignore)] // deadlocks without real threads
fn sync_once_cell_does_not_leak_partially_constructed_boxes() {
static ONCE_CELL: SyncOnceCell<String> = SyncOnceCell::new();

Expand All @@ -823,7 +803,7 @@ mod tests {

for _ in 0..n_readers {
let tx = tx.clone();
spawn(move || {
thread::spawn(move || {
loop {
if let Some(msg) = ONCE_CELL.get() {
tx.send(msg).unwrap();
Expand All @@ -835,7 +815,7 @@ mod tests {
});
}
for _ in 0..n_writers {
spawn(move || {
thread::spawn(move || {
let _ = ONCE_CELL.set(MSG.to_owned());
});
}
Expand Down