summaryrefslogtreecommitdiffstats
path: root/vendor/sharded-slab/src/macros.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
commit698f8c2f01ea549d77d7dc3338a12e04c11057b9 (patch)
tree173a775858bd501c378080a10dca74132f05bc50 /vendor/sharded-slab/src/macros.rs
parentInitial commit. (diff)
downloadrustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.tar.xz
rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.zip
Adding upstream version 1.64.0+dfsg1.upstream/1.64.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/sharded-slab/src/macros.rs')
-rw-r--r--vendor/sharded-slab/src/macros.rs67
1 files changed, 67 insertions, 0 deletions
diff --git a/vendor/sharded-slab/src/macros.rs b/vendor/sharded-slab/src/macros.rs
new file mode 100644
index 000000000..e431f64f1
--- /dev/null
+++ b/vendor/sharded-slab/src/macros.rs
@@ -0,0 +1,67 @@
+macro_rules! test_println {
+ ($($arg:tt)*) => {
+ if cfg!(test) && cfg!(slab_print) {
+ if std::thread::panicking() {
+ // getting the thread ID while panicking doesn't seem to play super nicely with loom's
+ // mock lazy_static...
+ println!("[PANIC {:>17}:{:<3}] {}", file!(), line!(), format_args!($($arg)*))
+ } else {
+ println!("[{:?} {:>17}:{:<3}] {}", crate::Tid::<crate::DefaultConfig>::current(), file!(), line!(), format_args!($($arg)*))
+ }
+ }
+ }
+}
+
+#[cfg(all(test, loom))]
+macro_rules! test_dbg {
+ ($e:expr) => {
+ match $e {
+ e => {
+ test_println!("{} = {:?}", stringify!($e), &e);
+ e
+ }
+ }
+ };
+}
+
+macro_rules! panic_in_drop {
+ ($($arg:tt)*) => {
+ if !std::thread::panicking() {
+ panic!($($arg)*)
+ } else {
+ let thread = std::thread::current();
+ eprintln!(
+ "thread '{thread}' attempted to panic at '{msg}', {file}:{line}:{col}\n\
+ note: we were already unwinding due to a previous panic.",
+ thread = thread.name().unwrap_or("<unnamed>"),
+ msg = format_args!($($arg)*),
+ file = file!(),
+ line = line!(),
+ col = column!(),
+ );
+ }
+ }
+}
+
+macro_rules! debug_assert_eq_in_drop {
+ ($this:expr, $that:expr) => {
+ debug_assert_eq_in_drop!(@inner $this, $that, "")
+ };
+ ($this:expr, $that:expr, $($arg:tt)+) => {
+ debug_assert_eq_in_drop!(@inner $this, $that, format_args!(": {}", format_args!($($arg)+)))
+ };
+ (@inner $this:expr, $that:expr, $msg:expr) => {
+ if cfg!(debug_assertions) {
+ if $this != $that {
+ panic_in_drop!(
+ "assertion failed ({} == {})\n left: `{:?}`,\n right: `{:?}`{}",
+ stringify!($this),
+ stringify!($that),
+ $this,
+ $that,
+ $msg,
+ )
+ }
+ }
+ }
+}