diff options
| author | Jhonny Bill Mena <jhonnybillm@gmail.com> | 2022-08-28 19:58:12 -0400 |
|---|---|---|
| committer | Jhonny Bill Mena <jhonnybillm@gmail.com> | 2022-10-07 10:03:45 -0400 |
| commit | d9197dbbcd35c69a210806cea18d2ce0f3691839 (patch) | |
| tree | ba20ce1f96be14911225766d51cac46430d014f1 /compiler/rustc_codegen_ssa/src | |
| parent | 086e70f13e9259d7949fbfeec6fa824c6327f42d (diff) | |
| download | rust-d9197dbbcd35c69a210806cea18d2ce0f3691839.tar.gz rust-d9197dbbcd35c69a210806cea18d2ce0f3691839.zip | |
UPDATE - migrate write.rs to new diagnostics infra
Diffstat (limited to 'compiler/rustc_codegen_ssa/src')
| -rw-r--r-- | compiler/rustc_codegen_ssa/src/back/write.rs | 41 | ||||
| -rw-r--r-- | compiler/rustc_codegen_ssa/src/errors.rs | 48 |
2 files changed, 67 insertions, 22 deletions
diff --git a/compiler/rustc_codegen_ssa/src/back/write.rs b/compiler/rustc_codegen_ssa/src/back/write.rs index 6188094bbbd..125b231b274 100644 --- a/compiler/rustc_codegen_ssa/src/back/write.rs +++ b/compiler/rustc_codegen_ssa/src/back/write.rs @@ -2,11 +2,11 @@ use super::link::{self, ensure_removed}; use super::lto::{self, SerializedModule}; use super::symbol_export::symbol_name_for_instance_in_crate; +use crate::errors; +use crate::traits::*; use crate::{ CachedModuleCodegen, CodegenResults, CompiledModule, CrateInfo, ModuleCodegen, ModuleKind, }; - -use crate::traits::*; use jobserver::{Acquired, Client}; use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::memmap::Mmap; @@ -530,7 +530,7 @@ fn produce_final_output_artifacts( // Produce final compile outputs. let copy_gracefully = |from: &Path, to: &Path| { if let Err(e) = fs::copy(from, to) { - sess.err(&format!("could not copy {:?} to {:?}: {}", from, to, e)); + sess.emit_err(errors::CopyPath::new(from, to, e)); } }; @@ -546,7 +546,7 @@ fn produce_final_output_artifacts( ensure_removed(sess.diagnostic(), &path); } } else { - let ext = crate_output + let extension = crate_output .temp_path(output_type, None) .extension() .unwrap() @@ -557,19 +557,11 @@ fn produce_final_output_artifacts( if crate_output.outputs.contains_key(&output_type) { // 2) Multiple codegen units, with `--emit foo=some_name`. We have // no good solution for this case, so warn the user. - sess.warn(&format!( - "ignoring emit path because multiple .{} files \ - were produced", - ext - )); + sess.emit_warning(errors::IgnoringEmitPath { extension }); } else if crate_output.single_output_file.is_some() { // 3) Multiple codegen units, with `-o some_name`. We have // no good solution for this case, so warn the user. - sess.warn(&format!( - "ignoring -o because multiple .{} files \ - were produced", - ext - )); + sess.emit_warning(errors::IgnoringOutput { extension }); } else { // 4) Multiple codegen units, but no explicit name. We // just leave the `foo.0.x` files in place. @@ -880,14 +872,19 @@ fn execute_copy_from_cache_work_item<B: ExtraBackendMethods>( ); match link_or_copy(&source_file, &output_path) { Ok(_) => Some(output_path), - Err(err) => { - let diag_handler = cgcx.create_diag_handler(); - diag_handler.err(&format!( - "unable to copy {} to {}: {}", - source_file.display(), - output_path.display(), - err - )); + Err(_) => { + // FIXME: + // Should we add Translations support in Handler, or should we pass a session here ? + // + // As Luis Cardoso mentioned here https://github.com/rust-lang/rust/pull/100753#discussion_r952975345, + // Translations support in Handler is tricky because SessionDiagnostic is not a trait, + // and we can't implement it in Handler because rustc_errors cannot depend on rustc_session. + // + // As for passing a session here, my understanding is that all these errors should be reported via + // the Shared Handler, which leads us to probably having to support Translations in another way. + + // let diag_handler = cgcx.create_diag_handler(); + // diag_handler.emit_err(errors::CopyPathBuf { source_file, output_path, error }); None } } diff --git a/compiler/rustc_codegen_ssa/src/errors.rs b/compiler/rustc_codegen_ssa/src/errors.rs index 05d89b32618..2ae5e659d2d 100644 --- a/compiler/rustc_codegen_ssa/src/errors.rs +++ b/compiler/rustc_codegen_ssa/src/errors.rs @@ -1,7 +1,10 @@ //! Errors emitted by codegen_ssa +use rustc_errors::{DiagnosticArgValue, IntoDiagnosticArg}; use rustc_macros::SessionDiagnostic; +use std::borrow::Cow; use std::io::Error; +use std::path::{Path, PathBuf}; #[derive(SessionDiagnostic)] #[diag(codegen_ssa::missing_native_static_library)] @@ -56,3 +59,48 @@ pub struct L4BenderExportingSymbolsUnimplemented; pub struct NoNatvisDirectory { pub error: Error, } + +#[derive(SessionDiagnostic)] +#[diag(codegen_ssa::copy_path_buf)] +pub struct CopyPathBuf { + pub source_file: PathBuf, + pub output_path: PathBuf, + pub error: Error, +} + +// Reports Paths using `Debug` implementation rather than Path's `Display` implementation. +#[derive(SessionDiagnostic)] +#[diag(codegen_ssa::copy_path)] +pub struct CopyPath<'a> { + from: DebugArgPath<'a>, + to: DebugArgPath<'a>, + error: Error, +} + +impl<'a> CopyPath<'a> { + pub fn new(from: &'a Path, to: &'a Path, error: Error) -> CopyPath<'a> { + CopyPath { from: DebugArgPath { path: from }, to: DebugArgPath { path: to }, error } + } +} + +struct DebugArgPath<'a> { + pub path: &'a Path, +} + +impl IntoDiagnosticArg for DebugArgPath<'_> { + fn into_diagnostic_arg(self) -> rustc_errors::DiagnosticArgValue<'static> { + DiagnosticArgValue::Str(Cow::Owned(format!("{:?}", self.path))) + } +} + +#[derive(SessionDiagnostic)] +#[diag(codegen_ssa::ignoring_emit_path)] +pub struct IgnoringEmitPath { + pub extension: String, +} + +#[derive(SessionDiagnostic)] +#[diag(codegen_ssa::ignoring_output)] +pub struct IgnoringOutput { + pub extension: String, +} |
