forked from tokio-rs/tokio
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
signal: add track_caller to public APIs
Functions that may panic can be annotated with #[track_caller] so that in the event of a panic, the function where the user called the panicking function is shown instead of the file and line within Tokio source. This change adds #[track_caller] to the signal() function which is the only function in the signal public API which can panic. Documentation was added to this function to indicate that it may panic. Not all panic cases can have #[track_caller] applied fully as the callstack passes through a closure which isn't yet supported by the annotation (e.g. signal() called from outside a tokio runtime). Tests are included to cover the case where signal() is called from a runtime without IO enabled. Refs: tokio-rs#4413
- Loading branch information
Showing
3 changed files
with
37 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#![warn(rust_2018_idioms)] | ||
#![cfg(feature = "full")] | ||
#![cfg(unix)] | ||
|
||
use std::error::Error; | ||
use tokio::runtime::Builder; | ||
use tokio::signal::unix::{signal, SignalKind}; | ||
|
||
mod support { | ||
pub mod panic; | ||
} | ||
use support::panic::test_panic; | ||
|
||
#[test] | ||
fn signal_panic_caller() -> Result<(), Box<dyn Error>> { | ||
let panic_location_file = test_panic(|| { | ||
let rt = Builder::new_current_thread().build().unwrap(); | ||
|
||
rt.block_on(async { | ||
let kind = SignalKind::from_raw(-1); | ||
let _ = signal(kind); | ||
}); | ||
}); | ||
|
||
// The panic location should be in this file | ||
assert_eq!(&panic_location_file.unwrap(), file!()); | ||
|
||
Ok(()) | ||
} |