-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathmain.rs
More file actions
56 lines (45 loc) · 928 Bytes
/
main.rs
File metadata and controls
56 lines (45 loc) · 928 Bytes
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
#![no_std]
#![no_main]
extern crate alloc;
extern crate unwinding;
use alloc::{borrow::ToOwned, string::String};
use unwinding::print::*;
#[link(name = "c")]
unsafe extern "C" {}
struct PrintOnDrop(String);
impl Drop for PrintOnDrop {
fn drop(&mut self) {
eprintln!("dropped: {:?}", self.0);
}
}
struct PanicOnDrop;
impl Drop for PanicOnDrop {
fn drop(&mut self) {
panic!("panic on drop");
}
}
#[track_caller]
fn foo() {
panic!("panic");
}
fn bar() {
let _p = PrintOnDrop("string".to_owned());
foo()
}
fn main() {
let _ = unwinding::panic::catch_unwind(|| {
bar();
eprintln!("done");
});
eprintln!("caught");
let _p = PanicOnDrop;
foo();
}
#[unsafe(export_name = "main")]
extern "C" fn start(_argc: isize, _argv: *const *const u8) -> isize {
unwinding::panic::catch_unwind(|| {
main();
0
})
.unwrap_or(101)
}