Skip to content

Commit 18135ec

Browse files
committed
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`
2 parents 8eef79c + ef13f27 commit 18135ec

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

library/std/src/panic.rs

+1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ pub use core::panic::{Location, PanicInfo};
5555
/// See the [`panic!`] macro for more information about panicking.
5656
#[stable(feature = "panic_any", since = "1.51.0")]
5757
#[inline]
58+
#[track_caller]
5859
pub fn panic_any<M: 'static + Any + Send>(msg: M) -> ! {
5960
crate::panicking::begin_panic(msg);
6061
}

0 commit comments

Comments
 (0)