Skip to content

Commit 0ceeb1b

Browse files
authored
Rollup merge of rust-lang#51973 - estk:master, r=abonander
Make Stdio handle UnwindSafe Closes rust-lang#51863 This is my first compiler PR. Thanks Niko for the mentor help! r? @nikomatsakis
2 parents bd0fe73 + 9797665 commit 0ceeb1b

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

src/libstd/io/stdio.rs

+22
Original file line numberDiff line numberDiff line change
@@ -712,9 +712,31 @@ pub fn _eprint(args: fmt::Arguments) {
712712

713713
#[cfg(test)]
714714
mod tests {
715+
use panic::{UnwindSafe, RefUnwindSafe};
715716
use thread;
716717
use super::*;
717718

719+
#[test]
720+
fn stdout_unwind_safe() {
721+
assert_unwind_safe::<Stdout>();
722+
}
723+
#[test]
724+
fn stdoutlock_unwind_safe() {
725+
assert_unwind_safe::<StdoutLock>();
726+
assert_unwind_safe::<StdoutLock<'static>>();
727+
}
728+
#[test]
729+
fn stderr_unwind_safe() {
730+
assert_unwind_safe::<Stderr>();
731+
}
732+
#[test]
733+
fn stderrlock_unwind_safe() {
734+
assert_unwind_safe::<StderrLock>();
735+
assert_unwind_safe::<StderrLock<'static>>();
736+
}
737+
738+
fn assert_unwind_safe<T: UnwindSafe + RefUnwindSafe>() {}
739+
718740
#[test]
719741
#[cfg_attr(target_os = "emscripten", ignore)]
720742
fn panic_doesnt_poison() {

src/libstd/sys_common/remutex.rs

+4
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use marker;
1313
use ops::Deref;
1414
use sys_common::poison::{self, TryLockError, TryLockResult, LockResult};
1515
use sys::mutex as sys;
16+
use panic::{UnwindSafe, RefUnwindSafe};
1617

1718
/// A re-entrant mutual exclusion
1819
///
@@ -28,6 +29,9 @@ pub struct ReentrantMutex<T> {
2829
unsafe impl<T: Send> Send for ReentrantMutex<T> {}
2930
unsafe impl<T: Send> Sync for ReentrantMutex<T> {}
3031

32+
impl<T> UnwindSafe for ReentrantMutex<T> {}
33+
impl<T> RefUnwindSafe for ReentrantMutex<T> {}
34+
3135

3236
/// An RAII implementation of a "scoped lock" of a mutex. When this structure is
3337
/// dropped (falls out of scope), the lock will be unlocked.

0 commit comments

Comments
 (0)