-
Notifications
You must be signed in to change notification settings - Fork 782
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
216405e
commit e716388
Showing
6 changed files
with
44 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/// Type which will panic if dropped. | ||
/// | ||
/// If this is dropped during a panic, this will cause an abort. | ||
/// | ||
/// Use this to avoid letting unwinds cross through the FFI boundary, which is UB. | ||
pub(crate) struct PanicTrap { | ||
msg: &'static str, | ||
} | ||
|
||
impl PanicTrap { | ||
#[inline] | ||
pub const fn new(msg: &'static str) -> Self { | ||
Self { msg } | ||
} | ||
|
||
#[inline] | ||
pub const fn disarm(self) { | ||
std::mem::forget(self) | ||
} | ||
} | ||
|
||
impl Drop for PanicTrap { | ||
fn drop(&mut self) { | ||
// Panic here will abort the process, assuming in an unwind. | ||
panic!("{}", self.msg) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters