|
1 | 1 | //! The various pretty-printing routines.
|
2 | 2 |
|
| 3 | +use crate::session_diagnostics::UnprettyDumpFail; |
3 | 4 | use rustc_ast as ast;
|
4 | 5 | use rustc_ast_pretty::pprust;
|
5 | 6 | use rustc_errors::ErrorGuaranteed;
|
@@ -357,12 +358,15 @@ fn get_source(input: &Input, sess: &Session) -> (String, FileName) {
|
357 | 358 | (src, src_name)
|
358 | 359 | }
|
359 | 360 |
|
360 |
| -fn write_or_print(out: &str, ofile: Option<&Path>) { |
| 361 | +fn write_or_print(out: &str, ofile: Option<&Path>, sess: &Session) { |
361 | 362 | match ofile {
|
362 | 363 | None => print!("{}", out),
|
363 | 364 | Some(p) => {
|
364 | 365 | if let Err(e) = std::fs::write(p, out) {
|
365 |
| - panic!("print-print failed to write {} due to {}", p.display(), e); |
| 366 | + sess.emit_fatal(UnprettyDumpFail { |
| 367 | + path: p.display().to_string(), |
| 368 | + err: e.to_string(), |
| 369 | + }); |
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