From c9149310778ac85ae85a985cc59f5077236fbddc Mon Sep 17 00:00:00 2001 From: Kyle Huey Date: Tue, 23 Sep 2025 20:29:37 -0700 Subject: [PATCH] Upgrade `cpp_demangle` to the latest version. cpp_demangle 0.5.0 drops the `Display` impl on the `Symbol` object because it can subtly violate the `Display` contract. The recommended replacement is `Symbol::demangle`. Changelog: https://github.com/gimli-rs/cpp_demangle/blob/0.5.0/CHANGELOG.md#050 --- Cargo.lock | 4 ++-- Cargo.toml | 2 +- src/symbolize/mod.rs | 14 ++++++++------ 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2730a4b1..1312460b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -66,9 +66,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "cpp_demangle" -version = "0.4.4" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96e58d342ad113c2b878f16d5d034c03be492ae460cdbc02b7f0f2284d310c7d" +checksum = "4dcc405d55da54ad965aff198909afdcc8aeefc8ac6ba26d6abd19aa8aeacb2a" dependencies = [ "cfg-if", ] diff --git a/Cargo.toml b/Cargo.toml index 7e1233c9..c0f6f8be 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -34,7 +34,7 @@ rustc-demangle = "0.1.24" serde = { version = "1.0", optional = true, features = ['derive'] } # Optionally demangle C++ frames' symbols in backtraces. -cpp_demangle = { default-features = false, version = "0.4.0", optional = true, features = [ +cpp_demangle = { default-features = false, version = "0.5.0", optional = true, features = [ "alloc", ] } diff --git a/src/symbolize/mod.rs b/src/symbolize/mod.rs index 137d2ea3..62714f04 100644 --- a/src/symbolize/mod.rs +++ b/src/symbolize/mod.rs @@ -373,8 +373,13 @@ impl<'a> fmt::Display for SymbolName<'a> { #[cfg(feature = "cpp_demangle")] { + // This may fail to print if the demangled symbol isn't actually + // valid, so handle the error here gracefully by not propagating + // it outwards. if let Some(ref cpp) = self.cpp_demangled.0 { - return cpp.fmt(f); + if let Ok(s) = cpp.demangle() { + return s.fmt(f); + } } } @@ -390,14 +395,11 @@ impl<'a> fmt::Debug for SymbolName<'a> { #[cfg(all(feature = "std", feature = "cpp_demangle"))] { - use std::fmt::Write; - - // This may to print if the demangled symbol isn't actually + // This may fail to print if the demangled symbol isn't actually // valid, so handle the error here gracefully by not propagating // it outwards. if let Some(ref cpp) = self.cpp_demangled.0 { - let mut s = String::new(); - if write!(s, "{cpp}").is_ok() { + if let Ok(s) = cpp.demangle() { return s.fmt(f); } }