From 8f8943547b1030a7629748a1dfa494c556a66fb1 Mon Sep 17 00:00:00 2001 From: David Mulder Date: Thu, 22 Aug 2024 15:23:15 -0600 Subject: [PATCH] Fix display of function names in debug Rust adds some odd `{{closure}}` bits to the function name that need to be removed, otherwise the debug is unreadable. Signed-off-by: David Mulder Reviewed-by: Alexander Bokovoy --- rust/dbg/src/lib.rs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/rust/dbg/src/lib.rs b/rust/dbg/src/lib.rs index 55447ba85f0..2104cdb0d1c 100644 --- a/rust/dbg/src/lib.rs +++ b/rust/dbg/src/lib.rs @@ -88,10 +88,15 @@ macro_rules! function { } let name = type_name_of(f); - match &name[..name.len() - 3].rfind(':') { - Some(pos) => &name[pos + 1..name.len() - 3], - None => &name[..name.len() - 3], - } + let base_name = match name.rfind("::") { + Some(pos) => &name[..pos], + None => name, + }; + let parts: Vec<&str> = base_name + .split("::") + .filter(|&p| p != "{{closure}}") + .collect(); + parts.join("::") }}; } @@ -103,7 +108,7 @@ macro_rules! DBG_PREFIX { let location_cstr = chelps::wrap_string(&location); let function = $crate::function!(); let function_msg = format!("{}: ", function); - let function_cstr = chelps::wrap_string(function); + let function_cstr = chelps::wrap_string(&function); let function_msg_cstr = chelps::wrap_string(&function_msg); let msg = format!($($arg),*); let msg_cstr = chelps::wrap_string(&msg); -- 2.47.3