@@ -782,15 +782,19 @@ fn format_object(rustfmt: Rustfmt, fmt_config: &FmtConfig, the_type: String) ->
782782 format ! ( "{}{{}}" , trimmed)
783783 } ;
784784
785- let formatted = match rustfmt. format ( object. clone ( ) , config) {
786- Ok ( lines) => match lines. rfind ( '{' ) {
785+ let formatted = match std :: panic :: catch_unwind ( || rustfmt. format ( object. clone ( ) , config) ) {
786+ Ok ( Ok ( lines) ) => match lines. rfind ( '{' ) {
787787 Some ( pos) => lines[ 0 ..pos] . into ( ) ,
788788 None => lines,
789789 } ,
790- Err ( e) => {
790+ Ok ( Err ( e) ) => {
791791 error ! ( "format_object: error: {:?}, input: {:?}" , e, object) ;
792792 trimmed. to_string ( )
793793 }
794+ Err ( _) => {
795+ error ! ( "format_object: rustfmt panicked on input: {:?}" , object) ;
796+ trimmed. to_string ( )
797+ }
794798 } ;
795799
796800 // If it's a tuple, remove the trailing ';' and hide non-pub components
@@ -2035,6 +2039,7 @@ pub mod test {
20352039
20362040 #[ test]
20372041 fn test_tooltip ( ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
2042+ let _ = env_logger:: try_init ( ) ;
20382043 use self :: test:: { LineOutput , Test , TooltipTestHarness } ;
20392044 use std:: env;
20402045
@@ -2125,6 +2130,7 @@ pub mod test {
21252130 #[ test]
21262131 #[ ignore]
21272132 fn test_tooltip_std ( ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
2133+ let _ = env_logger:: try_init ( ) ;
21282134 use self :: test:: { LineOutput , Test , TooltipTestHarness } ;
21292135 use std:: env;
21302136
0 commit comments