@@ -292,32 +292,15 @@ cfg_if::cfg_if! {
292292 OptionCppSymbol ( None )
293293 }
294294 }
295- } else {
296- use core:: marker:: PhantomData ;
297-
298- // Make sure to keep this zero-sized, so that the `cpp_demangle` feature
299- // has no cost when disabled.
300- struct OptionCppSymbol <' a>( PhantomData <& ' a ( ) >) ;
301-
302- impl <' a> OptionCppSymbol <' a> {
303- fn parse( _: & ' a [ u8 ] ) -> OptionCppSymbol <' a> {
304- OptionCppSymbol ( PhantomData )
305- }
306-
307- fn none( ) -> OptionCppSymbol <' a> {
308- OptionCppSymbol ( PhantomData )
309- }
310- }
311295 }
312296}
313297
314298/// A wrapper around a symbol name to provide ergonomic accessors to the
315299/// demangled name, the raw bytes, the raw string, etc.
316- // Allow dead code for when the `cpp_demangle` feature is not enabled.
317- #[ allow( dead_code) ]
318300pub struct SymbolName < ' a > {
319301 bytes : & ' a [ u8 ] ,
320302 demangled : Option < Demangle < ' a > > ,
303+ #[ cfg( feature = "cpp_demangle" ) ]
321304 cpp_demangled : OptionCppSymbol < ' a > ,
322305}
323306
@@ -327,6 +310,7 @@ impl<'a> SymbolName<'a> {
327310 let str_bytes = str:: from_utf8 ( bytes) . ok ( ) ;
328311 let demangled = str_bytes. and_then ( |s| try_demangle ( s) . ok ( ) ) ;
329312
313+ #[ cfg( feature = "cpp_demangle" ) ]
330314 let cpp = if demangled. is_none ( ) {
331315 OptionCppSymbol :: parse ( bytes)
332316 } else {
@@ -336,6 +320,7 @@ impl<'a> SymbolName<'a> {
336320 SymbolName {
337321 bytes : bytes,
338322 demangled : demangled,
323+ #[ cfg( feature = "cpp_demangle" ) ]
339324 cpp_demangled : cpp,
340325 }
341326 }
@@ -380,65 +365,45 @@ fn format_symbol_name(
380365 Ok ( ( ) )
381366}
382367
383- cfg_if:: cfg_if! {
384- if #[ cfg( feature = "cpp_demangle" ) ] {
385- impl <' a> fmt:: Display for SymbolName <' a> {
386- fn fmt( & self , f: & mut fmt:: Formatter <' _>) -> fmt:: Result {
387- if let Some ( ref s) = self . demangled {
388- s. fmt( f)
389- } else if let Some ( ref cpp) = self . cpp_demangled. 0 {
390- cpp. fmt( f)
391- } else {
392- format_symbol_name( fmt:: Display :: fmt, self . bytes, f)
393- }
394- }
368+ impl < ' a > fmt:: Display for SymbolName < ' a > {
369+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
370+ if let Some ( ref s) = self . demangled {
371+ return s. fmt ( f) ;
395372 }
396- } else {
397- impl <' a> fmt:: Display for SymbolName <' a> {
398- fn fmt( & self , f: & mut fmt:: Formatter <' _>) -> fmt:: Result {
399- if let Some ( ref s) = self . demangled {
400- s. fmt( f)
401- } else {
402- format_symbol_name( fmt:: Display :: fmt, self . bytes, f)
403- }
373+
374+ #[ cfg( feature = "cpp_demangle" ) ]
375+ {
376+ if let Some ( ref cpp) = self . cpp_demangled . 0 {
377+ return cpp. fmt ( f) ;
404378 }
405379 }
380+
381+ format_symbol_name ( fmt:: Display :: fmt, self . bytes , f)
406382 }
407383}
408384
409- cfg_if:: cfg_if! {
410- if #[ cfg( all( feature = "std" , feature = "cpp_demangle" ) ) ] {
411- impl <' a> fmt:: Debug for SymbolName <' a> {
412- fn fmt( & self , f: & mut fmt:: Formatter <' _>) -> fmt:: Result {
413- use std:: fmt:: Write ;
414-
415- if let Some ( ref s) = self . demangled {
416- return s. fmt( f)
417- }
418-
419- // This may to print if the demangled symbol isn't actually
420- // valid, so handle the error here gracefully by not propagating
421- // it outwards.
422- if let Some ( ref cpp) = self . cpp_demangled. 0 {
423- let mut s = String :: new( ) ;
424- if write!( s, "{cpp}" ) . is_ok( ) {
425- return s. fmt( f)
426- }
427- }
428-
429- format_symbol_name( fmt:: Debug :: fmt, self . bytes, f)
430- }
385+ impl < ' a > fmt:: Debug for SymbolName < ' a > {
386+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
387+ if let Some ( ref s) = self . demangled {
388+ return s. fmt ( f) ;
431389 }
432- } else {
433- impl <' a> fmt:: Debug for SymbolName <' a> {
434- fn fmt( & self , f: & mut fmt:: Formatter <' _>) -> fmt:: Result {
435- if let Some ( ref s) = self . demangled {
436- s. fmt( f)
437- } else {
438- format_symbol_name( fmt:: Debug :: fmt, self . bytes, f)
390+
391+ #[ cfg( all( feature = "std" , feature = "cpp_demangle" ) ) ]
392+ {
393+ use std:: fmt:: Write ;
394+
395+ // This may to print if the demangled symbol isn't actually
396+ // valid, so handle the error here gracefully by not propagating
397+ // it outwards.
398+ if let Some ( ref cpp) = self . cpp_demangled . 0 {
399+ let mut s = String :: new ( ) ;
400+ if write ! ( s, "{cpp}" ) . is_ok ( ) {
401+ return s. fmt ( f) ;
439402 }
440403 }
441404 }
405+
406+ format_symbol_name ( fmt:: Debug :: fmt, self . bytes , f)
442407 }
443408}
444409
0 commit comments