Skip to content

Commit 645de5b

Browse files
committed
Remove use of DiagnosticArgFromDisplay
1 parent 0d80ee7 commit 645de5b

File tree

3 files changed

+22
-30
lines changed

3 files changed

+22
-30
lines changed

compiler/rustc_interface/src/errors.rs

+12-10
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
use rustc_errors::DiagnosticArgFromDisplay;
21
use rustc_macros::SessionDiagnostic;
32
use rustc_span::{Span, Symbol};
43

4+
use std::io;
5+
use std::path::Path;
6+
57
#[derive(SessionDiagnostic)]
68
#[diag(interface::ferris_identifier)]
79
pub struct FerrisIdentifier {
@@ -34,21 +36,21 @@ pub struct ProcMacroDocWithoutArg;
3436
#[derive(SessionDiagnostic)]
3537
#[diag(interface::error_writing_dependencies)]
3638
pub struct ErrorWritingDependencies<'a> {
37-
pub path: DiagnosticArgFromDisplay<'a>,
38-
pub error: DiagnosticArgFromDisplay<'a>,
39+
pub path: &'a Path,
40+
pub error: io::Error,
3941
}
4042

4143
#[derive(SessionDiagnostic)]
4244
#[diag(interface::input_file_would_be_overwritten)]
4345
pub struct InputFileWouldBeOverWritten<'a> {
44-
pub path: DiagnosticArgFromDisplay<'a>,
46+
pub path: &'a Path,
4547
}
4648

4749
#[derive(SessionDiagnostic)]
4850
#[diag(interface::generated_file_conflicts_with_directory)]
4951
pub struct GeneratedFileConflictsWithDirectory<'a> {
50-
pub input_path: DiagnosticArgFromDisplay<'a>,
51-
pub dir_path: DiagnosticArgFromDisplay<'a>,
52+
pub input_path: &'a Path,
53+
pub dir_path: &'a Path,
5254
}
5355

5456
#[derive(SessionDiagnostic)]
@@ -61,8 +63,8 @@ pub struct OutDirError;
6163

6264
#[derive(SessionDiagnostic)]
6365
#[diag(interface::cant_emit_mir)]
64-
pub struct CantEmitMIR<'a> {
65-
pub error: DiagnosticArgFromDisplay<'a>,
66+
pub struct CantEmitMIR {
67+
pub error: io::Error,
6668
}
6769

6870
#[derive(SessionDiagnostic)]
@@ -82,6 +84,6 @@ pub struct RustcErrorUnexpectedAnnotation {
8284
#[derive(SessionDiagnostic)]
8385
#[diag(interface::failed_writing_file)]
8486
pub struct FailedWritingFile<'a> {
85-
pub path: DiagnosticArgFromDisplay<'a>,
86-
pub error: DiagnosticArgFromDisplay<'a>,
87+
pub path: &'a Path,
88+
pub error: io::Error,
8789
}

compiler/rustc_interface/src/passes.rs

+8-14
Original file line numberDiff line numberDiff line change
@@ -647,11 +647,8 @@ fn write_out_deps(
647647
.emit_artifact_notification(&deps_filename, "dep-info");
648648
}
649649
}
650-
Err(e) => {
651-
sess.emit_fatal(ErrorWritingDependencies {
652-
path: (&deps_filename.display()).into(),
653-
error: (&e).into(),
654-
});
650+
Err(error) => {
651+
sess.emit_fatal(ErrorWritingDependencies { path: &deps_filename, error });
655652
}
656653
}
657654
}
@@ -682,15 +679,12 @@ pub fn prepare_outputs(
682679
if let Some(ref input_path) = compiler.input_path {
683680
if sess.opts.will_create_output_file() {
684681
if output_contains_path(&output_paths, input_path) {
685-
let reported = sess
686-
.emit_err(InputFileWouldBeOverWritten { path: (&input_path.display()).into() });
682+
let reported = sess.emit_err(InputFileWouldBeOverWritten { path: input_path });
687683
return Err(reported);
688684
}
689-
if let Some(dir_path) = output_conflicts_with_dir(&output_paths) {
690-
let reported = sess.emit_err(GeneratedFileConflictsWithDirectory {
691-
input_path: (&input_path.display()).into(),
692-
dir_path: (&dir_path.display()).into(),
693-
});
685+
if let Some(ref dir_path) = output_conflicts_with_dir(&output_paths) {
686+
let reported =
687+
sess.emit_err(GeneratedFileConflictsWithDirectory { input_path, dir_path });
694688
return Err(reported);
695689
}
696690
}
@@ -994,8 +988,8 @@ pub fn start_codegen<'tcx>(
994988
info!("Post-codegen\n{:?}", tcx.debug_stats());
995989

996990
if tcx.sess.opts.output_types.contains_key(&OutputType::Mir) {
997-
if let Err(e) = rustc_mir_transform::dump_mir::emit_mir(tcx, outputs) {
998-
tcx.sess.emit_err(CantEmitMIR { error: (&e).into() });
991+
if let Err(error) = rustc_mir_transform::dump_mir::emit_mir(tcx, outputs) {
992+
tcx.sess.emit_err(CantEmitMIR { error });
999993
tcx.sess.abort_if_errors();
1000994
}
1001995
}

compiler/rustc_interface/src/queries.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -357,12 +357,8 @@ impl Linker {
357357
if sess.opts.unstable_opts.no_link {
358358
let encoded = CodegenResults::serialize_rlink(&codegen_results);
359359
let rlink_file = self.prepare_outputs.with_extension(config::RLINK_EXT);
360-
std::fs::write(&rlink_file, encoded).map_err(|err| {
361-
sess.emit_fatal(FailedWritingFile {
362-
path: (&rlink_file.display()).into(),
363-
error: (&err).into(),
364-
})
365-
})?;
360+
std::fs::write(&rlink_file, encoded)
361+
.map_err(|error| sess.emit_fatal(FailedWritingFile { path: &rlink_file, error }))?;
366362
return Ok(());
367363
}
368364

0 commit comments

Comments
 (0)