add UI test for unpretty
This commit is contained in:
parent
9678751a88
commit
77eb1aef52
5 changed files with 22 additions and 5 deletions
|
@ -1,5 +1,6 @@
|
||||||
//! The various pretty-printing routines.
|
//! The various pretty-printing routines.
|
||||||
|
|
||||||
|
use crate::session_diagnostics::UnprettyDumpFail;
|
||||||
use rustc_ast as ast;
|
use rustc_ast as ast;
|
||||||
use rustc_ast_pretty::pprust;
|
use rustc_ast_pretty::pprust;
|
||||||
use rustc_errors::ErrorGuaranteed;
|
use rustc_errors::ErrorGuaranteed;
|
||||||
|
@ -362,11 +363,10 @@ fn write_or_print(out: &str, ofile: Option<&Path>, sess: &Session) {
|
||||||
None => print!("{}", out),
|
None => print!("{}", out),
|
||||||
Some(p) => {
|
Some(p) => {
|
||||||
if let Err(e) = std::fs::write(p, out) {
|
if let Err(e) = std::fs::write(p, out) {
|
||||||
let mut err = sess.struct_fatal(&format!(
|
sess.emit_fatal(UnprettyDumpFail {
|
||||||
"pretty-print failed to write {} due to error `{e}`",
|
path: p.display().to_string(),
|
||||||
p.display()
|
err: e.to_string(),
|
||||||
));
|
});
|
||||||
err.emit();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,3 +31,10 @@ pub(crate) struct RLinkRustcVersionMismatch<'a> {
|
||||||
#[derive(SessionDiagnostic)]
|
#[derive(SessionDiagnostic)]
|
||||||
#[diag(driver::rlink_no_a_file)]
|
#[diag(driver::rlink_no_a_file)]
|
||||||
pub(crate) struct RlinkNotAFile;
|
pub(crate) struct RlinkNotAFile;
|
||||||
|
|
||||||
|
#[derive(SessionDiagnostic)]
|
||||||
|
#[diag(driver::unpretty_dump_fail)]
|
||||||
|
pub(crate) struct UnprettyDumpFail {
|
||||||
|
pub path: String,
|
||||||
|
pub err: String,
|
||||||
|
}
|
||||||
|
|
|
@ -9,3 +9,5 @@ driver_rlink_encoding_version_mismatch = .rlink file was produced with encoding
|
||||||
driver_rlink_rustc_version_mismatch = .rlink file was produced by rustc version `{$rustc_version}`, but the current version is `{$current_version}`
|
driver_rlink_rustc_version_mismatch = .rlink file was produced by rustc version `{$rustc_version}`, but the current version is `{$current_version}`
|
||||||
|
|
||||||
driver_rlink_no_a_file = rlink must be a file
|
driver_rlink_no_a_file = rlink must be a file
|
||||||
|
|
||||||
|
driver_unpretty_dump_fail = pretty-print failed to write `{$path}` due to error `{$err}`
|
||||||
|
|
4
src/test/ui/unpretty/avoid-crash.rs
Normal file
4
src/test/ui/unpretty/avoid-crash.rs
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
// normalize-stderr-test "error `.*`" -> "$$ERROR_MESSAGE"
|
||||||
|
// compile-flags: -o/tmp/ -Zunpretty=ast-tree
|
||||||
|
|
||||||
|
fn main() {}
|
4
src/test/ui/unpretty/avoid-crash.stderr
Normal file
4
src/test/ui/unpretty/avoid-crash.stderr
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
error: pretty-print failed to write `/tmp/` due to $ERROR_MESSAGE
|
||||||
|
|
||||||
|
error: aborting due to previous error
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue