Skip to content

Commit 77eb1ae

Browse files
committed
add UI test for unpretty
1 parent 9678751 commit 77eb1ae

File tree

5 files changed

+22
-5
lines changed

5 files changed

+22
-5
lines changed

compiler/rustc_driver/src/pretty.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//! The various pretty-printing routines.
22
3+
use crate::session_diagnostics::UnprettyDumpFail;
34
use rustc_ast as ast;
45
use rustc_ast_pretty::pprust;
56
use rustc_errors::ErrorGuaranteed;
@@ -362,11 +363,10 @@ fn write_or_print(out: &str, ofile: Option<&Path>, sess: &Session) {
362363
None => print!("{}", out),
363364
Some(p) => {
364365
if let Err(e) = std::fs::write(p, out) {
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+
sess.emit_fatal(UnprettyDumpFail {
367+
path: p.display().to_string(),
368+
err: e.to_string(),
369+
});
370370
}
371371
}
372372
}

compiler/rustc_driver/src/session_diagnostics.rs

+7
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,10 @@ pub(crate) struct RLinkRustcVersionMismatch<'a> {
3131
#[derive(SessionDiagnostic)]
3232
#[diag(driver::rlink_no_a_file)]
3333
pub(crate) struct RlinkNotAFile;
34+
35+
#[derive(SessionDiagnostic)]
36+
#[diag(driver::unpretty_dump_fail)]
37+
pub(crate) struct UnprettyDumpFail {
38+
pub path: String,
39+
pub err: String,
40+
}

compiler/rustc_error_messages/locales/en-US/driver.ftl

+2
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,5 @@ driver_rlink_encoding_version_mismatch = .rlink file was produced with encoding
99
driver_rlink_rustc_version_mismatch = .rlink file was produced by rustc version `{$rustc_version}`, but the current version is `{$current_version}`
1010
1111
driver_rlink_no_a_file = rlink must be a file
12+
13+
driver_unpretty_dump_fail = pretty-print failed to write `{$path}` due to error `{$err}`

src/test/ui/unpretty/avoid-crash.rs

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// normalize-stderr-test "error `.*`" -> "$$ERROR_MESSAGE"
2+
// compile-flags: -o/tmp/ -Zunpretty=ast-tree
3+
4+
fn main() {}
+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
error: pretty-print failed to write `/tmp/` due to $ERROR_MESSAGE
2+
3+
error: aborting due to previous error
4+

0 commit comments

Comments
 (0)