Skip to content

Commit

Permalink
Rollup merge of #75696 - matklad:mirit, r=RalfJung
Browse files Browse the repository at this point in the history
Remove `#[cfg(miri)]` from OnceCell tests

They were carried over from once_cell crate, but they are not entirely
correct (as miri now supports more things), and we don't run miri
tests for std, so let's just remove them.

Maybe one day we'll run miri in std, but then we can just re-install
these attributes.
  • Loading branch information
tmandry committed Aug 19, 2020
2 parents 0fdc8c0 + 34e7eac commit ad3db41
Showing 1 changed file with 4 additions and 24 deletions.
28 changes: 4 additions & 24 deletions library/std/src/lazy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,7 @@ mod tests {
mpsc::channel,
Mutex,
},
thread,
};

#[test]
Expand Down Expand Up @@ -553,26 +554,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 @@ -735,7 +718,6 @@ mod tests {
}

#[test]
#[cfg_attr(miri, ignore)] // leaks memory
fn static_sync_lazy() {
static XS: SyncLazy<Vec<i32>> = SyncLazy::new(|| {
let mut xs = Vec::new();
Expand All @@ -753,7 +735,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 @@ -812,7 +793,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 @@ -824,7 +804,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 @@ -836,7 +816,7 @@ mod tests {
});
}
for _ in 0..n_writers {
spawn(move || {
thread::spawn(move || {
let _ = ONCE_CELL.set(MSG.to_owned());
});
}
Expand Down

0 comments on commit ad3db41

Please sign in to comment.