Skip to content

Commit 28db348

Browse files
committed
Add enter_trace_span!() that checks if tracing is enabled
1 parent f4bc4cd commit 28db348

File tree

1 file changed

+19
-0
lines changed
  • compiler/rustc_const_eval/src/interpret

1 file changed

+19
-0
lines changed

compiler/rustc_const_eval/src/interpret/util.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,22 @@ pub(crate) fn create_static_alloc<'tcx>(
4545
assert!(ecx.memory.alloc_map.insert(alloc_id, (MemoryKind::Stack, alloc)).is_none());
4646
interp_ok(ecx.ptr_to_mplace(Pointer::from(alloc_id).into(), layout))
4747
}
48+
49+
/// This struct is needed to enforce `#[must_use]` on [tracing::span::EnteredSpan]
50+
/// while wrapping them in an `Option`.
51+
#[must_use]
52+
pub enum MaybeEnteredSpan {
53+
Some(tracing::span::EnteredSpan),
54+
None,
55+
}
56+
57+
#[macro_export]
58+
macro_rules! enter_trace_span {
59+
($machine:ident, $($tt:tt)*) => {
60+
if $machine::TRACING_ENABLED {
61+
$crate::interpret::tracing_utils::MaybeEnteredSpan::Some(tracing::info_span!($($tt)*).entered())
62+
} else {
63+
$crate::interpret::tracing_utils::MaybeEnteredSpan::None
64+
}
65+
}
66+
}

0 commit comments

Comments
 (0)