From: David Mulder Date: Thu, 22 Aug 2024 21:23:15 +0000 (-0600) Subject: Fix display of function names in debug X-Git-Tag: tdb-1.4.13~885 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=8f8943547b1030a7629748a1dfa494c556a66fb1;p=thirdparty%2Fsamba.git 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 --- 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);