diff options
| author | Stypox <stypox@pm.me> | 2025-05-13 17:06:23 +0200 |
|---|---|---|
| committer | Stypox <stypox@pm.me> | 2025-05-20 17:28:30 +0200 |
| commit | 28db348fdd8a22352826e31d793ae916a8a60385 (patch) | |
| tree | 16b478363a9cf9d58a0813475f63fc6e05a790bd | |
| parent | f4bc4cd1fdb39203740929a6ec2cfc42f8b1e86d (diff) | |
| download | rust-28db348fdd8a22352826e31d793ae916a8a60385.tar.gz rust-28db348fdd8a22352826e31d793ae916a8a60385.zip | |
Add enter_trace_span!() that checks if tracing is enabled
| -rw-r--r-- | compiler/rustc_const_eval/src/interpret/util.rs | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/compiler/rustc_const_eval/src/interpret/util.rs b/compiler/rustc_const_eval/src/interpret/util.rs index ba579e25f03..847905e8343 100644 --- a/compiler/rustc_const_eval/src/interpret/util.rs +++ b/compiler/rustc_const_eval/src/interpret/util.rs @@ -45,3 +45,22 @@ pub(crate) fn create_static_alloc<'tcx>( assert!(ecx.memory.alloc_map.insert(alloc_id, (MemoryKind::Stack, alloc)).is_none()); interp_ok(ecx.ptr_to_mplace(Pointer::from(alloc_id).into(), layout)) } + +/// This struct is needed to enforce `#[must_use]` on [tracing::span::EnteredSpan] +/// while wrapping them in an `Option`. +#[must_use] +pub enum MaybeEnteredSpan { + Some(tracing::span::EnteredSpan), + None, +} + +#[macro_export] +macro_rules! enter_trace_span { + ($machine:ident, $($tt:tt)*) => { + if $machine::TRACING_ENABLED { + $crate::interpret::tracing_utils::MaybeEnteredSpan::Some(tracing::info_span!($($tt)*).entered()) + } else { + $crate::interpret::tracing_utils::MaybeEnteredSpan::None + } + } +} |
