@@ -292,32 +292,15 @@ cfg_if::cfg_if! {
292
292
OptionCppSymbol ( None )
293
293
}
294
294
}
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
- }
311
295
}
312
296
}
313
297
314
298
/// A wrapper around a symbol name to provide ergonomic accessors to the
315
299
/// 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) ]
318
300
pub struct SymbolName < ' a > {
319
301
bytes : & ' a [ u8 ] ,
320
302
demangled : Option < Demangle < ' a > > ,
303
+ #[ cfg( feature = "cpp_demangle" ) ]
321
304
cpp_demangled : OptionCppSymbol < ' a > ,
322
305
}
323
306
@@ -327,6 +310,7 @@ impl<'a> SymbolName<'a> {
327
310
let str_bytes = str:: from_utf8 ( bytes) . ok ( ) ;
328
311
let demangled = str_bytes. and_then ( |s| try_demangle ( s) . ok ( ) ) ;
329
312
313
+ #[ cfg( feature = "cpp_demangle" ) ]
330
314
let cpp = if demangled. is_none ( ) {
331
315
OptionCppSymbol :: parse ( bytes)
332
316
} else {
@@ -336,6 +320,7 @@ impl<'a> SymbolName<'a> {
336
320
SymbolName {
337
321
bytes : bytes,
338
322
demangled : demangled,
323
+ #[ cfg( feature = "cpp_demangle" ) ]
339
324
cpp_demangled : cpp,
340
325
}
341
326
}
@@ -380,65 +365,45 @@ fn format_symbol_name(
380
365
Ok ( ( ) )
381
366
}
382
367
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) ;
395
372
}
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) ;
404
378
}
405
379
}
380
+
381
+ format_symbol_name ( fmt:: Display :: fmt, self . bytes , f)
406
382
}
407
383
}
408
384
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) ;
431
389
}
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) ;
439
402
}
440
403
}
441
404
}
405
+
406
+ format_symbol_name ( fmt:: Debug :: fmt, self . bytes , f)
442
407
}
443
408
}
444
409
0 commit comments