@@ -357,12 +357,16 @@ fn get_source(input: &Input, sess: &Session) -> (String, FileName) {
357357 ( src, src_name)
358358}
359359
360- fn write_or_print ( out : & str , ofile : Option < & Path > ) {
360+ fn write_or_print ( out : & str , ofile : Option < & Path > , sess : & Session ) {
361361 match ofile {
362362 None => print ! ( "{}" , out) ,
363363 Some ( p) => {
364364 if let Err ( e) = std:: fs:: write ( p, out) {
365- panic ! ( "print-print failed to write {} due to {}" , p. display( ) , e) ;
365+ let mut err = sess. struct_fatal ( & format ! (
366+ "pretty-print failed to write {} due to error `{e}`" ,
367+ p. display( )
368+ ) ) ;
369+ err. emit ( ) ;
366370 }
367371 }
368372 }
@@ -402,7 +406,7 @@ pub fn print_after_parsing(
402406 _ => unreachable ! ( ) ,
403407 } ;
404408
405- write_or_print ( & out, ofile) ;
409+ write_or_print ( & out, ofile, sess ) ;
406410}
407411
408412pub fn print_after_hir_lowering < ' tcx > (
@@ -468,7 +472,7 @@ pub fn print_after_hir_lowering<'tcx>(
468472 _ => unreachable ! ( ) ,
469473 } ;
470474
471- write_or_print ( & out, ofile) ;
475+ write_or_print ( & out, ofile, tcx . sess ) ;
472476}
473477
474478// In an ideal world, this would be a public function called by the driver after
@@ -512,7 +516,7 @@ fn print_with_analysis(
512516 _ => unreachable ! ( ) ,
513517 } ;
514518
515- write_or_print ( & out, ofile) ;
519+ write_or_print ( & out, ofile, tcx . sess ) ;
516520
517521 Ok ( ( ) )
518522}
0 commit comments