Repository: bevyengine/bevy
File: crates/bevy_tasks/src/task.rs (Rust)

Code before:
                    // using `resume_unwind` here is essentially keeping the same behavior while adding more information.
                    Poll::Ready(Ok(Err(_panic))) => crate::cfg::switch! {{
                        crate::cfg::std => {
                            std::panic::resume_unwind(_panic)
                        }
                        _ => {
                            unreachable!("catching a panic is only possible with std")
                        }
                    }},
                    Poll::Ready(Err(_)) => panic!("Polled a task after it was cancelled"),
                    Poll::Pending => Poll::Pending,
                }
            }
        } else {
            fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
                // `async_task` has `Task` implement `Future`, so we just poll it.
                Pin::new(&mut self.0).poll(cx)
            }
        }
    }
}

// All variants of Task<T> are expected to implement Unpin
impl<T> Unpin for Task<T> {}

// Derive dosn't work for macro types, so we have to implement this manually.
impl<T> fmt::Debug for Task<T> {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        self.0.fmt(f)
    }
}

// Utilities for catching unwinds on the web.
cfg::web! {
    use alloc::boxed::Box;
    use core::{
        panic::{AssertUnwindSafe, UnwindSafe},
        any::Any,
    };

    type Panic = Box<dyn Any + Send + 'static>;

    #[pin_project::pin_project]
    struct CatchUnwind<F: UnwindSafe>(#[pin] F);

    impl<F: Future + UnwindSafe> Future for CatchUnwind<F> {
        type Output = Result<F::Output, Panic>;
        fn poll(self: Pin<&mut Self>, cx: &mut Context) -> Poll<Self::Output> {
            let f = AssertUnwindSafe(|| self.project().0.poll(cx));

            let result = cfg::std! {

Review comment (suggestion):
```suggestion
// Derive doesn't work for macro types, so we have to implement this manually.
```

Code after:
                    Poll::Ready(Ok(Ok(value))) => Poll::Ready(value),
                    // NOTE: Propagating the panic here sorta has parity with the async_executor behavior.
                    // For those tasks, polling them after a panic returns a `None` which gets `unwrap`ed, so
                    // using `resume_unwind` here is essentially keeping the same behavior while adding more information.
                    Poll::Ready(Ok(Err(_panic))) => crate::cfg::switch! {{
                        crate::cfg::std => {
                            std::panic::resume_unwind(_panic)
                        }
                        _ => {
                            unreachable!("catching a panic is only possible with std")
                        }
                    }},
                    Poll::Ready(Err(_)) => panic!("Polled a task after it finished running"),
                    Poll::Pending => Poll::Pending,
                }
            }
        } else {
            fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
                // `async_task` has `Task` implement `Future`, so we just poll it.
                Pin::new(&mut self.0).poll(cx)
            }
        }
    }
}

// All variants of Task<T> are expected to implement Unpin
impl<T> Unpin for Task<T> {}

// Derive doesn't work for macro types, so we have to implement this manually.
impl<T> fmt::Debug for Task<T> {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        self.0.fmt(f)
    }
}

// Utilities for catching unwinds on the web.
cfg::web! {
    use alloc::boxed::Box;
    use core::{
        panic::{AssertUnwindSafe, UnwindSafe},
        any::Any,
    };

    type Panic = Box<dyn Any + Send + 'static>;

    #[pin_project::pin_project]
    struct CatchUnwind<F: UnwindSafe>(#[pin] F);

    impl<F: Future + UnwindSafe> Future for CatchUnwind<F> {
        type Output = Result<F::Output, Panic>;
        fn poll(self: Pin<&mut Self>, cx: &mut Context) -> Poll<Self::Output> {