diff options
| author | bors <bors@rust-lang.org> | 2021-05-28 06:08:58 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2021-05-28 06:08:58 +0000 |
| commit | 18135ec85be45df013ecd0d1eb4a49128d043e20 (patch) | |
| tree | f4c0be2032f0807d06fc6376ac9bc82e07a83f7d | |
| parent | 8eef79ca9a2ff47db25905e8c21e2ffba1d353cb (diff) | |
| parent | ef13f27bc7f35c4a790e2ccd94217e27869f1e14 (diff) | |
| download | rust-18135ec85be45df013ecd0d1eb4a49128d043e20.tar.gz rust-18135ec85be45df013ecd0d1eb4a49128d043e20.zip | |
Auto merge of #85745 - veber-alex:panic_any, r=m-ou-se
Add #[track_caller] to panic_any
Report the panic location from the user code.
```rust
use std::panic;
use std::panic::panic_any;
fn main() {
panic::set_hook(Box::new(|panic_info| {
if let Some(location) = panic_info.location() {
println!(
"panic occurred in file '{}' at line {}",
location.file(),
location.line(),
);
} else {
println!("panic occurred but can't get location information...");
}
}));
panic_any(42);
}
````
Before:
`panic occurred in file '/rustc/ff2c947c00f867b9f012e28ba88cecfbe556f904/library/std/src/panic.rs' at line 59`
After:
`panic occurred in file 'src/main.rs' at line 17`
| -rw-r--r-- | library/std/src/panic.rs | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/library/std/src/panic.rs b/library/std/src/panic.rs index b10dde42482..9e3880dfd41 100644 --- a/library/std/src/panic.rs +++ b/library/std/src/panic.rs @@ -55,6 +55,7 @@ pub use core::panic::{Location, PanicInfo}; /// See the [`panic!`] macro for more information about panicking. #[stable(feature = "panic_any", since = "1.51.0")] #[inline] +#[track_caller] pub fn panic_any<M: 'static + Any + Send>(msg: M) -> ! { crate::panicking::begin_panic(msg); } |
