File tree Expand file tree Collapse file tree 1 file changed +11
-7
lines changed Expand file tree Collapse file tree 1 file changed +11
-7
lines changed Original file line number Diff line number Diff line change @@ -248,13 +248,7 @@ fn default_hook(info: &PanicInfo<'_>) {
248248    // The current implementation always returns `Some`. 
249249    let  location = info. location ( ) . unwrap ( ) ; 
250250
251-     let  msg = match  info. payload ( ) . downcast_ref :: < & ' static  str > ( )  { 
252-         Some ( s)  => * s, 
253-         None  => match  info. payload ( ) . downcast_ref :: < String > ( )  { 
254-             Some ( s)  => & s[ ..] , 
255-             None  => "Box<dyn Any>" , 
256-         } , 
257-     } ; 
251+     let  msg = payload_as_str ( info. payload ( ) ) ; 
258252    let  thread = thread:: try_current ( ) ; 
259253    let  name = thread. as_ref ( ) . and_then ( |t| t. name ( ) ) . unwrap_or ( "<unnamed>" ) ; 
260254
@@ -731,6 +725,16 @@ pub const fn begin_panic<M: Any + Send>(msg: M) -> ! {
731725    } 
732726} 
733727
728+ fn  payload_as_str ( payload :  & dyn  Any )  -> & str  { 
729+     if  let  Some ( & s)  = payload. downcast_ref :: < & ' static  str > ( )  { 
730+         s
731+     }  else  if  let  Some ( s)  = payload. downcast_ref :: < String > ( )  { 
732+         s. as_str ( ) 
733+     }  else  { 
734+         "Box<dyn Any>" 
735+     } 
736+ } 
737+ 
734738/// Central point for dispatching panics. 
735739/// 
736740/// Executes the primary logic for a panic, including checking for recursive 
    
 
   
 
     
   
   
          
     
  
    
     
 
    
      
     
 
     
    You can’t perform that action at this time.
  
 
    
  
     
    
      
        
     
 
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments