@@ -357,12 +357,16 @@ fn get_source(input: &Input, sess: &Session) -> (String, FileName) {
357
357
( src, src_name)
358
358
}
359
359
360
- fn write_or_print ( out : & str , ofile : Option < & Path > ) {
360
+ fn write_or_print ( out : & str , ofile : Option < & Path > , sess : & Session ) {
361
361
match ofile {
362
362
None => print ! ( "{}" , out) ,
363
363
Some ( p) => {
364
364
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 ( ) ;
366
370
}
367
371
}
368
372
}
@@ -402,7 +406,7 @@ pub fn print_after_parsing(
402
406
_ => unreachable ! ( ) ,
403
407
} ;
404
408
405
- write_or_print ( & out, ofile) ;
409
+ write_or_print ( & out, ofile, sess ) ;
406
410
}
407
411
408
412
pub fn print_after_hir_lowering < ' tcx > (
@@ -468,7 +472,7 @@ pub fn print_after_hir_lowering<'tcx>(
468
472
_ => unreachable ! ( ) ,
469
473
} ;
470
474
471
- write_or_print ( & out, ofile) ;
475
+ write_or_print ( & out, ofile, tcx . sess ) ;
472
476
}
473
477
474
478
// In an ideal world, this would be a public function called by the driver after
@@ -512,7 +516,7 @@ fn print_with_analysis(
512
516
_ => unreachable ! ( ) ,
513
517
} ;
514
518
515
- write_or_print ( & out, ofile) ;
519
+ write_or_print ( & out, ofile, tcx . sess ) ;
516
520
517
521
Ok ( ( ) )
518
522
}
0 commit comments