rust-lang / rust-lang/rfcs

Add a std::panic::propagate function to pair with std::panic::recover

Open
#1,413 10 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

T-libs
Dominant language
Markdown
Stars
6.6k
Forks
1.7k
Avg merge
16h 14m
Merged PRs (30d)
1

Description

Say we're integrating with a C API where the control flow will pass from Rust to C and then back into Rust. If the inner Rust code panics, we have to stop that panic from unwinding through the C layer. std::panic::recover will allow us to do this. But now we would ideally want to carry the panic payload through the C layer and "restart" unwinding when we're back in Rust-land. We can just panic!(payload), but that will rerun the panic handler function, printing the "thread foo panicked" an extra time. This situation becomes a bit more unfortunate with custom panic handlers, since those handlers may do more expensive tasks than just printing a message.

To solve this, we could add a function which acts like panic!() but does not run the panic hander. Since we already have the payload, a normal function taking a Box<Any + Send> will suffice rather than a macro.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the issue's description of std::panic::recover and the proposed std::panic::propagate API, then inspect the Rust standard-library panic implementation. Done means carrying a Box<Any + Send> across a C boundary and resuming unwinding without invoking the panic handler a second time.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.