From d8c01af85798ece5763aa31fd9d798cbcd28fc27 Mon Sep 17 00:00:00 2001 From: Tony Arcieri Date: Sun, 4 Jan 2026 07:48:23 -0700 Subject: [PATCH] Add `#[track_caller]` to `CtOption::{expect, unwrap}` This option adds a location hint about the function which called it, which is useful when debugging panics since otherwise unless you set `RUST_BACKTRACE` you instead get the line in `subtle` where a particular `assert!` failed, rather than the location of the call site into `expect` or `unwrap`. See: https://doc.rust-lang.org/reference/attributes/codegen.html#the-track_caller-attribute --- src/lib.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 9fc143b..c6614bb 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -688,6 +688,7 @@ impl CtOption { /// /// Panics if the value is none with a custom panic message provided by /// `msg`. + #[track_caller] pub fn expect(self, msg: &str) -> T { assert_eq!(self.is_some.unwrap_u8(), 1, "{}", msg); @@ -697,6 +698,7 @@ impl CtOption { /// This returns the underlying value but panics if it /// is not `Some`. #[inline] + #[track_caller] pub fn unwrap(self) -> T { assert_eq!(self.is_some.unwrap_u8(), 1);