Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/rustc_interface/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ pub(crate) struct TempsDirError;
pub(crate) struct OutDirError;

#[derive(Diagnostic)]
#[diag("failed to write file {$path}: {$error}\"")]
#[diag("failed to write file {$path}: {$error}")]
pub(crate) struct FailedWritingFile<'a> {
pub path: &'a Path,
pub error: io::Error,
Expand Down
8 changes: 5 additions & 3 deletions compiler/rustc_interface/src/passes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -881,9 +881,11 @@ pub fn write_interface<'tcx>(tcx: TyCtxt<'tcx>) {
&tcx.sess.psess.attr_id_generator,
);
let export_output = tcx.output_filenames(()).interface_path();
let mut file = fs::File::create_buffered(export_output).unwrap();
if let Err(err) = write!(file, "{}", krate) {
tcx.dcx().fatal(format!("error writing interface file: {}", err));
let mut file = fs::File::create_buffered(&export_output).unwrap_or_else(|error| {
tcx.dcx().emit_fatal(diagnostics::FailedWritingFile { path: &export_output, error })
});
if let Err(error) = write!(file, "{}", krate) {
tcx.dcx().emit_fatal(diagnostics::FailedWritingFile { path: &export_output, error });
}
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub(crate) struct DropCheckOverflow<'tcx> {
}

#[derive(Diagnostic)]
#[diag("failed to write file {$path}: {$error}\"")]
#[diag("failed to write file {$path}: {$error}")]
pub(crate) struct FailedWritingFile<'a> {
pub path: &'a Path,
pub error: io::Error,
Expand Down
13 changes: 13 additions & 0 deletions tests/run-make/export/write-interface-nonexistent-dir/libr.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#![feature(export_stable)]
#![crate_type = "sdylib"]

pub mod m {
#[repr(C)]
pub struct S {
pub x: i32,
}

pub extern "C" fn foo1(x: S) -> i32 {
x.x
}
}
18 changes: 18 additions & 0 deletions tests/run-make/export/write-interface-nonexistent-dir/rmake.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Regression test for <https://github.com/rust-lang/rust/issues/143981>.

//@ ignore-cross-compile

// NOTE: `sdylib`'s platform support is basically that of `dylib`.
//@ needs-crate-type: dylib

use run_make_support::rustc;

fn main() {
rustc()
.input("libr.rs")
.output("does-not-exist/output")
.run_fail()
.assert_exit_code(1)
.assert_stderr_contains("failed to write file")
.assert_not_ice();
}
Loading