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 |
|
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_unwindis 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).