about summary refs log tree commit diff
diff options
context:
space:
mode:
authorStypox <stypox@pm.me>2025-07-31 15:36:44 +0200
committerStypox <stypox@pm.me>2025-07-31 15:42:29 +0200
commitbb08a4dfc784ad5558e42db3b41b4abbebafc5a9 (patch)
tree53da1bcad1b6eccb9b8ee23455be278213f777fa
parente1f674cfa962fc76adbc4cfe95e9b3434299eede (diff)
downloadrust-bb08a4dfc784ad5558e42db3b41b4abbebafc5a9.tar.gz
rust-bb08a4dfc784ad5558e42db3b41b4abbebafc5a9.zip
Make Miri's enter_trace_span! call const_eval's
-rw-r--r--compiler/rustc_const_eval/src/interpret/util.rs8
-rw-r--r--src/tools/miri/src/helpers.rs23
-rw-r--r--src/tools/miri/src/lib.rs4
3 files changed, 9 insertions, 26 deletions
diff --git a/compiler/rustc_const_eval/src/interpret/util.rs b/compiler/rustc_const_eval/src/interpret/util.rs
index 341756f837e..6696a0c5026 100644
--- a/compiler/rustc_const_eval/src/interpret/util.rs
+++ b/compiler/rustc_const_eval/src/interpret/util.rs
@@ -114,11 +114,11 @@ impl EnteredTraceSpan for tracing::span::EnteredSpan {}
 /// ```
 #[macro_export]
 macro_rules! enter_trace_span {
-    ($machine:ident, $name:ident :: $subname:ident $($tt:tt)*) => {{
+    ($machine:ty, $name:ident :: $subname:ident $($tt:tt)*) => {
         $crate::enter_trace_span!($machine, stringify!($name), $name = %stringify!($subname) $($tt)*)
-    }};
+    };
 
-    ($machine:ident, $($tt:tt)*) => {
+    ($machine:ty, $($tt:tt)*) => {
         <$machine as $crate::interpret::Machine>::enter_trace_span(|| tracing::info_span!($($tt)*))
-    }
+    };
 }
diff --git a/src/tools/miri/src/helpers.rs b/src/tools/miri/src/helpers.rs
index c52796d358d..43cb1c9ae05 100644
--- a/src/tools/miri/src/helpers.rs
+++ b/src/tools/miri/src/helpers.rs
@@ -1245,29 +1245,14 @@ impl ToU64 for usize {
     }
 }
 
-/// This struct is needed to enforce `#[must_use]` on values produced by [enter_trace_span] even
-/// when the "tracing" feature is not enabled.
-#[must_use]
-pub struct MaybeEnteredTraceSpan {
-    #[cfg(feature = "tracing")]
-    pub _entered_span: tracing::span::EnteredSpan,
-}
-
 /// Enters a [tracing::info_span] only if the "tracing" feature is enabled, otherwise does nothing.
-/// This is like [rustc_const_eval::enter_trace_span] except that it does not depend on the
-/// [Machine] trait to check if tracing is enabled, because from the Miri codebase we can directly
-/// check whether the "tracing" feature is enabled, unlike from the rustc_const_eval codebase.
+/// This calls [rustc_const_eval::enter_trace_span] with [MiriMachine] as the first argument, which
+/// will in turn call [MiriMachine::enter_trace_span], which takes care of determining at compile
+/// time whether to trace or not (and supposedly the call is compiled out if tracing is disabled).
 /// Look at [rustc_const_eval::enter_trace_span] for complete documentation, examples and tips.
 #[macro_export]
 macro_rules! enter_trace_span {
-    ($name:ident :: $subname:ident $($tt:tt)*) => {{
-        $crate::enter_trace_span!(stringify!($name), $name = %stringify!($subname) $($tt)*)
-    }};
-
     ($($tt:tt)*) => {
-        $crate::MaybeEnteredTraceSpan {
-            #[cfg(feature = "tracing")]
-            _entered_span: tracing::info_span!($($tt)*).entered()
-        }
+        rustc_const_eval::enter_trace_span!($crate::MiriMachine<'static>, $($tt)*)
     };
 }
diff --git a/src/tools/miri/src/lib.rs b/src/tools/miri/src/lib.rs
index 507d4f7b428..8d34b8fc23a 100644
--- a/src/tools/miri/src/lib.rs
+++ b/src/tools/miri/src/lib.rs
@@ -143,9 +143,7 @@ pub use crate::eval::{
     AlignmentCheck, BacktraceStyle, IsolatedOp, MiriConfig, MiriEntryFnType, RejectOpWith,
     ValidationMode, create_ecx, eval_entry,
 };
-pub use crate::helpers::{
-    AccessKind, EvalContextExt as _, MaybeEnteredTraceSpan, ToU64 as _, ToUsize as _,
-};
+pub use crate::helpers::{AccessKind, EvalContextExt as _, ToU64 as _, ToUsize as _};
 pub use crate::intrinsics::EvalContextExt as _;
 pub use crate::machine::{
     AllocExtra, DynMachineCallback, FrameExtra, MachineCallback, MemoryKind, MiriInterpCx,