-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathpanic.rs
72 lines (63 loc) · 1.63 KB
/
panic.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
pub struct PanicInfo<'a> {
payload: &'a (dyn Any + Send),
loc: &'a Location<'a>,
}
impl<'a> !Send for PanicInfo<'a> {}
impl<'a> !Sync for PanicInfo<'a> {}
impl<'a> PanicInfo<'a> {
pub fn payload(&self) -> &(dyn Any + Send) {
self.payload
}
#[unstable(feature = "panic_info_message", issue = "66754")]
pub fn message(&self) -> Option<&Arguments> {
self.payload.upcast()
}
pub fn location(&self) -> Option<&Location<'_>> {
Some(self.loc)
}
}
impl PanicInfo<'static> {
#[unstable(feature = "lccc_construct_panic")]
#[track_caller]
pub fn construct_panic(payload: &'static (dyn Any + Send)) -> Self {
Self {
payload,
location: Location::caller(),
}
}
}
pub struct Location<'a> {
file: &'a str,
line: u32,
col: u32,
}
impl<'a> Location<'a> {
#[track_caller]
#[inline]
pub fn caller() -> &'static Location<'static> {
{
#[__lccc::force_visible]
#[__lccc::abi_tag = ""]
fn __lccc__get_caller_location(
x: &'static Location<'static>,
) -> &'static Location<'static> {
x
}
}
extern "Rust" {
#[track_caller]
#[link_name = "_ZZNSt5panic8Location6callerEE27__lccc__get_caller_location"]
fn __lccc__get_caller_location() -> &'static Location<'static>;
}
unsafe { __lccc__get_caller_location() }
}
pub fn file(&self) -> &str {
self.file
}
pub fn line(&self) -> u32 {
self.line
}
pub fn col(&self) -> u32 {
self.col
}
}