-
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
Add std::panic::drop_unwind
#85927
Add std::panic::drop_unwind
#85927
Conversation
r? @m-ou-se (rust-highfive has picked a reviewer for you, use r? to override) |
That's quite a subtle but significant issue! I've opened #86027 for the issue. Adding |
☔ The latest upstream changes (presumably #84662) made this pull request unmergeable. Please resolve the merge conflicts. |
Ping from triage: After you've done that please set the PR to S-waiting-on-review |
5dae9ae
to
23fe346
Compare
23fe346
to
370cab2
Compare
@rustbot ready |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Marking as S-blocked on the discussion that is ongoing in #86027. A few alternatives are proposed. I don't think we would want to land this PR until there is some semblance of consensus around the alternative approaches.
This is unstable, so it seems okay to land such that it can be used (at least by std itself) until further consensus on #86027/rust-lang/lang-team#97 is reached. As an aside, it might be a good idea to call How I wrote
|
☔ The latest upstream changes (presumably #106228) made this pull request unmergeable. Please resolve the merge conflicts. |
@SabrinaJewson @rustbot label: +S-inactive |
A footgun in
std::panic::catch_unwind
is that panic payloads can panic when dropped. For example, this code:does not guarantee that unwinds will not occur in the outer function, because the user code could look like this:
This has caused many soundness bugs for me in the past, and I have encountered soundness bugs in other crates because of this.
The solution is to add a new function,
std::panic::drop_unwind
, that instead of returning aResult<T, Box<dyn Any + Send>>
returns aResult<T, ()>
. Panic payloads are safely dropped within the function by converting panics to aborts (it's such a rare case there's no reason to try and recover).