-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
stdio handles are not UnwindSafe
#51863
Comments
This is a good issue for mentoring, actually. I'm willing to mentor, or otherwise resolve it myself, once someone from libs decides on a solution. |
Sure, these should be unwindsafe. |
@sfackler what is your preferred solution? Implement |
I don't feel strongly on the implementation approach. Less sure on forwarding impls for AssertUnwindSafe. We do currently forward FnOnce but that's just to make catch_unwind(AssertUnwindSafe(|| ...)) work. Not sure we want to open the can of worms of forwarding impls for every trait. |
Could this perhaps be solved with an unsafe implementation of UnwindSafe/RefUnwindSafe for ReentrantMutex? |
I think |
@kennytm Can you mark this Mentor + Easy? Mentoring InstructionsThis one is really easy. The stdio handles (e.g. However, the stdio handles use an internal-only mutex type that is not While The solution is simple, add I would also like to see regression tests ensuring that fn assert_unwind_safe<T: UnwindSafe + RefUnwindSafe>() {} And call it using the turbofish operator and the type to test, e.g. ( |
Make Stdio handle UnwindSafe Closes rust-lang#51863 This is my first compiler PR. Thanks Niko for the mentor help! r? @nikomatsakis
Make Stdio handle UnwindSafe Closes rust-lang#51863 This is my first compiler PR. Thanks Niko for the mentor help! r? @nikomatsakis
io::{Stdout, Stderr, StdoutLock, StderrLock}
are notUnwindSafe
:However, because they are protected by mutexes, it doesn't make sense why these handles shouldn't be
UnwindSafe
. It seems to be an oversight because they useReentrantMutex
internally, which transitively opts-out ofUnwindSafe
because it contains anUnsafeCell
.This makes
io::Stdout
a pain to use withslog
which requiresSend + Sync + UnwindSafe
on its output, necessitating a second mutex wrapping the handle or a custom wrapper implementingUnwindSafe
.AssertUnwindSafe
is not a solution here because it doesn't implementWrite
for its contained type.Either
ReentrantMutex
should manually implementUnwindSafe
as well, or the stdio handles should. I also recommend adding delegated impls ofRead
,Write
andBufRead
toAssertUnwindSafe
.Addendum: I'm still having problems with
slog
but for another reason;slog_json::Json
is also notUnwindSafe
orSync
because it usesRefCell
internally.Addendum 2: because it uses
Mutex
and notReentrantMutex
,Stdin
is alreadyUnwindSafe + RefUnwindSafe
, and thusStdinLock
is too. My original code example didn't error for those types but I didn't notice.The text was updated successfully, but these errors were encountered: