---
title: "Discussion on \"Let's talk about unwind safety!\" | Hashnode"
description: "Discussion on \"Let's talk about unwind safety!\". My own notes and experience with unwind safety and drop guards in Rust"
url: "https://hashnode.com/posts/let-s-talk-about-unwind-safety/6b03f0209be40ec5796ba371"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [Let's talk about unwind safety!](https://asder8215.com/let-s-talk-about-unwind-safety?utm_source=hashnode&utm_medium=feed)

My own notes and experience with unwind safety and drop guards in Rust

Nov 23 · 18 min read · asder8215.com  
Read the article

## Written by

[Mahdi Ali-Raihan](https://hashnode.com/@asder5124)

@asder5124

  
[View profile](https://hashnode.com/@asder5124)

An Open Source Rust Developer!

I like contributing to open source Rust projects. I take away a lot from my open source experiences, so I tend to use this site to jot down what I understood from specific contributions. :)

## Responses 2

Markdown supported · ⌘↵ to post

[Two Wang](https://hashnode.com/@twowang59)

[Nov 23](https://hashnode.com/posts/let-s-talk-about-unwind-safety/6b03f0209be40ec5796ba371/comment/6b047c4533a57a177ba17081)

The framing that helped me most: UnwindSafe is a lint about observing broken invariants, not about memory safety. Rust still guarantees no UB when a panic unwinds through your code, so the trait exists to stop catch\_unwind from handing you back a value that was mid-update when the invariant broke.

Two practical consequences I keep running into:

1.  &mut T is deliberately not UnwindSafe. A panic halfway through a two-field invariant update leaves the struct memory-safe but not in the state your API promised, and the marker trait encodes exactly that.
    
2.  AssertUnwindSafe is usually right at the outer boundary of a fallible call (a plugin hook, a request handler) where the mutated state is discarded on panic anyway. It is usually wrong around a Vec you plan to keep using, because you are asserting the one thing you cannot prove.
    

The runtime version of the same idea is poisoning: Mutex poison and the RefCell borrow flag both record that a panic may have left things half-done, and the safe default is to refuse further access rather than optimistically continue.

[Mahdi Ali-Raihan](https://hashnode.com/@asder5124)

[Nov 23](https://hashnode.com/posts/let-s-talk-about-unwind-safety/6b03f0209be40ec5796ba371/comment/6b047c4533a57a177ba17081#reply-6b048a13506e513b77c18eac)

Thank you for the clear explanation of `UnwindSafe`!
