-
Notifications
You must be signed in to change notification settings - Fork 0
/
panic.hpp
46 lines (37 loc) · 950 Bytes
/
panic.hpp
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
// panic.hpp
#pragma once
#include "_include.hpp"
#include "thread/thread.hpp"
#include "sys_common/thread.hpp"
#include <exception>
#include <iostream>
#include <string>
#include <utility>
namespace rust {
template<class Msg>
[[noreturn]] void panic(Msg&& msg) {
#ifdef RUST_PANIC_SHOULD_ABORT
std::cerr << "rust::panic: " << msg << '\n';
std::abort();
#else // RUST_PANIC_SHOULD_ABORT
if (thread::impl::update_panic_count(1) > 1) {
std::cerr << "thread panicked while panicking. aborting.\n";
std::abort();
}
std::cerr << "rust::panic: " << msg << '\n';
sys::thread_exit();
#endif // RUST_PANIC_SHOULD_ABORT
}
[[noreturn]] void panic() {
panic("explicit panic");
}
void assert(bool const b) {
if (!b)
panic("rust::assert() failed");
}
template<class T, class U>
void assert_eq(T const& t, U const& u) {
if (t != u)
panic("rust::assert_eq() failed");
}
} // namespace rust