about summary refs log tree commit diff
path: root/compiler/rustc_codegen_ssa
diff options
context:
space:
mode:
authorJhonny Bill Mena <jhonnybillm@gmail.com>2022-11-03 01:53:06 -0400
committerJhonny Bill Mena <jhonnybillm@gmail.com>2022-11-04 01:17:03 -0400
commit28491a7b36a717e42081fc6ee788433feccb72e6 (patch)
tree75d01765d038839d18bd740884daf9bb7d7d70a1 /compiler/rustc_codegen_ssa
parent2678765d08df633b4804d1ba03e090c3bed878bb (diff)
downloadrust-28491a7b36a717e42081fc6ee788433feccb72e6.tar.gz
rust-28491a7b36a717e42081fc6ee788433feccb72e6.zip
UPDATE - address PR Comments
FIX - StrippingDebugInfoFailed typo

DELETE - unneeded FIXME comment

UPDATE - only declare the error with ExtractBundledLibsError as an enum and use the Diagnostic derive macro
Diffstat (limited to 'compiler/rustc_codegen_ssa')
-rw-r--r--compiler/rustc_codegen_ssa/src/back/archive.rs56
-rw-r--r--compiler/rustc_codegen_ssa/src/back/link.rs3
-rw-r--r--compiler/rustc_codegen_ssa/src/errors.rs64
3 files changed, 40 insertions, 83 deletions
diff --git a/compiler/rustc_codegen_ssa/src/back/archive.rs b/compiler/rustc_codegen_ssa/src/back/archive.rs
index b45fa247687..9113ddab048 100644
--- a/compiler/rustc_codegen_ssa/src/back/archive.rs
+++ b/compiler/rustc_codegen_ssa/src/back/archive.rs
@@ -10,7 +10,7 @@ use std::fs::File;
 use std::io;
 use std::path::{Path, PathBuf};
 
-use crate::errors::{ExtractBundledLibsError, ExtractBundledLibsErrorKind::*};
+use crate::errors::ExtractBundledLibsError;
 
 pub trait ArchiveBuilderBuilder {
     fn new_archive_builder<'a>(&self, sess: &'a Session) -> Box<dyn ArchiveBuilder<'a> + 'a>;
@@ -35,48 +35,30 @@ pub trait ArchiveBuilderBuilder {
         outdir: &Path,
         bundled_lib_file_names: &FxHashSet<Symbol>,
     ) -> Result<(), ExtractBundledLibsError<'_>> {
-        let archive_map = unsafe {
-            Mmap::map(File::open(rlib).map_err(|e| ExtractBundledLibsError {
-                kind: OpenFile,
-                rlib,
-                error: e.to_string(),
-            })?)
-            .map_err(|e| ExtractBundledLibsError {
-                kind: MmapFile,
-                rlib,
-                error: e.to_string(),
-            })?
-        };
-        let archive = ArchiveFile::parse(&*archive_map).map_err(|e| ExtractBundledLibsError {
-            kind: ParseArchive,
-            rlib,
-            error: e.to_string(),
-        })?;
+        let archive_map =
+            unsafe {
+                Mmap::map(File::open(rlib).map_err(|e| ExtractBundledLibsError::OpenFile {
+                    rlib,
+                    error: e.to_string(),
+                })?)
+                .map_err(|e| ExtractBundledLibsError::MmapFile { rlib, error: e.to_string() })?
+            };
+        let archive = ArchiveFile::parse(&*archive_map)
+            .map_err(|e| ExtractBundledLibsError::ParseArchive { rlib, error: e.to_string() })?;
 
         for entry in archive.members() {
-            let entry = entry.map_err(|e| ExtractBundledLibsError {
-                kind: ReadEntry,
-                rlib,
-                error: e.to_string(),
-            })?;
-            let data = entry.data(&*archive_map).map_err(|e| ExtractBundledLibsError {
-                kind: ArchiveMember,
-                rlib,
-                error: e.to_string(),
-            })?;
-            let name = std::str::from_utf8(entry.name()).map_err(|e| ExtractBundledLibsError {
-                kind: ConvertName,
-                rlib,
-                error: e.to_string(),
+            let entry = entry
+                .map_err(|e| ExtractBundledLibsError::ReadEntry { rlib, error: e.to_string() })?;
+            let data = entry.data(&*archive_map).map_err(|e| {
+                ExtractBundledLibsError::ArchiveMember { rlib, error: e.to_string() }
             })?;
+            let name = std::str::from_utf8(entry.name())
+                .map_err(|e| ExtractBundledLibsError::ConvertName { rlib, error: e.to_string() })?;
             if !bundled_lib_file_names.contains(&Symbol::intern(name)) {
                 continue; // We need to extract only native libraries.
             }
-            std::fs::write(&outdir.join(&name), data).map_err(|e| ExtractBundledLibsError {
-                kind: WriteFile,
-                rlib,
-                error: e.to_string(),
-            })?;
+            std::fs::write(&outdir.join(&name), data)
+                .map_err(|e| ExtractBundledLibsError::WriteFile { rlib, error: e.to_string() })?;
         }
         Ok(())
     }
diff --git a/compiler/rustc_codegen_ssa/src/back/link.rs b/compiler/rustc_codegen_ssa/src/back/link.rs
index 1e6a2b6ecaa..6f0a8d0a54c 100644
--- a/compiler/rustc_codegen_ssa/src/back/link.rs
+++ b/compiler/rustc_codegen_ssa/src/back/link.rs
@@ -1063,7 +1063,7 @@ fn strip_symbols_with_external_utility<'a>(
             if !prog.status.success() {
                 let mut output = prog.stderr.clone();
                 output.extend_from_slice(&prog.stdout);
-                sess.emit_warning(errors::StrippingDebuInfoFailed {
+                sess.emit_warning(errors::StrippingDebugInfoFailed {
                     util,
                     status: prog.status,
                     output: escape_string(&output),
@@ -1077,7 +1077,6 @@ fn strip_symbols_with_external_utility<'a>(
 fn escape_string(s: &[u8]) -> String {
     match str::from_utf8(s) {
         Ok(s) => s.to_owned(),
-        // FIXME: return a type that can conform to IntoDiagnosticArg
         Err(_) => format!("Non-UTF-8 output: {}", s.escape_ascii()),
     }
 }
diff --git a/compiler/rustc_codegen_ssa/src/errors.rs b/compiler/rustc_codegen_ssa/src/errors.rs
index 35eae30c4ba..265f466f2ca 100644
--- a/compiler/rustc_codegen_ssa/src/errors.rs
+++ b/compiler/rustc_codegen_ssa/src/errors.rs
@@ -423,7 +423,7 @@ pub struct UnableToRunDsymutil {
 #[derive(Diagnostic)]
 #[diag(codegen_ssa_stripping_debu_info_failed)]
 #[note]
-pub struct StrippingDebuInfoFailed<'a> {
+pub struct StrippingDebugInfoFailed<'a> {
     pub util: &'a str,
     pub status: ExitStatus,
     pub output: String,
@@ -485,52 +485,28 @@ pub struct RlibArchiveBuildFailure {
 #[diag(codegen_ssa_option_gcc_only)]
 pub struct OptionGccOnly;
 
-pub struct ExtractBundledLibsError<'a> {
-    pub kind: ExtractBundledLibsErrorKind,
-    pub rlib: &'a Path,
-    pub error: String,
-}
+#[derive(Diagnostic)]
+pub enum ExtractBundledLibsError<'a> {
+    #[diag(codegen_ssa_extract_bundled_libs_open_file)]
+    OpenFile { rlib: &'a Path, error: String },
 
-pub enum ExtractBundledLibsErrorKind {
-    OpenFile,
-    MmapFile,
-    ParseArchive,
-    ReadEntry,
-    ArchiveMember,
-    ConvertName,
-    WriteFile,
-}
+    #[diag(codegen_ssa_extract_bundled_libs_mmap_file)]
+    MmapFile { rlib: &'a Path, error: String },
 
-impl IntoDiagnostic<'_, !> for ExtractBundledLibsError<'_> {
-    fn into_diagnostic(self, handler: &'_ Handler) -> DiagnosticBuilder<'_, !> {
-        let mut diag = match self.kind {
-            ExtractBundledLibsErrorKind::OpenFile => {
-                handler.struct_fatal(fluent::codegen_ssa_extract_bundled_libs_open_file)
-            }
-            ExtractBundledLibsErrorKind::MmapFile => {
-                handler.struct_fatal(fluent::codegen_ssa_extract_bundled_libs_mmap_file)
-            }
-            ExtractBundledLibsErrorKind::ParseArchive => {
-                handler.struct_fatal(fluent::codegen_ssa_extract_bundled_libs_parse_archive)
-            }
-            ExtractBundledLibsErrorKind::ReadEntry => {
-                handler.struct_fatal(fluent::codegen_ssa_extract_bundled_libs_read_entry)
-            }
-            ExtractBundledLibsErrorKind::ArchiveMember => {
-                handler.struct_fatal(fluent::codegen_ssa_extract_bundled_libs_archive_member)
-            }
-            ExtractBundledLibsErrorKind::ConvertName => {
-                handler.struct_fatal(fluent::codegen_ssa_extract_bundled_libs_convert_name)
-            }
-            ExtractBundledLibsErrorKind::WriteFile => {
-                handler.struct_fatal(fluent::codegen_ssa_extract_bundled_libs_write_file)
-            }
-        };
+    #[diag(codegen_ssa_extract_bundled_libs_parse_archive)]
+    ParseArchive { rlib: &'a Path, error: String },
 
-        diag.set_arg("rlib", self.rlib);
-        diag.set_arg("error", self.error);
-        diag
-    }
+    #[diag(codegen_ssa_extract_bundled_libs_read_entry)]
+    ReadEntry { rlib: &'a Path, error: String },
+
+    #[diag(codegen_ssa_extract_bundled_libs_archive_member)]
+    ArchiveMember { rlib: &'a Path, error: String },
+
+    #[diag(codegen_ssa_extract_bundled_libs_convert_name)]
+    ConvertName { rlib: &'a Path, error: String },
+
+    #[diag(codegen_ssa_extract_bundled_libs_write_file)]
+    WriteFile { rlib: &'a Path, error: String },
 }
 
 #[derive(Diagnostic)]