Skip to content

Commit 540c3f9

Browse files
committed
UPDATE - accept dyn error and make Box<dyn error> conform to IntoDiagnosticArg
1 parent 28491a7 commit 540c3f9

File tree

3 files changed

+22
-22
lines changed

3 files changed

+22
-22
lines changed

compiler/rustc_codegen_ssa/src/back/archive.rs

+14-15
Original file line numberDiff line numberDiff line change
@@ -35,30 +35,29 @@ pub trait ArchiveBuilderBuilder {
3535
outdir: &Path,
3636
bundled_lib_file_names: &FxHashSet<Symbol>,
3737
) -> Result<(), ExtractBundledLibsError<'_>> {
38-
let archive_map =
39-
unsafe {
40-
Mmap::map(File::open(rlib).map_err(|e| ExtractBundledLibsError::OpenFile {
41-
rlib,
42-
error: e.to_string(),
43-
})?)
44-
.map_err(|e| ExtractBundledLibsError::MmapFile { rlib, error: e.to_string() })?
45-
};
38+
let archive_map = unsafe {
39+
Mmap::map(
40+
File::open(rlib)
41+
.map_err(|e| ExtractBundledLibsError::OpenFile { rlib, error: Box::new(e) })?,
42+
)
43+
.map_err(|e| ExtractBundledLibsError::MmapFile { rlib, error: Box::new(e) })?
44+
};
4645
let archive = ArchiveFile::parse(&*archive_map)
47-
.map_err(|e| ExtractBundledLibsError::ParseArchive { rlib, error: e.to_string() })?;
46+
.map_err(|e| ExtractBundledLibsError::ParseArchive { rlib, error: Box::new(e) })?;
4847

4948
for entry in archive.members() {
5049
let entry = entry
51-
.map_err(|e| ExtractBundledLibsError::ReadEntry { rlib, error: e.to_string() })?;
52-
let data = entry.data(&*archive_map).map_err(|e| {
53-
ExtractBundledLibsError::ArchiveMember { rlib, error: e.to_string() }
54-
})?;
50+
.map_err(|e| ExtractBundledLibsError::ReadEntry { rlib, error: Box::new(e) })?;
51+
let data = entry
52+
.data(&*archive_map)
53+
.map_err(|e| ExtractBundledLibsError::ArchiveMember { rlib, error: Box::new(e) })?;
5554
let name = std::str::from_utf8(entry.name())
56-
.map_err(|e| ExtractBundledLibsError::ConvertName { rlib, error: e.to_string() })?;
55+
.map_err(|e| ExtractBundledLibsError::ConvertName { rlib, error: Box::new(e) })?;
5756
if !bundled_lib_file_names.contains(&Symbol::intern(name)) {
5857
continue; // We need to extract only native libraries.
5958
}
6059
std::fs::write(&outdir.join(&name), data)
61-
.map_err(|e| ExtractBundledLibsError::WriteFile { rlib, error: e.to_string() })?;
60+
.map_err(|e| ExtractBundledLibsError::WriteFile { rlib, error: Box::new(e) })?;
6261
}
6362
Ok(())
6463
}

compiler/rustc_codegen_ssa/src/errors.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -488,25 +488,25 @@ pub struct OptionGccOnly;
488488
#[derive(Diagnostic)]
489489
pub enum ExtractBundledLibsError<'a> {
490490
#[diag(codegen_ssa_extract_bundled_libs_open_file)]
491-
OpenFile { rlib: &'a Path, error: String },
491+
OpenFile { rlib: &'a Path, error: Box<dyn std::error::Error> },
492492

493493
#[diag(codegen_ssa_extract_bundled_libs_mmap_file)]
494-
MmapFile { rlib: &'a Path, error: String },
494+
MmapFile { rlib: &'a Path, error: Box<dyn std::error::Error> },
495495

496496
#[diag(codegen_ssa_extract_bundled_libs_parse_archive)]
497-
ParseArchive { rlib: &'a Path, error: String },
497+
ParseArchive { rlib: &'a Path, error: Box<dyn std::error::Error> },
498498

499499
#[diag(codegen_ssa_extract_bundled_libs_read_entry)]
500-
ReadEntry { rlib: &'a Path, error: String },
500+
ReadEntry { rlib: &'a Path, error: Box<dyn std::error::Error> },
501501

502502
#[diag(codegen_ssa_extract_bundled_libs_archive_member)]
503-
ArchiveMember { rlib: &'a Path, error: String },
503+
ArchiveMember { rlib: &'a Path, error: Box<dyn std::error::Error> },
504504

505505
#[diag(codegen_ssa_extract_bundled_libs_convert_name)]
506-
ConvertName { rlib: &'a Path, error: String },
506+
ConvertName { rlib: &'a Path, error: Box<dyn std::error::Error> },
507507

508508
#[diag(codegen_ssa_extract_bundled_libs_write_file)]
509-
WriteFile { rlib: &'a Path, error: String },
509+
WriteFile { rlib: &'a Path, error: Box<dyn std::error::Error> },
510510
}
511511

512512
#[derive(Diagnostic)]

compiler/rustc_errors/src/diagnostic_impls.rs

+1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ into_diagnostic_arg_using_display!(
5959
i128,
6060
u128,
6161
std::io::Error,
62+
std::boxed::Box<dyn std::error::Error>,
6263
std::num::NonZeroU32,
6364
hir::Target,
6465
Edition,

0 commit comments

Comments
 (0)