Skip to content

Commit 7a0ca80

Browse files
authored
time: add #[track_caller] to FutureExt::timeout (#7588)
Signed-off-by: Martin Tzvetanov Grigorov <[email protected]>
1 parent d8e8037 commit 7a0ca80

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

tokio-util/src/future.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ pub trait FutureExt: Future {
2626
/// assert!(res.is_err());
2727
/// # }
2828
/// ```
29+
#[track_caller]
2930
fn timeout(self, timeout: std::time::Duration) -> tokio::time::Timeout<Self>
3031
where
3132
Self: Sized,

tokio-util/tests/panic.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,23 @@ fn delay_queue_reserve_panic_caller() -> Result<(), Box<dyn Error>> {
217217
Ok(())
218218
}
219219

220+
#[test]
221+
fn future_ext_to_panic_caller() -> Result<(), Box<dyn Error>> {
222+
use tokio::{sync::oneshot, time::Duration};
223+
use tokio_util::future::FutureExt;
224+
225+
let panic_location_file = test_panic(|| {
226+
let (_tx, rx) = oneshot::channel::<()>();
227+
// this panics because there is no runtime available
228+
let _res = rx.timeout(Duration::from_millis(10));
229+
});
230+
231+
// The panic location should be in this file
232+
assert_eq!(&panic_location_file.unwrap(), file!());
233+
234+
Ok(())
235+
}
236+
220237
fn basic() -> Runtime {
221238
tokio::runtime::Builder::new_current_thread()
222239
.enable_all()

0 commit comments

Comments
 (0)