Skip to content

Commit 7261a79

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

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

compiler/rustc_const_eval/src/interpret/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ mod place;
1414
mod projection;
1515
mod stack;
1616
mod step;
17+
mod tracing_utils;
1718
mod traits;
1819
mod util;
1920
mod validity;
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/// This struct is needed to enforce `#[must_use]` on [tracing::span::EnteredSpan]
2+
/// while wrapping them in an `Option`.
3+
#[must_use]
4+
pub enum MaybeEnteredSpan {
5+
Some(tracing::span::EnteredSpan),
6+
None,
7+
}
8+
9+
#[macro_export]
10+
macro_rules! enter_trace_span {
11+
($machine:ident, $($tt:tt)*) => {
12+
if $machine::TRACING_ENABLED {
13+
$crate::interpret::tracing_utils::MaybeEnteredSpan::Some(tracing::info_span!($($tt)*).entered())
14+
} else {
15+
$crate::interpret::tracing_utils::MaybeEnteredSpan::None
16+
}
17+
}
18+
}

0 commit comments

Comments
 (0)