15
15
issue = "44489" ) ]
16
16
17
17
use any:: Any ;
18
+ use fmt;
18
19
19
20
/// A struct providing information about a panic.
20
21
///
@@ -38,6 +39,7 @@ use any::Any;
38
39
#[ derive( Debug ) ]
39
40
pub struct PanicInfo < ' a > {
40
41
payload : & ' a ( Any + Send ) ,
42
+ message : Option < & ' a fmt:: Arguments < ' a > > ,
41
43
location : Location < ' a > ,
42
44
}
43
45
@@ -47,8 +49,11 @@ impl<'a> PanicInfo<'a> {
47
49
and related macros",
48
50
issue = "0" ) ]
49
51
#[ doc( hidden) ]
50
- pub fn internal_constructor ( payload : & ' a ( Any + Send ) , location : Location < ' a > , ) -> Self {
51
- PanicInfo { payload, location }
52
+ pub fn internal_constructor ( payload : & ' a ( Any + Send ) ,
53
+ message : Option < & ' a fmt:: Arguments < ' a > > ,
54
+ location : Location < ' a > )
55
+ -> Self {
56
+ PanicInfo { payload, location, message }
52
57
}
53
58
54
59
/// Returns the payload associated with the panic.
@@ -73,6 +78,16 @@ impl<'a> PanicInfo<'a> {
73
78
self . payload
74
79
}
75
80
81
+ /// If the `panic!` macro from the `core` crate (not from `std`)
82
+ /// was used with a formatting string and some additional arguments,
83
+ /// returns that message ready to be used for example with [`fmt::write`]
84
+ ///
85
+ /// [`fmt::write`]: ../fmt/fn.write.html
86
+ #[ unstable( feature = "panic_info_message" , issue = "44489" ) ]
87
+ pub fn message ( & self ) -> Option < & fmt:: Arguments > {
88
+ self . message
89
+ }
90
+
76
91
/// Returns information about the location from which the panic originated,
77
92
/// if available.
78
93
///
0 commit comments